Page 1 of 1
RVCT port: heap init problem
Posted: Sun Feb 20, 2011 1:43 am
by liamstask
Hi - I'm trying to adapt the STM32F103 Keil demo for use in a project of mine. Things mostly seem to be working, until I tried to integrate the Flash filesystem from Keil that we use, called FlashFS.
I'm using the following file to retarget standard C routines to my hardware:
http://pastebin.com/V93jQGUS This is essentially the same as the given file from Keil, modified only to use the ChibiOS serial routines for printf output. However, once I add these in I see an unhandled exception failure inside __Heap_Initialize during startup.
I tried to use the symbol #pragma import(__use_no_heap) to ensure that the heap is not even used, but it appears that the Keil implementation of fopen() uses it, unfortunately. I've been looking through the info at
http://infocenter.arm.com/help/index.js ... heidg.html but haven't yet found a good resolution.
Any tips? Thanks!
Re: RVCT port: heap init problem
Posted: Sun Feb 20, 2011 8:27 am
by Giovanni
Hi Liam,
In order to make the Keil compiler export the symbols for the ChibiOS heap initialization I had to be "creative" with options.
I had to add "__heap_base__=Image$$RW_IRAM1$$ZI$$Limit __heap_end__=Image$$RW_IRAM2$$Base" and also define a dummy IRAM2 area marking the end of the heap, see the existing demos. You should also use the startup file provided by ChibiOS because the double stack requirement.
Assuming you did all the above then it would be a good idea to verify if everything is OK into the map file.
BTW: pastebin is not available because load it seems, I see an image with a cat there

, it's no problem, I like cats.
Giovanni
Re: RVCT port: heap init problem
Posted: Sun Feb 20, 2011 8:52 am
by liamstask
Hi Giovanni - thanks for the quick response, as usual

Actually, I don't see __heap_base__ or __heap_end__ in os\ports\RVCT\ARMCMx\cstartup.s, whereas it is included in os\ports\IAR\ARMCMx\cstartup.s, for example. Of course it does not exist in the map file either, even for the unmodified demo at demos\ARMCM3-STM32F103\keil. Perhaps it's just a small typo then?
Re: RVCT port: heap init problem
Posted: Sun Feb 20, 2011 9:03 am
by Giovanni
Those symbols are not in the startup files but are generated automatically using those defines into the compiler options, C/C++ tab, Define field.
The IAR startup is different, I had to use different solutions for the two compilers. In the IAR port it is done in the scatter file.
After all the work I decided to stay with GCC for my personal projects

Both IAR and Keil are, IMHO, missing one fundamental feature for embedded real time: an option to align functions to a flash buffer page boundary, at least I have been unable to find it so far.
Giovanni
Re: RVCT port: heap init problem
Posted: Sun Feb 20, 2011 9:12 am
by liamstask
Hm - but you would still expect to see them in the map file? I have not found them there, and I'm not sure I understand how the following section in the cstartup.s is related:
__heap_base
Heap_Mem SPACE heap_size
__heap_limit
I don't see __heap_base or __heap_limit in the amp file either, for what it's worth. I do see the Heap_Mem definition, located just after the proc_stack_mem as follows:
CSTACK 0x20000668 Section 1024 p2e4-3(CSTACK)
proc_stack_mem 0x20000668 Data 1024 p2e4-3(CSTACK)
HEAP 0x20000a68 Section 1024 p2e4-3(HEAP)
Heap_Mem 0x20000a68 Data 1024 p2e4-3(HEAP)
MSTACK 0x20000e68 Section 1024 p2e4-3(MSTACK)
Does this seem correct?
Re: RVCT port: heap init problem
Posted: Sun Feb 20, 2011 9:39 am
by Giovanni
__heap_base and __heap_limit are not visible in the map file but still present or you would have undefined symbol errors from the linker.
The heap referred from the cstartup is the C-runtime heap, it is not related to ChibiOS. The startup file is a modified version of the one provided by Keil.
BTW, I am using uVision 4.13a.
Giovanni
Re: RVCT port: heap init problem
Posted: Sun Feb 20, 2011 2:53 pm
by liamstask
Right, of course - those are different heaps, indeed. Sorry bout that.
However, I'm still seeing something strange - __initial_sp is given the same value as Heap_Mem. Is this likely to cause any problems?
In any event, I think the problem in __Heap_Initialize is as follows. Here's the implementation:
0x08002720 2100 MOVS r1,#0x00
0x08002722 6001 STR r1,[r0,#0x00]
0x08002724 E9C01001 STRD r1,r0,[r0,#0x04]
0x08002728 4770 BX lr
However, the value in r0 at this point happens to be the size of my read-only data (Load Region LR_IROM1 (Base: 0x08000000, Size: 0x0000387c, Max: 0x00020000, ABSOLUTE)), and r0 == 0x0800387c, so it seems that the STRD instruction that reads from that address with an offset of 4 trips an exception.
I'm not sure what the reason for this is yet.
(Oh, and I'm on 4.14 but I'm not sure if that's likely to be a cause for this difference)