2020-09-04 01:06 PM
Hi all,
I am using Nucleo-L552 Evaluation board running , CMSIS_RTOSV2 (FreeRTOS), firmware STM32Cube FW_L5 V1.3.0. Debugging via built-in ST-Link. I have a Hard fault on HAL_GetTick() when running UART transmit on one of the threads. It debugs fine with the threads toggle the LEDs, but running into hard fault when add code trying to send via uart. I wonder anyone ran into the same problem?
Solved! Go to Solution.
2020-09-06 09:10 AM
Thanks selcukozb, I suspect there is something to do with the timebase source. I reconfigured the timebase to use SysTick instead of TM6 as suggested by various youtub tutorials and it works.
Although, when using STM32 with freeRTOS the CubeMX gives you a warning:
when freeRTOS is used it is strongly recommended to use a HAL time base source other than the systick"
I think I will use SysTick as timebase for now.
Thanks again selcukozb.
2020-09-04 02:17 PM
It could be a lot of things. Can you post relevant sections of the code?
Look out for buffer/stack overflows.
2020-09-04 10:03 PM
I would check to make it sure IT Priority of UART is lower than Systick.
BR
2020-09-06 04:00 AM
Thank you very much for your responses.
Before including FreeRTOS I ran the serial Comm in the main's while loop and it worked. The send is simple as shown below. Notice that I used virtual Commport to send:
/* Private user code --------------------------------------------*/
/* USER CODE BEGIN 0 */
void sendUart(void)
{
char *data = "Hello Task Default\r\n";
HAL_UART_Transmit(&hlpuart1, (uint8_t*)data, strlen(data), 10);
}
/* USER CODE END 0 */
and
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);
sendUart();
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
Then I added FreeRTOS middleware and picked TM6 as timebase Source. use default task to send.
Then the code to send now changed to:
//--------------------Task1------------------------------
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);
sendUart();
osDelay(500);
}
/* USER CODE END 5 */
}
I then run debug but it keeps failing on
I don't see where I can change or check for the IT priority of the UART. I would appreciate if you show me.
Thanks again
2020-09-06 08:16 AM
Hi TDinh,
I couldn't check the data you've given completely. But shortly answer where to find and change IRQ priorities.
Within your code you can learn the priority level of a specific IRQ, you can use :
HAL_NVIC_GetPriority(IRQn, PriorityGroup, pPreemptPriority, pSubPriority);
And setting its priority amy required value :
HAL_NVIC_SetPriority(IRQn, PriorityGroup, pPreemptPriority, pSubPriority);
You can also set priority level during project configuration within cubeMX, under System/NVIC settings window. See thee attached screen shot. As you can see I set Time3 and UART2 interrupts a lower level compared to sysTick.
Hope this will help.
Kind Regards,
2020-09-06 08:29 AM
Hi TDinh, I looked into your code and noticed that you don't use UART with Interrupts. So, my comments in the previous posts are invalid. There should be something else, which I can not suggest anything without debugging with SWV. I advise you to do so.
Sorry, I could not help.
BR
2020-09-06 09:10 AM
Thanks selcukozb, I suspect there is something to do with the timebase source. I reconfigured the timebase to use SysTick instead of TM6 as suggested by various youtub tutorials and it works.
Although, when using STM32 with freeRTOS the CubeMX gives you a warning:
when freeRTOS is used it is strongly recommended to use a HAL time base source other than the systick"
I think I will use SysTick as timebase for now.
Thanks again selcukozb.
2023-02-19 03:38 AM
Man, you saved me!!!!