Embedded application review knowledge points summary

1. Final exam questions

  • 1. Multiple choice questions 40'
  • 2. True or False 10'
  • 3. Short answer questions 20'
  • 4. Comprehensive design questions (6+6+10+8)

2. Knowledge points of multiple choice questions

1. Embedded system

1. Definition

IEEE (International Institute of Electrical and Electronics Engineers) definition:

  • Devices used to control, monitor, or assist the operation of equipment, machinery orplants。

    Translation: Embedded system is "a device used to control, monitor or assist in the operation of machines and equipment or devices

    It can be seen from this that an embedded system is a combination of software and hardware , and can also cover auxiliary devices such as machinery, which can be considered a broad definition .

The generally accepted definition in the country:

  • Application - centric, computer technology- based, software and hardware can be tailored to meet the application system's strict requirements on function, reliability, cost, volume, power consumption , etc.

    Let's narrow down this domestic definition, and we have the characteristics of embeddedness: embeddedness, specificity and computer system.

2. Features

  • Embeddedness : must meet the environmental requirements of the target system, such as physical environment (small), electrical/atmospheric environment (reliable), cost (cheap) and other requirements.
  • Specificity : tailoring of software and hardware; minimum software and hardware configurations that meet the requirements of the object, etc.
  • Computer system : The embedded system must be a computer system that can meet the control requirements of the object system.

3. Hardware and software

insert image description here

Hardware characteristics of embedded systems :

  • (1) Embedded systems are electronic devices or equipment composed of electronic components such as embedded processors, memories, and related supporting devices;
  • (2) The electrical performance indicators of the embedded system can be parameterized;
  • (3) The embedded system needs to be realized through a series of technological processes of hardware architecture, circuit schematic diagram, circuit board, product mold design, production and testing.

Note here that personal computers are not what we call embedded, but vehicle control systems, network digital set-top boxes, smart phones, etc. are what we call embedded.

So if you encounter the question of judging which of the following are embedded systems, first exclude computer systems and laptops.

Software characteristics of embedded systems :

  • (1) The software requires solidified storage;
  • (2) The software code requires high refinement, high quality, high reliability, and high stability;
  • (3) The high real-time performance of the system software (OS) is the basic requirement;
  • (4) The multitasking operating system is the platform of knowledge integration and the foundation of the road to industrial standardization.

Product features of embedded systems:

  • (1) The embedded system must be user-oriented, product-oriented, and application-oriented;
  • (2) The power consumption, volume, cost, reliability, speed, processing power, electromagnetic compatibility and other aspects of embedded system processors are all restricted by application requirements, which are the hot spots of competition among semiconductor manufacturers;
  • (3) Both the software and hardware of the embedded system must be designed efficiently, tailored to suit the situation, and redundant, and strive to achieve higher performance on the same silicon chip area.

The hardware and software features here are the key.

2. Typical structure of embedded system

An embedded computer system generally consists of a hardware layer, a hardware abstraction layer (middle layer), an operating system layer and an application software layer.

(The level is described from bottom to top)

1. Hardware layer

Embedded microprocessors , the core of the embedded system hardware layer, are different from general-purpose microprocessors (the tasks completed by general-purpose computer boards are integrated in the chip).
Its architecture can adopt von Neumann structure or Harvard structure . The command system can adopt CISC or RISC.

memory

  • CACHE: Located between the main memory and the microprocessor core, it stores a piece of program code and data that the microprocessor uses most recently
    . Small capacity, fast access speed.
  • The main memory is a register that the microprocessor can directly access, and stores the programs and data of the system and users. The internal capacity is small, the speed is fast, and the external capacity is large.
  • Auxiliary memory , which stores program codes or information with a large amount of data, is used to store user information for a long time. Large capacity, slow speed (compared to main memory).

Embedded systems need some form of common device interface to interact with the outside world. Common equipment interfaces include: A/D, D/A conversion interface, etc. The I/0 interface includes: RS-232 interface, Ethernet interface, USB interface, audio interface, video interface, I2C interface, SPI and IrDA interface, etc.

2. Intermediate layer (HAL or BSP)

Function: Separate the upper layer software of the system from the underlying hardware, so that the underlying driver of the system has nothing to do with the hardware.

This layer generally includes:

  • Initialization of relevant underlying hardware
  • Data input/output operations
  • Configuration of hardware devices

BSP has the following two characteristics:

  • hardware dependencies
  • OS dependencies

BSP is a software layer between the operating system and the underlying hardware , including most of the software modules in the system that are closely related to the hardware.

Designing a complete BSP should include hardware initialization and hardware-related device drivers .

3. Operating system layer (system software layer)

The system software layer is composed of real-time multitasking operating system (RTOS) , file system, graphical user interface (GUI), network system and general component modules. RTOS is the foundation and development platform of embedded application software .

4. Application software layer

The application software layer is composed of application programs developed based on the real-time system, and is used to realize the control function of the controlled object . The functional layer is oriented to the controlled object and the user. For the convenience of the user's operation, it is often necessary to provide a friendly man-machine interface.

3. Von Neumann structure and Harvard structure

insert image description here

Von Neumann architecture: Instructions and data share the same memory and bus.

insert image description here

Harvard structure: Instructions and data are stored in separate memories and buses.

4. Embedded minimum system

To build an embedded system, it is first necessary to let the core component of the system, the embedded processor, work, so that the functions of the system can be gradually increased, and finally a complete system that meets the requirements can be formed.

insert image description here

5. RISC and CISC

