RAM 內存消耗

我剛剛添加了一個小代碼來閃爍 2 個 LED。 總 RAM 消耗為 3KB。 我知道堆棧大小是 512 字節(jié)。 我不明白默認包含文件的哪一部分正在消耗 2.5 KB 的 RAM。 如何找到它并優(yōu)化不需要的分配?


11.jpg

Hey bro I'm guessing you're not native Chinese speaker so I'll answer in English.

Just go to "Project" menu and check this:

image.png

Then build the project and you'll see the dialog:

image.png

So you can inspect which thing caused the most occupation of RAM.


感謝您的答復。 但仍然無法找到。 這是使用默認模板創(chuàng)建的新項目。 2.5K RAM 對于 LED 閃爍來說是巨大的。


22.jpg


If they're unable to see in that dialog, they might be the "highcode" entities, which "highcode" means they are stored in FLASH but being loaded into RAM at startup so finally they run in RAM, in order to get faster.

To confirm this hypothesis, I created a new project for CH582F and used the same code as yours.

I compiled then head to the list file like this:

image.png

From the image we can see the rows with a red arrow are using RAM at runtime(Their VMA is at 0x2*******). Accumulate sizes and you'll find A0Ch+4h+4h+200h=3092(dec).

To find which function is "highcode", we just need to search .map file for more info. Here's mine below(only contains necessary part):

.highcode???????0x0000000020000000??????0xa0c?load?address?0x0000000000000004
????????????????0x0000000020000000????????????????.?=?ALIGN?(0x4)
????????????????0x0000000020000000????????????????PROVIDE?(_highcode_vma_start?=?.)
?*(.vector)
?.vector????????0x0000000020000000???????0x90?./Startup/startup_CH583.o
?*(SORT_NONE(.vector_handler))
?.vector_handler
????????????????0x0000000020000090????????0x2?./Startup/startup_CH583.o
????????????????0x0000000020000090????????????????GPIOB_IRQHandler
????????????????0x0000000020000090????????????????GPIOA_IRQHandler
????????????????0x0000000020000090????????????????SysTick_Handler
????????????????0x0000000020000090????????????????NMI_Handler
????????????????0x0000000020000090????????????????UART1_IRQHandler
????????????????0x0000000020000090????????????????UART0_IRQHandler
????????????????0x0000000020000090????????????????BB_IRQHandler
????????????????0x0000000020000090????????????????Break_Point_Handler
????????????????0x0000000020000090????????????????TMR0_IRQHandler
????????????????0x0000000020000090????????????????Ecall_M_Mode_Handler
????????????????0x0000000020000090????????????????RTC_IRQHandler
????????????????0x0000000020000090????????????????UART2_IRQHandler
????????????????0x0000000020000090????????????????PWMX_IRQHandler
????????????????0x0000000020000090????????????????ADC_IRQHandler
????????????????0x0000000020000090????????????????TMR2_IRQHandler
????????????????0x0000000020000090????????????????USB_IRQHandler
????????????????0x0000000020000090????????????????I2C_IRQHandler
????????????????0x0000000020000090????????????????USB2_IRQHandler
????????????????0x0000000020000090????????????????LLE_IRQHandler
????????????????0x0000000020000090????????????????WDOG_BAT_IRQHandler
????????????????0x0000000020000090????????????????Ecall_U_Mode_Handler
????????????????0x0000000020000090????????????????TMR3_IRQHandler
????????????????0x0000000020000090????????????????SW_Handler
????????????????0x0000000020000090????????????????SPI0_IRQHandler
????????????????0x0000000020000090????????????????UART3_IRQHandler
????????????????0x0000000020000090????????????????TMR1_IRQHandler
?*(.highcode)
?.highcode??????0x0000000020000092??????0x554?./StdPeriphDriver/CH58x_sys.o
????????????????0x0000000020000092????????????????SetSysClock
????????????????0x0000000020000460????????????????SYS_ResetExecute
????????????????0x00000000200004de????????????????HardFault_Handler
????????????????0x00000000200005b0????????????????mDelayuS
????????????????0x00000000200005be????????????????mDelaymS
?.highcode??????0x00000000200005e6??????0x426?../StdPeriphDriver\libISP583.a(ISP583.o)
????????????????0x00000000200005e6????????????????FLASH_ROM_BEG
????????????????0x00000000200005f8????????????????FLASH_ROM_END
????????????????0x0000000020000606????????????????FLASH_ROM_IN
????????????????0x0000000020000614????????????????FLASH_ROM_OUT
????????????????0x0000000020000622????????????????FLASH_ROM_ADDR
????????????????0x000000002000066a????????????????FLASH_ROM_WAIT
????????????????0x00000000200006a2????????????????FLASH_EEPROM_CMD

So we know the vector table used 90h bytes, vector handlers used 2h bytes, functions from CH58x_sys.c used 554h bytes, functions from libISP583.a used 426h bytes. Accumulate them we got A0Ch bytes.

If you're not programming the flash onchip at runtime, maybe you can remove libISP583. But some functions in CH58x_sys.c call flash command functions, and remove of libISP583 may cause problems. Functions from CH58x_sys.c cannot be moved to run in flash because they MUST run in RAM, so MUST keep them as "highcode".



Thanks for explaining clearly...


只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频