Notes on IAP migration of STM32F0 via serial port (including RAM & ROM address settings)

Publisher:温柔之风Latest update time:2018-04-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

STSW-STM32116 is a USART import IAP sample program for STM32F0 based on the standard library on ST official website. Download link: http://www.stmcu.org/document/detail/index/id-213120

The project was originally designed for STM32F051. This article will introduce how to migrate to STM32F070 and deal with the problems encountered during the migration process one by one.

2 KEIL transplantation

IAP programs are generally divided into two, one is IAP and the other is APP. IAP is stored at the starting position of 0x8000000 of the built-in FLASH, while APP is stored at a certain distance from this position. This distance must be greater than or equal to the space occupied by IAP itself. In this example, it is 0x8003000.

After downloading the resources, open the binary_template project under STM32F0xx_AN4065_FW_V1.0.0\Project\STM32F0xx_IAP\. This is the APP project. First, open it with KEIL and change the device to STM32F070.


And compile, it turns out that the original formula cannot be compiled, with the following error message:

  1. linking...  

  2. .\STM320518_EVAL\STM320518_EVAL.axf: Error: L6971E: system_stm32f0xx.o(.data) type RW incompatible with main.o(.ARM.__AT_0x20000000) type ZI in er RW_IRAM1.  

  3. Not enough information to list image symbols.  

  4. Finished: 1 information, 0 warning and 1 error messages.  

  5. ".\STM320518_EVAL\STM320518_EVAL.axf" - 1 Error(s), 0 Warning(s).  

  6. Target not created.  

  7. Build Time Elapsed: 00:00:08  

Judging from the literal meaning, the RW data in the data segment (.data) of the target file system_stm32f0xx.o generated by compiling the system_stm32f0xx.c file conflicts with the data in main.o at address 0x20000000.

Looking at the code carefully, I found this paragraph before the main function:

  1. #if (defined ( __CC_ARM ))  

  2.   __IO uint32_t VectorTable[48] __attribute__((at(0x20000000)));  

  3. #elif (defined (__ICCARM__))  

  4. #pragma location = 0x20000000  

  5.   __no_init __IO uint32_t VectorTable[48];  

  6. #elif defined ( __GNUC__ )  

  7.   __IO uint32_t VectorTable[48] __attribute__((section(".RAMVectorTable")));  

  8. #elif defined ( __TASKING__ )  

  9.   __IO uint32_t VectorTable[48] __at(0x20000000);  

  10. #endif  

It can be seen that the code is to force the interrupt vector table VectorTable to be defined at memory 0x20000000, but this address conflicts with the global variable position defined in system_stm32f0xx.c. Therefore, it needs to be modified to avoid the conflict. The address of the interrupt vector is fixed, but the addresses of other global variables can be moved accordingly, and the burning location of the APP is 0x8003000, as shown below:

Compile again and the error should go away.

In addition, you need to modify the first few lines of code in the main function:

  1. int main(void)  

  2. {  

  3.   uint32_t i = 0;  

  4.   

  5.   /*!< At this stage the microcontroller clock setting is already configured,  

  6.        this is done through SystemInit() function which is called from startup 

  7.        file (startup_stm32f0xx.s) before to branch to application main. 

  8.        To reconfigure the default setting of SystemInit() function, refer to 

  9.        system_stm32f0xx.c file 

  10.      */   

  11.   

  12. /* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/    

  13.   

  14.   /* Copy the vector table from the Flash (mapped at the base of the application 

  15.      load address 0x08003000) to the base address of the SRAM at 0x20000000. */  

  16.   for(i = 0; i < 48; i++)  

  17.   {  

  18.     VectorTable[i] = *(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));  

  19.   }  

  20.   

  21.   /* Enable the SYSCFG peripheral clock*/  

  22.   //RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);   

  23.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); //Need to be modified like this  

  24.   /* Remap SRAM at 0x00000000 */  

  25.   SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);  

  26.   

  27. /...  

  28. }  

Open the corresponding map file, which contains the following content:

  1. GPIO_PIN 0x08003470 Data 8 stm320518_eval.o(.constdata)  

  2.    GPIO_CLK 0x08003478 Data 16 stm320518_eval.o(.constdata)  

  3.    BUTTON_PIN 0x08003488 Data 14 stm320518_eval.o(.constdata)  

  4.    BUTTON_CLK 0x08003498 Data 28 stm320518_eval.o(.constdata)  

  5.    BUTTON_EXTI_LINE 0x080034b4 Data 14 stm320518_eval.o(.constdata)  

  6.    BUTTON_PORT_SOURCE 0x080034c2 Data 14 stm320518_eval.o(.constdata)  

  7.    BUTTON_PIN_SOURCE 0x080034d0 Data 14 stm320518_eval.o(.constdata)  

  8.    BUTTON_IRQn 0x080034de Data 14 stm320518_eval.o(.constdata)  

  9.    COM_USART_CLK 0x080034ec Data 4 stm320518_eval.o(.constdata)  

  10.    COM_TX_PORT_CLK 0x080034f0 Data 4 stm320518_eval.o(.constdata)  

  11.    COM_RX_PORT_CLK 0x080034f4 Data 4 stm320518_eval.o(.constdata)  

  12.    COM_TX_PIN 0x080034f8 Data 2 stm320518_eval.o(.constdata)  

  13.    COM_RX_PIN 0x080034fa Data 2 stm320518_eval.o(.constdata)  

  14.    COM_TX_PIN_SOURCE 0x080034fc Data 2 stm320518_eval.o(.constdata)  

  15.    COM_RX_PIN_SOURCE 0x080034fe Data 2 stm320518_eval.o(.constdata)  

  16.    COM_TX_AF 0x08003500 Data 2 stm320518_eval.o(.constdata)  

  17.    COM_RX_AF 0x08003502 Data 2 stm320518_eval.o(.constdata)  

  18.    RegionBase 0x08003504 Number 0 anonTable)  

  19.    RegionLimit 0x08003524 Number 0 anonTable)  

  20.    VectorTable 0x20000000 Data 192 main.o(.ARM.__AT_0x20000000) //The vector table location is 0x20000000  

  21.    SystemCoreClock 0x200000c0 Data 4 system_stm32f0xx.o(.data) //The starting position of other global variables is 0x200000C0  

  22.    AHBPrescTable 0x200000c4 Data 16 system_stm32f0xx.o(.data)  

  23.    GPIO_PORT 0x200000d4 Data 16 stm320518_eval.o(.data)  

  24.    BUTTON_PORT 0x200000e4 Data 28 stm320518_eval.o(.data)  

  25.    COM_USART 0x20000100 Data 4 stm320518_eval.o(.data)  

  26.    COM_TX_PORT 0x20000104 Data 4 stm320518_eval.o(.data)  

  27.    COM_RX_PORT 0x20000108 Data 4 stm320518_eval.o(.data)  

  28.    __initial_sp 0x20000510 Data 0 startup_stm32f0xx.o(STACK)  


As mentioned above, the interrupt vector table is compiled at 0x20000000, the beginning of the memory, and the global variable SystemCoreClock under system_stm32f0xx.c is compiled by KEIL to be placed next to 0x200000C0, which is exactly as expected. Burn IAP and APP into FLASH respectively, and the test can run normally.

Note: Under KEIL, IAP must exist to debug the APP! This is different from IAR.


3 Porting under IAR

There is nothing special about IAP under IAR, it mainly depends on the configuration of the APP.

Use IAR to open the APP project and change the device to STM32F070:


Link configuration:

Interrupt vector table:


Memory Map:



As above, the APP is stored in the FLASH location 0x8003000, and the memory is still set to: 0x20000000.