General characteristics of RISC structure:

  • Single-cycle execution.
  • Adopt efficient pipeline operation.
  • Hardwired control with no microcode.
  • Standardization and simplification of the instruction format.
  • Register bank-oriented instructions are employed.
  • Adopt Load/Store (load/store) instruction structure.
  • Pay attention to the optimization of compilation, and strive to effectively support high-level language programs.

insert image description here

6. ARM core architecture and features

Features of ARM processors:

  • ➢Small size, low power consumption, low cost, high performance.
  • ➢Support Thumb (16-bit)/ARM (32-bit) dual instruction set, which is well compatible with 8-bit/16-bit devices.
  • ➢A large number of registers are used, and the instruction execution speed is faster.
  • ➢Most data operations are done in registers.
  • ➢The addressing mode is flexible and simple, and the execution efficiency is high.
  • ➢The command length is fixed.

Common ARM core architectures include ARMv6, ARMv6, ARMv7, ARMv8, and more.

7. Handle working mode and working status

insert image description here

The Cortex-A9 processor is a 32-bit processor that can execute 32-bit ARM instruction set instructions and is compatible with 16-bit Thumb-2 instruction set instructions and data types. There are 3 working states , which are controlled and switched by the T and J bits of the program status register (CPSR) .

  • ➢ARM state: Execute 32-bit word-aligned ARM instruction set instructions, T bit and J bit are 0;
  • ➢Thumb state: execute 16-bit or 32-bit half-word aligned Thumb-2 instruction set instructions, T bit is 1, J bit is 0;
  • ➢ThumbEE state: executes a variant of the 16-bit or 32-bit halfword-aligned Thumb-2 instruction set designed for dynamically generated targets, and the T and J bits are 1.

ARM instructions must be executed in ARM state; Thumb instructions must also be executed in Thumb state.
The ARM processor can switch between the two states, as long as the ATPCS calling rules are followed, the ARM subroutine and the Thumb subroutine can call each other.
Switching between the ARM state and the Thumb state does not affect the processor operating mode and the contents of the register set. When the processor starts executing code after a reset, it is in the ARM state.

Switching between processor states:

  • (1) When switching between ARM state and Thumb state and
    executing BX and BL.X instructions, copy the target address value stored in the general register to the program register PC, and switch to the program register PC if the lowest bit of the target address value is 1. Thumb state. If an exception occurs when the processor is in the Thumb state (exception processing must be in the ARM state), it will automatically switch to the Thumb state when the exception processing returns.
    When executing the BX and BL.X instructions, copy the target address value stored in the general register to the program register PC, and switch to the ARM state if the lowest bit of the target address value is 0. When the processor handles exceptions, it puts the PC value into the exception mode link register, starts to execute the program from the exception vector address, and the system automatically enters the ARM state.

  • (2) To switch between Thumb state and ThumbEE state
    use ENTERX instruction and LEAVEX instruction.

    It is concluded that the ARM processor switches the working state automatically.

8. Big/little endian storage mode

In the big-endian mode , the high byte of the stored word data is stored in the low address of the storage system, and the low byte of the stored word data is stored in the high address of the storage system. (High to low, low to high) In
the little-endian mode , the low address of the storage system stores the content of the low byte in the stored word data, and the high address of the storage system stores the high word in the stored word data Section content. (low to low, high to high)

9. Memory management unit MMU

When faced with some complex and multi-task embedded applications, an embedded operating system is often used to manage the operation of the entire system and tasks. Advanced embedded operating systems all have a memory management unit MMU (Memory Management Unit) to manage the respective storage space of each task.

The range of virtual addresses (virtual address space) is determined by the number of bits of the CPU, and the physical address space is only a subset of it.

Virtual addresses are assigned by the compiler and linker when locating programs; physical addresses are used to access actual main memory hardware modules. In ARM, a page (Page) virtual storage management method is adopted. The virtual address space is divided into units called pages, and the corresponding physical address space is also divided into units of page frames.

The blocks in the process are called pages, the blocks in memory are called page frames or page frames, and the blocks in external storage are called blocks or disk blocks.

How is the mapping between the page and the page frame under the scheduling of the MMU:

The virtual address 0 is sent to the MMU, and the MMU finds that the address is within the page 0 (0~4095)range, and the page frame mapped to page 0 is 2 (the address range of page frame 2 is 8192~12287). So the MMU converts the virtual address into a physical address 8192, and sends the address 8192 to the memory address bus. The mapping process of memory to address is not clear, it just receives an access request to address 8192 and executes it.

If you don’t understand this passage, please click Understand memory management from the perspective of the operating system

An important task of the MMU is to allow each task to run in its own virtual storage space . As a converter, MM∪ converts the virtual addresses of programs and data into actual physical addresses, which is to realize the mapping from virtual storage space to physical storage space.
In addition to this, other important functions of the MMU include:

  • (1) Control of memory access authority, providing memory access authorization of hardware mechanism.
  • (2) Set the characteristics of the virtual storage space buffer.

10. Exception handling

Exceptions are a way for ARM processors to handle external asynchronous events, also known as interrupts . When the processor is executing a program normally, an external or internal abnormal event occurs, the processor temporarily interrupts the execution of the current program, and jumps to the corresponding exception handler entry to perform exception handling. Before handling this abnormal event, the processor should save the current processor state and return address, so that after the exception handler ends, it can return to the original program and continue to execute. If multiple exceptions occur at the same time, the processor will handle these exceptions according to the priority of the exception interrupt.

Here, the exception is equivalent to the interrupt. In the meter group, the exception is an internal interrupt, which is an interrupt that occurs during the execution of instructions, and the external interrupt belongs to the external device interrupt such as hardware.

1. Exception vector and priority

There are 7 exception interrupts in the ARM architecture . When an exception occurs, the processor sets the PC register to a specific memory address called the exception vector. The exception vectors for all exceptions are collected in a contiguous address space in the program memory, called the exception vector table . Each exception vector occupies only 4 bytes, and there are some jump instructions at the exception vector to jump to the corresponding exception handler.

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-rVPw7cOU-1687739242359) (C:\Users\Hongzelin\AppData\Roaming\Typora\typora-user-images\ image-20230622091906948.png)]

As you can see in the table above, each exception causes the kernel to enter a specific mode. In addition, it is also possible to change the CPSR through programming and enter the ARM processor mode. It should be noted that user mode and system mode are the only two modes that cannot be entered through exceptions. That is to say, to enter these two modes, you must pass Programmatically change the CPSR.
When multiple exceptions occur at the same time, the system handles them in descending order according to the priority of different exceptions. The 7 abnormalities are divided into 6 levels, 1 with the highest priority and 6 with the lowest priority. Among them, both the undefined instruction exception and the software interrupt exception are generated by the special decoding of the instruction. The two are mutually exclusive and cannot be generated at the same time.

2. Abnormal response process

Usually, abnormal (interrupt) response can be roughly divided into the following steps:

  • (1) Protect the breakpoint, that is, save the address of the next instruction to be executed, that is, send this address to the stack;
  • (2) Find the interrupt entry, and search for different entry addresses according to the interrupts generated by different interrupt sources;
  • (3) Execute the interrupt handler;
  • (4) Return from interrupt. After executing the interrupt instruction, it returns to the main program from the interrupt and continues to execute.

1 and 2 are automatically completed by the hardware, and the rest are completed by the interrupt program.

The interrupt processing process is actually after the instruction execution cycle, so except that the reset exception will immediately interrupt the program, the rest of the interrupts are completed within the interrupt cycle.

3. Abnormal return process

After the reset exception occurs, because the system automatically restarts the program from 0x00000000, there is no need to return after the reset exception handler is executed. After other exceptions are handled, it must return to the breakpoint of the original program to continue execution.
The ARM processor returns from an exception handler as follows:

  • (1) Restore the original saved user registers.
  • (2) Copy the value of the SPSR_mode register to the CPSR to restore the interrupted program working state.
  • (3) Restore the value of the PC register to the breakpoint address according to the exception type, so as to execute the program originally interrupted by the interrupt.
  • (4) Clear the interrupt mask flags I and F in the CPSR, open the external interrupt and fast interrupt.

11. ARM instruction features

  • Most data operations are done in registers.
  • The addressing mode is flexible and simple, and the execution efficiency is high.
  • The instruction length is fixed.

In order to ensure that the ARM processor has high performance and further reduce the size and power consumption of the chip, the ARM processor adopts the following special technologies

  • All instructions can be executed according to the previous execution results, so as to improve the execution efficiency of the instructions.
  • Load/store instructions can be used to transfer data in batches to improve data transfer efficiency.
  • Logic processing and shift processing can be completed simultaneously in one data processing instruction.
  • Use the automatic increase and decrease of the address in the cycle processing to improve the operation efficiency.

12. Embedded Operating System

Definition: System software that runs on an embedded hardware platform and coordinates, directs and
controls resources such as the entire system and its operated components and devices.

Features:

  • miniaturization
  • Tailorability
  • real-time
  • high reliability
  • portability

13. Real-time operating system (RTOS)

There are two ways to define:

  • RTOS is an operating system that has real-time performance and can support the work of real-time control systems.
  • An RTOS is a program that schedules execution in a sequential manner, manages system resources, and provides a consistent basis for developing application code.

After learning the operating system, we know that the operating system itself belongs to the software level, but that layer is called system software.

The primary task of RTOS is to dispatch all available resources to complete real-time control tasks , and then focus on improving the efficiency of computer systems . Its important feature is to meet the time constraints and requirements . In real-time computing, the correctness of the system depends not only on the logical results of the calculation, but also on the time when the results are generated.

14. Cross Compilation

Local compilation: Compile on the current platform, and the compiled program is executed locally.

Cross Compilation: Generate executable code on one platform for another platform.

Three common cross-compilation methods:

  • On Windows PC, use ADS (ARM development environment), use armcc compiler. Compiler to compile executable code for ARM CPU
  • On a Linux PC, use the arm-linux-gc compiler to compile executable code for the Linux ARM platform
  • On a Windows PC, use the cygwin environment to run the arm-elf-gcc compiler to compile executable code for the ARM CPU

Generally, the storage size of the embedded development system is limited, and a cross-compilation tool chain for the target machine is usually established on a PC with superior performance.

The cross-compilation toolchain is a comprehensive development environment composed of compilers, linkers and interpreters. The cross-compilation toolchain is mainly composed of binutils, gcc and glibc. Sometimes for the sake of reducing the size of the libc library, other c libraries can be used instead of g|ibc, such as uClibc, dietlibc and newlib.

Production of cross-compilation toolchain:

Generally, crosstool or crosstool_NG is used to make arm-linux cross-compilation toolchain. The former is easy to use, but the production will be subject to some restrictions. Using crosstool can only compile gcc 4.1.1 and glibc 2. x versions at most. However, crosstool_NG has better customization and has been kept updated. It supports the new version of the compilation tool chain better, and must be configured and installed first.

15. Linux file system

The file system is an organization responsible for accessing and managing file information. It is used to control access to data, files, and devices. It provides hierarchical organization of files and directories, data buffering, and control of file access permissions.

