cancel
Showing results for 
Search instead for 
Did you mean: 

How to access structure size a build argument, in stm32cubeIDE

CJami
Associate II

Hi,

I have a structure in code with name Config_t, i want to access the size of this struct in my post build command.

How can i do that? The Config_t may get change next time so giving a constant size in the post build command is not an option.

 

Thanks

2 REPLIES 2
TDK
Guru

You want sizeof(Config_t)? No easy way to do that in the general case.

You could make a static assert in the code that has the same size as what you use in your post build script. When that static assert fails, update it and the post build script at the same time.

If you feel a post has answered your question, please click "Accept as Solution".

Should be able to pull sizes from .MAP file and symbols/debug in .ELF

Example here from External Loader, which has a 200 (0xC8) size structure StorageInfo

.MAP
.info           0x00000000       0xc8
 *(.rodata.StorageInfo)
 .rodata.StorageInfo
                0x00000000       0xc8 out/Dev_Inf.o
                0x00000000                StorageInfo
.ELF
0000000B 200044EC 00000000 00030000 $d
000002A8 20004514 00000004 00050011 Mapped_Mode
000002B4 00000000 000000C8 00010011 * StorageInfo
000002C0 20003389 00000136 00020212 __divsf3
000002C9 200037F1 00000180 00020012 * Init
000002CE 200044FC 00000000 00040010 __exidx_end
000002DA 20003D69 00000134 00020012 HAL_RCC_GetSysClockFreq
000002F2 20003971 00000004 00020012 * DeInit
000002F9 20003B9D 00000002 00020022 HAL_MspInit
00000305 20003A75 000000A0 00020012 * Write
0000030B 20003A05 00000070 00020012 * Read
00000310 200041C9 000000A4 00020012 HAL_XSPI_Command

 

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..