-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with HAL_getTick() after first call to _sbrk_r #13
Comments
I never call printf before starting the OS, as I use OS resources to handle redirected output, and IIRC any storage used in newlib reentrancy structures will be wasted once OS starts. |
Thank you for your answer ! After further investigation I found the source of the bug. The problem come from the calls to vTaskSuspendAll() and xTaskResumeAll() defined in DRN_ENTER_CRITICAL_SECTION and DRN_EXIT_CRITICAL_SECTION in heap_useNewLib_ST.c. This function will enter a critical section in port.c which will increment the variable uxCriticalNesting. When the critical section is exited this variable is decremented and only if uxCriticalNesting equals 0 are the interrupts reactivated. Since the function is called before the kernel is started the variable uxCriticalNesting is not set to 0 so the interrupts will no be reactivated before the start of the kernel. I tried to solved the bug by adding a condition to the call to vTaskSuspendAll() and xTaskResumeAll() : I finally decided to put all my initializations before the infinite loop of my tasks and to add a barrier mutex before entering the loops. |
I am currently using FreeRTOS with CMSIS-RTOS v2 interface directly in STM32CubeIDE 1.12.1 with my nucleo-F103RB. I am new to the thing and after getting systematic hardfault I found your article . After following all the steps it solve my problems ! I also added
#define configISR_STACK_SIZE_WORDS (0x500)
at the begining since it wasn't previously declared, as suggested in a previous issue.Although adding the heap_useNewLib_ST.c file solved my problems I noticed that, before I start the os kernel, the HAL_getTick() and HAL_delay() functions were no longer working. After some investigation, it seems that after the first call to _sbrk_r, the TIM1 interrupt that I use as a Timebase source is no longer triggered.
example of code that provoque the failure :
`HAL_Init(); // first line in main()
HAL_delay( 1000 ); // working
printf( "test" ); // will call _sbrk_r
HAL_delay( 1000); // stay stuck`
My guess would be that the NVIC is overwritten in _sbrk_r, but I'm not quite sure... Could it be possible that my problem come from my
#define configISR_STACK_SIZE_WORDS (0x500)
?If further information is required, I will be happy to provide it to you.
The text was updated successfully, but these errors were encountered: