我刚刚添加了一个小代码来闪烁 2 个 LED。 总 RAM 消耗为 3KB。 我知道堆栈大小是 512 字节。 我不明白默认包含文件的哪一部分正在消耗 2.5 KB 的 RAM。 如何找到它并优化不需要的分配?
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:
Then build the project and you'll see the dialog:
So you can inspect which thing caused the most occupation of RAM.
感谢您的答复。 但仍然无法找到。 这是使用默认模板创建的新项目。 2.5K RAM 对于 LED 闪烁来说是巨大的。
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:
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...