Use trace32 for flash Programming

Source: Internet
Author: User

As the complexity of software and hardware increases, the debugger plays an increasingly important role in the development progress and quality of projects in embedded system development. Among the many debuggers, lauterbach's trace32 has become a debugging tool widely used in embedded system development, especially in high-end systems, thanks to its powerful functions and outstanding performance.

In addition to setting breakpoints and tracing debugging for code, trace32 can also control the programming of flash in the target system. This article first compares two trace32 flash programming methods: "emulator controlled flash programming" and "target controlled flash programming", and points out the advantages of "target controlled flash programming; the trace32 script commands related to flash programming and the communication mechanism between trace32 script commands and flash programming software are introduced. Finally, the control process of the "target controlled flash programming" method is given.

Note: The term "programming" used in this article not only has the meaning of Flash burning, but also includes erasure, verification, and other flash operations.

I. Flash programming methods

Two programming methods are available for flash in the target system: emulator controlled flash programming and target controlled flash programming ".

In the "emulator controlled flash programming" mode, all flash programming operations are completed by emulator and the resources of the target system are not used. Trace32 software supports almost all the flash chips on the market (you can access the http://www.lauterbach.com/ylist.html to query trace32 supported flash models), as long as the script command flash. in create, specify the target flash model, address range, and bus configuration. You can use the script command to directly write data to flash without writing any code for flash operations.

In the "target controlled flash programming" mode, the flash Programming Control is completed by the flash programming software running on the target system, which must be developed by the user. In this case, trace32 uses scripts to access the memory address space of the target system and transmits control parameters and data to the Flash programming software.

Because it runs directly on the processor of the target system, the "target controlled flash programming" method can achieve much faster programming speed than the "emulator controlled flash programming" method. This is very important for writing large files and production lines. In addition, as long as you compile the corresponding flash programming software, any flash you choose can be supported.

Therefore, you can use the "emulator controlled flash programming" method if Flash programming requires less content or less time. However, the "target controlled flash programming" method is the only option for files that require high programming speed. This article only discusses the "target controlled flash programming" method.



Ii. trace32 script

On the trace32 interface, you can use the menu, mouse to complete the operation, or use commands. In fact, trace32 is embedded with powerful command and script processing functions. The trace32 command can not only complete all functions, but also provide more control and flexibility than the menu method. The script is suffixed with. CMM.

The following describes the flash operation-related commands in trace32, as shown in the following table:

The detailed format of the command to be used is listed here for reference.

1. Flash. Create
Format:

FLASH.Create <unit_number> <physical_range> <sector_size> <family_code><bus_width><family_code>: I28F001B | I28F200B | ... | TARGET | EEPROM | NOP<bus_width>: Byte | Word | Long | Quad

For example, define am29lv640 (16 Bit mode, 16 bit bus, 128 sectors, 64 Kbyte/sector)

FLASH.RESetFLASH.Create 1. 0x0 -- 0x7FFFFF 0x10000 AM29LV100 Word

If the target controlled flash programming mode is used, familiy_code must be set to target. The connection with Flash programming software is completed by flash. Target.

2. Flash. Erase
Format:

FLASH.Erase <unit> | <address_range> | ALL

For example:

FLASH.Erase 0x0 -- 0x1FFFFFLASH.Erase ALL

3. Flash. Program
Format:

FLASH.Program [<unit> | <address_range> | ALL | OFF]

Once the programming mode is activated, any write access to the flash Address Space will lead to flash programming. For example:

Flash. Program alldata. Load. binary data. bin/word <-load data to the Flash space flash. program off...

4. Flash. Target
Format:

FLASH.TARGET <code_address> <data_address> [<buffer_size>] [<file>] <code_address>

The starting RAM address of the flash programming software downloaded to the target system. The size occupied is the size of the flash programming software, plus 32 bytes.

  • <Data_address>
    The starting address of the parameter block. The size is 32 bytes (parameter block) + <buffer_size> + 256 bytes (stack ).
  • <Buffer_size>
    The number of bytes of data transferred from the trace32 software to the Flash programming software at a time. The recommended buffer size is 4 kb.
  • <Flash_algorithm>
    Binary flash programming software.

The general steps for flash programming using the above commands are:

1) First, use flash. Create to define the address space, type, and bus configuration of the target flash.

2) for the "target controlled flash programming" method, flash programming software must be loaded to the target system. The Flash. Target command notifies trace32 of the starting address of the flash programming software, the starting address of the parameter block, and the buffer size. The Flash. Program and Flash. Erase commands call the specified flash programming software and pass the appropriate parameters.

3) Flash. after program starts the programming mode, if data transmission commands (such as data. set or data. load), trace32 will check whether the data transmission address falls into the flash address space defined in 1. If yes, trace32 will fill some data into the data buffer according to the buffer size, initialize the parameter block, set the target system PC as the starting address of the flash programming software, and start execution. After the execution is complete, control is returned to trace32. Trace32 checks the returned information (also in the parameter block). If it is normal, continue to process the remaining data.

The following is an example:

The Flash configured in the target system is Intel strata flash 28f320j3a (16 Bit mode, word access), and the CPU is ARM core.

The memory image (memory map) of the target system is:

  • Flash: 0x0-0x3fffff
  • Ram start address: 0xa0000000

The corresponding trace32 script is:

FLASH.RESetFLASH.Create 1. 0x0--0x3FFFFF 0x20000 TARGET WordFLASH.Target 0xA0000000 0xA0001000 0x1000 ~~/demo/arm/FLASH/word/i28f200j3.binFLASH.Erase 1.FLASH.Program 1.Data.LOAD.Elf my_application.elf /WordFLASH.Program OFF

