cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for solution to hard fault when using UART to transmit. Particularly, when it calls HAL_GetTick() in Uart function

TDinh.1
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TDinh.1
Associate II

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.

View solution in original post

7 REPLIES 7
DWann
Associate III

It could be a lot of things. Can you post relevant sections of the code?

Look out for buffer/stack overflows.

selcukozb
Associate III

I would check to make it sure IT Priority of UART is lower than Systick.

BR

TDinh.1
Associate II

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

0693W000003QrCJQA0.png

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

selcukozb
Associate III

0693W000003QrMdQAK.pngHi 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,

selcukozb
Associate III

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

TDinh.1
Associate II

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.

Man, you saved me!!!!