Mistake on this page?
Report an issue in GitHub or email us
qspi_test_utils.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2018-2018 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MBED_QSPI_TEST_UTILS_H
17 #define MBED_QSPI_TEST_UTILS_H
18 
19 #include "flash_configs/flash_configs.h"
20 #include "unity/unity.h"
21 
22 #define QSPI_NONE (-1)
23 
24 enum QspiStatus {
25  sOK,
26  sError,
27  sTimeout,
28  sUnknown
29 };
30 
31 class QspiCommand {
32 public:
33  void configure(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width,
34  qspi_bus_width_t alt_width, qspi_address_size_t addr_size, qspi_alt_size_t alt_size,
35  int dummy_cycles = 0);
36 
37  void set_dummy_cycles(int dummy_cycles);
38 
39  void build(int instruction, int address = QSPI_NONE, int alt = QSPI_NONE);
40 
41  qspi_command_t *get();
42 
43 private:
44  qspi_command_t _cmd;
45 };
46 
47 struct Qspi {
48  qspi_t handle;
49  QspiCommand cmd;
50 };
51 
52 // MODE_Command_Address_Data_Alt
53 #define MODE_1_1_1 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE
54 #define MODE_1_1_2 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL
55 #define MODE_1_2_2 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL
56 #define MODE_2_2_2 QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL
57 #define MODE_1_1_4 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD
58 #define MODE_1_4_4 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD
59 #define MODE_4_4_4 QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD
60 
61 #define WRITE_1_1_1 MODE_1_1_1, QSPI_CMD_WRITE_1IO
62 #ifdef QSPI_CMD_WRITE_2IO
63 #define WRITE_1_2_2 MODE_1_2_2, QSPI_CMD_WRITE_2IO
64 #endif
65 #ifdef QSPI_CMD_WRITE_1I4O // Quad page program - command: 0x32
66 #define WRITE_1_1_4 MODE_1_1_4, QSPI_CMD_WRITE_1I4O
67 #endif
68 #ifdef QSPI_CMD_WRITE_4IO
69 #define WRITE_1_4_4 MODE_1_4_4, QSPI_CMD_WRITE_4IO
70 #endif
71 #ifdef QSPI_CMD_WRITE_DPI
72 #define WRITE_2_2_2 MODE_2_2_2, QSPI_CMD_WRITE_DPI
73 #endif
74 #ifdef QSPI_CMD_WRITE_QPI
75 #define WRITE_4_4_4 MODE_4_4_4, QSPI_CMD_WRITE_QPI
76 #endif
77 
78 
79 #define READ_1_1_1 MODE_1_1_1, QSPI_CMD_READ_1IO, QSPI_READ_1IO_DUMMY_CYCLE
80 #define READ_1_1_2 MODE_1_1_2, QSPI_CMD_READ_1I2O, QSPI_READ_1I2O_DUMMY_CYCLE
81 #define READ_1_2_2 MODE_1_2_2, QSPI_CMD_READ_2IO, QSPI_READ_2IO_DUMMY_CYCLE
82 #define READ_1_1_4 MODE_1_1_4, QSPI_CMD_READ_1I4O, QSPI_READ_1I4O_DUMMY_CYCLE
83 #define READ_1_4_4 MODE_1_4_4, QSPI_CMD_READ_4IO, QSPI_READ_4IO_DUMMY_CYCLE
84 #ifdef QSPI_CMD_READ_DPI
85 #define READ_2_2_2 MODE_2_2_2, QSPI_CMD_READ_DPI, QSPI_READ_2IO_DUMMY_CYCLE
86 #endif
87 #ifdef QSPI_CMD_READ_QPI
88 #define READ_4_4_4 MODE_4_4_4, QSPI_CMD_READ_QPI, QSPI_READ_4IO_DUMMY_CYCLE
89 #endif
90 
91 #define ADDR_SIZE_8 QSPI_CFG_ADDR_SIZE_8
92 #define ADDR_SIZE_16 QSPI_CFG_ADDR_SIZE_16
93 #define ADDR_SIZE_24 QSPI_CFG_ADDR_SIZE_24
94 #define ADDR_SIZE_32 QSPI_CFG_ADDR_SIZE_32
95 
96 #define ALT_SIZE_8 QSPI_CFG_ALT_SIZE_8
97 #define ALT_SIZE_16 QSPI_CFG_ALT_SIZE_16
98 #define ALT_SIZE_24 QSPI_CFG_ALT_SIZE_24
99 #define ALT_SIZE_32 QSPI_CFG_ALT_SIZE_32
100 
101 #define STATUS_REG QSPI_CMD_RDSR
102 #define CONFIG_REG0 QSPI_CMD_RDCR0
103 #ifdef QSPI_CMD_RDCR1
104 #define CONFIG_REG1 QSPI_CMD_RDCR1
105 #endif
106 #ifdef QSPI_CMD_RDCR2
107 #define CONFIG_REG2 QSPI_CMD_RDCR2
108 #endif
109 #define SECURITY_REG QSPI_CMD_RDSCUR
110 
111 #ifndef QSPI_CONFIG_REG_1_SIZE
112 #define QSPI_CONFIG_REG_1_SIZE 0
113 #endif
114 
115 #ifndef QSPI_CONFIG_REG_2_SIZE
116 #define QSPI_CONFIG_REG_2_SIZE 0
117 #endif
118 
119 
120 #define SECTOR_ERASE QSPI_CMD_ERASE_SECTOR
121 #define BLOCK_ERASE QSPI_CMD_ERASE_BLOCK_64
122 
123 
124 #define SECTOR_ERASE_MAX_TIME QSPI_ERASE_SECTOR_MAX_TIME
125 #define BLOCK32_ERASE_MAX_TIME QSPI_ERASE_BLOCK_32_MAX_TIME
126 #define BLOCK64_ERASE_MAX_TIME QSPI_ERASE_BLOCK_64_MAX_TIME
127 #define PAGE_PROG_MAX_TIME QSPI_PAGE_PROG_MAX_TIME
128 #define WRSR_MAX_TIME QSPI_WRSR_MAX_TIME
129 #define WAIT_MAX_TIME QSPI_WAIT_MAX_TIME
130 
131 
132 
133 qspi_status_t read_register(uint32_t cmd, uint8_t *buf, uint32_t size, Qspi &q);
134 qspi_status_t write_register(uint32_t cmd, uint8_t *buf, uint32_t size, Qspi &q);
135 
136 QspiStatus flash_wait_for(uint32_t time_us, Qspi &qspi);
137 
138 void flash_init(Qspi &qspi);
139 
140 qspi_status_t write_enable(Qspi &qspi);
141 qspi_status_t write_disable(Qspi &qspi);
142 
143 void log_register(uint32_t cmd, uint32_t reg_size, Qspi &qspi, const char *str = NULL);
144 
145 qspi_status_t mode_enable(Qspi &qspi, qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
146 qspi_status_t mode_disable(Qspi &qspi, qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
147 
148 qspi_status_t fast_mode_enable(Qspi &qspi);
149 qspi_status_t fast_mode_disable(Qspi &qspi);
150 
151 qspi_status_t erase(uint32_t erase_cmd, uint32_t flash_addr, Qspi &qspi);
152 
153 bool is_extended_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
154 bool is_dual_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
155 bool is_quad_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
156 
157 #define WAIT_FOR(timeout, q) TEST_ASSERT_EQUAL_MESSAGE(sOK, flash_wait_for(timeout, q), "flash_wait_for failed!!!")
158 
159 
160 #endif // MBED_QSPI_TEST_UTILS_H
QSPI command.
Definition: qspi_api.h:74
struct qspi_s qspi_t
QSPI HAL object.
Definition: qspi_api.h:40
enum qspi_alt_size qspi_alt_size_t
Alternative size in bits.
enum qspi_address_size qspi_address_size_t
Address size in bits.
enum qspi_bus_width qspi_bus_width_t
QSPI Bus width.
int32_t flash_init(flash_t *obj)
Initialize the flash peripheral and the flash_t object.
enum qspi_status qspi_status_t
QSPI return status.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.