First, create a flash area 1 through flash. Create. The address range is 0x0 to 0x3fffff, and the sector size is 0x20000. The programming software for this flash area is specified by target. The word parameter indicates the data width (which can also be byte, long or quad) of the target system CPU to Access Flash ).

Flash. Target specifies that the programming software for the flash area is located at 0xa0000000, and the parameter block is located at 0xa0001000. The parameter block is usually followed by the data buffer, and the buffer size is 0x1000. The programming software is ~~ /Demo/ARM/flash/word/i28f200j3. Bin.

Then erase flash Area 1 and start the flash programming mode.

The data. Load. Elf command loads my_application.elf to the Flash area, triggering the flash programming software and writing it to the specified flash area.

Finally, disable the flash programming mode.



3. Communication between trace32 commands and flash Programming Software

The preceding example shows that there is a data exchange zone-parameter block between the trace32 software and the flash operating program, which is used to pass control commands and data and return operation results. The parameter block location is specified by data_address in the Flash. Target command. The parameter block is a buffer.

Parameter blocks are defined as follows:

After the operation is complete, the returned results of the parameter block storage operation are as follows:

The parameter block and the corresponding C language that follows the buffer are defined as follows:

struct {    ulong32 flashaddr;    ulong32 flashwidth;    ulong32 width;    ulong32 offset;    ulong32 addr;    ulong32 size;    ulong32 reserved;    ulong32 status;/* in: 1=program, 2=erase, out: 0=o.k., 0x100=fail */    uchar8 data[4096];/* Programming Buffer, size can be made smaller (FLASH.TARGET command) */} FlashParameter;


4. Target controlled flash Programming process

The general process for developing the "target controlled flash programming" method is as follows:

1. Compile the flash programming software running on the target system

2. Load the flash programming software to the ram of the target system (using the data. Load command)

3. Run the Flash. Create and Flash. Target commands to connect trace32 to the Flash programming software on the target system.

4. Use commands such as flash. Program and Flash. Erase to control flash operations on the target system. These commands will call the relevant functions in the Flash programming software and pass appropriate parameters

Instance (am29f800)

The target system has two flash models: am29f800. The data width of each flash block is 16 bits, and the two are merged into 32 bits. Each flash disk has a size of 1 MB, and its starting address is 0x200000.

The target system is also configured with SRAM, which is 8 KB and the address range is 0 h to 1 fffh.

The Flash programming software developed for the target system is flashprog. Bin (450 h in size, in binary format ). The parameter block is scheduled to start at the address 0 h of the SRAM.

The application that needs to be burned into the flash of the target system is application. Elf (ELF format, starting from 0x200000 ). It must be noted that when application. Elf is generated during the connection, the start position of the script-SCL file must be specified as 0x200000. In this way, the "data. Load. Elf application. Elf" command loads application. Elf to the address space starting from 0x200000.

For such an application, you need to write a control script (CMM file) and develop a flash programming software. The following describes the content of the control script, and then provides the flash programming software process.

Control script

The content of the control script is as follows:

1) make necessary target system settings, especially the chip selection configuration, so that both the SRAM and Flash are in the allocated address space.

2) Load flash programming software flashprog. bin to the SRAM address 0x1200: Data. Load. B flashprog. Bin 1200

3) set a breakpoint (break. Set swbp) at the end of the fl_3 programming software. After the execution, the control can be returned to trace32.

4) Notify trace32 about flash configuration, flash programming software location, parameter block and data buffer location

FLASH.Create 200000--3fffff TARGET LONGFLASH.TARGET 1200 0 1000

The memory of the SRAM is:

5) erase the entire flash
Flash. Erase all

6) Programming Application application. Elf
Flash. Program all
Data. Load. Elf application. Elf
Flash. program off

When the Flash. Erase all command is executed, the erased function of the flash programming software is called, and the corresponding parameter blocks are filled:

At this time, the data buffer has no content.

After the erasure is complete, when a breakpoint is set, the control is handed back to trace32, And the status is returned in the parameter table:

When data. Load. Bin application. Bin is executed, the programming function of the flash programming software is called, and the corresponding parameter blocks are filled:

In this case, the buffer is filled with the data to be programmed.

After the programming is complete, the control is handed back to trace32, And the status is returned in the parameter table:

If no error occurs, the above programming process will continue until all data in application. Bin is transferred.

Flash Programming Software

The Flash programming software process is as follows:

1) define the data structure of the parameter block:
Struct flashparameter flash_param;
For definitions of flashparameter, see the preceding section.

2) define the function numbers corresponding to each function:

# Define flash_program 0x00000001 # define flash_erase 0x00000002 # define flash_chip_erase 0x00000005... Other feature numbers

3) Main Control Process:

Switch (flash_param.status) {Case flash_program: flash_program (); break; Case flash_erase: flash_erase (); break ;... Other functions} The flash_program () function obtains the programming data, size, and programming target address from the parameter block to implement the flash programming function. The flash_erase () function obtains the destination address and size of the erased object from the parameter block to implement the flash erasure function.

4) Check the SCL file.

RAM 0x200000{    CODE 0x200000     {      main.o (+RO)      * (+RO)    }    APP_RAM +0x0    {      * (+RW, +ZI)    }}    

References

  • Trace32 online help

  • Arm ads online book

About the author

 

Tang Kai can contact him through tangk73@hotmail.com.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.