The file system has the following main functions:

  • 1. Manage the file storage device, record the free area and the occupied area separately, so as to facilitate the operation of the space when the user creates, modifies and deletes files.
  • 2. Access by name and hierarchical organization of files and directories.
  • 3. Create, delete and modify file functions.
  • 4. Data protection function.
  • 5. File sharing function

Supplement (Virtual File System VFS):

In order to support many different file systems, the virtual file system VFS (Virtual File system) technology is adopted. The virtual file system is an abstraction of the common functions of various actual file systems . It shields the differences in the implementation details of various file systems and provides a unified, abstract, and standard interface for user programs. Access, such as open, read, write and other operations.
The virtual file system VFS ensures that all files are accessed in exactly the same way .

The main Linux file systems consist of ext2, ext3, ext4.

16. Embedded file system

The embedded file system refers to the modules in the embedded system that implement functions such as file access management. These modules provide a series of file
management functions such as file input and output, and provide file system support for embedded systems and devices.

In an embedded system, the file system is a component of the embedded system. It is provided to the user as a loadable option of the system, and it is up to the user to decide whether to load it. The embedded file system has the characteristics of compact structure, simple and convenient use, safety and reliability, support for multiple storage devices, scalability, tailoring, and portability.

Mainstream embedded file operating systems: QNX, VxWorks, yaffs/yaffs2, Cramfs, NFS (Network File System),

insert image description here

The root file system is a special file system. This file system not only has the function of storing data files of the ordinary file system, but also the first file system mounted when the kernel starts. The image file of the kernel code is saved In the root file system, the system boot program will load some initialization scripts and services into the memory to run after the root file system is mounted.

17.Flash

Flash is a ROM-based memory. Its main feature is that it can store information for a long time without power on, and can be quickly erased and rewritten online.

Comparison of Nor Flash and Nand Flash:

Nor Flash usually has a small capacity, and its main feature is that the program code can run directly in Flash. Nor Flash has a RAM interface and is easy to access. The disadvantage
is that the erasing circuit is complex, and the writing speed and erasing speed are relatively slow. The maximum number of times of erasing and writing is about 100,000 times, and the typical block size is 128kB.
Nand Flash usually has a large capacity and high storage density, which reduces the unit price. The block size of Nand Flash is small, the typical size is 8kB,
the erasing speed is fast, the service life is longer, and the maximum number of erasing and writing can reach 1 million times, but its access interface is a complex I/O port, and bad blocks and There are many bit inversion phenomena, and the requirements for the driver are higher.

General conclusion: Since Nor Flash and Nand Flash have their own characteristics, their uses are also different. Nor Flash is generally used to store small-volume codes, while Nand Flash is used to store large-volume data.

18.U-boot

U-Boot, the full name of Universal Boot Loader (universal bootloader), is an open source project that follows the terms of the GPL. Developed and maintained by the German DENX group, its superb technology enables U-Boot to be easily transplanted to various embedded CPUs, and supports the booting of various embedded operating system kernels.

Here is the download address of all versions of U-boot: download please click me

The implementation of BootLoader depends on the architecture of the processor. For the convenience of transplantation, most BootLoaders can be divided into two stages stage1 and stage2. Codes that depend on the processor architecture, such as CPU initialization, are generally placed in stage1, usually implemented in assembly language, and stage1 must be position-independent code. Stage2 is usually implemented in C language, which can implement complex functions, and the code will have better readability and portability.

The first stage of U-Boot is mainly written in assembly language . The entry of the program is in start.s, and the CONFIG_ SPL _BUILD macro often appears, which is used to control the conditional compilation of the program.

U-boot porting steps:

insert image description here

  • Step 1: Build your own platform
  • Step 2: Create development board information
  • Step 3: Modify the top-level Makefile
  • Step 4: Modify start.S and lowlevel init.S
  • Step 5: Realize serial port output
  • Step 6: NIC porting
  • Step 7: Flash Migration

19. Linux device driver

An important feature of Linux: Treat all devices as files --- device files.

The device driver is a part of the kernel, which mainly completes the following functions:

  • Initialize and release the device
  • Transfer data from the kernel to the hardware and read data from the hardware
  • Read data sent by the application to the device file and return data requested by the application
  • Detecting Errors and Handling Interrupts

insert image description here

20. GPIO driver

"General purpose input and output" GPI0 (general purpose .input output) is the simplest and most commonly used I/0 interface in embedded systems. GPI0 is a group of programmable pins controlled by multiple registers at the same time. By setting the corresponding registers, you can set the corresponding status and functions of the GPI0 port, such as reading data status, setting input and output directions, clearing, interrupt enabling and other functions.

The main function of the GPI0 driver is to read the content of the GPI0 port, or set the state of the GPI0 port. GPIO is closely related to the hardware system. In
the relevant files under the linux kernel directory, we can find the definition and usage of GPI0 for different hardware chips. The linux kernel also has corresponding driver support (in /drivers/gpio/). Of course, the linux kernel also provides a model framework that can use a unified interface to operate GPI0. This architecture is called "gpiolib", and the system describes the architecture through the gpiolib.c file.

21. SoC system on chip

SoC (System-on-a-Chip, system on chip) is a technology that integrates multiple functional modules on a single chip. SoC usually includes processor core (such as CPU, GPU), memory, peripheral interface and other functional modules, and these modules together form a complete system. SoC technology can reduce the power consumption, size and cost of devices, so it has been widely used in embedded systems, mobile devices and other fields.

