STM32F0x IAP application software

Publisher:电子创新者Latest update time:2019-03-11 Source: eefocusKeywords:STM32F0x Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

-------------------------------------------------------------------------------------------


IAP+APP is the most basic remote upgrade kit, but many people ignore the importance of IAP upgrade software. Here we will talk about this IAP upgrade software. I will not consider xmode and ymode for now, because they are not practical at all: they are not compatible with different WINDOWS platforms, and they have to be divided into X86/64BIT versions. The IAP segment code takes up a lot of space... It can only be used for experiments at most.


-------------------------------------------------------------------------------------------


The STM32F0xx series is much cheaper than the F1 series, and cheapness also brings good things: low power consumption per unit, fewer pins, and a full range of products. However, there are some disadvantages, such as small FLASH capacity, slow computing speed, and even the IAP mechanism cannot be used with the F1 series.


So this article will introduce an IAP and PC-side upper-level IAP application software that can be used by F0.


As we all know, the IAP of F1 series usually takes up 12K space (08000000-08003000), or a smaller one takes up 8K space (08000000-08002000). This is not much for the 32K starting point of FLASH of F1 series; but it is too much for economical MCU like F0, so first of all, we need to reduce the IAP code segment by half to within 4K (08000000-08001000), which is especially effective for 16K FLASH such as STM32F030F4.


IAP generally uses serial port 1, but for STM32F042xx and other chips, it is recommended to use serial port 2. The IAP code should be modified because the serial port 1 of these chips is mostly reused for CAN/USB, and these modifications are also relatively easy.


Then the next part is the key content provided in this article: APP code modification, file merging tools, and IAP application software.


-------------------------------------------------------------------------------------------


1. APP code modification


This should be a long-standing topic. First of all, the interrupt vector offset problem. The interrupt vector offset of the F1 series is relatively simple, while that of the F0 series is slightly different, as follows:


     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);


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

        VectorTable[i] = *(__IO uint32_t *)(APPLICATION_ADDRESS + (i << 2));//APPLICATION_ADDRESS =0x08001000

    SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);

    


Please note: the above paragraph must be placed at the very beginning of the MAIN function, especially before each NVIC configuration; if the position is wrong, it is very likely to cause a runaway due to an unexpected interrupt!!!


Secondly, in order to save FLASH space, the FLASH flag is not used as the jump basis, but BKP0 is used as the flag register, as follows:


#ifdef IAP_DEBUG

        case 0xe0:

            if((UART1_RXB[2] == 0x01) && (UART1_RXB[3] == 0x01)) //The serial port receives specific data and enters IAP mode

            {

                RTC_WriteBackupRegister(RTC_BKP_DR0, 0xABABABAB); //Write IAP flag at BKP0 (0xABABABAB)

                NVIC_SystemReset(); //After restarting, IAP will check the BKP0 register

            }

            break;

#endif


Because as long as the power is not lost, the data of the BKP register will not be lost during the SystemReset process, and it is completely possible to save the key flag data during the APP jump to IAP. Of course, the use of BKP needs to follow the ST manual and turn on the PWR\RTC function. Minor details will not be explained here.


Note: One advantage of using the BKP register is that the IAP code segment does not need to consider the FLASH size of the chip, and can be made universal for the entire series. Because the BKP addresses of chips with different capacities are consistent, the entire series can use the same IAP code; while using the FLASH method, the IAP segment code must be modified and recompiled according to the FLASH capacity of the chip. For example, the IAP segment of the stm32F0XX6/XX8 series cannot be universal, one is 32K and the other is 64K. Because the end FLASH addresses are different, the corresponding upgrade flag address must be modified, resulting in poor universality.


Then you need to set the starting position in the development tool. Here we take IAR as an example:


-------------------------------------------------------------------------------------------


2. File Merger Tool


Regardless of the type of IAP, you need to use a burning tool to burn the IAP segment first, and then burn the APP through IAP. However, this will cause troublesome operation and complicated production process.


Using a file consolidation tool can reduce this time.


This tool is used to merge the IAP segment and APP segment into the same file, which is convenient for one-time burning and avoids the trouble of secondary burning.



Of course, this tool will also write all the free FLASH in the APP segment to FF to avoid unexpected problems caused by residual code.


-------------------------------------------------------------------------------------------


3. IAP Application Software


Why spend so much time and effort to develop UI software? MCU engineers always take on some outsourcing projects, and inevitably encounter such problems:


    A. Authorize burning, but cannot control the quantity;


    B. Burning by yourself is time-consuming and laborious, and the logistics cost is high;


    C. Risk of code leakage or decryption;


    D. It is inconvenient to upgrade and difficult to deal with emergencies.


Because tools like JLINK, STLINK, and ULINK do not have counting functions or authorization files, anyone can burn and read all the codes, even if the read protection is not effective. This brings the above embarrassing problems.


IAP application software can solve these problems.



The authorization file is under development, so stay tuned (actually, I find it troublesome. The encryption function is inconvenient to use, and the most important thing is that I forgot the encryption algorithm once and got myself into trouble. I will add it in later if needed)


-----------------------------------------------------------------------------------------

Keywords:STM32F0x Reference address:STM32F0x IAP application software

Previous article:LIN bus development: STM32F0 TJA1020
Next article:STM32F0 USART wakeup from STOP mode

Latest Microcontroller Articles
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号