Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Hard Fault with FreeRTOS+FatFS on STM32

Posted by Thomas Jespersen on December 8, 2012
Hi all.
I have never really been the RTOS guy but I have decided to give it a try now, especially because of the need of a proper IP stack with Socket integration.
So I decided to get the FreeRTOS example with the lwIP stack provided by ST running on my STM32-E407 from Olimex, that contains an STM32F4ZGT6.
After successfully adding the FatFS library I was able to both get Ethernet and SD card working great.

But then I started making my LCD library and got that working, but when I tried my BMP writing routine, which repeatedly fetches 512 bytes (fills a buffer) from a file the application reads and displays two full buffers but then goes into a Hard Fault.

I have tried getting most information out of this Hard Fault exception as possible which can be seen below:
[Hard fault handler - all numbers in hex]
R0 = 20001158
R1 = 1eaf00b4
R2 = 80031a5
R3 = 80031a5
R12 = 20000cac
LR [R14] = a5a5a5a5 subroutine call return address
PC [R15] = fffffffd program counter
PSR = 80078c2
BFAR = 1eaf00b4
CFSR = 8200
HFSR = 40000000
DFSR = 1
AFSR = 0
SCB_SHCSR = 400


I am using the pvPortMalloc(512) to get a pointer to the required 512 bytes buffer, but that didn't fix the problem.

You can download the CoIDE project (IDE for GCC compiler) and have a look for yourself: http://www.tkjelectronics.dk/uploads/TheBlastFootball_FreeRTOS_HardFault.zip
I really hope that someone can bring me some suggestions.

Best Regards
Thomas Jespersen

RE: Hard Fault with FreeRTOS+FatFS on STM32

Posted by Dave on December 8, 2012
The registers in your post are strange. The PC looks how I would expect LR to look in an interrupt, and LR looks like it has been loaded from a stack byte that has never been written to since the stack was created.

Do you have stack overflow protection on?

RE: Hard Fault with FreeRTOS+FatFS on STM32

Posted by Thomas Jespersen on December 8, 2012
I don't know about the Hard Fault register output either, as I agree with you that the PC looks very odd!
No, I haven't enabled stack overflow due to the missing function to make it work -> " undefined reference to `vApplicationStackOverflowHook' "

RE: Hard Fault with FreeRTOS+FatFS on STM32

Posted by Thomas Jespersen on December 8, 2012
I mean, I haven't implemented this monitoring function to warn and require a restart.

RE: Hard Fault with FreeRTOS+FatFS on STM32

Posted by Thomas Jespersen on December 8, 2012
Thanks a lot - giving that hint to me made me find the reason for the problem! :-)

When creating the thread which executes the BMP LCD write function I didn't make the stack for this thread large enough to hold the buffer.
The stack was only set to 256 bytes, where the buffer itself takes 512!

By increasing the size to 1024 bytes the program works perfectly.
xTaskCreate(UserGUI, "UserGUI", 1024, NULL, GUI_TASK_PRIO, NULL);


Thanks a lot.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists