STM32存储布局

内存映射

单片机是内存映射控件,应用程序通过读写对应地址完成对外设的控制。

以STM32为例, 程序存储器、数据存储器、寄存器和输入输出端口被组织在同一个4GB的线性地址空间内。

地址范围为0x0000 0000至0xFFFF FFFF。

image-20240118102645673.png

从内存映射布局可以看到:

  1. 片上Flash被映射到0x0800 0000-0x0801 FFFF的地址空间,通过读写这个地址空间,可以对Flash进行读写。
  2. 运行内存RAM被映射到0x2000 0000开始的一片区域。

更进一步,在MDK下,通过生成的map文件,可以直观地看到FLash和RAM更加细节的布局。

FLash布局

Memory Map of the image
Image Entry point : 0x080000b9
Load Region LR_IROM1 (Base: 0x08000000, Size: 0x000061d8, Max: 0x00020000, ABSOLUTE)
Execution Region ER_IROM1 (Exec base: 0x08000000, Load base: 0x08000000, Size: 0x00006120, Max: 0x00020000, ABSOLUTE)
Exec Addr    Load Addr    Size         Type   Attr Idx    E Section Name        Object                                        
0x08000000   0x08000000   0x000000b8   Data   RO   1193    RESET               startup_stm32g070xx.o
0x080000b8   0x080000b8   0x00000000   Code   RO   3003  * .ARM.Collect$$$$00000000  mc_p.l(entry.o)
0x080000b8   0x080000b8   0x00000004   Code   RO   3315    .ARM.Collect$$$$00000001  mc_p.l(entry2.o)
0x080000bc   0x080000bc   0x00000004   Code   RO   3318    .ARM.Collect$$$$00000004  mc_p.l(entry5.o)
0x080000c0   0x080000c0   0x00000000   Code   RO   3320    .ARM.Collect$$$$00000008  mc_p.l(entry7b.o)
0x080000c0   0x080000c0   0x00000000   Code   RO   3322    .ARM.Collect$$$$0000000A  mc_p.l(entry8b.o)
0x080000c0   0x080000c0   0x00000008   Code   RO   3323    .ARM.Collect$$$$0000000B  mc_p.l(entry9a.o)
0x080000c8   0x080000c8   0x00000000   Code   RO   3325    .ARM.Collect$$$$0000000D  mc_p.l(entry10a.o)
0x080000c8   0x080000c8   0x00000000   Code   RO   3327    .ARM.Collect$$$$0000000F  mc_p.l(entry11a.o)
0x080000c8   0x080000c8   0x00000004   Code   RO   3316    .ARM.Collect$$$$00002712  mc_p.l(entry2.o)
0x080000cc   0x080000cc   0x0000001c   Code   RO   1194    .text               startup_stm32g070xx.o
0x080000e8   0x080000e8   0x0000002c   Code   RO   3006    .text               mc_p.l(uidiv.o)
0x08000114   0x08000114   0x00000028   Code   RO   3008    .text               mc_p.l(idiv.o)
0x0800013c   0x0800013c   0x00000024   Code   RO   3010    .text               mc_p.l(memseta.o)
0x08000160   0x08000160   0x0000000e   Code   RO   3012    .text               mc_p.l(strlen.o)
0x0800016e   0x0800016e   0x0000001c   Code   RO   3014    .text               mc_p.l(strcmp.o)
0x0800018a   0x0800018a   0x0000001e   Code   RO   3016    .text               mc_p.l(strncmp.o)
0x080001a8   0x080001a8   0x0000007a   Code   RO   3307    .text               mf_p.l(fmul.o)
0x08000222   0x08000222   0x0000007c   Code   RO   3309    .text               mf_p.l(fdiv.o)
0x0800029e   0x0800029e   0x00000016   Code   RO   3311    .text               mf_p.l(fflti.o)
0x080002b4   0x080002b4   0x0000000e   Code   RO   3313    .text               mf_p.l(ffltui.o)
0x080002c2   0x080002c2   0x00000060   Code   RO   3330    .text               mc_p.l(uldiv.o)
0x08000322   0x08000322   0x00000000   Code   RO   3338    .text               mc_p.l(iusefp.o)
0x08000322   0x08000322   0x00000082   Code   RO   3339    .text               mf_p.l(fepilogue.o)
0x080003a4   0x080003a4   0x00000164   Code   RO   3341    .text               mf_p.l(dadd.o)
0x08000508   0x08000508   0x000000d0   Code   RO   3343    .text               mf_p.l(dmul.o)
0x080005d8   0x080005d8   0x000000f0   Code   RO   3345    .text               mf_p.l(ddiv.o)
0x080006c8   0x080006c8   0x00000040   Code   RO   3347    .text               mf_p.l(dfixul.o)
0x08000708   0x08000708   0x00000028   Code   RO   3349    .text               mf_p.l(cdrcmple.o)
0x08000730   0x08000730   0x00000024   Code   RO   3351    .text               mc_p.l(init.o)
0x08000754   0x08000754   0x00000020   Code   RO   3353    .text               mc_p.l(llshl.o)
0x08000774   0x08000774   0x00000022   Code   RO   3355    .text               mc_p.l(llushr.o)
0x08000796   0x08000796   0x00000026   Code   RO   3357    .text               mc_p.l(llsshr.o)
0x080007bc   0x080007bc   0x000000be   Code   RO   3359    .text               mf_p.l(depilogue.o)
0x0800087a   0x0800087a   0x00000002   PAD        
0x0800087c   0x0800087c   0x00000098   Code   RO   2859    i.HAL_DMA_Abort     stm32g0xx_hal_dma.o
0x08000914   0x08000914   0x00000094   Code   RO   2860    i.HAL_DMA_Abort_IT  stm32g0xx_hal_dma.o
0x080009a8   0x080009a8   0x000001d8   Code   RO   1868    i.HAL_GPIO_Init     stm32g0xx_hal_gpio.o
0x08000b80   0x08000b80   0x00000012   Code   RO   1870    i.HAL_GPIO_ReadPin  stm32g0xx_hal_gpio.o
0x08000b92   0x08000b92   0x0000000c   Code   RO   1872    i.HAL_GPIO_WritePin  stm32g0xx_hal_gpio.o
0x08000b9e   0x08000b9e   0x00000002   PAD        
0x08000ba0   0x08000ba0   0x0000000c   Code   RO   1209    i.HAL_GetTick       stm32g0xx_hal.o
0x08000bac   0x08000bac   0x0000002c   Code   RO   1216    i.HAL_Init          stm32g0xx_hal.o
0x08000bd8   0x08000bd8   0x00000060   Code   RO   1217    i.HAL_InitTick      stm32g0xx_hal.o
0x08000c38   0x08000c38   0x00000002   Code   RO   1219    i.HAL_MspInit       stm32g0xx_hal.o
0x08000c3a   0x08000c3a   0x00000002   PAD        
0x08000c3c   0x08000c3c   0x0000003c   Code   RO   1393    i.HAL_NVIC_DisableIRQ  stm32g0xx_hal_cortex.o
0x08000c78   0x08000c78   0x00000024   Code   RO   1394    i.HAL_NVIC_EnableIRQ  stm32g0xx_hal_cortex.o
0x08000c9c   0x08000c9c   0x00000012   Code   RO   1398    i.HAL_NVIC_SetPriority  stm32g0xx_hal_cortex.o
0x08000cae   0x08000cae   0x00000002   PAD        
0x08000cb0   0x08000cb0   0x00000058   Code   RO   1752    i.HAL_PWREx_ControlVoltageScaling  stm32g0xx_hal_pwr_ex.o
0x08000d08   0x08000d08   0x000001d4   Code   RO   1504    i.HAL_RCC_ClockConfig  stm32g0xx_hal_rcc.o
0x08000edc   0x08000edc   0x0000000c   Code   RO   1510    i.HAL_RCC_GetHCLKFreq  stm32g0xx_hal_rcc.o
0x08000ee8   0x08000ee8   0x00000028   Code   RO   1512    i.HAL_RCC_GetPCLK1Freq  stm32g0xx_hal_rcc.o
0x08000f10   0x08000f10   0x000000e4   Code   RO   1514    i.HAL_RCC_GetSysClockFreq  stm32g0xx_hal_rcc.o
0x08000ff4   0x08000ff4   0x000005ac   Code   RO   1518    i.HAL_RCC_OscConfig  stm32g0xx_hal_rcc.o
0x080015a0   0x080015a0   0x00000038   Code   RO   1402    i.HAL_SYSTICK_Config  stm32g0xx_hal_cortex.o
0x080015d8   0x080015d8   0x00000002   Code   RO   1943    i.HAL_UARTEx_RxEventCallback  stm32g0xx_hal_uart.o
0x080015da   0x080015da   0x00000002   Code   RO   2375    i.HAL_UARTEx_RxFifoFullCallback  stm32g0xx_hal_uart_ex.o
0x080015dc   0x080015dc   0x00000002   Code   RO   2379    i.HAL_UARTEx_TxFifoEmptyCallback  stm32g0xx_hal_uart_ex.o
0x080015de   0x080015de   0x00000002   Code   RO   2380    i.HAL_UARTEx_WakeupCallback  stm32g0xx_hal_uart_ex.o
0x080015e0   0x080015e0   0x00000002   Code   RO   1959    i.HAL_UART_ErrorCallback  stm32g0xx_hal_uart.o
0x080015e2   0x080015e2   0x00000002   PAD        
0x080015e4   0x080015e4   0x0000042e   Code   RO   1962    i.HAL_UART_IRQHandler  stm32g0xx_hal_uart.o
0x08001a12   0x08001a12   0x00000082   Code   RO   1963    i.HAL_UART_Init     stm32g0xx_hal_uart.o
0x08001a94   0x08001a94   0x00000090   Code   RO    350    i.HAL_UART_MspInit  elab_uart_debug.o
0x08001b24   0x08001b24   0x00000092   Code   RO   1968    i.HAL_UART_Receive_IT  stm32g0xx_hal_uart.o
0x08001bb6   0x08001bb6   0x00000002   PAD        
0x08001bb8   0x08001bb8   0x00000034   Code   RO    351    i.HAL_UART_RxCpltCallback  elab_uart_debug.o
0x08001bec   0x08001bec   0x00000118   Code   RO   1974    i.HAL_UART_Transmit_IT  stm32g0xx_hal_uart.o
0x08001d04   0x08001d04   0x00000040   Code   RO    352    i.HAL_UART_TxCpltCallback  elab_uart_debug.o
0x08001d44   0x08001d44   0x00000004   Code   RO   1125    i.HardFault_Handler  stm32g0xx_it.o
0x08001d48   0x08001d48   0x00000004   Code   RO   1126    i.NMI_Handler       stm32g0xx_it.o
0x08001d4c   0x08001d4c   0x00000010   Code   RO    328    i.SysTick_Handler   elab_time.o
0x08001d5c   0x08001d5c   0x00000002   Code   RO   1161    i.SystemInit        system_stm32g0xx.o
0x08001d5e   0x08001d5e   0x000000f0   Code   RO   1977    i.UART_AdvFeatureConfig  stm32g0xx_hal_uart.o
0x08001e4e   0x08001e4e   0x00000002   PAD        
0x08001e50   0x08001e50   0x00000078   Code   RO   1978    i.UART_CheckIdleState  stm32g0xx_hal_uart.o
0x08001ec8   0x08001ec8   0x00000018   Code   RO   1979    i.UART_DMAAbortOnError  stm32g0xx_hal_uart.o
0x08001ee0   0x08001ee0   0x00000084   Code   RO   1989    i.UART_EndRxTransfer  stm32g0xx_hal_uart.o
0x08001f64   0x08001f64   0x00000038   Code   RO   1990    i.UART_EndTransmit_IT  stm32g0xx_hal_uart.o
0x08001f9c   0x08001f9c   0x000000e8   Code   RO   1992    i.UART_RxISR_16BIT  stm32g0xx_hal_uart.o
0x08002084   0x08002084   0x00000210   Code   RO   1993    i.UART_RxISR_16BIT_FIFOEN  stm32g0xx_hal_uart.o
0x08002294   0x08002294   0x000000e8   Code   RO   1994    i.UART_RxISR_8BIT   stm32g0xx_hal_uart.o
0x0800237c   0x0800237c   0x0000020c   Code   RO   1995    i.UART_RxISR_8BIT_FIFOEN  stm32g0xx_hal_uart.o
0x08002588   0x08002588   0x00000230   Code   RO   1996    i.UART_SetConfig    stm32g0xx_hal_uart.o
0x080027b8   0x080027b8   0x000001b4   Code   RO   1998    i.UART_Start_Receive_IT  stm32g0xx_hal_uart.o
0x0800296c   0x0800296c   0x00000078   Code   RO   1999    i.UART_TxISR_16BIT  stm32g0xx_hal_uart.o
0x080029e4   0x080029e4   0x00000098   Code   RO   2000    i.UART_TxISR_16BIT_FIFOEN  stm32g0xx_hal_uart.o
0x08002a7c   0x08002a7c   0x00000074   Code   RO   2001    i.UART_TxISR_8BIT   stm32g0xx_hal_uart.o
0x08002af0   0x08002af0   0x00000094   Code   RO   2002    i.UART_TxISR_8BIT_FIFOEN  stm32g0xx_hal_uart.o
0x08002b84   0x08002b84   0x00000120   Code   RO   2003    i.UART_WaitOnFlagUntilTimeout  stm32g0xx_hal_uart.o
0x08002ca4   0x08002ca4   0x00000010   Code   RO   1127    i.USART3_4_IRQHandler  stm32g0xx_it.o
0x08002cb4   0x08002cb4   0x00000020   Code   RO   3251    i.__0printf         mc_p.l(printfa.o)
0x08002cd4   0x08002cd4   0x00000028   Code   RO   3253    i.__0sprintf        mc_p.l(printfa.o)
0x08002cfc   0x08002cfc   0x0000002e   Code   RO   3361    i.__ARM_clz         mf_p.l(depilogue.o)
0x08002d2a   0x08002d2a   0x0000001c   Code   RO   1011    i.__ARM_common_switch8  shell.o
0x08002d46   0x08002d46   0x00000002   PAD        
0x08002d48   0x08002d48   0x00000078   Code   RO   1404    i.__NVIC_SetPriority  stm32g0xx_hal_cortex.o
0x08002dc0   0x08002dc0   0x00000006   Code   RO   2004    i.__get_PRIMASK     stm32g0xx_hal_uart.o
0x08002dc6   0x08002dc6   0x0000000e   Code   RO   3365    i.__scatterload_copy  mc_p.l(handlers.o)
0x08002dd4   0x08002dd4   0x00000002   Code   RO   3366    i.__scatterload_null  mc_p.l(handlers.o)
0x08002dd6   0x08002dd6   0x0000000e   Code   RO   3367    i.__scatterload_zeroinit  mc_p.l(handlers.o)
0x08002de4   0x08002de4   0x00000006   Code   RO   2005    i.__set_PRIMASK     stm32g0xx_hal_uart.o
0x08002dea   0x08002dea   0x00000002   PAD        
0x08002dec   0x08002dec   0x0000008c   Code   RO    586    i._assert           elab_assert.o
0x08002e78   0x08002e78   0x00000060   Code   RO     38    i._check_pin_name_valid  eio_pin.o
0x08002ed8   0x08002ed8   0x00000006   Code   RO    207    i._error_handler    bsp.o
0x08002ede   0x08002ede   0x00000002   PAD        
0x08002ee0   0x08002ee0   0x00000174   Code   RO   3258    i._fp_digits        mc_p.l(printfa.o)
0x08003054   0x08003054   0x0000009c   Code   RO    475    i._get_init_export_table  elab_export.o
0x080030f0   0x080030f0   0x000000cc   Code   RO    476    i._get_poll_export_table  elab_export.o
0x080031bc   0x080031bc   0x00000078   Code   RO    477    i._init_func_execute  elab_export.o
0x08003234   0x08003234   0x00000088   Code   RO    478    i._poll_func_execute  elab_export.o
0x080032bc   0x080032bc   0x000006ec   Code   RO   3259    i._printf_core      mc_p.l(printfa.o)
0x080039a8   0x080039a8   0x00000020   Code   RO   3260    i._printf_post_padding  mc_p.l(printfa.o)
0x080039c8   0x080039c8   0x0000002c   Code   RO   3261    i._printf_pre_padding  mc_p.l(printfa.o)
0x080039f4   0x080039f4   0x0000000a   Code   RO   3263    i._sputc            mc_p.l(printfa.o)
0x080039fe   0x080039fe   0x00000076   Code   RO    208    i._system_clock_config  bsp.o
0x08003a74   0x08003a74   0x000000e0   Code   RO     39    i._translate_pin_name  eio_pin.o
0x08003b54   0x08003b54   0x0000000c   Code   RO    209    i.bsp_init          bsp.o
0x08003b60   0x08003b60   0x00000044   Code   RO     40    i.eio_pin_get_status  eio_pin.o
0x08003ba4   0x08003ba4   0x000000ec   Code   RO     41    i.eio_pin_init      eio_pin.o
0x08003c90   0x08003c90   0x00000098   Code   RO     42    i.eio_pin_set_status  eio_pin.o
0x08003d28   0x08003d28   0x00000004   Code   RO    587    i.elab_assert_func  elab_assert.o
0x08003d2c   0x08003d2c   0x00000070   Code   RO    354    i.elab_debug_uart_init  elab_uart_debug.o
0x08003d9c   0x08003d9c   0x00000028   Code   RO    355    i.elab_debug_uart_receive  elab_uart_debug.o
0x08003dc4   0x08003dc4   0x00000060   Code   RO    356    i.elab_debug_uart_send  elab_uart_debug.o
0x08003e24   0x08003e24   0x0000002c   Code   RO    479    i.elab_run          elab_export.o
0x08003e50   0x08003e50   0x0000000c   Code   RO    329    i.elab_time_ms      elab_time.o
0x08003e5c   0x08003e5c   0x0000000e   Code   RO    414    i.elib_queue_init   elib_queue.o
0x08003e6a   0x08003e6a   0x00000012   Code   RO    415    i.elib_queue_is_empty  elib_queue.o
0x08003e7c   0x08003e7c   0x00000030   Code   RO    417    i.elib_queue_pop    elib_queue.o
0x08003eac   0x08003eac   0x00000042   Code   RO    418    i.elib_queue_pull   elib_queue.o
0x08003eee   0x08003eee   0x00000056   Code   RO    419    i.elib_queue_pull_pop  elib_queue.o
0x08003f44   0x08003f44   0x00000040   Code   RO    420    i.elib_queue_push   elib_queue.o
0x08003f84   0x08003f84   0x00000002   Code   RO    653    i.fkey_null_func    shell.o
0x08003f86   0x08003f86   0x00000002   PAD        
0x08003f88   0x08003f88   0x00000044   Code   RO    610    i.fputc             elab_log.o
0x08003fcc   0x08003fcc   0x00000024   Code   RO    274    i.led_init          led.o
0x08003ff0   0x08003ff0   0x00000040   Code   RO    275    i.led_poll          led.o
0x08004030   0x08004030   0x0000000e   Code   RO      1    i.main              main.o
0x0800403e   0x0800403e   0x00000002   Code   RO    481    i.module_null_init  elab_export.o
0x08004040   0x08004040   0x00000028   Code   RO    654    i.shellAdd          shell.o
0x08004068   0x08004068   0x0000000e   Code   RO    655    i.shellBackspace    shell.o
0x08004076   0x08004076   0x00000002   PAD        
0x08004078   0x08004078   0x00000044   Code   RO    656    i.shellCheckPassword  shell.o
0x080040bc   0x080040bc   0x0000003e   Code   RO    657    i.shellCheckPermission  shell.o
0x080040fa   0x080040fa   0x00000002   PAD        
0x080040fc   0x080040fc   0x0000001c   Code   RO    658    i.shellClear        shell.o
0x08004118   0x08004118   0x00000028   Code   RO    659    i.shellClearCommandLine  shell.o
0x08004140   0x08004140   0x00000014   Code   RO    660    i.shellCmds         shell.o
0x08004154   0x08004154   0x00000010   Code   RO    661    i.shellDelete       shell.o
0x08004164   0x08004164   0x000000de   Code   RO    662    i.shellDeleteByte   shell.o
0x08004242   0x08004242   0x00000002   PAD        
0x08004244   0x08004244   0x00000028   Code   RO    663    i.shellDeleteCommandLine  shell.o
0x0800426c   0x0800426c   0x00000010   Code   RO    664    i.shellDown         shell.o
0x0800427c   0x0800427c   0x00000014   Code   RO    666    i.shellEnter        shell.o
0x08004290   0x08004290   0x0000007c   Code   RO    667    i.shellExec         shell.o
0x0800430c   0x0800430c   0x0000005a   Code   RO   1048    i.shellExtNumType   shell_ext.o
0x08004366   0x08004366   0x00000046   Code   RO   1049    i.shellExtParseChar  shell_ext.o
0x080043ac   0x080043ac   0x000000e6   Code   RO   1050    i.shellExtParseNumber  shell_ext.o
0x08004492   0x08004492   0x0000005c   Code   RO   1051    i.shellExtParsePara  shell_ext.o
0x080044ee   0x080044ee   0x0000004a   Code   RO   1052    i.shellExtParseString  shell_ext.o
0x08004538   0x08004538   0x00000026   Code   RO   1053    i.shellExtParseVar  shell_ext.o
0x0800455e   0x0800455e   0x000000ce   Code   RO   1054    i.shellExtRun       shell_ext.o
0x0800462c   0x0800462c   0x00000036   Code   RO   1055    i.shellExtToNum     shell_ext.o
0x08004662   0x08004662   0x00000030   Code   RO    668    i.shellGetCommandDesc  shell.o
0x08004692   0x08004692   0x00000002   PAD        
0x08004694   0x08004694   0x00000050   Code   RO    669    i.shellGetCommandName  shell.o
0x080046e4   0x080046e4   0x00000034   Code   RO    670    i.shellGetCurrent   shell.o
0x08004718   0x08004718   0x00000056   Code   RO    671    i.shellGetVarValue  shell.o
0x0800476e   0x0800476e   0x00000002   PAD        
0x08004770   0x08004770   0x00000100   Code   RO    672    i.shellHandler      shell.o
0x08004870   0x08004870   0x0000002e   Code   RO    673    i.shellHelp         shell.o
0x0800489e   0x0800489e   0x000000c0   Code   RO    674    i.shellHistory      shell.o
0x0800495e   0x0800495e   0x00000080   Code   RO    675    i.shellHistoryAdd   shell.o
0x080049de   0x080049de   0x00000002   PAD        
0x080049e0   0x080049e0   0x000000a8   Code   RO    676    i.shellInit         shell.o
0x08004a88   0x08004a88   0x000000e0   Code   RO    677    i.shellInsertByte   shell.o
0x08004b68   0x08004b68   0x00000014   Code   RO    678    i.shellKeys         shell.o
0x08004b7c   0x08004b7c   0x0000001a   Code   RO    679    i.shellLeft         shell.o
0x08004b96   0x08004b96   0x0000000c   Code   RO    680    i.shellListAll      shell.o
0x08004ba2   0x08004ba2   0x00000002   PAD        
0x08004ba4   0x08004ba4   0x0000004c   Code   RO    681    i.shellListCommand  shell.o
0x08004bf0   0x08004bf0   0x000000f8   Code   RO    682    i.shellListItem     shell.o
0x08004ce8   0x08004ce8   0x0000005c   Code   RO    683    i.shellListKey      shell.o
0x08004d44   0x08004d44   0x0000005c   Code   RO    684    i.shellListUser     shell.o
0x08004da0   0x08004da0   0x0000005c   Code   RO    685    i.shellListVar      shell.o
0x08004dfc   0x08004dfc   0x0000001c   Code   RO    686    i.shellNormalInput  shell.o
0x08004e18   0x08004e18   0x00000096   Code   RO    687    i.shellParserParam  shell.o
0x08004eae   0x08004eae   0x00000068   Code   RO    689    i.shellRemoveParamQuotes  shell.o
0x08004f16   0x08004f16   0x0000001e   Code   RO    690    i.shellRight        shell.o
0x08004f34   0x08004f34   0x000000b4   Code   RO    692    i.shellRunCommand   shell.o
0x08004fe8   0x08004fe8   0x00000082   Code   RO    693    i.shellSeekCommand  shell.o
0x0800506a   0x0800506a   0x00000002   PAD        
0x0800506c   0x0800506c   0x00000068   Code   RO    694    i.shellSetUser      shell.o
0x080050d4   0x080050d4   0x0000006c   Code   RO    695    i.shellSetVar       shell.o
0x08005140   0x08005140   0x00000098   Code   RO    696    i.shellSetVarValue  shell.o
0x080051d8   0x080051d8   0x000000c0   Code   RO    697    i.shellShowVar      shell.o
0x08005298   0x08005298   0x0000002e   Code   RO    698    i.shellStringCompare  shell.o
0x080052c6   0x080052c6   0x00000018   Code   RO    699    i.shellStringCopy   shell.o
0x080052de   0x080052de   0x00000002   PAD        
0x080052e0   0x080052e0   0x00000124   Code   RO    700    i.shellTab          shell.o
0x08005404   0x08005404   0x0000005a   Code   RO    702    i.shellToDec        shell.o
0x0800545e   0x0800545e   0x00000002   PAD        
0x08005460   0x08005460   0x00000024   Code   RO    703    i.shellToHex        shell.o
0x08005484   0x08005484   0x0000000e   Code   RO    704    i.shellUp           shell.o
0x08005492   0x08005492   0x00000014   Code   RO    705    i.shellUsers        shell.o
0x080054a6   0x080054a6   0x00000014   Code   RO    706    i.shellVars         shell.o
0x080054ba   0x080054ba   0x0000000e   Code   RO    707    i.shellWriteByte    shell.o
0x080054c8   0x080054c8   0x0000005c   Code   RO    708    i.shellWriteCommandDesc  shell.o
0x08005524   0x08005524   0x00000068   Code   RO    709    i.shellWriteCommandHelp  shell.o
0x0800558c   0x0800558c   0x00000070   Code   RO    711    i.shellWritePrompt  shell.o
0x080055fc   0x080055fc   0x00000070   Code   RO    712    i.shellWriteReturnValue  shell.o
0x0800566c   0x0800566c   0x00000022   Code   RO    713    i.shellWriteString  shell.o
0x0800568e   0x0800568e   0x00000002   PAD        
0x08005690   0x08005690   0x0000002c   Code   RO    240    i.shell_poll        shell_export.o
0x080056bc   0x080056bc   0x00000034   Code   RO    241    i.shell_uart_init   shell_export.o
0x080056f0   0x080056f0   0x00000058   Code   RO   1098    i.test_func_led     test_led.o
0x08005748   0x08005748   0x000000eb   Data   RO    715    .constdata          shell.o
0x08005833   0x08005833   0x00000025   Data   RO   1099    .constdata          test_led.o
0x08005858   0x08005858   0x00000068   Data   RO   1162    .constdata          system_stm32g0xx.o
0x080058c0   0x080058c0   0x00000020   Data   RO   2006    .constdata          stm32g0xx_hal_uart.o
0x080058e0   0x080058e0   0x0000004c   Data   RO     44    .conststring        eio_pin.o
0x0800592c   0x0800592c   0x0000000b   Data   RO    482    .conststring        elab_export.o
0x08005937   0x08005937   0x00000001   PAD        
0x08005938   0x08005938   0x000001d8   Data   RO    716    .conststring        shell.o
0x08005b10   0x08005b10   0x00000015   Data   RO    243    .conststrlit        shell_export.o
0x08005b25   0x08005b25   0x00000003   PAD        
0x08005b28   0x08005b28   0x00000011   Data   RO    278    .conststrlit        led.o
0x08005b39   0x08005b39   0x00000003   PAD        
0x08005b3c   0x08005b3c   0x00000019   Data   RO    483    .conststrlit        elab_export.o
0x08005b55   0x08005b55   0x00000003   PAD        
0x08005b58   0x08005b58   0x00000020   Data   RO   3363    Region$$Table       anon$$obj.o
0x08005b78   0x08005b78   0x0000001c   Data   RO    245    elab_export         shell_export.o
0x08005b94   0x08005b94   0x0000001c   Data   RO    280    elab_export         led.o
0x08005bb0   0x08005bb0   0x0000001c   Data   RO    485    elab_export         elab_export.o
0x08005bcc   0x08005bcc   0x0000001c   Data   RO    246    expoll              shell_export.o
0x08005be8   0x08005be8   0x0000001c   Data   RO    281    expoll              led.o
0x08005c04   0x08005c04   0x0000001c   Data   RO    486    expoll              elab_export.o
0x08005c20   0x08005c20   0x000004c0   Data   RO    718    shellCommand        shell.o
0x080060e0   0x080060e0   0x00000040   Data   RO   1100    shellCommand        test_led.o

Flash又可以细分为文本段、只读数据段、数据复制段。

其中文本段包含代码和代码中的常量部分。

只读数据区通常存放程序中以const关键字修饰的数据。

数据复制段存放的则是程序中初始化不为0的全局变量的数据,在每次单片机复位后要对这些变量重新赋值。

可以看到被调用的HAL库的函数、应用程序自定义的函数都被放在了FLASH中,编译器会自动给他们分配不同的section。

用户也可以使用__attribute__((section(x)))来自定义section。

letter shell中的代码为例:

#ifndef SHELL_SECTION
    #if defined(__CC_ARM) || defined(__CLANG_ARM)
        #define SHELL_SECTION(x)                __attribute__((section(x)))
    #elif defined (__IAR_SYSTEMS_ICC__)
        #define SHELL_SECTION(x)                @ x
    #elif defined(__GNUC__)
        #define SHELL_SECTION(x)                __attribute__((section(x)))
    #else
        #define SHELL_SECTION(x)
    #endif
#endif

    #define SHELL_EXPORT_CMD(_attr, _name, _func, _desc) \
            const char shellCmd##_name[] = #_name; \
            const char shellDesc##_name[] = #_desc; \
            SHELL_USED const ShellCommand \
            shellCommand##_name SHELL_SECTION("shellCommand") =  \
            { \
                .magic_head = SHELL_MAGIC_NUM, \
                .magic_tail = SHELL_MAGIC_NUM, \
                .attr.value = _attr, \
                .data.cmd.name = shellCmd##_name, \
                .data.cmd.function = (int (*)())_func, \
                .data.cmd.desc = shellDesc##_name \
            }

使用SHELL_EXPORT_CMD定义的某个命令的数据结构会存放在名为shellCommand的section中。

由于数据结构前声明为const,所以最终会存放在Flash中。

如果前面没有被声明为const,则对应的数据结构会被存放在RAM中。

RAM布局

image-20240118111439157.png

data段:存放初始化非0的全局变量

bss段:存放未初始化或初始化为0的全局变量

Heap(堆)段:由程序员通过malloc/free申请和释放

Stack(栈)段:存放局部变量和函数的入口地址

Execution Region RW_IRAM1 (Exec base: 0x20000000, Load base: 0x08006140, Size: 0x00000a88, Max: 0x00009000, ABSOLUTE)
Exec Addr    Load Addr    Size         Type   Attr  Idx    E Section Name   Object
0x20000000   0x08006140   0x00000014   Data   RW       45    .data          eio_pin.o
0x20000014   0x08006154   0x00000004   Data   RW      244    .data          shell_export.o
0x20000018   0x08006158   0x00000008   Data   RW      279    .data          led.o
0x20000020   0x08006160   0x00000004   Data   RW      330    .data          elab_time.o
0x20000024   0x08006164   0x00000001   Data   RW      359    .data          elab_uart_debug.o
0x20000025   0x08006165   0x00000003   PAD
0x20000028   0x08006168   0x00000019   Data   RW      484    .data          elab_export.o
0x20000041   0x08006181   0x00000002   Data   RW      614    .data          elab_log.o
0x20000043   0x08006183   0x00000001   PAD
0x20000044   0x08006184   0x00000060   Data   RW      717    .data          shell.o
0x200000a4   0x080061e4   0x00000004   Data   RW     1164    .data          system_stm32g0xx.o
0x200000a8   0x080061e8   0x00000009   Data   RW     1230    .data          stm32g0xx_hal.o
0x200000b1   0x080061f1   0x00000003   PAD
0x200000b4   0x080061f4   0x00000004   Data   RW     3330    .data          mc_p.l(stdout.o)
0x200000b8   0x080061f8   0x0000001c   Data   RW      245    elab_export    shell_export.o
0x200000d4   0x08006214   0x0000001c   Data   RW      280    elab_export    led.o
0x200000f0   0x08006230   0x0000001c   Data   RW      485    elab_export    elab_export.o
0x2000010c        -       0x00000274   Zero   RW      242    .bss           shell_export.o
0x20000380        -       0x0000000c   Zero   RW      276    .bss           led.o
0x2000038c        -       0x000001b8   Zero   RW      357    .bss           elab_uart_debug.o
0x20000544        -       0x00000120   Zero   RW      611    .bss           elab_log.o
0x20000664        -       0x0000001d   Zero   RW      714    .bss           shell.o
0x20000681   0x0800624c   0x00000007   PAD
0x20000688        -       0x00000400   Zero   RW     1192    STACK          startup_stm32g070xx.o

refrence

  1. 了解STM32的内部FLASH空间
  2. STM32内存分配以及堆栈、变量、代码等的存储位置理解与分析
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 207,113评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,644评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 153,340评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,449评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,445评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,166评论 1 284
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,442评论 3 401
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,105评论 0 261
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,601评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,066评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,161评论 1 334
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,792评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,351评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,352评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,584评论 1 261
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,618评论 2 355
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,916评论 2 344

推荐阅读更多精彩内容