Hard fault when implementing RTOS in driver with Interrupts
Hi.
Let me preface by saying, that this is the first time I try using RTOS on any device.
I am using a custom board with a STM32f410R8T6 MCU, where it retrieves some sensorvalues through SPI, and transmits data to another MCU, also through SPI.
Currently I have setup up the driver with bare metal programming, using some nested interrupts, to properly prioritize the flow of the driver. I have been strongly advised to use multithreading instead, as this should make my life alot easier. I've tried implementing it, following a simple guide: https://www.youtube.com/watch?v=OPrcpbKNSjU.
However, I get a hard fault when I hit the function osKernelStart(); in the main loop. When I use 'Step into' when debugging, I see that it happens, when vTaskScheduler is called from cmsis_os2.c (l.262).
I use STM32CubeIDE, and setup the RTOS as mentioned in the guide (by pretty much just enabling it and doing nothing more).
I have attached pictures of the settings below aswell:
Then I go to sys, select my form of debugging (5 pin SWD) and chose another timebase source (TIM9).
When I generate code, the IDE shows errormessages regarding my current interrupts, as these have preemption levels under 5. They should be within 5-15 due to the RTOS, but these can't be changed from the GUI.
So I navigate my way into the automatically generated code, and set the priorities myself.
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 1);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);I get my automatically generated default task function with a for-loop, where I try to turn on an LED, but I never get there, as a hard fault occurs 2 seconds after I start debugging.
Default task can be seen here:
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
HAL_GPIO_WritePin(LED_3_GPIO_Port, LED_3_Pin, GPIO_PIN_SET);
osDelay(1);
}
/* USER CODE END 5 */
}When i start debugging, and send pulses which gives the program an external interrupt, I am able to do so, and have the MCU toggle another LED for 2 seconds, before the hardfault occurs. This is because the interrupt occurs multiple times before the osKernelStart(); function is reached, and the hard fault occurs.
I want to use something like theTaskNotificationFromISR() function, to initialize my different tasks from interrupts, but I'm at a loss with this hard fault.
I am using an ST-Link v2 and running STM32CubeIDE at v1.5.0
Best regards Victor