The main advantages of SoC are as follows:

  • 1. High integration: SoC integrates multiple functional modules on one chip, reducing the need for external connectors and circuit boards, thereby reducing the complexity of the system.
  • 2. Small size and light weight: Due to the high level of integration, SoC can greatly reduce the size and weight of the device, making it suitable for various portable devices.
  • 3. Low power consumption: SoC adopts a highly integrated design, which reduces the signal transmission distance between circuits, thereby reducing power consumption.
  • 4. Low cost: SoC integrates multiple functional modules on one chip, which reduces the cost of assembly and testing, and reduces the total cost of the device.

However, the design and manufacturing process of SoC is relatively complex, requiring more research and development resources. In addition, the scalability and upgradeability of SoC are relatively limited, because hardware functions are already integrated on the chip, making it difficult to upgrade or replace them individually.

System on a Chip (SoC) is a new technology produced in the ASIC (Application Specific Integrated Circuits) design methodology, which refers to the embedded system as the core, based on IP (Intellectual Property) multiplexing technology, Integrate software and hardware into one, and pursue the most inclusive integrated chip in the product system.

22. Linux kernel clipping

Linux kernel pruning refers to removing unnecessary functional modules according to specific application requirements, so as to reduce the size and resource consumption of the kernel. This is especially important in embedded systems, since embedded devices often have limited storage space and computing power. By cutting the core, the performance and efficiency of the system can be improved, the power consumption can be reduced, and the special needs of embedded devices can be met.

The main steps for Linux kernel pruning are as follows:

  1. Get the Linux kernel source code: Get the Linux kernel source code for the target hardware platform from the official website or the device manufacturer.
  2. Configure kernel options: Use a kernel configuration tool (eg make menuconfig) to select functional modules and drivers that need to be kept, and disable unnecessary parts. It can be selected according to the hardware characteristics and application requirements of the target device.
  3. Compile the kernel: Use the cross-compilation toolchain on the host to compile the customized kernel source code to generate a kernel image file (such as zImageor uImage).
  4. Install the kernel: deploy the compiled kernel image file to the target device to replace the original kernel. This can be done by flashing to the device's flash memory or by booting from the network.
  5. Testing and Validation: Power up the target device to verify that the customized kernel is functioning properly and that required functionality is fully available.

It should be noted that when tailoring the Linux kernel, it is necessary to ensure that the necessary drivers and functional modules are retained to ensure the normal operation of the system. During the tailoring process, several attempts and adjustments to configuration options may be required to achieve the best balance of performance and resource usage.

23. Microcontroller

The biggest feature of the microcontroller is monolithic, the size is greatly reduced, so that the power consumption and cost are reduced, and the reliability is improved.

3. Knowledge points of judgment questions

1. Embedded system design process

Embedded system design refers to the development and implementation of a highly integrated, dedicated computing system for specific application requirements. Embedded systems usually consist of hardware and software. The hardware includes processors, memory, peripheral interfaces, etc., and the software includes operating systems, drivers, and applications. Embedded system design needs to consider a variety of factors, such as performance, power consumption, reliability, cost, etc., to meet the needs of specific application scenarios.

  1. Requirements analysis: analyze the requirements of the application scenario, and determine the system's functions, performance, size, power consumption and other indicators.
  2. Architecture design: Architecture design refers to determining the overall structure of the system and the relationship between modules according to application requirements and performance indicators. This involves the selection of the processor, the design of the bus structure, the organization of the memory and storage system, the configuration of the peripheral interface, etc.
  3. Hardware design: Select appropriate processor, memory, peripheral interface and other hardware components, design circuit board and hardware architecture.
  4. Software design: choose an appropriate operating system (such as Linux, RTOS, etc.), develop drivers, middleware and applications. This may involve writing low-level hardware control code, implementing communication protocols, developing user interfaces, and more.
  5. System Integration: Bringing hardware and software components together for system-level testing and validation. This may include functional testing, performance testing, stability testing, etc.
  6. Optimization and debugging: According to the test results, optimize and debug the hardware and software to improve the performance, stability and reliability of the system.
  7. Production and deployment: mass-produce the designed embedded system and deploy it in the actual application environment.

2. ARM processor registers

The Cortex-A9 processor has a total of 40 32-bit registers, including 33 general-purpose registers and 7 status registers. The status registers include one CPSR (Current Program Status Register, current program status register) and six SPSRs (Saved Program Status Register, backup program status register). These registers cannot be accessed at the same time, and only a set of corresponding register groups can be accessed in different processor operating modes.

insert image description here

1) General register set:

  • R0~R7 are general-purpose registers that are not grouped;
  • R8~R15 are general-purpose registers for grouping;
  • In the ARM state, at any time, 16 data registers R0~R15 and 1~2 status registers are accessible. In the privileged mode, the register array in the specific mode is valid.

Ungrouped general-purpose registers R0~R7 are used to hold data and addresses. Each of them points to a physical register in all operating modes of the processor, and is not used for special purposes by the system. When the processor operating mode is switched, the data in the register may be destroyed because the same physical memory is used.

The grouped general-purpose registers R8~R15 have different characteristics of physical registers accessed by different processor operating modes. As shown in the figure above, the form of each physical register name is Rx_ <mode>,<mode>a mode identifier, and each mode identifier indicates the current working mode.

2) Status register:
ARM processor has two types of program status registers: 1 current program status register CPSR and 6 backup program status registers SPSR. Their main functions are:

  • ➢ save information about the most recently performed arithmetic or logic operations;
  • ➢Enabling or prohibiting control interruption;
  • ➢Set the processor working mode.

Each processor mode uses a dedicated backup program status register. When a specific interrupt or exception occurs, the processor switches to the corresponding working mode, and the backup program status register in this mode saves the content of the current program status register. When the exception handler returns, its content is restored to the current program status register from the backup program status register.

