Page 1 of 1

Memory Alignment on STM32

Posted: Thu Feb 24, 2011 1:54 am
by brian360
Hi,

I was trying to do a call such as:

Code: Select all

chPoolFree(&mp, chCoreAlloc(512));


and was getting an assert failure. Upon further investigation, it looks like chCoreAlloc was returning memory alligned on 4 bytes rather than 8. It, in turn, seems to be doing that because the global variable __heap_base__ (from where nextmem is set) is set to an address of 0x20009f94 which doesn't seem to be aligned on 8 bytes.

Since I'm nothing close to an expert on linker files, what should I be modifying in ch.ld to fix this? Should I replace every instance of "ALIGN(4)" with "ALIGN(8)" in the whole file? Or just for the data (and/or bss) section?

I'm using the linker file as-is from the ARMCM3-STM32F107-GCC demo.

Thanks!

Re: Memory Alignment on STM32

Posted: Thu Feb 24, 2011 9:03 am
by Giovanni
Hi Brian,

I would add an ". = ALIGN(8);" just before "PROVIDE(end = .);". There is no need to align every section to 8 bytes.

I will add this issue to the tracker.

Giovanni

Re: Memory Alignment on STM32

Posted: Thu Feb 24, 2011 6:20 pm
by brian360
That was it. Thanks Giovanni.