Memory Alignment on STM32

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
brian360
Posts: 27
Joined: Wed Dec 08, 2010 5:47 pm

Memory Alignment on STM32

Post 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!
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Memory Alignment on STM32

Post 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
brian360
Posts: 27
Joined: Wed Dec 08, 2010 5:47 pm

Re: Memory Alignment on STM32

Post by brian360 »

That was it. Thanks Giovanni.
Post Reply