System Software Design
Previously, the chapter described in detail the on-chip resources of the STM32, the basic configuration of the LCD ILI9341, the SD card driver and file system, as well as the function of the OV7725 camera. The hardware platform is built on an STM32 development board along with other peripheral modules. This chapter focuses on a top-down, layered programming approach to explain the software implementation process of the entire system in a modular way.
3.1 Top-Level ProgrammingThe basic flow of the STM32 camera can be summarized as: system initialization followed by image processing. First, the system is initialized, which includes clock configuration for buttons, enabling GPIO interrupts, initializing the LED’s GPIO, reinitializing the LCD’s GPIO, registers, and internal bus functions on FSMC. The FATFS also initializes the SD card file system and enables the SDIO interrupt. Additionally, after setting up the analog bus SCCB, the OV7725 requires configuring its GPIO, FIFO, and internal registers, as well as initializing the field and signal lines. Then, the image processing stage begins: waiting for the frame synchronization signal, entering the camera mode, waiting for a button press to start capturing the image (i.e., capturing the LCD screen), and saving the image to the SD card, as shown in Figure 3.1.
3.2 System Initialization Program Design3.2.1 GPIO Initialization
The input and output modes of the GPIO registers and pins were introduced in Chapter 2, and the implementation of multiplexing functions was also detailed. Under the control of the LED, KEY, and LCD, as well as the SD card, all GPIO pins or special functions related to the camera must be configured. This is illustrated in Figure 3.2 through a flowchart.
3.2.2 LCD Initialization
LCD initialization mainly involves two aspects: configuring the FSMC bus and setting up the LCD registers, as shown in Figure 3.3. All read and write operations involving the LCD screen—such as clearing the screen, setting the scanning direction, and writing image data—are implemented by sending commands and data to the Bank1_LCD_C and Bank1_LCD_D areas. The meaning of the command/data signals can be found in the ILI9341 reference manual, while some instruction details are also explained in the LCD module of Chapter 2.
3.2.3 SD Card File System Initialization
The initialization of the SD card file system is divided into two parts: SD card interrupt initialization and hardware initialization. How to set up the interrupt function interface and FatFs file system has already been covered earlier. Figure 3.4 presents the overall flowchart of the SD card file system initialization.
3.2.4 OV7725 Initialization
The initialization of the OV7725 camera consists of three main parts: GPIO initialization for the SCCB bus and FIFO, sensor initialization, and field signal line initialization. The timing of the SCCB bus was discussed in the previous chapter. Figure 3.5 shows the program flowchart for the OV7725 initialization.
Figure 3.1 Main Program Flow Chart
Figure 3.2 GPIO Configuration and Multiplexing
Figure 3.3 LCD Initialization Process
Figure 3.4 SD Card File Initialization Process
Figure 3.5 OV7725 Initialization Process
3.3 Image Processing Program DesignThe earlier sections have detailed the implementation of each sub-module's initialization. From the main block diagram, there are also steps such as FIFO preparation, image acquisition and display, interrupt service routines, LCD screen capture, and save subroutines. FIFO preparation involves enabling the data output from the FIFO. Image acquisition and display are achieved by repeatedly reading the FIFO output and writing the data to the LCD register, which can be referenced from the FIFO section in the LCD and image acquisition modules of Chapter 2. Finally, this section focuses on the process control of LCD screen capture and image saving, as shown in Figure 3.6.
Figure 3.6 LCD Screen Capture and Save Process
Diesel Generating Set,Genset Generator,Independent Power Supply,Office Buildings Generator
Shaoxing AnFu Energy Equipment Co.Ltd , https://www.sxanfu.com