stm32duino / STM32FreeRTOS

Real Time Operating System implemented for STM32
302 stars 59 forks source link

How to use other timebase for HAL, cause the freeRTOS use the Systick? #50

Closed KiraVerSace closed 2 years ago

KiraVerSace commented 2 years ago

As we all know it, When using FreeRTOS, the CubeMX suggests not to use SysTick as timebase for the HAL. I believe this is because there is conflict between the HAL and RTOS use of the SysTick timer? I found a bug that when I use stm32g070 with STM32FreeRTOS, I use the delay(10) in my setup() function before the osKernalStart, and my program will always in the delay(10) and never jump out, the HAL_Tick never increase cause they use the same timebase?

How to make the HAL use other timebase as TIM1, TIM2 or other to avoid the conflict?

fpistm commented 2 years ago

Hi @KiraVerSace

This limitation is explained in the README.md: https://github.com/stm32duino/STM32FreeRTOS#limitations

On Cortex-M0 and Cortex-M0+, all IT are disabled between xTaskCreate() and vTaskStartScheduler(). So it is not possible to use IT inbetween, like Serial.print() ... This is the reason why, in example "frLiyLayland", between xTaskCreate() and vTaskStartScheduler(), we use direct printf(), which will access directly USART without interrupt

You are in this case so avoid to use delay at this stage.

/cc @ABOSTM if you have any comment on this.

KiraVerSace commented 2 years ago

Hi @KiraVerSace

This limitation is explained in the README.md: https://github.com/stm32duino/STM32FreeRTOS#limitations

On Cortex-M0 and Cortex-M0+, all IT are disabled between xTaskCreate() and vTaskStartScheduler(). So it is not possible to use IT inbetween, like Serial.print() ... This is the reason why, in example "frLiyLayland", between xTaskCreate() and vTaskStartScheduler(), we use direct printf(), which will access directly USART without interrupt

You are in this case so avoid to use delay at this stage.

/cc @ABOSTM if you have any comment on this.

Thank you for your help, you give me the result but do not give me the reason? I want to know the details, How can I understand the " between xTaskCreate() and vTaskStartScheduler()", I use it before xTaskCreate it would not work, but after the rtos start, it can work , I just use it for testing, In the fact, I use vTaskDelay?

Thank you!

KiraVerSace commented 2 years ago

Sorry ,May be my reply is not so kind cause I do not good at English, Thank you sincerely!

ABOSTM commented 2 years ago

Thank you for your help, you give me the result but do not give me the reason? I want to know the details,

This is the way FreeRTOS works: See FreeRTOS documentation https://www.freertos.org/FAQHelp.html

  1. Interrupts are not executing ... If a FreeRTOS API function is called before the scheduler has been started then interrupts will deliberately be left disabled, and not re-enable again until the first task starts to execute. This is done to protect the system from crashes caused by interrupts attempting to use FreeRTOS API functions during system initialisation, before the scheduler has been started, and while the scheduler may be in an inconsistent state. ...
KiraVerSace commented 2 years ago

OK, Thank you for your help,. Now I figure out the reason why the system will stop in the delay(), there are different results in the different chip [cortex-m4/cortex-mo]although they have the same program. I know the purpose why FreeRTOS do with it. But I think they are different ways to achieve it between the two chips, on cortex-m0 all the interrupts will disable until the scheduler is start, but no limitation on the cortex-m3. Am I right? HaHa!

ABOSTM commented 2 years ago

Yes, it work differently depending on cortex:

KiraVerSace commented 2 years ago

Thank you for your help, I am very happy!