Abstract
This note mainly introduces how to develop stable and reliable, fully functional QSPI drivers.
2. Prepare
1, IAR 8.32.1
2, STM32Cube_fw_h7_v1.6.0
3. Introduction to QSPI
4. QSPI driver
In the development of the project, we often use plug-in Flash to do some applications, and STM32H743 with QSPI interface, can be used to plug qspi flash, in the previous push, we will give you QSPI as an example in the previous push of WinBond Wahon. Operation, with the ST's HAL library routine, you can quickly verify that different models of QSPI Flash will have some parameters and command differences. When you are applying, you should pay attention to, such as beautiful or Huangbang's order code is different. The STM32H743 evaluation board is as an example with Mt25T_QLKT_L_01G of Magic. If you use different models, please pay attention to distinguish, since it is an evaluation board, then just give you a reference, in the formal project, some other problems are needed.
5. Drive architecture
The driven architecture can refer to the QSPI Flash drive architecture in STM32Cube_fw_h7, you can also make itself a schema, as simple as possible, easy to use and stable. The driver for specific model Flash can be placed under one file to establish a .c and .h. As we take the W25Q series of Huabang,
You can also create a text document to record some changes to the drive, release notes, etc.
The BSP layer can establish QSPI drivers under the BSP folder. You can refer to the ST library or in accordance with your own naming rules, or the company's software file naming rules are set.
After establishing these documents, you can develop it next. When developing, you can draw some pictures. In addition to normal initialization, you will be initialized, however, considering those features, those modes, those commands, those safety management. Those interruptions can be operated with DMA operations. It is also necessary to consider the data structure type, configuration information, error code, etc. These must be considered and analyzed in conjunction with the data manual.
5.1 Initialization and initialization
This part is relatively simple, you can refer to the routine, the development board on the market, the coding style, and good mix, you should use the official information and documentation to consider checking the return value, initialization is successful. With the hardware-related pin, the clock, etc., according to your own application, H743 I usually run 400m. Most of the official routines are also running 400m.
5.2 Drive mode
From the manual, you can know that divided into indirect mode, status polling mode, memory mapping mode, then our driver is capable of supporting these three modes. These modes and other data types are defined in STM32H743i_EVAL_QSPI.H. These can refer to the official definition
Define data types, structures, macro definitions, etc. related to flash, structures, etc. in W25Q256.h. Such as QSPI's operating mode, here you must understand the meaning of 1-1-1, 1-1-2, 1-1-4, 1-4-4, because QSPI contains these four, instruction single line, address single line / 4 Line, data single-line / two-wire / four lines, these are marked in the Flash data manual instruction table, supporting that operation, and we have to consider these four in the driver.
The definition of the command table, pay attention to the different models of Flash, will be slightly different, even if the same number of different models may also be different, such as the Directive of Huabang 256M and 1G will have some differences. I have used these two paragraphs, and I will mention it here. Due to the more of the instructions, this is not listed here, only part of it, the definition of the specific instruction table can be referred to the flash manual.
However, it is recommended that everyone supports all instructions when they do their drivers, so it is very convenient to use, rather than use, and find less, in order to fill. You can make a subunies, such as reading ID, you can do some checks
Many instructions are not driven in the company's driver, you need to do it yourself.
5.3 Status Register Read and write
The W25Q series typically has three status registers, used to represent some states, such as status register 1, can determine the state of flash by reading, is there all, whether there is no opening, and the protection bit protects those addresses, these It is necessary to implement itself, there is no in the market, including the official routine driver, if you don't judge, if you want to write, if you want to write, you can't write, it may have an exception, which can be readily read. Registers 1 and 2 are judged and processed. And combine WP feet.
These features we must consider in formal products, otherwise your driver is unstable, unsafe, because the industrial scene is interfering, and other abnormalities. Maybe you run well in the laboratory, you can't go on the scene.
5.4 Read and write
When the erase operation is time consuming, if you use the query mode, you should continue to query the status, but you can't die, from the manual to see the time magnitude, the maximum need for 1000S, or time consumption, even The erasing unit 4K erase, the worst case also requires 400ms. If you operate in an interrupt or DMA mode, the DMA is interrupted. There are several, with command, completion, status match, and completion of the transceiver. Be familiar with these approximate time levels. Convenient reference. Based on different models, we introduce you to everyone in the public.
Reading and writing, you can refer to the official website, but to add some changes, if you think about reading and writing failure, timeout exit, if you have a failure, how to consider, we generally consider trying three times, if the first failed Try the second reading, the second failed, try the third time, this can greatly enhance security, may be successful in the case of 99.99%, but it does not rule out the possibility of failure. In addition, consider the protection of parameters.
5.4.1 Erase
You can write a function according to the erase unit.
It is important to pay attention to the difference between W25Q256 and W25Q01J. If some instructions support the four lines of the command address, the latter is not supported.
5.4.2 Reading operation
Reading operations should be considered to be Single or DUAL mode, and two subunies are different, and they are different, and the timing is different.
It is recommended to make a sub-function one instruction. If the timing and operation mode of 0x6c and 0xec is different, such as 0x6C
Code
You can see the instruction single line, address single line, and 1-1-4 mode of the data from the timing chart. 0xec leaves everyone to contact the implementation.
5.4.3 Write operation
There are several different orders in writing manipulation.
Different timing and ways, can be written into different subunies, we take 34h as an example
It can be seen by the timing chart that is instruction single line, address single line, and data four lines, which can be implemented.
5.5 abnormal
Usually we also need to manage and process some abnormalities, such as the definition below, you can also follow your own way, in short, do some management.
The official example basically has a return value, you can go to refer to, so that your drive is safer and reliable.
5.6 Others
Everything you should consider, you can add it according to your needs and applications, here is not described here.
6. Test verification
After the development is complete, you can write a short answer, test your own driver, because I use it in the Freertos system, so build a QSPI test task, to achieve the function of rub, write, read, and compare And verification. Intercept a few test charts
7. Reference documentation
Serial number
literature
1
STM32H743RM
2
STM32Cube_fw_h7_v1.6.0
Original title: How to write QSPI driver
Article Source: [WeChat public number: embedded program] Welcome to add attention! Please indicate the source of the article.
Editor in charge: HAQ, read full article, original title: How to write QSPI driver
Article Source: [Micro Signal: Interruptism, WeChat public number: Spicy hardware and software] Welcome to add attention! Please indicate the source of the article.
Our other product: