Skip to content

Commit

Permalink
tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
celery6 committed Sep 30, 2024
1 parent 3869951 commit 03102ff
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 165 deletions.
72 changes: 12 additions & 60 deletions STM32Cube/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "otits.h"
#include "sdmmc.h"
#include "vn_handler.h"
#include "blinky.h"
#include "fast_blinky.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -97,6 +99,8 @@ TaskHandle_t healthChecksTaskHandle = NULL;
TaskHandle_t controllerHandle = NULL;
TaskHandle_t flightPhaseHandle = NULL;
TaskHandle_t oTITSHandle = NULL;
TaskHandle_t blinkyTaskHandle = NULL;
TaskHandle_t fastBlinkyTaskHandle = NULL;

/* USER CODE END PV */

Expand All @@ -123,55 +127,6 @@ void StartDefaultTask(void *argument);

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
Otits_Result_t test_defaultTaskPass() {
Otits_Result_t res;
res.info = "this should pass";
res.outcome = TEST_OUTCOME_PASSED;
return res;
}

Otits_Result_t test_defaultTaskFail() {
Otits_Result_t res;
res.info = "this should fail";
res.outcome = TEST_OUTCOME_FAILED;
return res;
}

Otits_Result_t test_taskStackUsage() {
Otits_Result_t res;
const int numTasks = 9;
int stackWatermarks[numTasks];

stackWatermarks[0] = uxTaskGetStackHighWaterMark(logTaskhandle);
stackWatermarks[1] = uxTaskGetStackHighWaterMark(VNTaskHandle);
stackWatermarks[2] = uxTaskGetStackHighWaterMark(trajectoryTaskHandle);
stackWatermarks[3] = uxTaskGetStackHighWaterMark(stateEstTaskHandle);
stackWatermarks[4] = uxTaskGetStackHighWaterMark(canhandlerhandle);
stackWatermarks[5] = uxTaskGetStackHighWaterMark(healthChecksTaskHandle);
stackWatermarks[6] = uxTaskGetStackHighWaterMark(controllerHandle);
stackWatermarks[7] = uxTaskGetStackHighWaterMark(flightPhaseHandle);
stackWatermarks[8] = uxTaskGetStackHighWaterMark(oTITSHandle);

for (int i = 0; i < numTasks; i++) {
if (stackWatermarks[i] < 50) {
char info[10];
snprintf_(info, 10, "low%d", i);
res.info = info;
res.outcome = TEST_OUTCOME_FAILED;
return res;
} else if (stackWatermarks[i] > 1000) {
char info[10];
snprintf_(info, 10, "high%d", i);
res.info = info;
res.outcome = TEST_OUTCOME_FAILED;
return res;
}
}

res.info = "";
res.outcome = TEST_OUTCOME_PASSED;
return res;
}
/* USER CODE END 0 */

/**
Expand Down Expand Up @@ -253,11 +208,6 @@ int main(void)
initRes &= state_est_init();
initRes &= vn_handler_init();

// otits is ifdef guarded within itself so can leave these
initRes &= otitsRegister(test_defaultTaskPass, TEST_SOURCE_DEFAULT, "DefaultPass");
initRes &= otitsRegister(test_defaultTaskFail, TEST_SOURCE_DEFAULT, "DefaultFail");
initRes &= otitsRegister(test_taskStackUsage, TEST_SOURCE_DEFAULT, "StackUsage");

if (!initRes) {
Error_Handler();
}
Expand All @@ -271,19 +221,21 @@ int main(void)
/* add threads, ... */
BaseType_t xReturned = pdPASS;

//dunno if casting from CMSIS priorities is valid
xReturned &= xTaskCreate(vnIMUHandler, "VN Task", 1024, NULL, (UBaseType_t) osPriorityNormal, &VNTaskHandle);
// Create a FreeRTOS task for blinky
xReturned &= xTaskCreate(blinkyTask, "blinky task", 512, NULL, (UBaseType_t) osPriorityNormal, &blinkyTaskHandle);
// Create a FreeRTOS task for faster blinky
// xReturned &= xTaskCreate(fastBlinkyTask, "fast blinky task", 512, NULL, (UBaseType_t) osPriorityNormal, &fastBlinkyTaskHandle);

// For this tutorial we can ignore the other tasks processor usually runs
/*xReturned &= xTaskCreate(vnIMUHandler, "VN Task", 1024, NULL, (UBaseType_t) osPriorityNormal, &VNTaskHandle);
xReturned &= xTaskCreate(canHandlerTask, "CAN handler", 512, NULL, (UBaseType_t) osPriorityNormal, &canhandlerhandle);
xReturned &= xTaskCreate(stateEstTask, "StateEst", 1024, NULL, (UBaseType_t) osPriorityNormal, &stateEstTaskHandle);
xReturned &= xTaskCreate(trajectory_task, "traj", 512, NULL, (UBaseType_t) osPriorityNormal, &trajectoryTaskHandle);
xReturned &= xTaskCreate(logTask, "Logging", 1024, NULL, (UBaseType_t) osPriorityNormal, &logTaskhandle);
xReturned &= xTaskCreate(healthCheckTask, "health checks", 512, NULL, (UBaseType_t) osPriorityNormal, &healthChecksTaskHandle);
xReturned &= xTaskCreate(controlTask, "Controller", 512, NULL, (UBaseType_t) osPriorityNormal, &controllerHandle);
xReturned &= xTaskCreate(flightPhaseTask, "Flight Phase", 512, NULL, (UBaseType_t) osPriorityNormal, &flightPhaseHandle);
#if defined(TEST_MODE) && defined(DEBUG)
xReturned &= xTaskCreate(otitsTask, "oTITS", 1024, NULL, (UBaseType_t) osPriorityNormal, &oTITSHandle);
#endif

*/
if(xReturned != pdPASS)
{
//one or more tasks failed to be created
Expand Down
33 changes: 33 additions & 0 deletions STM32Cube/Tasks/blinky.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* blinky.c
* Demo task
*
*/


#include "FreeRTOS.h"
#include "stm32h7xx_hal.h"
#include "task.h"

#include "printf.h"

// FreeRTOS task functions always have the function signature `void taskname(void *argument)`
void blinkyTask(void *argument) {
// This loop repeats for infinity and must never exit! (tasks never end)
for (;;) {
// Write 0 to the LED pin (turn it off)
// HAL functions are provided by STM32 to easily interact with hardware
// LEDs are wired to the STM32's GPIO pins - this one specifically is wired to GPIO_B pin 5
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0);

// FreeRTOS function that puts this task on pause for 500 ticks (0.5 sec)
// Other tasks will run while this task is paused
vTaskDelay(500);

// Write 1 to the LED pin (turn it on)
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1);

// Pause task for 500 ticks (0.5 sec)
vTaskDelay(500);
}
}
11 changes: 11 additions & 0 deletions STM32Cube/Tasks/blinky.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* blinky.h
*
*/

#ifndef BLINKY_H_
#define BLINKY_H_

void blinkyTask(void *argument);

#endif /* BLINKY_H_ */
19 changes: 19 additions & 0 deletions STM32Cube/Tasks/fast_blinky.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* fast_blinky.c
* Demo task
*
*/


#include "FreeRTOS.h"
#include "stm32h7xx_hal.h"
#include "task.h"

#include "printf.h"


void fastBlinkyTask(void *argument) {
for (;;) {
// TODO: blink the green LED FAST!
}
}
11 changes: 11 additions & 0 deletions STM32Cube/Tasks/fast_blinky.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* fast_blinky.h
*
*/

#ifndef FAST_BLINKY_H_
#define FAST_BLINKY_H_

void fastBlinkyTask(void *argument);

#endif /* FAST_BLINKY_H_ */
Loading

0 comments on commit 03102ff

Please sign in to comment.