After compilation, open the corresponding map file as shown below:


  1. Entry Address Size Type Object  

  2. ----- ------- ---- ---- ------  

  3. .iar.init_table$$Base 0x080034fc -- Gb - Linker created -  

  4. .iar.init_table$$Limit 0x08003510 -- Gb - Linker created -  

  5. ?main 0x08003511 Code Gb cmain.o [4]  

  6. CSTACK$$Base 0x200000d8 -- Gb - Linker created -  

  7. CSTACK$$Limit 0x200010d8 -- Gb - Linker created -  

  8. Delay 0x080031e3 0x10 Code Gb main.o [1]  

  9. GPIO_PIN 0x080035a0 0x8 Data Gb stm320518_eval.o [1]  

  10. GPIO_PORT 0x200000c0 0x10 Data Gb stm320518_eval.o [1] //The global variable GPIO_PORT array in the stm320518_eval.c file is stored at 0x200000c0  

  11. HardFault_Handler 0x08003573 0x4 Code Gb stm32f0xx_it.o [1]  

  12. NMI_Handler 0x08003571 0x2 Code Gb stm32f0xx_it.o [1]  

  13. NVIC_SetPriority 0x080030c1 0x84 Code Lc main.o [1]  

  14. PendSV_Handler 0x08003579 0x2 Code Gb stm32f0xx_it.o [1]  

  15. RCC_APB2PeriphClockCmd 0x08003229 0x20 Code Gb stm32f0xx_rcc.o [1]  

  16. RegionBase 0x080034fc -- Gb - Linker created -  

  17. RegionLimit 0x08003510 -- Gb - Linker created -  

  18. STM_EVAL_LEDToggle 0x08003315 0x26 Code Gb stm320518_eval.o [1]  

  19. SVC_Handler 0x08003577 0x2 Code Gb stm32f0xx_it.o [1]  

  20. SYSCFG_MemoryRemapConfig  

  21.                         0x0800324d 0x14 Code Gb stm32f0xx_syscfg.o [1]  

  22. SetSysClock 0x080033b7 0xbe Code Lc system_stm32f0xx.o [1]  

  23. SysTick_Config 0x08003145 0x32 Code Lc main.o [1]  

  24. SysTick_Handler 0x0800357b 0x8 Code Gb stm32f0xx_it.o [1]  

  25. SystemCoreClock 0x200000d0 0x4 Data Gb system_stm32f0xx.o [1]  

  26. SystemInit 0x08003349 0x6e Code Gb system_stm32f0xx.o [1]  

  27. TimingDelay 0x200000d4 0x4 Data Lc main.o [1]  

  28. TimingDelay_Decrement 0x080031f3 0x16 Code Gb main.o [1]  

  29. VectorTable 0x20000000 0xc0 Data Gb main.o [1] //The vector table is compiled at 0x20000000  

  30. __aeabi_idiv0 0x08003345 Code Gb IntDivZer.o [4]  

  31. __aeabi_uidiv 0x08003265 Code Gb I32DivModFast.o [4]  

  32. __aeabi_uidivmod 0x08003265 Code Gb I32DivModFast.o [4]  

  33. __cmain 0x08003511 Code Gb cmain.o [4]  

  34. __exit 0x08003545 0x14 Code Gb exit.o [5]  

  35. __iar_copy_init3 0x080034a5 0x30 Code Gb copy_init3.o [4]  

  36. __iar_data_init3 0x080034d5 0x28 Code Gb data_init.o [4]  

  37. __iar_program_start 0x08003595 Code Gb cstartup_M.o [4]  

  38. __low_level_init 0x0800352b 0x4 Code Gb low_level_init.o [3]  

  39. __vector_table 0x08003000 Data Gb startup_stm32f0xx.o [1]  

  40. _call_main 0x0800351d Code Gb cmain.o [4]  

  41. _exit 0x08003539 Code Gb cexit.o [4]  

  42. _main 0x08003527 Code Gb cmain.o [4]  

  43. exit 0x0800352f 0x8 Code Gb exit.o [3]  

  44. main 0x08003177 0x6c Code Gb main.o [1]  


As shown above, under IAR compilation, the interrupt vector table is compiled at 0x20000000, the starting position of the memory, and the global variable GPIO_PORT under stm320518_eval.c is compiled by IAR to be placed at the next position 0x200000C0. Burn IAP and APP into FLASH respectively, and the test can run normally.



Note: From the link configuration of the IAR project, the RAM location is not configured as 0x2000000 like KEIL, and the resulting vector table after compilation will not conflict with other global variables. It can be seen that the IAR compiler has automatically calculated and avoided this conflict, unlike KEIL, which will not cause a link error to prompt the user.


In addition: Under IAR, you can debug the APP even if there is no IAP. This is a feature that KEIL does not have. It seems that IAR is better than KEIL in handling details.


Reference address:Notes on IAP migration of STM32F0 via serial port (including RAM & ROM address settings)

Previous article:Detailed explanation of hex file stm32
Next article:STM32F030 ADC1 DMA sampling problem

Recommended ReadingLatest update time:2024-11-16 19:31

Understanding of peripheral working clock and control clock in STM32F0
When using the I2C1 of the STM32F0 chip, according to the STM32F0 reference manual, the clock of I2C1 can be selected as HSI or SYSCLK.  For example, when selecting HSI as the working clock of I2C1, when generating the initialization code with the STM32CUBEMX configuration, the APB clock of I2C1 must also be configure
[Microcontroller]
Understanding of peripheral working clock and control clock in STM32F0
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号