2

I'm trying to start FreeRTOS in exisiting STM32 firmware project. I copied all files, corrected interrupts priority to th elowest. However, processor got stuck in xTaskIncrementTick for loop, it can't go out of that loop. In the same time, all other timers interrupt stopped working.

I'm using HAL library. HAL timer uses TIM1 instead of SysTick, so it can be used by FreeRTOS.

VIPPER
  • 326
  • 4
  • 24

4 Answers4

2

I can't see a loop in xTaskIncrementTick() - see line 2589 on this link: https://sourceforge.net/p/freertos/code/HEAD/tree/tags/V10.0.1/FreeRTOS/Source/tasks.c Which line are you stuck in?

Why is it necessary to use TIM1 instead of the default SysTick? That would be very unusual unless you were wanting an ultra low power application, in which case you might select to use a low power clock - but I don't think TIM1 is low power.

I think the STM32Cube software also uses SysTick. The normal way of handling a third party library also wanting to use SysTick in addition to the RTOS is to have FreeRTOS manage the tick interrupt, and use the FreeRTOS tick hook (https://www.freertos.org/a00016.html) to call the library's tick handler. Although I think the STM32Cube software does it the other way around - it installs its own tick handler and calls the FreeRTOS tick interrupt from that.

Richard
  • 3,081
  • 11
  • 9
  • Look at line 2624. My firmware can't go out of that loop. – VIPPER Feb 05 '18 at 22:10
  • Actually, STM32Cube uses additional timer for HAL if you choose to use FreeRTOS - then SysTick is only used by FreeRTOS. This is ST's recommendation. Personally, I think this is wasting resources. So, you mean adding HAL_IncTIck() to callback function? I can add it, but I'll be still in the loop I mentioned above. – VIPPER Feb 05 '18 at 22:12
  • Updated to code to your advice. Now HAL_IncTick() is called from vApplicationTickHook(). It works fine until I call anything related to RTOS, such as xTaskCreate. Than SysTick interrupt stops working and MCU ends in HardFault_Handler. – VIPPER Feb 06 '18 at 07:49
  • But in this case - do you actually have a problem with SysTick or with the fact that you get the HardFault exception? – J_S Feb 06 '18 at 13:22
  • It's hard to say. After adding vApplicationTickHook I have a problem with hard fault. – VIPPER Feb 06 '18 at 14:03
  • This is my stack after ending in Default_Handler: 1. SysTick Exception 2. xTaskCreate 3. xTimerCreateTimerTask 4. vTaskStartScheduler 5. main 6. Reset_Handler After proper setting priorities of interrupts to the lowest, MCU ends in HardFault with following stack: 1. HardFault 2. prvPortStartFirstStack 3. xPortStartScheduler 4. vTaskStartScheduler Found that assembler instruction SVC 0 causes MCU to run into Default_Handler. – VIPPER Feb 10 '18 at 12:41
1

In my experience, it is much faster to port existing code to a fresh FreeRTOS-based project than to install FreeRTOS inside an existing project. Is there a particular reason you have to do it this way ?

My own approach is to create a new project with CubeMX that includes FreeRTOS and is setup to support your existing code, then once I've generated the code for that new project, I'll paste my existing code into it as the default task. This usually gives me a stable starting point.

Jean Roch
  • 185
  • 14
1

At this day the best way to include FreeRTOS to your project is by using the included in de project configuration in Stm32CubeIDE, you can activate it in middleware section.

I higly recomend to wath the latest oficial stm32 videos about FreeRTOS Here's a link to all the videos in Lab format with a lot of interesting details.

0

You can download examples for the board you're using in the offical page of ST Microelectronics. Once you download you have different examples using the peripherals and also integrations with FreeRTOS and other resources. I'm using the STM32F746G Disco, the link for the STM32F7 devices is this:

STM32F7 examples