Solution to STM32 IAP not being able to run user programs

Publisher:真诚相伴Latest update time:2016-10-07 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
IAP Program:
It mainly sets the starting address of the user program, APPLICATION_ADDRESS, such as 0x08004000, and writes the user code into the user area of ​​FLASH through the peripheral. When the conditions are met, jump to the starting address of the user area.
Explain the jump code:
/* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */
if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000) // Check if the stack top address is between 0x2000 0000 - 0x2000 2000
// Determine whether the user application has been downloaded by judging whether the stack top address value is correct. Because the user program startup file will initialize the stack space at the beginning, if the stack top address is correct, it means that the user program has been downloaded.
__set_PRIMASK(1); // Disable global interrupt. Note that global interrupt must be disabled before jumping. After entering the user program, enable interrupt after the interrupt vector table address is set.
 
printf("Jump to the new program.\r\n");
/* Jump to user application */
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); // The first 4 bytes are the interrupt vector table
Jump_To_Application = (pFunction) JumpAddress; // Point to the address where the user program reset function is located
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); // Set the stack pointer of the user program
Jump_To_Application(); // Execute user program
}
 
It should be noted that in the IAP program, the global interrupt needs to be disabled before jumping to the user program.
You can see the discussion on the forum http://www.amobbs.com/thread-5606964-1-1.html
 
User Program:
The main thing is to set the offset address of the interrupt vector table and the ROM start address in the project options. It should be noted that the interrupt vector table should be set after SystemInit(), and the global interrupt should be enabled.
The interrupt vector table can be set at the beginning of main.
Modification of project options
Solution to STM32 IAP not being able to run user programs - yaoohui - Two-person factory
 
 
Add the part of setting the interrupt vector table at the beginning of the main function
//Use IAP to modify the base address of the user program area. It must be an integer multiple of 0x200 (stm32f205)
// Note: Modify the project options accordingly: IROM1: start: 0x8004000
#ifdef VECT_TAB_RAM  
/* Set the Vector Table base location at 0x20000000 */ 
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 
#else /* VECT_TAB_FLASH */ // Modify the FLASH vector table, the starting address starts from 0x8004000 as the user program area
/* Set the Vector Table base location at 0x08000000 */ 
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000);   
__set_PRIMASK(0); // Enable global interrupt
#endif
 
The user program needs to be converted to .bin format. In the project options, add fromelf.exe --bin -o "$L@L.bin" "#L" in User->After Build/Rebuild to output the bin file in the output directory.
Solution to STM32 IAP not being able to run user programs - yaoohui - Two-person factory
You can also add a .bat file to copy the .hex and .bin files, for example:
copy ..\Objects\output.hex Flash\acq_v2_IAPMain.hex
copy ..\Objects\output.bin Flash\acq_v2_IAPMain.bin
 
 
Combined burning:
When burning the program, you need to use the burner to burn the IAP program first, which is the BOOTLOADER part, and then write the user program through the peripheral.
But in fact, these two steps can be combined into one step of burning.
Delete the last ending sentence of IAP's .hex file, that is, delete: 00000001FF; then copy all the contents of the user program's .hex file to the back of IAP's .hex file; finally, burn the integrated .hex file to the starting address of 0x0800 0000.
Keywords:STM32 Reference address:Solution to STM32 IAP not being able to run user programs

Previous article:STM32 ADC and DMA multi-channel processing
Next article:How to release pa15, pb3, pb4 as gpio ports in stm32

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号