3. Processor working mode

insert image description here

  • Privileged mode : For service interruption or exception, or access to protected resources, it has full access to multiple system resources and can freely switch working modes.
  • System mode : System mode cannot be entered by any exception. It has exactly the same registers as user mode. System mode is used by operating system tasks that need to access system resources. This avoids the use of registers related to exception mode and ensures that when any exception occurs Neither makes the state of the task unreliable.
  • Abnormal mode : In addition to being able to enter through program switching, it can also be entered when a specific abnormal interrupt occurs. Each exception mode has a group of dedicated registers to ensure that the registers in the user mode (save the program running state before the work mode is switched) are not destroyed when entering the exception mode.

4. Processor working status

The Cortex-A9 processor is a 32-bit processor that can execute 32-bit ARM instruction set instructions and is compatible with 16-bit Thumb-2 instruction set instructions and data types. There are 3 working states , which are controlled and switched by the T and J bits of the program status register (CPSR) .

  • ➢ARM state: Execute 32-bit word-aligned ARM instruction set instructions, T bit and J bit are 0;
  • ➢Thumb state: execute 16-bit or 32-bit half-word aligned Thumb-2 instruction set instructions, T bit is 1, J bit is 0;
  • ➢ThumbEE state: executes a variant of the 16-bit or 32-bit halfword-aligned Thumb-2 instruction set designed for dynamically generated targets, and the T and J bits are 1.

ARM instructions must be executed in ARM state; Thumb instructions must also be executed in Thumb state.
The ARM processor can switch between the two states, as long as the ATPCS calling rules are followed, the ARM subroutine and the Thumb subroutine can call each other.
Switching between the ARM state and the Thumb state does not affect the processor operating mode and the contents of the register set. When the processor starts executing code after a reset, it is in the ARM state.

Switching between processor states:

  • (1) When switching between ARM state and Thumb state and
    executing BX and BL.X instructions, copy the target address value stored in the general register to the program register PC, and switch to the program register PC if the lowest bit of the target address value is 1. Thumb state. If an exception occurs when the processor is in the Thumb state (exception processing must be in the ARM state), it will automatically switch to the Thumb state when the exception processing returns.
    When executing the BX and BL.X instructions, copy the target address value stored in the general register to the program register PC, and switch to the ARM state if the lowest bit of the target address value is 0. When the processor handles exceptions, it puts the PC value into the exception mode link register, starts to execute the program from the exception vector address, and the system automatically enters the ARM state.

  • (2) To switch between Thumb state and ThumbEE state
    use ENTERX instruction and LEAVEX instruction.

    It is concluded that the ARM processor switches the working state automatically.

5. CISC and RISC

Look at the knowledge points of the single-choice questions

6. Embedded Linux operating system

Look at the knowledge points of the single-choice questions

7. Embedded Linux operating system porting

Embedded Linux operating system porting refers to the customization and optimization of the Linux operating system so that it can run on a specific embedded hardware platform. This process usually includes steps such as kernel customization, driver development, file system construction, and bootloader configuration.

The following are the main steps of transplanting the embedded Linux operating system:

  1. Preparations: Obtain the technical documents and reference materials of the target hardware platform, and understand the features and interfaces of the hardware. At the same time, build a cross-compilation environment for compiling the Linux kernel and applications of the target hardware platform on the host computer.
  2. Kernel customization: tailor and optimize the Linux kernel according to the characteristics of the target hardware platform. This includes choosing an appropriate processor architecture, disabling unneeded feature blocks, adding hardware support, and more. Configure with a kernel configuration tool such as make menuconfig, and then compile the kernel with a cross-compilation toolchain.
  3. Driver development: According to the peripheral interface of the target hardware platform, develop the corresponding device driver. This may include driver development for GPIO, UART, SPI, I2C and other interfaces. Integrate the driver into the kernel, or load it as a module.
  4. File system construction: Create an applicable file system for the target hardware platform. This can be a read-only root filesystem (such as SquashFS), a read-write root filesystem (such as ext4), or a temporary RAM-based filesystem (such as initramfs). The file system needs to contain the basic components of the Linux operating system, such as library files, system tools, configuration files, etc., as well as programs and data for specific applications.
  5. Bootloader Configuration: Configure a bootloader (such as U-Boot) to load a custom Linux kernel and filesystem. The boot program needs to set correct kernel parameters, memory layout, device tree and other information to ensure that the system can start normally.
  6. Testing and debugging: Deploy the customized Linux operating system to the target hardware platform for functional testing, performance testing and stability testing. Based on the test results, tune and optimize the kernel, drivers, and applications to improve system performance, stability, and reliability.
  7. Problem location and solution: In the process of testing and debugging, various problems may be encountered, such as system startup failure, driver failure to load, application crash, etc. For these problems, it is necessary to use debugging tools (such as gdb, strace, etc.) and log information to locate and analyze, and take corresponding measures to solve them.

8. Embedded system development and debugging

Embedded system development and debugging is to test and analyze hardware and software through various tools and methods in the process of embedded system development to find out potential problems and solve them to ensure the normal operation and performance of the system.

