cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX 4.3.1 - FreeRTOS SysTick and HardFault

George.P
Associate III
Posted on September 29, 2014 at 11:38

Hello,

I am using the STM32F3 Discovery Board to try out CubeMX for IAR and FreeRTOS.

I have encountered the following situation, where the system hangs:

SysTick_Handler

 is never reached. The system hangs in the 

HardFault_Handler

.

I have replaced the code in 

SysTick_Handler

 as mentioned in the fora by ST employees to:

if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)

 

  {

 

    xPortSysTickHandler();

 

  }

 

  HAL_IncTick();

 

but this is irrelevant, since the device branches to the 

HardFault_Handler 

before ever reaching the 

SysTick_Handler.

The solution I have found to this, is to comment out the 

osDelay(1)

 line in 

StartThread

 thread, or completely avoid using this thread.

I have tested this with a single other thread, written by me and it works well.

I will reply to this post, after testing with more threads.

I do not know the true cause to this mishap, but I'd like to see this fixed since it's something that is given as a starting point for Discovery and Development Kits.

Regards,

George

#freertos #cubemx
6 REPLIES 6
George.P
Associate III
Posted on September 29, 2014 at 13:25

Also tested this with 2 threads with thread messaging and delays.

All seem to work just fine.

It seems that for some reason, the Cube generated thread caused problems.

serge
Associate II
Posted on September 30, 2014 at 22:12

Hi,

have similar problem with F2 on custom board.

Project generated by F2CubeMX for Keil MDK, only FreeRTOS included (and oscillator pins enabled), all RTOS setting on default values, no user code, and it does not work.

On very first Systick called chain xPortSysTickHandler() - xTaskIncrementTick() and system is getting in Hard Fault.

As I figured out on very first Systick pointer pxCurrentTCB is still not enabled (==NULL), and when it is used in xTaskIncrementTick() it causes HardFault error.

That happened when FreeRTOS configured with both ''configUSE_PREEMPTION'' and ''configUSE_TIME_SLICING'' enabled.

I added check for NULL before pxCurrentTCB  accessed, and now it works

        #if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) )

        {  if (pxCurrentTCB != NULL)   { ......

Would be interesting to hear from ST, is it some kind of bug of CubeMX, or I am missing something in FreeRTOS configuration?

Thanks guys

PS. CubeMX is great product!! even with such features

George.P
Associate III
Posted on October 01, 2014 at 08:30

Hello,

To be honest I am about to abandon FreeRTOS generated projects from CubeMX.

I have tried to add more threads with messaging queues, but the code branches always to hard faults. 

I traced execution, and right now it hard faults before entering the scheduler, while running

MX_GPIO_Init()

.

This is before running any User or RTOS code, so I can't figure out what's going on.

Edit: Also changing compiler optimization produces hard faults in different places, before starting the scheduler.

stm32cube-t
Senior III
Posted on October 08, 2014 at 13:57

Hello,

There is an issue with the generated code that will be fixed in CubeMX 4.4.

Modify the stm32f3xx_it.c generated file as follows:

First add:

#include ''cmsis_os.h''

Second - add an if condition to call xPortSysTickHandler only once the scheduler has started:

void SysTick_Handler(void)

{

// Add this If condition (missing from MX 4_3_1 and earlier versions

if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)

{

xPortSysTickHandler();

}

HAL_IncTick();

}

Please find attached a simple example.

Other recommendations are:

When using FreeRTOS functions from ISR the priority of interrupt should be lower (higher numerical value) than configMAX_SYSCALL_INTERRUPT_PRIORITY.

Check heap and stack size (freeRTOS parameters in MX config tab), as well as your project heap/stack size (adjust within your IDE) Best Regards

________________

Attachments :

simple_F3Disco_CubeMX_FreeRTOS_project.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzXM&d=%2Fa%2F0X0000000bNE%2FhaHmGAub7pvqLxGTAEuZfBbOXfkBslNG9opyyywXPy0&asPdf=false
Davydenko.Sergey
Associate II
Posted on October 22, 2014 at 19:00

Hi, George.

I think that faced with a similar problem ... 

All the matter in �?¡ubeMX. I use in conjunction with IAR 6.70.

When re-generation project Cube does not include in the project file 

startup_stm32f373xc.s 

This does not always happen. Remarked casually.

The project is compiled, but after the start in different places jumping to Hard Fault.

Try to Generate project several times and open in you IDE.

Maybe the problem is solved in 4.40, have not tried it.

Nickname3515_O
Associate
Posted on November 06, 2014 at 10:17

Solved through CubeMX 4.4.0