AnsweredAssumed Answered

How much free RAM do I have?

Question asked by László Monda on Sep 27, 2017
Latest reply on Oct 6, 2017 by Erich Styger

Hi All,

 

I attached uhk-left.elf generated by the "left" project of our open source Ultimate Hacking Keyboard firmare repo. I'd like to see how much free RAM do I have, and the results of the arm-none-eabi-size and nm utilities seem to contradict each other.

 

$ arm-none-eabi-size --format=berkeley "uhk-left.elf"

text data bss dec hex filename
3104 416 1184 4704 1260 uhk-left.elf

According to my understanding and based on the above, data (416) + bss (1184) = 1600 bytes are being used out of the 2K RAM of the KL03.

 

Now let's compare this with the output of the nm utility:

 

$ nm --print-size --size-sort uhk-left.elf
200000b6 00000001 b byteIn.4509
200001d8 00000001 b prevEvent.4488
200001cc 00000001 b rxMessagePos.4489
000006e5 00000002 W __aeabi_idiv0
000006e5 00000002 W __aeabi_ldiv0
200001e0 00000002 b crc16data.4497
00000f0d 00000002 T _exit
00000541 00000004 W ADC0_IRQHandler
00000541 00000004 W CMP0_IRQHandler
00000541 00000004 W DefaultISR
00000541 00000004 W FTFA_IRQHandler
00000f1c 00000004 T _global_impure_ptr
00000549 00000004 W HardFault_Handler
00000559 00000004 W I2C0_IRQHandler
200001d0 00000004 b I2C_Watchdog.4507
200001c8 00000004 b I2C_WatchdogInnerCounter.4487
200001d4 00000004 b I2C_WatchdogOuterCounter.4506
00000541 00000004 W LLWU_IRQHandler
00000541 00000004 W LPUART0_DriverIRQHandler
00000561 00000004 W LPUART0_IRQHandler
00000545 00000004 W NMI_Handler
00000551 00000004 W PendSV_Handler
00000541 00000004 W PMC_IRQHandler
00000541 00000004 W PORTA_IRQHandler
00000541 00000004 W PORTB_IRQHandler
200001dc 00000004 b prevWatchdogCounter.4128.4486
00000541 00000004 W Reserved16_IRQHandler
00000541 00000004 W Reserved17_IRQHandler
00000541 00000004 W Reserved18_IRQHandler
00000541 00000004 W Reserved19_IRQHandler
00000541 00000004 W Reserved20_IRQHandler
00000541 00000004 W Reserved25_IRQHandler
00000541 00000004 W Reserved27_IRQHandler
00000541 00000004 W Reserved29_IRQHandler
00000541 00000004 W Reserved30_IRQHandler
00000541 00000004 W Reserved35_IRQHandler
00000541 00000004 W Reserved38_IRQHandler
00000541 00000004 W Reserved39_IRQHandler
00000541 00000004 W Reserved40_IRQHandler
00000541 00000004 W Reserved41_IRQHandler
00000541 00000004 W Reserved42_IRQHandler
00000541 00000004 W Reserved43_IRQHandler
00000541 00000004 W Reserved45_IRQHandler
00000541 00000004 W RTC_IRQHandler
00000541 00000004 W RTC_Seconds_IRQHandler
200001bc 00000004 b s_i2cHandle.5355.4492
200001c0 00000004 b s_i2cMasterIsr.5350.4498
200001c4 00000004 b s_i2cSlaveIsr.5352.4490
00000541 00000004 W SPI0_DriverIRQHandler
0000055d 00000004 W SPI0_IRQHandler
0000054d 00000004 W SVC_Handler
1ffffec0 00000004 d SystemCoreClock.4485
00000555 00000004 W SysTick_Handler
00000541 00000004 W TPM0_IRQHandler
00000541 00000004 W TPM1_IRQHandler
00000f10 00000008 t lircFreqs.4791.4918.4510
00000efd 00000010 T memset
000006d1 00000012 T __aeabi_idivmod
00000611 00000012 T __aeabi_uidivmod
000003c0 00000020 R BootloaderConfig
00000e61 00000024 T SystemInit
00000895 0000002c t CLOCK_GetLircClkFreq.4841.4480
000008c1 0000002c t CLOCK_GetOutClkFreq.4476
00000e85 0000002c T exit
00000a55 00000034 T I2C0_DriverIRQHandler
00000eb1 0000004c T __libc_init_array
1ffffe00 00000050 d __compound_literal.1.4555.4495
000004e9 00000058 W Reset_Handler
1fffff34 00000060 d impure_data
1ffffe50 00000070 d __compound_literal.0.4554.4494
1ffffec4 00000070 d keyMatrix.4493
00000df1 00000070 T LPTMR0_IRQHandler
00000589 00000088 T __udivsi3
00000625 000000ac T __divsi3
00000000 000000c0 R __isr_vector
1fffffb4 00000102 b rxMessage.4508
200000b7 00000102 b txMessage.4496
000008ed 00000168 t i2cSlaveCallback.4289.4113
000006e9 000001ac t I2C_SlaveTransferHandleIRQ.4216
00000a89 00000368 T main

 

According to my knowledge the "b" and "d" records are relevant for RAM allocation, so I computed these records by executing the following on Linux:

 

$ nm --print-size --size-sort uhk-left.elf | egrep '^[0-9a-f]{8} [0-9a-f]{8} [bd]' | awk '{print $2}' | awk '{print "0x" $0}' | awk '{s+=strtonum($1)} END {print s}'
953

 

1600 vs 953 bytes are quite a difference. Would any of you explain which is right and why the two values don't match?

 

Thank you very much in advance!

- Laci

Original Attachment has been moved to: uhk-left.map.zip

Original Attachment has been moved to: uhk-left.elf.zip

Outcomes