Communication control system and method based on Quad-SPI controller and external FLASH
Through the communication control system based on the Quad-SPI controller and the SPI interface Flash memory chip, the problem of low data transmission efficiency on the SPI bus in the ARM Cortex-M4 processor is solved, efficient data storage and transmission is achieved, and the circuit design complexity is reduced. sex and cost.
Patent Information
- Application Number
- CN202010577581.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-23
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2040-06-23
AI Technical Summary
In the existing technology, the SPI bus of the ARM Cortex-M4 processor transmits data through the Quad-SPI controller and the external serial Flash memory chip is still blank. There is a lack of effective communication control methods, resulting in low data storage and transmission efficiency, which increases the Circuit design complexity and cost.
A communication control system based on the Quad-SPI controller and SPI interface FLASH memory chip is used, through the four modules of the Quad-SPI controller (control register, clock generator, transmit/receive control logic and shift register) and the SPI interface Flash Memory chip connection, configure Quad-SPI port mode and SPI bus parameters to achieve full-duplex transmission communication, including configuring control registers, clock generators, transmit/receive control logic and shift registers, and perform data transmission through six control lines.
It achieves efficient full-duplex transmission communication between the Quad-SPI controller and the SPI interface Flash memory chip, reduces project development costs, meets the need for fast data storage, and improves chip utilization and development efficiency.
Smart Images

Figure CN111897749B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of embedded system development, in particular to a communication control system and method based on a Quad-SPI controller and an external expansion FLASH. Background Art
[0002] At present, the research direction of ship-aircraft inertial navigation alignment support is determined to be self-controllable, and relying on domestic standardized chip software and hardware platforms, the combat missions have put forward higher requirements for the alignment information storage medium and the fast reading and writing data speed. The traditional solution has always used additional SD cards or EPROM as storage devices. On the one hand, it will increase the circuit design tasks and hardware overhead; on the other hand, the small-capacity SD card resources are not guaranteed, and the large-capacity SD card is limited to the structural design. The same capacity occupies a large chip area, and the cost is naturally high. In order to reduce power consumption and project costs, meet data storage requirements, no jumper is required, and chip utilization is improved. Flash storage chips are used as data storage devices. Embedded processors can meet the application requirements of intensive computing and match the equipment application requirements to the maximum extent. The more representative series include ARM's ARM processor core. Cortex-M4 is an ARM microprocessor based on ARMv7. It is an embedded processor specially optimized for microcontrollers and low-cost applications. It is a series of high-efficiency and easy-to-use processors that are upwardly compatible, which optimizes the operation process and improves the efficiency of alignment support.
[0003] The storage module and data processing module are embedded inside the handheld terminal. The storage module realizes the cyclic storage of the ship alignment information of the arm value of the relative reference position of the inertial navigation in the carrier coordinate system, and quickly exchanges data with the data processing module through the SPI bus. The data processing module solves the data through the arm compensation, and compensates the arm speed with the inertial navigation output speed to obtain the reference speed at the inertial navigation position.
[0004] Currently, there is no method for transmitting data through the SPI bus of the ARMCortex-M4 processor through the external serial Flash storage chip via the Quad-SPI controller. There is an urgent need for a method that can control the communication between the Quad-SPI controller and the SPI interface FLASH. Summary of the invention
[0005] The purpose of the present invention is to overcome the deficiencies of the prior art and to propose a communication control system and method based on a Quad-SPI controller and an external FLASH, which can periodically read data in the cache of an HP3458A digital multimeter.
[0006] The present invention solves the technical problem by adopting the following technical solutions:
[0007] A communication control system based on a Quad-SPI controller and an external FLASH includes a Quad-SPI controller and an SPI interface FLASH storage chip. The Quad-SPI controller includes four modules inside and is connected to the SPI interface FLASH storage chip through six control lines. The four modules are: a control register, a clock generator, a send / receive control logic and a shift register. The six control lines are: a control line SCK, a control line NSS, a control line MOSI, a control line MISO, a control line IO2 and a control line IO3.
[0008] Moreover, the Quad-SPI controller uses a 32-bit industrial-grade single-board computer GD32F450XX series device based on an ARMCortex-M4 processor, and the SPI interface Flash memory chip uses a 16Mbit serial Flash memory chip GD25Q32E.
[0009] The Quad-SPI controller configures the internal registers through the control register, the control register stores temporary data during the transmission process through the included send buffer and receive buffer, and controls the communication speed through the control register frequency division selection;
[0010] The Quad-SPI controller generates an SCK communication clock through a clock generator, and the SCK pin provides the timing of serial input and output operations;
[0011] The Quad-SPI controller transmits the send buffer and receive buffer data through the shift register, and controls the sending and receiving of serial data on the control lines MOSI, MISO, IO2, and IO3;
[0012] The Quad-SPI controller generates control logic according to the Quad-SPI command through the send / receive control logic, performs I / O control, generates output signals and controls communication, and controls receiving communication according to the received SCK signal and NSS signal;
[0013] The APB bus of the Quad-SPI controller connects peripherals and serves as a standard on-chip peripheral bus structure; the control line SCK is a clock signal line, and the control line NSS is a chip select control line; the control line MOSI, the control line MISO, the control line IO2, and the control line IO3 are data lines, wherein the control line MOSI is the control line IO0, and the control line MISO is the control line IO1.
[0014] The invention discloses a control method based on a Quad-SPI controller and an external FLASH communication control system, including a method for configuring a Quad-SPI port mode, a method for configuring SPI bus parameters, a method for enabling an SPI bus, a method for obtaining an address of a Flash storage chip, a method for waiting for the end of command execution or waiting for idleness, a method for enabling chip write, a method for erasing data, a method for sending data, a method for receiving data, and a method for disabling a SPI bus four-way mode and shutting down an SPI bus.
[0015] Furthermore, the method for configuring the Quad-SPI port mode comprises the following steps:
[0016] Step 1, configure the control line IO2 to the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0017] Step 2: Configure the control line IO3 to a multiplexed push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0018] Step 3, configure the control line MISO to the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0019] Step 4: Configure the control line SCK to the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0020] Step 5, configure the control line MOSI to the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0021] Step 6. Configure the control line NSS to a push-pull output mode without pull-up and pull-down resistors, with a maximum output speed of 50M.
[0022] The method for configuring SPI bus parameters comprises the following steps:
[0023] Step 1: Configure the SPI bus running direction and set the SPI bus to two-line bidirectional full-duplex mode;
[0024] Step 2: Configure the SPI bus working mode and set the SPI bus to work in host mode;
[0025] Step 3: Configure the SPI bus transmission data length and data frame format, and set the SPI bus communication data size to 8 bits;
[0026] Step 4: Configure the SPI bus clock polarity. When the SPI bus is in idle state before and after data transmission, the SCK pin is pulled high.
[0027] Step 5: Configure the SPI bus sampling delay and set it to collect the first data at the second clock transition edge;
[0028] Step 6: Configure whether to use hardware to control the chip select NSS signal;
[0029] Step 7. Configure the PSC[2:0] bits in the control register SPI_CTL0 to generate the communication speed SCK signal of the expected baud rate. The SPI bus clock is 25MHz.
[0030] Step 8: Configure the frame format data bit order, send the most significant bit first, and start data transmission from the high bit.
[0031] Moreover, the method for enabling the SPI bus includes the following steps:
[0032] Step 1: Configure the SPI bus to work in four-wire I / O mode;
[0033] Step 2, IO2 pin and IO3 pin output high level;
[0034] Step 3, enable the SPI bus function;
[0035] The method for obtaining the address of the Flash storage chip comprises the following steps:
[0036] Step 1. Pull down the NSS pin to enable the chip, select chip select, select the Flash storage chip, and drive the NSS pin to a low level;
[0037] Step 2: Send a command to obtain the address to the chip;
[0038] Step 3: Read three bytes continuously;
[0039] Step 4: Pull up the NSS pin to disable the chip, cancel the chip select, release the chip, and drive the NSS pin to a high level to complete the command;
[0040] Step 5: Combine the addresses obtained from the three bytes to obtain the ID number of the Flash memory chip.
[0041] Moreover, the method of waiting for the command execution to end or waiting for idleness comprises the following steps:
[0042] Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0043] Step 2, send a read status register command;
[0044] Step 3, read a byte status register;
[0045] Step 4: Repeat step 3 and wait for the WIP position to clear;
[0046] Step 5: Pull up the NSS pin to disable the chip, cancel the chip select, and release the chip.
[0047] Moreover, the method for enabling chip write enable includes the following steps:
[0048] Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0049] Step 2, send a write enable command;
[0050] Step 3: Pull up the NSS pin to disable the chip and release the chip.
[0051] Furthermore, the data erasing method comprises the following steps:
[0052] Step 1, turn on the chip write enable and send a write enable command;
[0053] Step 2. Pull down NSS to enable the chip, select chip select, and select the chip;
[0054] Step 3, send sector erase command;
[0055] Step 4: Send the starting address to be erased, which requires sending three 8-bit addresses;
[0056] Step 5: Pull up the NSS disabled chip to release the chip;
[0057] Step 6: Wait for the erase command to complete.
[0058] Furthermore, the method for sending data comprises the following steps:
[0059] Step 1: Determine whether the written area is empty, if not, perform data erasure;
[0060] Step 2: Enable chip write enable and send a write enable command;
[0061] Step 3: Configure the four-wire SPI bus operation chip;
[0062] Step 4, wait for the execution of the write status register command to be completed;
[0063] Step 5. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0064] Step 6, configure the QMOD bit in the four-way SPI control register SPI_QCTL to enable the SPI bus to work in the four-line I / O mode, and configure the QRD bit in the four-way SPI control register SPI_QCTL to select the SPI bus four-way mode write operation;
[0065] Step 7, send a quadruple speed page editing command;
[0066] Step 8: Send the starting address of the data to be written, where three 8-bit addresses need to be sent;
[0067] Step 9, write one byte of data to the data register SPI_DATA, and the TBE bit in the status register SPI_STAT will be cleared;
[0068] Step 10, wait for the hardware to reset the TBE bit in the status register SPI_STAT, the send buffer is empty, and then write the next byte of data;
[0069] Step 11, repeat steps 9 and 10 to write 256 bytes;
[0070] Step 12, pull up the NSS pin to disable the chip, cancel the chip select, and release the chip;
[0071] Step 13, waiting for the execution of the quadruple speed page editing command to be completed;
[0072] The method for receiving data comprises the following steps:
[0073] Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0074] Step 2, send a four-port output fast read data command;
[0075] Step 3: Send the starting address of the data to be read, where three 8-bit addresses need to be sent;
[0076] Step 4: Send an 8-bit dummy byte to allow the internal circuit of the Flash memory chip to have extra time to set the start address and work at the highest frequency;
[0077] Step 5, configure the QMOD bit in the four-way SPI control register SPI_QCTL to enable the SPI bus to work in the four-line I / O mode, and configure the QRD bit in the four-way SPI control register SPI_QCTL to select the SPI bus four-way mode read operation;
[0078] Step 6, write idle data to the data register SPI_DATA to generate the SCK clock signal;
[0079] Step 7, wait for the RBNE position in the status register SPI_STAT to be 1, the receive buffer is not empty, and then read the data register SPI_DATA to obtain the received data;
[0080] Step 8: Repeat steps 6 and 7. After data transmission starts, the TBE bit in the status register SPI_STAT is checked for each data frame sent. If the send buffer is empty, write idle data to the data register SPI_DATA to receive the next byte of data.
[0081] Step 9, pull up the NSS pin to disable the chip, cancel the chip select, and release the chip;
[0082] Step 10: Wait for the four-port output fast read data command to be executed.
[0083] Furthermore, the method of disabling the SPI bus quad mode and shutting down the SPI bus comprises the following steps:
[0084] Step 1. Before disabling the SPI bus quad mode and turning off the SPI bus function, check whether the TBE bit in the status register SPI_STAT is set and the TRANS bit is cleared;
[0085] Step 2: Configure the QMOD bit in the quad SPI control register SPI_QCTL to disable the SPI bus from operating in the four-line I / O mode;
[0086] Step 3: Configure the SPIEN bit in the control register SPI_CTL0 to disable the SPI bus device.
[0087] The advantages and positive effects of the present invention are:
[0088] The present invention connects four modules inside the Quad-SPI controller with an SPI interface FLASH memory chip, and realizes full-duplex transmission communication between the Quad-SPI controller and the SPI interface FLASH memory chip by configuring the Quad-SPI port mode, configuring SPI bus parameters, turning on the SPI bus enable, obtaining the Flash memory chip address, waiting for command execution to end or waiting for idleness, turning on the chip write enable, data erasing, sending data, receiving data, disabling the SPI bus four-way mode, and turning off the SPI bus, thereby meeting the use function of the equipment, reducing the project development cost, meeting the demand for fast data storage, improving chip utilization, shortening the project development cycle, and being easy to maintain, efficient, and convenient to operate. BRIEF DESCRIPTION OF THE DRAWINGS
[0089] Figure 1 It is a block diagram of the Quad-SPI controller structure of the present invention;
[0090] Figure 2 It is a hardware connection diagram of the Quad-SPI controller and the SPI interface Flash storage chip of the present invention;
[0091] Figure 3It is a schematic diagram of the timing sequence of a read command in a four-line I / O mode of the present invention;
[0092] Figure 4 is a timing diagram of the sending operation of the present invention;
[0093] Figure 5 is a timing diagram of the receiving operation of the present invention;
[0094] Figure 6 It is the SPI timing diagram in the four-wire I / O mode of the present invention;
[0095] Figure 7 This is a timing diagram of writing data to the Flash storage chip of the present invention;
[0096] Figure 8 This is a timing diagram of the Flash storage chip reading data of the present invention;
[0097] Fig. 9 It is a verification step diagram of the test method of the present invention;
[0098] Fig.10 It is the SPI clock frequency waveform diagram of the present invention;
[0099] Fig.11 It is a structural diagram of the test verification process of the present invention;
[0100] Fig.12 It is the SPI bus test effect verification interface of the present invention. DETAILED DESCRIPTION
[0101] The present invention is further described in detail below with reference to the accompanying drawings.
[0102] Based on the Quad-SPI controller and external FLASH communication control system, the Quad-SPI controller is configured using the 32-bit industrial-grade single-board computer GD32F450XX series device based on the ARM Cortex-M4 processor, and the Flash storage chip uses the 16Mbit serial Flash storage chip GD25Q32E, such as Figure 1 As shown, the Quad-SPI controller includes four modules: a control register, a clock generator, a send / receive control logic and a shift register. The Quad-SPI controller includes six control lines: a control line SCK, a control line NSS, a control line MOSI, a control line MISO, a control line IO2 and a control line IO3. The Quad-SPI controller also includes an APB bus, in which the control line MOSI is the control line IO0 and the control line MISO is the control line IO1.
[0103] The Quad-SPI controller configures the internal registers through the control registers, the control registers store temporary data during the transmission process through the included sending buffer and receiving buffer, and controls the communication speed through the control register frequency division selection;
[0104] The Quad-SPI controller generates an SCK communication clock through a clock generator, and the SCK pin provides the timing of serial input and output operations;
[0105] The Quad-SPI controller transmits the send buffer and receive buffer data through the shift register, and controls the sending and receiving of serial data on the control lines MOSI, MISO, IO2, and IO3;
[0106] The Quad-SPI controller generates control logic according to the Quad-SPI command through the send / receive control logic, performs I / O control, generates output signals and controls communication, and controls receiving communication according to the received SCK signal and NSS signal.
[0107] The APB bus of the Quad-SPI controller connects peripheral devices and serves as a standard on-chip peripheral bus structure; the control line SCK is a clock signal line, and the control line NSS is a chip select control line; the control line MOSI, the control line MISO, the control line IO2 and the control line IO3 are data lines, the control line MOSI is the control line IO0, and the control line MISO is the control line IO1.
[0108] like Figure 2 The figure shows the hardware connection diagram between the Quad-SPI controller and the Flash memory chip. The connection line SCK of the Quad-SPI controller corresponds to the PG13 pin of the industrial-grade single-board computer GD32F450XX series device and is connected to the SCK pin of the Flash memory chip, and an external 10KΩ pull-up resistor is connected. The connection line MOSI corresponds to the PG14 pin of the industrial-grade single-board computer GD32F450XX series device and is connected to the DI pin of the Flash memory chip. The connection line MISO corresponds to the PG14 pin of the industrial-grade single-board computer GD32F450XX series device and is connected to the DI pin of the Flash memory chip. The connection line IO2 corresponds to the PG10 pin of the industrial-grade single-board computer GD32F450XX series device and is connected to the / WP pin of the Flash memory chip. The connection line IO3 corresponds to the PG11 pin of the industrial-grade single-board computer GD32F450XX series device and is connected to the / HOLD pin of the Flash memory chip. The connection line NSS corresponds to the PG8 pin of the industrial-grade single-board computer GD32F450XX series device and is connected to the NSS pin of the Flash memory chip.
[0109] The chip select signal NegativeSlaveSelect, that is, the NSS pin, is used to enable and disable the operation of the Flash memory chip. When NSS is at a high level, the Flash memory chip is deselected, indicating that the chip is not selected. At this time, the DI pin, DO pin, / WP pin, and / HOLD signal pin are all in a high-impedance state unless the Flash memory chip is erased or page edited. When not selected, the Flash memory chip is in a low-power standby state. When the NSS pin becomes a low level, it means that the Flash memory chip is selected, and its power consumption will increase to a normal level. The Quad-SPI controller sends data to or receives data from the Flash memory chip through the SPI bus. After power-on, the NSS pin must be converted from a high level to a low level before receiving a new Flash command.
[0110] The serial data input signal DI pin and the serial output signal DO pin are both bidirectional I / O ports, which serve as both input and output. At the rising edge of the serial clock input signal SCK, the bidirectional I / O pin is used to serially write the Flash memory chip command, store the address or data in the Flash memory chip, and at the falling edge of the serial clock input signal SCK, the data or status in the Flash memory chip is serially output through the bidirectional I / O pin.
[0111] The write protection signal WriteProtest, i.e., the / WP pin, is used to prevent the status register of the Flash memory chip from being written with erroneous data. The / WP pin is valid at a low level. However, when the status register is set to enable the four-line I / O mode, the / WP pin loses its hardware write protection function, i.e., the pin is invalid. This pin acts as the bidirectional data transmission IO2 pin.
[0112] The HOLD signal, i.e., the / HOLD pin, is used to suspend the operation of the Flash storage chip, and the / HOLD pin is valid at a low level. When the / HOLD pin is low and the NSS pin is also low, the serial output signal DO pin will be in a high-impedance state, and the serial input signal DI pin and the serial clock SCK pin will be ignored by the chip. When the / HOLD pin is pulled high, the read and write operations of the Flash can continue, and the chip returns to normal. When multiple SPI bus slave devices share the same signal of the same group of SPI buses, the / HOLD pin is used to switch the direction of the signal. Like the / WP signal, when the status register is set to enable the four-wire I / O mode, the / HOLD pin is not available, that is, the pin is invalid, and this pin acts as the IO3 pin for bidirectional data transmission.
[0113] The serial clock input SCK pin is used to provide the timing of serial input and output operations, that is, the clock of serial input and output operations.
[0114] The SPI bus of the Quad-SPI controller is connected to external devices through six pins. Table 1 describes the type and overview of each pin.
[0115] Table 1
[0116] Pin Name type Overview SCK Output Quad-SPI clock output. MOSI(IO0) Input / Output Send or receive data 0 line. MISO(IO1) Input / Output Send or receive data 1 line. IO2 Input / Output Send or receive data 2 wires. IO3 Input / Output Send or receive data 3 wires. NSS Output Controls the Quad-SPI chip select signal.
[0117] like Figure 3 The figure shows the timing diagram of the read command in the four-wire I / O mode of the Quad-SPI controller, where each command includes five stages: instruction + address + multiplexed byte + empty cycle + data. The Quad-SPI controller configures different stages according to the instruction timing. Any stage can be skipped, but at least one of the instruction, address, multiplexed byte or data stages must be included. The NSS pin level drops before each command starts and rises again after each command is completed.
[0118] The instruction stage: In this stage, an 8-bit instruction is sent to the Flash memory chip to specify the type to be executed.
[0119] The address stage: In this stage, 3 bytes are sent to the Flash memory chip to indicate the address of the operation. In this stage, 4 bits are sent at a time through the IO0 pin, IO1 pin, IO2 pin and IO3 pin within one clock.
[0120] The multiplexed byte stage: In this stage, 1 or 2 or 3 or 4 bytes are sent to the Flash memory chip to control the operation mode.
[0121] The idle cycle phase: In this phase, no data is sent or received within a given 1 to 31 cycles. The purpose is to give the Flash memory chip time to prepare the data phase when a higher clock frequency is used.
[0122] The data phase: In this phase, any number of bytes are received from or sent to the Flash memory chip. In this phase, if data is sent, the I / O port is output, and if data is received, the I / O port is switched to input, and 4 bits are transmitted at a time through the IO0 pin, IO1 pin, IO2 pin and IO3 pin in one clock.
[0123] Each time the Quad-SPI controller sends a command to the Flash memory chip, the chip select signal NSS pin has a process of being pulled low and then pulled high. Table 2 describes the Flash commands on the Quad-SPI controller in this article.
[0124] Table 2
[0125]
[0126] Table 3 describes the status register of the Flash memory chip GD25Q32E.
[0127] Table 3
[0128]
[0129] The suspend status bit SUS1 and the suspend status bit SUS0 are read-only bits S15 and S10 in the status register respectively, which are set to 1 after executing the erase suspend command, and the suspend status bit SUS is cleared to 0 through the erase resume command and the power-off and power-on cycles.
[0130] The CMP is a non-volatile read / write bit S14 in the status register. Together with BP4, BP3, BP2, BP1, and BP0, it provides more flexible protection. When the "CMP bit" is set to 0, the top 4KB sector of the Flash memory chip is protected, while the rest is not protected. When the "CMP bit" is set to 1, the protection function set by BP4, BP3, BP2, BP1, and BP0 will be retained, the top 4K sector becomes unprotected, and the rest is read-only, and the default setting is 0.
[0131] The security register lock bit LB2, security register lock bit LB1 and security register lock bit LB0 are non-volatile one-time programming protection bits OTP bits S13, S12 and S10 in the status register respectively. The default is 0, and the security register is not locked. The security register lock bit LB is independently set to 1 through the write status register command. When it is set to 1, the OTP protection is locked, and the corresponding 256-byte security register will be permanently read-only.
[0132] The quad enable bit QE is a non-volatile read / write bit S9 in the status register, which allows four-wire SPI operation. The factory default value of the quad enable bit QE is 0. When the quad enable bit QE is set to 0, the / WP pin and the / HOLD pin are enabled. Before enabling the four-wire I / O mode, turn on the enable bit of the four-wire read and write function and set the quad enable bit QE to 1. At this time, the IO2 pin and IO3 pin are enabled, and the / WP pin and / HOLD pin functions are disabled.
[0133] The status register protection bit SRP1 is the non-volatile read / write bit S8 in the status register, and the status register protection bit SRP0 is the non-volatile read / write bit S7 in the status register. The SRP bit controls write protection in the following ways: software protection, hardware protection, power lock or one-time programmable OTP protection.
[0134] The block protection bit BP4 is the non-volatile read / write bit S6 of the status register, the block protection bit BP3 is the non-volatile read / write bit S5 of the status register, the block protection bit BP2 is the non-volatile read / write bit S4 of the status register, the block protection bit BP1 is the non-volatile read / write bit S3 of the status register, and the block protection bit BP0 is the non-volatile read / write bit S2 of the status register, providing write protection control and status. Use the write status register command to set the block protection bit to protect all, some blocks, or none of them. The default setting of the block protection bit is 0, which is not protected at all.
[0135] The write enable latch bit WEL is the read-only bit S1 in the status register. After power-on, the Flash memory chip automatically sets the write enable latch bit WEL to 0, and the state is write-prohibited. Before executing page edit, quad-speed page edit, sector erase, block erase, chip erase and write status register commands, write enable needs to be set, that is, this position is 1. After completing these commands, the write enable latch bit WEL automatically changes to write-prohibited state, that is, the WEL bit is cleared.
[0136] The chip busy / idle indication bit WIP is a read-only bit S0 in the status register. When the Flash memory chip executes a page edit, quad-speed page edit, sector erase, block erase, chip erase or write status register command, this bit is set to 1. At this time, except for reading the status register and erasing pause, other commands are ignored. When the above commands are completed, the chip will perform operations internally and clear the WIP bit to 0, indicating that the Flash memory chip is ready to execute other commands.
[0137] The SPI bus communication structure includes four modules: deviceID module, transmitter module, receiver module and command execution completion module.
[0138] The deviceID module of the Flash memory chip: There are many devices on the SPI bus. First, the address process of the device must be obtained. Each Flash memory chip has a unique deviceID inside. The chip ID is read to determine the chip;
[0139] The transmitter module: Figure 4As shown, when the SPI bus starts to send a data frame, the data frame to be sent is first written into the send buffer by writing the data register SPI_DATA, and then the data frame is loaded from the send buffer into the shift register, and then the loaded data frame is sent. In this mode, the MOSI pin, MISO pin, IO2 pin and IO3 pin are all used as output pins. After SCK generates a clock signal, the data is written into the data register SPI_DATA, the TBE bit is cleared, and the written data will be sent through these four pins. After the first byte of the data frame is successfully sent, the TBE flag position of the status register SPI_STAT is set to 1, indicating that the send buffer is empty. At this time, the continuous sending function is realized. Before the current data frame is sent, the next data frame is written into the data register SPI_DATA, and after the SPI bus starts to send data, the TBE flag bit is detected for each data frame sent. If the send buffer empty condition cannot be met, the sending is stopped. The TBE bit is the send buffer empty flag bit. When the send buffer is empty, the TBE flag position is set to 1. The next data to be sent is written into the send buffer by writing the data register SPI_DATA;
[0140] The receiver module: Figure 5 As shown, after a sampling clock edge, the received data is stored from the shift register to the receive buffer. At this time, the RBNE bit is set to 1, and then the received data is obtained by reading the data register SPI_DATA. After this operation, the RBNE flag is cleared. In this mode, the MOSI pin, MISO pin, IO2 pin and IO3 pin are all used as input pins. In order to receive the next data frame, the hardware needs to send the SCK clock signal continuously. In order to generate the SCK clock signal, it is necessary to write data to the data register SPI_DATA, write any data, and always write idle data to the data register SPI_DATA. After the SPI starts sending data, once the data is written to the data register SPI_DATA, the TBE bit will be cleared. Therefore, the TBE bit must be detected for each data frame sent. If the send buffer empty condition is not met, the transmission will be stopped. The RBNE bit is the receive buffer non-empty flag. When the receive buffer is not empty, RBNE is set to 1, indicating that a data is received at this time and has been stored in the receive buffer. The data is read by reading the data register SPI_DATA. This operation automatically clears the RBNE flag;
[0141] The module for waiting for the command execution to end: When the Flash storage chip executes a page edit, quad-speed page edit, sector erase, block erase, chip erase or write status register command, the WIP flag of the status register of the Flash storage chip will be changed, and the WIP bit will be set. During this period, except for reading the status register, all other commands of the Flash chip will be ignored. It is necessary to wait for the command execution to end or wait for idleness, that is, to detect whether the chip is in a busy state. When the command execution is completed or idle, the WIP bit of the status register of the Flash storage chip will be cleared, indicating that the command execution has been completed and it is ready to execute other commands.
[0142] The control method based on Quad-SPI controller and external FLASH communication control system includes: configuring Quad-SPI port mode, configuring SPI bus parameters, turning on SPI enable, obtaining Flash chip address, waiting for command execution to end or waiting for idleness, turning on chip write enable, data erasing, sending data, receiving data, disabling SPI bus four-way mode and shutting down SPI bus.
[0143] The specific steps of configuring the Quad-SPI port mode include:
[0144] Step 1. Configure the PG10 pin to multiplex push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0145] Step 2: Configure the PG11 pin to multiplex push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0146] Step 3: Configure the PG12 pin to multiplex the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0147] Step 4. Configure the PG13 pin to multiplex the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0148] Step 5. Configure the PG8 pin to multiplex push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M;
[0149] Step 6. Configure the control line NSS to push-pull output mode without pull-up and pull-down resistors, with a maximum output speed of 50M.
[0150] The configuration of the SPI bus parameters is to configure the control register SPI_CTL0, and the specific steps include:
[0151] Step 1, configure the running direction of the SPI bus, that is, configure the RO bit, BDEN bit and BDOEN bit in the control register SPI_CTL0, and set the SPI bus to two-line bidirectional full-duplex mode;
[0152] Step 2, configure the working mode of the SPI bus, that is, configure the MSTMOD bit in the control register SPI_CTL0, and set the SPI bus to work in the master mode;
[0153] Step 3, configure the SPI bus transmission data length and data frame format, that is, configure the FF16 bit in the control register SPI_CTL0. The data frame length of the SPI bus in the four-wire I / O mode is fixed to 8 bits, so set the SPI bus communication data size to 8 bits;
[0154] Step 4, configure the SPI bus clock polarity, that is, configure the CKPL bit in the control register SPI_CTL0. When the SPI bus is in the idle state before and after data transmission, the SCK pin is pulled high;
[0155] Step 5, configure the SPI bus sampling delay, that is, configure the CKPH bit in the control register SPI_CTL0, and set it to collect the first data at the second clock transition edge;
[0156] Step 6. Configure whether to use hardware to control the chip select NSS pin mode, that is, configure the SWANSSEN bit and NSSDRV bit in SPI_CTL0. Because the chip select uses the PG8 pin, set the software to control the SPI bus chip select, that is, manage the slave device, and specify that the NSS pin signal is managed by software. At this time, the NSS pin is pulled high and maintained at a high level. When the sending or receiving process starts, the NSS pin becomes a low level;
[0157] Step 7, configure the PSC[2:0] bits in the control register SPI_CTL0 to generate the communication speed SCK signal of the expected baud rate, set the APB maximum clock frequency to 100MHz, and set the send and receive SCK clock division to 32 (=2^(4+1)), so the SPI clock = 100MHz / 4 = 25MHz;
[0158] Step 8. Configure the frame format data bit order, that is, configure the LF bit in the control register SPI_CTL0, send the most significant bit MSB first, and data transmission starts from the high bit.
[0159] The enabling of the SPI bus is to configure the four-way SPI control register SPI_QCTL and the control register SPI_CTL0, wherein the SPI bus timing in the four-wire I / O mode is as follows: Figure 6 As shown, the specific steps include:
[0160] Step 1: Configure the SPI bus to work in four-line I / O mode, that is, configure the QMOD bit in the four-way SPI control register SPI_QCTL;
[0161] Step 2: Drive the IO2 and IO3 pins to output high level, that is, configure the IO23_DRV bit in the quad SPI control register SPI_QCTL;
[0162] Step 3: Enable the SPI bus function, that is, configure the SPIEN bit in the control register SPI_CTL0.
[0163] The command to obtain the Flash chip address is 9F. The first byte sent by the command is the command byte, and the second byte is the returned manufacturer identification. The third and fourth bytes are the returned chip identification. The specific steps to read the chip address are:
[0164] Step 1. Pull down the NSS pin to enable the chip, select chip select, select the Flash chip, and drive the NSS pin to a low level;
[0165] Step 2: Send command 9F to the chip to obtain the address;
[0166] Step 3: Read three bytes continuously;
[0167] Step 4: Pull up the NSS pin to disable the chip, cancel the chip select, release the chip, and drive the NSS pin to a high level to complete the command;
[0168] Step 5: Combine the addresses obtained from the three bytes to obtain the Flash ID number.
[0169] The command for reading the status register is 05. The first byte sent by the command is the command byte, and the second byte is the status register return value. Therefore, the specific steps of waiting for the command execution to end or waiting for idleness include:
[0170] Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0171] Step 2, send the read status register command 05;
[0172] Step 3, read a byte status register;
[0173] Step 4: Repeat step 3 and wait for the WIP position to be cleared;
[0174] Step 5: Pull up the NSS pin to disable the chip, cancel the chip select, and release the chip.
[0175] When executing the Flash storage chip page editing and data erasing commands, it is necessary to enable the chip write enable function. The specific steps of enabling the chip write enable include:
[0176] Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0177] Step 2, send write enable command 06;
[0178] Step 3: Pull up the NSS pin to disable the chip and release the chip.
[0179] The data erasure is performed by sector erasure, block erasure or chip erasure. The sector erasure command (20) has the first byte as the command byte, and the second, third and fourth bytes as the sector erasure address. The chip erasure operation flow is as follows:
[0180] Step 1, turn on the chip write enable and send the write enable command 06;
[0181] Step 2. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0182] Step 3, sending sector erase command 20;
[0183] Step 4: Send the starting address to be erased, which requires sending three 8-bit addresses;
[0184] Step 5, pull up the NSS pin to disable the chip and release the chip;
[0185] Step 6: Wait for the erase command to complete.
[0186] After completing the SPI bus initialization process, turn on the SPI bus enable and keep it in idle state. The SPI bus works in write mode. When writing data, it can only be written according to the page. The data is written in the page writing mode. It supports writing up to 256 bytes of data at a time, that is, a page of space, page alignment, and when editing the page, it is necessary to ensure that the write area bits are all 1, that is, data must be erased, so generally each write must be done before writing. From the command table 2, it can be seen that the first byte of the quadruple speed page edit command 32 is the command byte, the second, third and fourth bytes are the write data address, the fifth is the data byte to be sent, and then the next byte of data is written. Figure 7 The figure shows the timing of writing data to the Flash memory chip. The specific steps of register configuration when sending data include:
[0187] Step 1: Determine whether the written area is empty, if not, perform data erasure;
[0188] Step 2: Enable chip write enable and send a write enable command;
[0189] Step 3, configure the four-wire SPI operation chip, send the write status register command 01, send 00 and 02, and set the status register QE bit of the Flash memory chip to allow the four-wire SPI to operate the Flash memory chip;
[0190] Step 4, wait for the execution of the write status register command to be completed;
[0191] Step 5. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0192] Step 6, configure the QMOD bit in the four-way SPI control register SPI_QCTL to enable the SPI bus to work in the four-line I / O mode, and configure the QRD bit in the four-way SPI control register SPI_QCTL to select the SPI four-way mode write operation;
[0193] Step 7, sending a quadruple speed page editing command 32;
[0194] Step 8: Send the starting address of the data to be written, where three 8-bit addresses need to be sent;
[0195] Step 9, write one byte of data to the data register SPI_DATA, and the TBE bit in the status register SPI_STAT will be cleared;
[0196] Step 10, wait for the hardware to reset the TBE bit in the status register SPI_STAT, the send buffer is empty, and then write the next byte of data;
[0197] Step 11, repeat steps 9 and 10 to write 256 bytes;
[0198] Step 12, pull up the NSS pin to disable the chip, cancel the chip select, and release the chip;
[0199] Step 13: Wait for the execution of the quad-speed page editing command to be completed.
[0200] The four-port output fast read data command is 6B. This command starts a 24-bit address to enter the DI pin of the Flash memory chip. The address is latched on the SCK pin on the rising edge. After receiving the address, the data byte of the addressed storage unit will be shifted out on the DO pin at the falling edge of SCK. The most significant bit MSB is first. After each data byte is shifted out, it is allowed to continue. The address is automatically incremented to the next higher address data stream. As long as one command is used, the entire Flash memory chip can be accessed continuously. In order to generate the SCK clock signal, data must be written to the data register SPI_DATA. This command allows more than one data byte to be read sequentially from the Flash memory chip. The four-port output fast read command transmits data at four times the rate of the standard SPI device. The I / O pin is in a high-impedance state before the falling edge of the first data output clock. The first byte of the four-port output fast read data command 6B is the command byte, the second, third and fourth bytes are the read data addresses, the fifth byte is a dummy byte, and the sixth byte starts to return data. If it is read continuously, the next byte of data will be returned. Figure 8 The figure shows the timing of reading data from the Flash memory chip. The specific steps of receiving data include:
[0201] Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip;
[0202] Step 2, send a four-port output fast read data command 6B;
[0203] Step 3: Send the starting address of the data to be read, where three 8-bit addresses need to be sent;
[0204] Step 4: Send an 8-bit pseudo byte, such as 0XA5, so that the internal circuit of the Flash memory chip has extra time to set the start address and work at the highest frequency;
[0205] Step 5, configure the QMOD bit in the quad SPI control register SPI_QCTL to enable SPI to work in four-line I / O mode, and the QRD bit to select the SPI bus four-way mode read operation;
[0206] Step 6, write idle data such as 0xFF to the data register SPI_DATA to generate the SCK clock signal;
[0207] Step 7, wait for the RBNE position in the status register SPI_STAT to be 1, the receive buffer is not empty, and then read the data register SPI_DATA to obtain the received data;
[0208] Step 8: Repeat steps 6 and 7. After data transmission starts, the TBE bit in the status register SPI_STAT is checked for each data frame sent. If the send buffer is empty, write idle data to the data register SPI_DATA to receive the next byte of data.
[0209] Step 9, pull up the NSS pin to disable the chip, cancel the chip select, and release the chip;
[0210] Step 10: Wait for the four-port output fast read data command to be executed.
[0211] The specific steps of disabling the SPI bus four-way mode and shutting down the SPI bus include:
[0212] Step 1: Before disabling the SPI bus quad mode and turning off the SPI bus function, first check whether the TBE bit in the status register SPI_STAT is set and whether the TRANS bit is cleared. The TRANS bit is the SPI bus communication in progress flag bit. The TRANS bit is a status flag bit used to indicate whether the current transmission is in progress or ended. It is set and cleared by internal hardware and cannot be controlled by software.
[0213] Step 2: Configure the QMOD bit in the quad SPI control register SPI_QCTL to disable the SPI bus from operating in four-wire I / O mode;
[0214] Step 3: Configure the SPIEN bit in the control register SPI_CTL0 to disable the SPI device.
[0215] According to the above-mentioned communication control system and method based on Quad-SPI controller and external FLASH, use Fig. 9 The verification method shown is tested, and the specific steps are:
[0216] Step 1, hardware power-on test: During the test, check that the power supply, clock and configuration signals are normal, that there is no short circuit or cold solder joint on the pins of each device, and use the synchronous serial port controller Quad-SPI5 to realize the sending and receiving functions with the Flash storage chip;
[0217] Step 2: Correctly configure the test environment: Build a platform test on the handheld terminal prototype. First, set the baud rate of the hyperterminal to 57600, 8 data bits, and 1 stop bit. Then jumper the JP13 pin to the 1-way serial port of the handheld terminal, and jumper the JP10 pin to SPI5. The data processing module communicates with the Flash storage chip through the Quad-SPI5 pin. Finally, observe the running status on the hyperterminal.
[0218] Step 3, SPI bus driver debugging: View the data through the breakpoint window to determine whether the configuration of each register being debugged is correct;
[0219] Step 4: Get the Flash memory chip ID number and see the manufacturer logo and chip logo of the memory chip on the HyperTerminal.
[0220] Step 5, SPI bus clock frequency measurement: Use a signal oscilloscope to measure the SPI bus clock frequency, observe the waveform for analysis, and each horizontal grid represents 20 nanoseconds. Fig.10 As shown, one cycle is 0.04 microseconds, or 25MHz. The actual measurement is completely consistent with the theory.
[0221] After following the above steps, if Fig.11 As shown, check whether the ID number of the Flash storage chip is consistent with that shown by the chip manufacturer on the hyperterminal. First write 256 bytes of data into the Flash, and then read it out. The hyperterminal will display the 256 bytes of data written and read out of the FLASH. Then compare whether the written data and the read data are consistent. If they are consistent, finally, print out "SPI-GD25Q32TestPassed!", otherwise, print out "Err: DataReadandWritearen'tMatching.".
[0222] Test results such as Fig.12 As shown, by testing the above-mentioned communication control system and method based on Quad-SPI controller and external FLASH, it is verified that this method can realize data transmission between SPI bus and Flash storage chip, reduce project development cost, meet the demand for fast data storage, improve chip utilization, shorten project development cycle, facilitate maintenance, high efficiency and convenient operation.
[0223] It should be emphasized that the embodiments described in the present invention are illustrative rather than restrictive. Therefore, the present invention includes but is not limited to the embodiments described in the specific implementation manner. Any other implementation manners derived by those skilled in the art based on the technical solution of the present invention also fall within the scope of protection of the present invention.
Claims
1. A control method for a communication control system based on a Quad-SPI controller and an external FLASH, characterized in that: The control system includes a Quad-SPI controller and an SPI interface FLASH memory chip. The Quad-SPI controller includes four modules inside and is connected to the SPI interface FLASH memory chip through six control lines. The four modules are: a control register, a clock generator, a send / receive control logic and a shift register. The six control lines are: a control line SCK, a control line NSS, a control line MOSI, a control line MISO, a control line IO2 and a control line IO3. The Quad-SPI controller uses the 32-bit industrial-grade single-board computer GD32F450XX series device based on the ARM Cortex-M4 processor, and the SPI interface Flash memory chip uses the 16Mbit serial Flash memory chip GD25Q32E. The Quad-SPI controller configures the internal registers through the control register, the control register stores temporary data during the transmission process through the included send buffer and receive buffer, and controls the communication speed through the control register frequency division selection; The Quad-SPI controller generates an SCK communication clock through a clock generator, and the SCK pin provides the timing of serial input and output operations; The Quad-SPI controller transmits the send buffer and receive buffer data through the shift register, and controls the sending and receiving of serial data on the control lines MOSI, MISO, IO2, and IO3; The Quad-SPI controller generates control logic according to the Quad-SPI command through the send / receive control logic, performs I / O control, generates output signals and controls communication, and controls receiving communication according to the received SCK signal and NSS signal; The APB bus of the Quad-SPI controller connects peripherals and serves as a standard on-chip peripheral bus structure; the control line SCK is a clock signal line, and the control line NSS is a chip select control line; the control lines MOSI, MISO, IO2, and IO3 are data lines, wherein the control line MOSI is the control line IO0, and the control line MISO is the control line IO1; The control method includes a method for configuring the Quad-SPI port mode, a method for configuring SPI bus parameters, a method for enabling the SPI bus, a method for obtaining the address of a Flash storage chip, a method for waiting for the command execution to end or waiting for idleness, a method for enabling chip write, a method for erasing data, a method for sending data, a method for receiving data, and a method for disabling the SPI bus quad-mode and shutting down the SPI bus; The specific steps of configuring the Quad-SPI port mode include: Step 1, configure the control line IO2 to the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M; Step 2: Configure the control line IO3 to a multiplexed push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M; Step 3, configure the control line MISO to the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M; Step 4: Configure the control line SCK to the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M; Step 5, configure the control line MOSI to the push-pull SPI function mode without pull-up and pull-down resistors, set pull-up and pull-down resistors externally, and the maximum output speed is 25M; Step 6. Configure the control line NSS to push-pull output mode without pull-up and pull-down resistors, with a maximum output speed of 50M. The configuration of the SPI bus parameters is to configure the control register SPI_CTL0, and the specific steps include: Step 1, configure the running direction of the SPI bus, configure the RO bit, BDEN bit and BDOEN bit in the control register SPI_CTL0, and set the SPI bus to two-line bidirectional full-duplex mode; Step 2: Configure the working mode of the SPI bus, configure the MSTMOD bit in the control register SPI_CTL0, and set the SPI bus to work in the master mode; Step 3, configure the SPI bus transmission data length, data frame format, configure the FF16 bit in the control register SPI_CTL0, the data frame length of the SPI bus in the four-wire I / O mode is fixed to 8 bits, so set the SPI bus communication data size to 8 bits; Step 4: Configure the SPI bus clock polarity and the CKPL bit in the control register SPI_CTL0. When the SPI bus is in the idle state before and after data transmission, the SCK pin is pulled high. Step 5, configure the SPI bus sampling delay, configure the CKPH bit in the control register SPI_CTL0, and set it to collect the first data at the second clock transition edge; Step 6. Configure whether to use hardware to control the chip select NSS pin mode, configure the SWANSSEN bit and NSSDRV bit in SPI_CTL0. Because the chip select uses the NSS pin, set the software to control the SPI bus chip select and manage the slave device. Specify that the NSS pin signal is managed by software. At this time, the NSS pin is pulled high and maintained at a high level. When the sending or receiving process starts, the NSS pin becomes a low level. Step 7. Configure the PSC[2:0] bits in the control register SPI_CTL0 to generate the communication speed SCK signal of the expected baud rate. Set the APB maximum clock frequency to 100MHz, and set the send and receive SCK clock division to 32, so the SPI clock = 100MHz / 4 = 25MHz; Step 8. Configure the frame format data bit order, configure the LF bit in the control register SPI_CTL0, send the most significant bit MSB first, and data transmission starts from the high bit. The specific steps of enabling the configuration of the four-way SPI control register SPI_QCTL and the control register SPI_CTL0 of the SPI bus include: Step 1: Configure the SPI bus to work in four-line I / O mode and configure the QMOD bit in the four-way SPI control register SPI_QCTL; Step 2: Drive the IO2 and IO3 pins to output high level, and configure the IO23_DRV bit in the quad SPI control register SPI_QCTL; Step 3: Enable the SPI bus function and configure the SPIEN bit in the control register SPI_CTL0. The command for obtaining the address of the Flash storage chip is 9F. The first byte sent by the command is the command byte, and the second byte is the returned manufacturer identification. The third and fourth bytes are the returned chip identification. The specific steps for reading the chip address are: Step 1. Pull down the NSS pin to enable the chip, select chip select, select the Flash chip, and drive the NSS pin to a low level; Step 2: Send command 9F to the chip to obtain the address; Step 3: Read three bytes continuously; Step 4: Pull up the NSS pin to disable the chip, cancel the chip select, release the chip, and drive the NSS pin to a high level to complete the command; Step 5: Combine the three bytes to get the Flash ID number. The command for reading the status register is 05. The first byte sent by the command is the command byte, and the second byte is the status register return value. Therefore, the specific steps of waiting for the command execution to end or waiting for idleness include: Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip; Step 2, send the read status register command 05; Step 3, read a byte status register; Step 4: Repeat step 3 and wait for the WIP position to be cleared; Step 5: Pull up the NSS pin to disable the chip, cancel the chip select, and release the chip. When executing Flash storage chip page editing and data erasing commands, you need to enable the chip write enable function. The specific steps to enable the chip write enable are as follows: Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip; Step 2, send write enable command 06; Step 3: Pull up the NSS pin to disable the chip and release the chip. The data erasure is performed by sector erasure, block erasure or chip erasure. The sector erasure command 20 has the first byte being the command byte, and the second, third and fourth bytes being the sector erasure address. The chip erasure operation flow specifically includes: Step 1, turn on the chip write enable and send the write enable command 06; Step 2. Pull down the NSS pin to enable the chip, select chip select, and select the chip; Step 3, sending sector erase command 20; Step 4: Send the starting address to be erased, which requires sending three 8-bit addresses; Step 5, pull up the NSS pin to disable the chip and release the chip; Step 6: Wait for the erase command to complete. After completing the SPI bus initialization process, turn on the SPI bus enable and keep it in idle state. The SPI bus works in write mode. When writing data, it can only be written according to the page. The data is written in the page writing mode. It supports writing 256 bytes of data at a time. The space of a page is page aligned. In addition, when editing the page, it is necessary to ensure that the write area bits are all 1. Data must be erased, so generally, each write must be erased before writing. The first byte of the quadruple speed page edit command 32 is the command byte, the second, third and fourth bytes are the write data address, and the fifth is the data byte to be sent. Then write the next byte of data. The specific steps of register configuration when sending data include: Step 1: Determine whether the written area is empty, if not, perform data erasure; Step 2: Enable chip write enable and send a write enable command; Step 3, configure the four-wire SPI operation chip, send the write status register command 01, send 00 and 02, and set the status register QE bit of the Flash memory chip to allow the four-wire SPI to operate the Flash memory chip; Step 4, wait for the execution of the write status register command to be completed; Step 5. Pull down the NSS pin to enable the chip, select chip select, and select the chip; Step 6, configure the QMOD bit in the four-way SPI control register SPI_QCTL to enable the SPI bus to work in the four-line I / O mode, and configure the QRD bit in the four-way SPI control register SPI_QCTL to select the SPI four-way mode write operation; Step 7, sending a quadruple speed page editing command 32; Step 8: Send the starting address of the data to be written, where three 8-bit addresses need to be sent; Step 9, write one byte of data to the data register SPI_DATA, and the TBE bit in the status register SPI_STAT will be cleared; Step 10, wait for the hardware to reset the TBE bit in the status register SPI_STAT, the send buffer is empty, and then write the next byte of data; Step 11, repeat steps 9 and 10 to write 256 bytes; Step 12, pull up the NSS pin to disable the chip, cancel the chip select, and release the chip; Step 13: Wait for the execution of the quad-speed page editing command to be completed. The four-port output fast read data command is 6B. This command starts a 24-bit address to enter the DI pin of the Flash memory chip. The address is latched on the SCK pin on the rising edge. After receiving the address, the data byte of the addressed storage unit will be shifted out on the DO pin at the falling edge of SCK. The most significant bit MSB is first. After each data byte is shifted out, it is allowed to be continuous. The address is automatically incremented to the next higher address data stream. As long as one command is used, the entire Flash memory chip can be accessed. In order to generate the SCK clock signal, data must be written to the data register SPI_DATA. This command allows more than one data byte to be read sequentially from the Flash memory chip. The four-port output fast read command transmits data at four times the rate of the standard SPI device. The I / O pin is in a high-impedance state before the falling edge of the first data output clock. The first byte of the four-port output fast read data command 6B is the command byte, the second, third and fourth bytes are the read data addresses, the fifth byte is a dummy byte, and the sixth byte starts to return data. If it is read again, the next byte of data will be returned. The specific steps for receiving data include: Step 1. Pull down the NSS pin to enable the chip, select chip select, and select the chip; Step 2, send a four-port output fast read data command 6B; Step 3: Send the starting address of the data to be read, where three 8-bit addresses need to be sent; Step 4: Send an 8-bit pseudo byte 0XA5 to allow the internal circuit of the Flash memory chip to have extra time to set the start address and work at the highest frequency; Step 5, configure the QMOD bit in the quad SPI control register SPI_QCTL to enable SPI to work in four-line I / O mode, and the QRD bit to select the SPI bus four-way mode read operation; Step 6, write idle data 0xFF to the data register SPI_DATA to generate the SCK clock signal; Step 7, wait for the RBNE position in the status register SPI_STAT to be 1, the receive buffer is not empty, and then read the data register SPI_DATA to obtain the received data; Step 8: Repeat steps 6 and 7. After data transmission starts, the TBE bit in the status register SPI_STAT is checked for each data frame sent. If the send buffer is empty, write idle data to the data register SPI_DATA to receive the next byte of data. Step 9, pull up the NSS pin to disable the chip, cancel the chip select, and release the chip; Step 10: Wait for the four-port output fast read data command to be executed. The specific steps of disabling the SPI bus four-way mode and shutting down the SPI bus include: Step 1: Before disabling the SPI bus quad mode and turning off the SPI bus function, first check whether the TBE bit in the status register SPI_STAT is set and whether the TRANS bit is cleared. The TRANS bit is the SPI bus communication in progress flag bit. The TRANS bit is a status flag bit used to indicate whether the current transmission is in progress or ended. It is set and cleared by internal hardware and cannot be controlled by software. Step 2: Configure the QMOD bit in the quad SPI control register SPI_QCTL to disable the SPI bus from operating in four-wire I / O mode; Step 3: Configure the SPIEN bit in the control register SPI_CTL0 to disable the SPI device.
Citation Information
Patent Citations
SoC bootstrap IP circuit with APB interface
CN107291655A
Communication IP circuit with serial FLASH interface control
CN111008171A
