I am developing a project for an STM32 processor, using FreeRTOS, Eclipse and gcc. I use the stm32_flash.ld linker file supplied with FreeRTOS examples, and I have been able to debug code without any major problems. However, I have now added routines that use library functions, in particular gmtime() to handle real-time, so I have added the time.h header file.
When I first compiled the project I got an error message '“syscalls_r.c undefined reference to ‘end’”. I eventually tracked this down to a problem with the linker script. I modified my makefile to instead invoke stm32rom.ld, supplied by ST in their examples for the STM32 processor. This didn’t give any errors, but the resulting code couldn’t be downloaded to the target for debugging.
I then looked at the differences between the two linker scripts. I am struggling to understand all the nuances of them, but I found a line at the end of the latter “PROVIDE(end = .);” to set a variable ‘end’ equal to the current location pointer. I copied this to the end of the STM32_flash.ld file and it then compiled without error. I could then download the code to my target and run it. However, when execution reached the line " TimeArray = *gmtime(&TimeCnt);" it crashes with a Hard Fault.
Can anyone suggest a fix for this?
I have tried stepping through the disassembly code and it appears that gmtime() calls malloc() which creates a number of local variables of type struct_malloc_chunk*. This structure comprises int previous_size, int size, struct_malloc_chunk* fd and struct_malloc_chunk* bk. As far as I can see this creates an infinite number of struct_malloc_chunk*'s!
My analysis may be wrong, but whatever the cause of the fault I can’t progress with my development until I can overcome the problem.