当前位置:网站首页>[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)

[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)

2022-04-23 17:58:00 Tomorrow is like noon

introduction

  1. bootloader The function of

  2. How to establish reliable bus communication ?

  3. Parsing programming files (S19/HEX/BIN)

  4. NVM Driver development

  5. bootloader Other points of development
    a. bootloader Relationship with Applications
    b.bootloader Jump method to application
    c. Development bootloader Need to master the knowledge and debugging methods and skills
    d. In mass production bootloader And how to download the application

————————————————————

4. NVM Driver development

ECU Of NVM Generally including its MCU Integrated on-chip for storing data EEPROM perhaps Data-Flash And for storing program code / Data Code-Flash/Program-Flash as well as MPU Extended off chip NOR Flash perhaps NAND-Flash;
NVM The driver includes a pair of NVM The erasure of (erase)、 Programming (program) And check (verify) And so on , It also includes the right to NVM The encryption (secure)/ Decrypt (unsecure) And protection (protection)/ Remove the protection (unprotection) operation .

Tips:

a. MCU On chip integration NVM in EEPROM/D-Flash and C_Flash/P-Flash Generally belong to different block, So you can go straight to Flash Up operation NVM Drive right EEPROM/D-Flash Erase and program ;

b. NVM drive Usually by running a NVM command Sequence , To pass through NVM The controller registers give different values NVM Operation command code 、NVM Programming data and target address , Typical NVM command The sequence is as follows (Freescale Of S12(X) series MCU Flash write command Sequence ):
 Insert picture description here

c. because NVM The working speed of is generally CPU Low core frequency and bus frequency , therefore function NVM Before driving, it is necessary to NVM To initialize , Set the working frequency of the frequency divider to the frequency range required for normal operation ;

d. **MCU Intraslice NVM The same block Can't run on NVM The driver erases and programs itself , Otherwise, it will spread read while write Bus access conflict ( Every NVM block There is only one data bus , You can only read or write at a time , Simultaneous read and write are not supported ).** So for only one block Flash Of MCU Come on , Must be in RAM Call it in NVM drive , To erase and program itself , At the same time launch Flash command To wait command Must be closed during completion CPU Global interrupt , Disable peripheral interrupt response , Otherwise, take the interrupt vector and run interrupt ISR Will visit Flash. Make it possible to interrupt , You must offset the interrupt vector table to RAM perhaps NVM block(EEPROM/D-Flash) And interrupt the response ISR Also copy to other RAM perhaps NVM block On ( Of course, the interrupt vector table must also be updated to guide new interrupts ISR);

e. Because of the above b The requirements of , It is usually necessary to bootloader Of NVM Drive copy to MCU Of RAM Run in , What it can do NVM copy to RAM Run in , You can also copy only NVM command launch To wait command Several completed instructions to RAM Execution can be , because NVM Other operations in the drive ( For example, fill in NVM Operation command 、 Write programming address and data, etc ) It does not go to the occupied data bus NVM Middle write data ;

f. NVM The driver for resides in Flash in , In case of stack overflow and other accidents, the program runs away and runs unexpectedly NVM Drivers can cause NVM Accidental erasure, loss or modification of content . Therefore, the key data or code ( such as bootloader In itself ) Protect against accidental modifications , Or a safer way is not to NVM The driver is stored in NVM in , But in bootloader At first, it was downloaded to... Through the upper computer RAM Run in ,bootloader After that, the area RAM eliminate , So as to avoid accidental operation NVM Caused by the driver NVM Data loss and modification .(PS: Later, I will write an article to introduce the relevant methods , Please pay attention to reading )

g. commonly MCU Manufacturers will give their MCU Of NVM Driver library , Users can use this class library to realize NVM operation , If it is Freescale/NXP Car class MCU, You can also use CodeWarrior IDE Integrated Processor Expert Generate corresponding NVM The driver ;

5. bootloader Other points of development

a. bootloader Relationship with Applications

bootloader And applications are two complete MCU Software Engineering , Each has its own startup code 、main() function 、 Link to the file 、 Peripheral driver and interrupt vector table ;
 Insert picture description here
therefore bootloader And the link file of the application , Yes NVM The allocation of address space must be separate , It can't overlap (overlap), But it's RAM There are no constraints on allocation , Both can use the entire RAM Space , Because after jumping to application engineering , The startup code will reinitialize RAM;