The following are some commonly used embedded system development and debugging methods and tools:

  1. Simulators and emulators: In the early stages of development, simulators and emulators can be used to simulate the target hardware platform on a PC for software development and preliminary testing. This saves hardware costs and speeds up the development process. Commonly used simulators and emulators include QEMU, Keil MDK, etc.
  2. JTAG debugging: JTAG (Joint Test Action Group) is a commonly used hardware debugging interface, which can directly access resources such as CPU, memory and registers of the target hardware through the JTAG interface. Using JTAG debugger (such as OpenOCD, J-Link, etc.) and debugging software (such as GDB, IAR Embedded Workbench, etc.), you can realize functions such as single-step execution of code, breakpoint setting, memory viewing, etc., which is convenient for hardware-level debugging.
  3. Serial port debugging: In embedded systems, serial ports are usually used to output debugging information and communicate with external devices. Through serial port debugging tools (such as minicom, putty, etc.), you can check the running status and error information of the system in real time, which is convenient for software debugging.
  4. Logic Analyzer: A logic analyzer is a hardware debugging tool that captures and analyzes the waveform and timing of digital signals. Through the logic analyzer, you can observe the signal changes of hardware interfaces (such as GPIO, SPI, I2C, etc.) to help locate hardware problems and communication errors.
  5. Oscilloscope: An oscilloscope is a commonly used electronic measuring instrument that can observe the waveform and frequency of a signal. For debugging of analog signals and high-speed digital signals, an oscilloscope is an essential tool.

9. ARM interrupt exception concept

Exceptions are a way for ARM processors to handle external asynchronous events, also known as interrupts. When the processor is executing a program normally, an external or internal abnormal event occurs, the processor temporarily interrupts the execution of the current program, and jumps to the corresponding exception handler entry to perform exception handling. Before handling this exception event, the processor should save the state of the current processor and the return address, so that after the exception handler ends, it can return to the original program and continue to execute. If multiple exceptions occur at the same time, the processor will handle these exceptions according to the priority of the exception interrupt.

10. Von Neumann structure and Harvard structure

See the Multiple Choice section.

4. Knowledge points of short answer questions

1. Embedded system definition, characteristics and composition

Definition: application -centered, computer- based, dedicated computer systems that can be tailored for software and hardware, and meet the strict requirements of application systems for functionality, reliability, cost, volume, and power consumption .

Features: embeddedness, specificity, computer system

Composition: hardware layer, middle layer, operating system layer, application software layer

2. Embedded hardware system

1. Embedded processor

insert image description here

2. Abnormal response process

Usually, abnormal (interrupt) response can be roughly divided into the following steps:

  • (1) Protect the breakpoint, that is, save the address of the next instruction to be executed, that is, send this address to the stack;
  • (2) Find the interrupt entry, and search for different entry addresses according to the interrupts generated by different interrupt sources;
  • (3) Execute the interrupt handler;
  • (4) Interrupt return, after executing the interrupt instruction, it returns to the main program from the interrupt and continues to execute.

3. Embedded software system

1. Embedded Linux kernel

The soul of the Linux operating system is the Linux kernel, which provides system services for other parts of the system. The ARM-Linux kernel is a Linux kernel specially adapted to the design of the ARM architecture, responsible for the entire system: process management and scheduling, memory management, file management, device management and network management and other main system functions.

ARM-Linux kernel version changes keep pace with Linux kernel version changes.

insert image description here

These five systems depend on each other and are indispensable, but relatively speaking, the process management is in a more important position, and the other subsystems must rely on the participation of the process scheduling subsystem to suspend and resume the running of the process.

2. Real-time operating system

There are two ways to define:

  • RTOS is an operating system that has real-time performance and can support the work of real-time control systems.
  • An RTOS is a program that schedules execution in a sequential manner, manages system resources, and provides a consistent basis for developing application code.

After learning the operating system, we know that the operating system itself belongs to the software level, but that layer is called system software.

The primary task of RTOS is to dispatch all available resources to complete real-time control tasks , and then focus on improving the efficiency of computer systems . Its important feature is to meet the time constraints and requirements . In real-time computing, the correctness of the system depends not only on the logical results of the calculation, but also on the time when the results are generated.

3.VFS

The virtual file system is an abstraction of the common functions of various actual file systems . It shields the differences in the implementation details of various file systems and provides a unified, abstract, and standard interface for user programs. Access, such as open, read, write and other operations.
The virtual file system VFS ensures that all files are accessed in exactly the same way .

VFS is the main component (interface) of the underlying file system. This component exports a set of interfaces and then abstracts them to individual filesystems whose behavior can vary widely. VFS has two caches for file system objects: inode index node objects and dentry directory entry objects , which cache recently used file system objects. Each file system implementation (such as ext2, JFFS2, etc.) can export a set of common interfaces for use by VFS. The buffer cache caches requests between the file system and associated block devices.

Thought: Object-Oriented Design Thought

4. Embedded system application field

  • Wireless communication products : Wireless communication devices such as mobile phones, base stations and wireless switches use a large number of embedded OS and middleware (communication protocols, etc.).
  • Network products : such as routers, switches, access devices and information security products, etc., widely use RTOS and open source Linux OS.
  • Smart home appliances : products such as smart TVs, IP set-top boxes, and Internet refrigerators use a large number of embedded OSs including Android.
  • Aerospace and military equipment : including aircraft, spacecraft, ships and weaponry, etc. are using certified RTOS, this field is also one of the earliest markets for embedded OS development.
  • Automotive electronics : MCU technology is widely used in modern automobiles and vehicles, and they are shifting from private RTOS to standard and open RTOS and general embedded OS technology. With the development of intelligent transportation and Internet of Vehicles, automotive electronics will give embedded OS development Bring a new spring.
  • **Internet of Things industry and technology:**The Internet of Things and cloud computing are the two driving forces behind the technological development of the IT industry. Among them, the development of Internet of Things technology and industry has a greater impact on embedded systems and embedded OS. Embedded OS needs to support better low power consumption and wireless network technology. With the development and maturity of the industry, the demand will increase. .

5. Embedded Linux system construction process

