With the development of informatization, intelligence and networking, embedded system technology will also have a broad space for development. Embedded technology has been fully developed and has become the common development direction of communication and consumer products. In the field of communication, digital technology is replacing analog technology in an all-round way. In the field of radio and television, the United States has begun to transform from analog television to digital television, and Europe's DVB (digital television broadcasting) technology has been promoted in most countries around the world. Digital audio broadcasting (DAB) has also entered the commercial trial broadcast stage. The role of software, integrated circuits and new components in industrial development is becoming increasingly important. All of the above products are inseparable from embedded system technology. The core technology of Venus, which has an immeasurable future, is to use embedded technology at the chip level of more than 32 bits. In the personal field, embedded products will mainly be used for personal commercial purposes as personal mobile data processing and communication software. This article proposes a design scheme for upgrading embedded systems using the SD card of LPC2148.
2. Overall system upgrade solution design
After the manufacturer produces the product, the user buys it and uses it. When the device has a system vulnerability or the user is not satisfied with the existing functions and puts forward more requirements, the system needs to be upgraded or the system functions need to be maintained. The manufacturer only needs to take back the SD card, put the updated program into the SD card, and then distribute it to the user. The user only needs to insert the SD card into the terminal device. The purpose of system upgrade can be achieved. Figure 1 shows the communication flow chart between the manufacturer and the user. Figure 2 shows the entire system design flow chart. As shown in Figure 1, the communication process between the manufacturer and the user is as follows:
(1) The manufacturer downloads a program similar to the boot loader to the Flash through the ISP method, as shown in Figure 2.
(2) Put the upgrade program into the SD card and ship it with the product.
(3) After the user gets the SD card, he inserts it into the SD card slot and the terminal device starts working.
(4) After using the device for a period of time, if there is a problem or if an upgrade or maintenance is required, the user only needs to return the SD card to the manufacturer.
(5) The manufacturer puts the upgraded program into the returned SD card and returns it to the user. Or the manufacturer directly reissues the SD card to the user without the user having to return the SD card.
(6) After the user gets the SD card, he can directly insert it into the terminal device card to achieve the purpose of upgrading.
Before leaving the factory, a program similar to the Boot Loader is burned into the chip through ISP programming. The implementation of this program is roughly divided into three steps:
(1) SD card underlying driver in SPI mode;
(2) Read the system program from the SD card and put it into the specified Flash address segment:
(3) Jump to the specified Flash address segment and execute the upgraded system.
Before the user inserts the SD card, the program constantly checks whether the SD card is inserted. After the user inserts the SD card, the program first drives the SD card to make it work properly, then reads the upgrade program in the SD card and puts it into the specified Flash address segment. Finally, it jumps to the specified segment and starts working. Manufacturers can arrange the location of the upgrade program as needed.
3. System hardware design
The core processor is LPC2148 from PHILIPS. It is a 32-bit ARM7 microcontroller that supports real-time simulation and embedded tracing. It has 32KB and 512KB embedded high-speed Flash memory. The 128-bit wide memory interface and unique acceleration structure enable 32-bit code to run at the maximum clock rate and have an SPI bus. The selection of this processor mainly considers its rich internal resources, no need to expand the memory and SPI bus, and excellent performance, strong anti-interference ability, low price, and extremely high cost performance. This design is only part of the product circuit. Its hardware circuit is shown in Figure 3. LPC2148 has a synchronous, full-duplex serial interface (SPI), and its maximum data bit frequency is 1/8 of the input clock frequency. It can be set to work as a host or slave. The SD card is driven by the SPI bus protocol, and data is being transmitted. The host always sends one byte of data to the slave, and the slave always sends one byte of data to the host. In Figure 3, the left side is LPC2148 and the right side is the SD card slot. SCK1 is the serial clock, which is used as the data transmission clock signal between LPC2148 and SD card; MISO1 is a unidirectional signal, which is used to transfer data from SD card to LPC2148; MOSll is also a unidirectional signal. It is used to transfer data from LPC2148 to SD card; SSEL1 is the selection signal, which is used to select SD card. Pins 3 and 6 in Figure 3 are grounded respectively, pin 4 is connected to power supply, and pin 8 is used to detect whether SD card is inserted, and can be selected according to actual requirements. The SD card and LPC2148 can coordinate communication through SPI protocol and the organizational form of SD file system. [page] 4. System software design
The system software first initializes the SD card through the SPI protocol, then reads the data in the SD card according to the FAF32 file system organization of the SD card, writes the read data into the Flash through the IAP method, and finally uses a jump program to jump to the segment to achieve the purpose of upgrading.
4.1 SD card initialization
SD card (Secure Digital Memory Card) is a new generation memory device based on semiconductor flash memory. It is widely used in portable devices such as digital cameras, personal digital assistants (PDAs) and multimedia players. SD card was jointly developed by Japan's Panasonic, Toshiba and the United States SanDisk in August 1999. The size of an SD memory card is like a stamp and weighs only 2 grams, but it has high memory capacity, fast data transfer rate, great mobility and good security.
User applications usually access SD cards in the form of files and store and access data in the form of files; the file system layer is implemented by calling the relevant functions of the SD card physical layer, so if you want to access the SD card in the form of a file system, you must first drive the SD. The read and write operations of the SD card are all command-based, and the SD card is controlled by sending corresponding commands to the SD card and reading the corresponding responses. Before reading and writing the SD card, you must first perform initialization operations. This is the premise to ensure that the SD card can read and write data normally in SPI mode. After the SD card is powered on and reset, the default is SD mode. In order to make the SD card enter SPI mode, CS must be set low (at least 74 clocks delayed) and CMDn must be sent through the SPI bus to reset the SD card and activate it at the same time, and perform internal initialization processing to make the SD card exit the idle state.
The SD card initialization flow chart is shown in Figure 4. The read operation of the SPI module in the SD card includes single block read and multiple block read. This system only implements the single block read function. The initialization length is 512 bytes. The implementation of the function is divided into 4 steps: ① LPC2148 sends a single block read command (CMD17) to the SD card, and the SD card responds (Rl format); ② Wait for the SD card to send a read start token; ③ Determine whether the received token is 0xFE; ④ Read data from the SD card.
4.2 SD card file system
After the SD card completes the underlying driver, the data on the SD card can be operated according to the FAT32 file system format, thereby realizing operations such as reading and writing files on the SD card. The FAT32 file system is the highest version of Microsoft's FAT-type file system. It is the most commonly used hard disk file system under Windows today.
When reading a file in an SD card, you must first search for the file's information structure based on the file name. The content of the first cluster in the data area can be found based on the starting cluster number in the file information structure, and the second cluster number can also be found in the FAT table. The content of the second cluster and the third cluster number in the FAT table can be found based on the second cluster number until the end-of-file mark is encountered. In this way, all file data can be read based on the cluster number in the FAT table. Taking Figure 5 as an example, the specific steps for reading SD card files are explained:
(1) First find the file name that matches the directory entry table, such as "Mvfile". From the directory entry corresponding to "Myfile", you can read the first cluster number of the file, 0004:
(2) Access the FAT table according to the first cluster number 0004, and read the FAT table entry content 0005 corresponding to the first cluster number, which is the second cluster number. Access the FAT table again according to the second cluster number, and read the corresponding FAT table content, which is the third cluster number 0006... and so on. Do this in sequence until the last table entry content is FFFF;
(3) From step (2), we know that the file "Myfile" occupies 4 clusters. These 4 cluster numbers form a cluster chain 000dH-0005H-0006H-0008H. The 4 data storage areas corresponding to these 4 cluster numbers are accessed according to the cluster chain formed by these cluster numbers. The file "Myfile" is divided into 4 parts and stored in these 4 storage areas 161.
4.3 Implementation of IAP Function
IAP: In Application Programming refers to in-application programming, that is, programming while the program is running. The chip provides a series of mechanisms (hardware/software) that can provide a method to change flash data when the chip is running the program. In layman's terms, this means that the program can write data or modify the program in the program memory. The typical application of this method is to use a small piece of code to download the program. In fact, the ISP function of the microcontroller is realized through IAP technology, that is, the chip already has a small boot program in it before leaving the factory. After the chip is powered on, it starts to run this program. When it detects that the host computer has a download request, it communicates with the host computer and then downloads the data to the storage area.
LPC2148 supports multiple ways to program Flash to write user code or data. The first way is to program through the built-in serial JTAG interface; the second way is to perform in-system programming (ISP) through UART0; the third way is to perform in-application programming (IAP). The IAP program is thumb code with an address of 0x7FFFFFF0. During the IAP erase and programming operation, the on-chip Flash memory is inaccessible. When the user runs the application, the interrupt vector of the user Flash area is valid. Therefore, before calling the Flash erase and write IAP, the user should disable interrupts and ensure that the user interrupt vector is valid in RAM and the interrupt handler is located in RAM. The IAP code does not use or disable interrupts. The data read from the SD card can be burned into the specified Flash segment using C code:
4.4 Program implementation jumps to any line of code segment for execution
The following example illustrates this program. If the program jumps to the absolute address 0xFFFF0 for execution, the code is as follows:
typedef void (*run) (); //Define a function pointer type with no parameters and no return type
run address = (run) 0xFFFFO; // define a function pointer to point to the jump location
address(): //call function
In the above application, no function entity is seen at all, but a function call is executed; in fact, it plays the role of a "soft shoulder", jumping to the position of the first instruction to be executed after the CPU is started, that is, realizing the program jump.
5. Conclusion
This design scheme takes LPC2148 as the core, realizes the module design of system upgrade through SD card driver, FAT32 file system, IAP function and program jump, and is used in actual development. This design enhances system maintenance and shortens the product development cycle. It saves a lot of manpower and financial resources and increases the communication with users. Compared with traditional designs, it has advantages in development time, cost and flexibility. This design has been successfully debugged and used as a functional module in an electronic product, playing a huge role in adding new functions to the product and maintaining system stability. It should be noted that this program design is compiled under Keil, and the generated HEX file cannot be directly put into the SD card, because this file is different from the file burned into Flash through ISP, and some modifications must be made. In addition, this scheme can not only be used for system upgrades, but also for program patches and writing data, etc., and can also be used for ARM9. Therefore, this design scheme has broad application prospects.
Previous article:Embedded Ethernet Controller Design
Next article:Design and implementation of LCD driver program under embedded Linux
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- What is this device and what does it do?
- NeoPixel NanoRing
- How to optimize the area of FPGA design
- LED screen blanking technology
- Integer division problem
- MSP430F5529LP (I) HELLOWRLD of IIC and OLED
- I would like to ask all the power supply experts, how to effectively suppress and reduce the noise of the switching power supply in audio equipment
- Analog Filter and Circuit Design Handbook
- SensorTile.Box Kit Operation Mode Programming Mode Trial
- Teach you how to design a power supply step by step