== bootloader You have to use MCU Default interrupt vector table , Because after each reset MCU It is executed by taking the address from the reset vector of its default interrupt vector table ==; The interrupt vector of the application must be offset ( Through the corresponding interrupt vector offset register , Such as S12(X) series MCU Of IVBR Register or ARM Cortex M series MCU Of SCB->VTOR register ); and NVM(P-Flash) All erasures are in accordance with sector On going , So in order to make full use of NVM(P-Flash) Space , All will bootloader Partition to several tables containing the default interrupt vector NVM(P-Flash)sector(S12(X) series MCU Of NVM The last few sector, ARM Cortex M series MCU from 0 The address starts with a number of sector);

b.bootloader Jump method to application

Development use bootloader after , Every time ECU After reset, it will run first bootloader, If there is no remote application download request, directly jump to the application reset function address , There are two questions to consider :

How to get the address of the application reset function : There are methods :
1) Fix the reset startup function address of the application through the linked file ;
2) Get from the reset vector address of the application interrupt vector table ;
Recommended approach 2): Because of its good flexibility , Every time the application changes, there is no need to care that the application reset function is compiled into NVM The specific address of , Just take out the reset vector in the application interrupt vector table and run it :

Typical methods are as follows ( hypothesis S12(X) series MCU Application interrupt vector table base address register IVBR=0x7F):

typedef void (near tIsrFunc)(void);/ ISR prototype definition */

word *Ptr; /pointer used for ISR vector fecth/

Ptr = (word *)0x7FFE; /*get the ISR vector from the interrupt vector table of APP project */

((tIsrFunc)(*Ptr))(); /covert and run/

Jump timing : There are methods :
1)bootloader Update the application and verify its integrity OK after , Peripherals to be used ( such as CAN/LIN Communication bus module 、 Timer 、GPIO etc. ) The register returns to the default state after reset , Then jump directly ;【 Software reset 】
2)bootloader Update the application and verify its integrity OK after , Wait for watchdog timer timeout overflow reset , stay bootloader At first, judge that there is no remote application download request and jump ;【 Hardware reset 】
Recommended use 2): Because of the method 1) Equivalent to software reset , When it jumps to the application reset startup function MCU Your hardware environment may be different from running applications directly , and Method 2) The watchdog reset belongs to hardware reset , It will most peripherals ( simulation 、 Clocks and peripherals ) Circuit reset , Closer to running the application directly .

c. Development bootloader Need to master the knowledge and debugging methods and skills

First , Development bootloader Need to be right ECU Used MCU Of RAM and NVM Resources are very clear , And then partition it , Ensure that the application and bootloader Of NVM The allocation does not overlap . Therefore, we must understand the software development tools used IDE How to use and write rules of linked files ;

secondly , You need to judge whether the interrupt vector table offset is successful ,NVM Information such as the address and size of the driver copy , Therefore, we must master the software development tools used IDE In the compilation link results of map Details of the document ;

Besides , Master how to NVM Function redirection ( Separate the storage address of function program code from the runtime address ) To RAM The methods implemented in are also very useful ;

Tips:

When developing an application , It needs to be debugged separately to ensure its normal function , At this time, although the peripheral interrupt vector table has been offset , But its reset vector must be placed in the address of the reset vector in the default interrupt vector table , Otherwise, it cannot run after downloading , Conduct normal commissioning , Because if the reset vector of the application is placed in the offset application interrupt vector table , be The default reset vector content is 0xFFFF(Flash Status after erasure ),CPU The kernel will arrive 0xFFFF Address fetching operation of , Obviously not a real project startup function , So it can't run , The result is a new MCU When no program is written, the power on operation is the same , Will continue to appear illegal address reset ; And after the application development is completed , Then offset it into the application interrupt vector , To avoid contact with bootloader engineering Flash Address conflict ;

Last , Master the of using debugger Hotsync perhaps attach Method loading elf The debugging information in the file is correct bootloader Seamless debugging with applications is also very practical , Can be greatly improved bootloader Debugging efficiency ;

d. In mass production bootloader And how to download the application

recommend take bootloader Merge with the programming files generated by the application compilation link , Disposable Use mass production tools ( Such as Cyclone The programmer ) download To improve productivity .

This paper introduces automobile electronics in detail ECU bootloader General working principle and key points of development , It applies to all automotive electronics ECU bootloader Development , Of course it's different MCU Its software development tools IDE and CPU The processing mechanism of interrupt in kernel is different

版权声明
本文为[Tomorrow is like noon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230546376421.html