insert image description here

An embedded linux system usually consists of a boot program and parameters, a linux kernel, a file system, and user applications. Since the running environment of the embedded system is different from that of the development host, it puts forward the special requirement of the development environment for the development of the embedded system. It is against this background that the cross-development environment emerges as the times require.

  • The first step: Transplant according to the status of the system hardware platform
  • Step 2: Take cross-compilation to compile the source code to form the image file needed at runtime

5. Comprehensive Design Questions

1.makefile、make

The role of make: 1. Automatic compilation 2. Processing multiple files 3. Document processing

How the makefile works:

  • The work of Makefile requires the make program and the makefile text file
  • Call the make command in the system to interpret the current makefile and complete the specific functions in it

Write makefile code, please click

2. GPIO programming, LED driver

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

#define LED2_GPIO 87 // GPX2_7
#define LED3_GPIO 16 // GPX1_0
#define LED4_GPIO 84 // GPX2_4
#define LED5_GPIO 125 // GPF3_5

// 导出GPIO
void gpio_export(int gpio) {
    
    
    int fd;
    char buf[10];
    fd = open("/sys/class/gpio/export", O_WRONLY);
    snprintf(buf, sizeof(buf), "%d", gpio);
    write(fd, buf, strlen(buf));
    close(fd);
}

// 设置GPIO方向
void gpio_set_direction(int gpio, const char *direction) {
    
    
    int fd;
    char buf[50];
    snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction", gpio);
    fd = open(buf, O_WRONLY);
    write(fd, direction, strlen(direction));
    close(fd);
}

// 设置GPIO值
void gpio_set_value(int gpio, int value) {
    
    
    int fd;
    char buf[50];
    snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/value", gpio);
    fd = open(buf, O_WRONLY);
    snprintf(buf, sizeof(buf), "%d", value);
    write(fd, buf, strlen(buf));
    close(fd);
}

int main() {
    
    
    int led_gpios[] = {
    
    LED2_GPIO, LED3_GPIO, LED4_GPIO, LED5_GPIO};

    // 导出GPIO并设置为输出模式
    for (int i = 0; i < sizeof(led_gpios) / sizeof(led_gpios[0]); i++) {
    
    
        gpio_export(led_gpios[i]);
        gpio_set_direction(led_gpios[i], "out");
    }

    // 循环控制LED的亮灭
    while (1) {
    
    
        for (int i = 0; i < sizeof(led_gpios) / sizeof(led_gpios[0]); i++) {
    
    
            gpio_set_value(led_gpios[i], 1); // 输出高电平,点亮LED
            sleep(1);
            gpio_set_value(led_gpios[i], 0); // 输出低电平,熄灭LED
            sleep(1);
        }
    }

    return 0;
}

3. Experimental case

Not all embedded systems need an operating system, you must learn to analyze and judge!!!

Embedded hardware platform selection:

Embedded software can be divided into the following categories according to function and level:

  1. Application software : This is the software part of an embedded system that directly interacts with the user or other systems. Application software is responsible for realizing specific functions or tasks, such as data acquisition, control algorithms, graphical interfaces, etc. Application software is usually developed based on an operating system or other underlying software, written in a high-level programming language (such as C, C++, Python, etc.).
  2. Network software : This part of the software is responsible for the network communication functions in the embedded system, such as TCP/IP protocol stack, Wi-Fi, Bluetooth, LoRa, etc. Networking software can be a component built into the operating system, or it can be a third-party library or driver. Networking software enables embedded devices to exchange data and control them remotely with other devices or cloud services.
  3. System software : This is the core part of an embedded system, whether it is an operating system, real-time operating system (RTOS), or a bare-metal system. System software is responsible for managing hardware resources (such as CPU, memory, peripherals, etc.), and providing basic operating environment and services for application software. Common embedded operating systems include Linux, FreeRTOS, VxWorks, uC/OS, etc.
  4. Driver software : Driver software is the underlying software responsible for communicating with hardware devices in embedded systems. The driver abstracts the operation of the hardware device into a simple interface for the upper layer software to call. Driver software is usually closely related to the operating system or hardware platform, and may need to be written in assembly language or hardware-related C language. Common driver types include GPIO, UART, I2C, SPI, USB, etc.

4. Device characteristics of main memory

  1. SRAM (Static Random Access Memory) :

    • Volatile: Yes, data is lost after power failure
    • Read and write speed: very fast, usually faster than DRAM and NAND Flash
    • Features: No refresh requirement, low power consumption, high speed, high cost, low integration, small capacity, usually used for cache (such as CPU cache)
  2. DRAM (Dynamic Random Access Memory) :

    • Volatile: Yes, data is lost after power failure
    • Read and write speed: faster, usually faster than NAND Flash, but slower than SRAM
    • Features: It needs to be refreshed regularly to maintain data, high power consumption, fast speed, moderate cost, high integration, large capacity, usually used for main memory (such as computer, mobile phone RAM)
  3. NAND Flash (NAND type flash memory) :

    • Volatile: No, data retained after power failure
    • Read and write speed: slow, usually slower than SRAM and DRAM
    • Features: non-volatile, no need to refresh, low power consumption, slow speed, low cost, high integration, large capacity, usually used for data storage (such as SSD, U disk, SD card, memory of embedded devices)
      system . System software is responsible for managing hardware resources (such as CPU, memory, peripherals, etc.), and providing basic operating environment and services for application software. Common embedded operating systems include Linux, FreeRTOS, VxWorks, uC/OS, etc.

insert image description here

Guess you like

Origin blog.csdn.net/weixin_51496226/article/details/131389721