Skip to content

Commit 812c6d5

Browse files
authored
Merge pull request #7783 from maciejbocianski/feature-qspi_merging
merge QSPI feature branch
2 parents 70814d6 + 883ea2f commit 812c6d5

File tree

68 files changed

+3775
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3775
-23
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
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_FLASH_MX25R6435F_H
17+
#define MBED_QSPI_FLASH_MX25R6435F_H
18+
19+
20+
#define QSPI_FLASH_CHIP_STRING "macronix MX25R6435F"
21+
22+
// Command for reading status register
23+
#define QSPI_CMD_RDSR 0x05
24+
// Command for reading configuration register
25+
#define QSPI_CMD_RDCR0 0x15
26+
// Command for writing status/configuration register
27+
#define QSPI_CMD_WRSR 0x01
28+
// Command for reading security register
29+
#define QSPI_CMD_RDSCUR 0x2B
30+
31+
// Command for setting Reset Enable
32+
#define QSPI_CMD_RSTEN 0x66
33+
// Command for setting Reset
34+
#define QSPI_CMD_RST 0x99
35+
36+
// Command for setting write enable
37+
#define QSPI_CMD_WREN 0x06
38+
// Command for setting write disable
39+
#define QSPI_CMD_WRDI 0x04
40+
41+
// WRSR operations max time [us] (datasheet max time + 15%)
42+
#define QSPI_WRSR_MAX_TIME 34500 // 30ms
43+
// general wait max time [us]
44+
#define QSPI_WAIT_MAX_TIME 100000 // 100ms
45+
46+
47+
// Commands for writing (page programming)
48+
#define QSPI_CMD_WRITE_1IO 0x02 // 1-1-1 mode
49+
#define QSPI_CMD_WRITE_4IO 0x38 // 1-4-4 mode
50+
51+
// write operations max time [us] (datasheet max time + 15%)
52+
#define QSPI_PAGE_PROG_MAX_TIME 11500 // 10ms
53+
54+
#define QSPI_PAGE_SIZE 256 // 256B
55+
56+
// Commands for reading
57+
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode
58+
#define QSPI_CMD_READ_1IO 0x03 // 1-1-1 mode
59+
#define QSPI_CMD_READ_2IO 0xBB // 1-2-2 mode
60+
#define QSPI_CMD_READ_1I2O 0x3B // 1-1-2 mode
61+
#define QSPI_CMD_READ_4IO 0xEB // 1-4-4 mode
62+
#define QSPI_CMD_READ_1I4O 0x6B // 1-1-4 mode
63+
64+
#define QSPI_READ_1IO_DUMMY_CYCLE 0
65+
#define QSPI_READ_FAST_DUMMY_CYCLE 8
66+
#define QSPI_READ_2IO_DUMMY_CYCLE 4
67+
#define QSPI_READ_1I2O_DUMMY_CYCLE 8
68+
#define QSPI_READ_4IO_DUMMY_CYCLE 6
69+
#define QSPI_READ_1I4O_DUMMY_CYCLE 8
70+
71+
// Commands for erasing
72+
#define QSPI_CMD_ERASE_SECTOR 0x20 // 4kB
73+
#define QSPI_CMD_ERASE_BLOCK_32 0x52 // 32kB
74+
#define QSPI_CMD_ERASE_BLOCK_64 0xD8 // 64kB
75+
#define QSPI_CMD_ERASE_CHIP 0x60 // or 0xC7
76+
77+
// erase operations max time [us] (datasheet max time + 15%)
78+
#define QSPI_ERASE_SECTOR_MAX_TIME 276000 // 240 ms
79+
#define QSPI_ERASE_BLOCK_32_MAX_TIME 3450000 // 3s
80+
#define QSPI_ERASE_BLOCK_64_MAX_TIME 4025000 // 3.5s
81+
82+
// max frequency for basic rw operation
83+
#define QSPI_COMMON_MAX_FREQUENCY 32000000
84+
85+
#define QSPI_STATUS_REG_SIZE 1
86+
#define QSPI_CONFIG_REG_0_SIZE 2
87+
#define QSPI_SECURITY_REG_SIZE 1
88+
#define QSPI_MAX_REG_SIZE 2
89+
90+
// status register
91+
#define STATUS_BIT_WIP (1 << 0) // write in progress bit
92+
#define STATUS_BIT_WEL (1 << 1) // write enable latch
93+
#define STATUS_BIT_BP0 (1 << 2) //
94+
#define STATUS_BIT_BP1 (1 << 3) //
95+
#define STATUS_BIT_BP2 (1 << 4) //
96+
#define STATUS_BIT_BP3 (1 << 5) //
97+
#define STATUS_BIT_QE (1 << 6) // Quad Enable
98+
#define STATUS_BIT_SRWD (1 << 7) // status register write protect
99+
100+
// configuration register 0
101+
// bit 0, 1, 2, 4, 5, 7 reserved
102+
#define CONFIG0_BIT_TB (1 << 3) // Top/Bottom area protect
103+
#define CONFIG0_BIT_DC (1 << 6) // Dummy Cycle
104+
105+
// configuration register 1
106+
// bit 0, 2, 3, 4, 5, 6, 7 reserved
107+
#define CONFIG1_BIT_LH (1 << 1) // 0 = Ultra Low power mode, 1 = High performance mode
108+
109+
110+
// single quad enable flag for both dual and quad mode
111+
#define QUAD_ENABLE() \
112+
\
113+
uint8_t reg_data[QSPI_STATUS_REG_SIZE]; \
114+
\
115+
if (write_enable(qspi) != QSPI_STATUS_OK) { \
116+
return QSPI_STATUS_ERROR; \
117+
} \
118+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
119+
\
120+
reg_data[0] = STATUS_BIT_QE; \
121+
qspi.cmd.build(QSPI_CMD_WRSR); \
122+
\
123+
if (qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
124+
reg_data, QSPI_STATUS_REG_SIZE, NULL, 0) != QSPI_STATUS_OK) { \
125+
return QSPI_STATUS_ERROR; \
126+
} \
127+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
128+
\
129+
memset(reg_data, 0, QSPI_STATUS_REG_SIZE); \
130+
if (read_register(STATUS_REG, reg_data, \
131+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
132+
return QSPI_STATUS_ERROR; \
133+
} \
134+
\
135+
return ((reg_data[0] & STATUS_BIT_QE) != 0 ? \
136+
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
137+
138+
139+
140+
#define QUAD_DISABLE() \
141+
\
142+
uint8_t reg_data[QSPI_STATUS_REG_SIZE]; \
143+
\
144+
if (write_enable(qspi) != QSPI_STATUS_OK) { \
145+
return QSPI_STATUS_ERROR; \
146+
} \
147+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
148+
\
149+
reg_data[0] = 0; \
150+
qspi.cmd.build(QSPI_CMD_WRSR); \
151+
\
152+
if (qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
153+
reg_data, QSPI_STATUS_REG_SIZE, NULL, 0) != QSPI_STATUS_OK) { \
154+
return QSPI_STATUS_ERROR; \
155+
} \
156+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
157+
\
158+
reg_data[0] = 0; \
159+
if (read_register(STATUS_REG, reg_data, \
160+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
161+
return QSPI_STATUS_ERROR; \
162+
} \
163+
\
164+
return ((reg_data[0] & STATUS_BIT_QE) == 0 ? \
165+
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
166+
167+
168+
169+
#define FAST_MODE_ENABLE() \
170+
\
171+
qspi_status_t ret; \
172+
const int32_t reg_size = QSPI_STATUS_REG_SIZE + QSPI_CONFIG_REG_0_SIZE; \
173+
uint8_t reg_data[reg_size]; \
174+
\
175+
if (read_register(STATUS_REG, reg_data, \
176+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
177+
return QSPI_STATUS_ERROR; \
178+
} \
179+
if (read_register(CONFIG_REG0, reg_data + QSPI_STATUS_REG_SIZE, \
180+
QSPI_CONFIG_REG_0_SIZE, qspi) != QSPI_STATUS_OK) { \
181+
return QSPI_STATUS_ERROR; \
182+
} \
183+
\
184+
reg_data[2] |= CONFIG1_BIT_LH; \
185+
qspi.cmd.build(QSPI_CMD_WRSR); \
186+
\
187+
return qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
188+
reg_data, reg_size, NULL, 0)
189+
190+
191+
192+
#endif // MBED_QSPI_FLASH_MX25R6435F_H
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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_FLASH_N25Q128A_H
17+
#define MBED_QSPI_FLASH_N25Q128A_H
18+
19+
20+
#define QSPI_FLASH_CHIP_STRING "Micron N25Q128A"
21+
22+
// Command for reading status register
23+
#define QSPI_CMD_RDSR 0x05
24+
// Command for reading configuration register 0 (NONVOLATILE CONFIGURATION REGISTER)
25+
#define QSPI_CMD_RDCR0 0xB5
26+
// Command for reading configuration register 1 (VOLATILE CONFIGURATION REGISTER)
27+
#define QSPI_CMD_RDCR1 0x85
28+
// Command for reading configuration register 2 (ENHANCED VOLATILE CONFIGURATION REGISTER)
29+
#define QSPI_CMD_RDCR2 0x65
30+
// Command for writing status
31+
#define QSPI_CMD_WRSR 0x01
32+
// Command for writing configuration register 0 (NONVOLATILE CONFIGURATION REGISTER)
33+
#define QSPI_CMD_WRCR0 0xB1
34+
// Command for writing configuration register 1 (VOLATILE CONFIGURATION REGISTER)
35+
#define QSPI_CMD_WRCR1 0x81
36+
// Command for writing configuration register 2 (ENHANCED VOLATILE CONFIGURATION REGISTER)
37+
#define QSPI_CMD_WRCR2 0x61
38+
// Command for reading security register
39+
#define QSPI_CMD_RDSCUR 0x2B
40+
41+
// Command for setting Reset Enable
42+
#define QSPI_CMD_RSTEN 0x66
43+
// Command for setting Reset
44+
#define QSPI_CMD_RST 0x99
45+
46+
// Command for setting write enable
47+
#define QSPI_CMD_WREN 0x06
48+
// Command for setting write disable
49+
#define QSPI_CMD_WRDI 0x04
50+
51+
// WRSR operations max time [us] (datasheet max time + 15%)
52+
#define QSPI_WRSR_MAX_TIME 9200 // 8ms
53+
// general wait max time [us]
54+
#define QSPI_WAIT_MAX_TIME 100000 // 100ms
55+
56+
57+
// Commands for writing (page programming)
58+
#define QSPI_CMD_WRITE_1IO 0x02 // 1-1-1 mode
59+
#define QSPI_CMD_WRITE_2IO 0xD2 // 1-2-2 mode
60+
#define QSPI_CMD_WRITE_4IO 0x12 // 1-4-4 mode
61+
62+
// write operations max time [us] (datasheet max time + 15%)
63+
#define QSPI_PAGE_PROG_MAX_TIME 5750 // 5ms
64+
65+
#define QSPI_PAGE_SIZE 256 // 256B
66+
67+
// Commands for reading
68+
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode
69+
#define QSPI_CMD_READ_1IO 0x03 // 1-1-1 mode
70+
#define QSPI_CMD_READ_2IO 0xBB // 1-2-2 mode
71+
#define QSPI_CMD_READ_1I2O 0x3B // 1-1-2 mode
72+
#define QSPI_CMD_READ_4IO 0xEB // 1-4-4 mode
73+
#define QSPI_CMD_READ_1I4O 0x6B // 1-1-4 mode
74+
75+
76+
#define QSPI_READ_1IO_DUMMY_CYCLE 0
77+
#define QSPI_READ_FAST_DUMMY_CYCLE 8
78+
// 8 dummy (10 dummy when quad SPI protocol is enabled)
79+
#define QSPI_READ_2IO_DUMMY_CYCLE 8
80+
#define QSPI_READ_1I2O_DUMMY_CYCLE 8
81+
#define QSPI_READ_4IO_DUMMY_CYCLE 10
82+
#define QSPI_READ_1I4O_DUMMY_CYCLE 8
83+
84+
// Commands for erasing
85+
#define QSPI_CMD_ERASE_SECTOR 0x20 // 4kB
86+
#define QSPI_CMD_ERASE_BLOCK_32 0x52 // 32kB
87+
#define QSPI_CMD_ERASE_BLOCK_64 0xD8 // 64kB
88+
#define QSPI_CMD_ERASE_CHIP 0x60 // or 0xC7
89+
90+
// erase operations max time [us] (datasheet max time + 15%)
91+
#define QSPI_ERASE_SECTOR_MAX_TIME 276000 // 240 ms
92+
#define QSPI_ERASE_BLOCK_32_MAX_TIME 3000000 // 3s
93+
#define QSPI_ERASE_BLOCK_64_MAX_TIME 3500000 // 3.5s
94+
95+
// max frequency for basic rw operation
96+
#define QSPI_COMMON_MAX_FREQUENCY 50000000
97+
98+
#define QSPI_STATUS_REG_SIZE 1
99+
#define QSPI_CONFIG_REG_0_SIZE 2
100+
#define QSPI_CONFIG_REG_1_SIZE 1
101+
#define QSPI_CONFIG_REG_2_SIZE 1
102+
#define QSPI_MAX_REG_SIZE 2
103+
104+
// status register
105+
#define STATUS_BIT_WIP (1 << 0) // write in progress bit
106+
#define STATUS_BIT_WEL (1 << 1) // write enable latch
107+
#define STATUS_BIT_BP0 (1 << 2) // block
108+
#define STATUS_BIT_BP1 (1 << 3) //
109+
#define STATUS_BIT_BP2 (1 << 4) //
110+
#define STATUS_BIT_BP_TB (1 << 5) // Block protect top/bottom
111+
#define STATUS_BIT_BP3 (1 << 6) //
112+
#define STATUS_BIT_SRWD (1 << 7) // status register write protect
113+
114+
// configuration register 0 (Nonvolatile Configuration Register)
115+
// bit 1, 5, reserved
116+
#define CONFIG0_BIT_LOCK (1 << 0) // Lock nonvolatile configuration register
117+
#define CONFIG0_BIT_DE (1 << 2) // Dual Enable 0 = Enabled / 1 = Disabled
118+
#define CONFIG0_BIT_QE (1 << 3) // Quad Enable 0 = Enabled / 1 = Disabled
119+
#define CONFIG0_BIT_RH (1 << 4) // Reset/hold
120+
#define CONFIG0_BIT_ODS0 (1 << 6) // Output driver strength
121+
#define CONFIG0_BIT_ODS1 (1 << 7) // Output driver strength
122+
#define CONFIG0_BIT_ODS2 (1 << 8) // Output driver strength
123+
#define CONFIG0_BIT_XIP_MODE0 (1 << 9) // XIP mode at power-on reset
124+
#define CONFIG0_BIT_XIP_MODE1 (1 << 10) // XIP mode at power-on reset
125+
#define CONFIG0_BIT_XIP_MODE2 (1 << 11) // XIP mode at power-on reset
126+
#define CONFIG0_BIT_DCYCLE0 (1 << 12) // Dummy Cycle
127+
#define CONFIG0_BIT_DCYCLE1 (1 << 13) // Dummy Cycle
128+
#define CONFIG0_BIT_DCYCLE2 (1 << 14) // Dummy Cycle
129+
#define CONFIG0_BIT_DCYCLE3 (1 << 15) // Dummy Cycle
130+
#define CONFIG0_BITS_DEFAULT 0xFFFF // reg default state
131+
132+
133+
// configuration register 1 (Volatile Configuration Register)
134+
// bit 2, reserved
135+
#define CONFIG1_BIT_WRAP0 (1 << 0) // Output data wrap
136+
#define CONFIG1_BIT_WRAP1 (1 << 1) // Output data wrap
137+
#define CONFIG1_BIT_XIP (1 << 3) // 0 = Enable / 1 = Disable (default)
138+
#define CONFIG1_BIT_DCYCLE0 (1 << 4) // Number of dummy clock cycles
139+
#define CONFIG1_BIT_DCYCLE1 (1 << 5) // Number of dummy clock cycles
140+
#define CONFIG1_BIT_DCYCLE2 (1 << 6) // Number of dummy clock cycles
141+
#define CONFIG1_BIT_DCYCLE3 (1 << 7) // Number of dummy clock cycles
142+
#define CONFIG1_BITS_DEFAULT 0xB // reg default state
143+
144+
145+
// configuration register 2 (Enhanced Volatile Configuration Register)
146+
// bit 5, reserved
147+
#define CONFIG2_BIT_ODS0 (1 << 0) // Output driver strength 111 = 30 Ohms (Default)
148+
#define CONFIG2_BIT_ODS1 (1 << 1) // Output driver strength
149+
#define CONFIG2_BIT_ODS2 (1 << 2) // Output driver strength
150+
#define CONFIG2_BIT_VPP (1 << 3) // VPP accelerator 1 = Disabled (Default)
151+
#define CONFIG2_BIT_RH (1 << 4) // Reset/hold
152+
#define CONFIG2_BIT_DE (1 << 6) // Dual I/O protocol 0 = Enabled / 1 = Disabled (Default, extended SPI protocol)
153+
#define CONFIG2_BIT_QE (1 << 7) // Quad I/O protocol 0 = Enabled / 1 = Disabled (Default, extended SPI protocol)
154+
#define CONFIG2_BITS_DEFAULT 0xDF // reg default state
155+
156+
157+
#define DUAL_ENABLE() \
158+
/* TODO: add implementation */ \
159+
return QSPI_STATUS_OK
160+
161+
162+
#define DUAL_DISABLE() \
163+
/* TODO: add implementation */ \
164+
return QSPI_STATUS_OK
165+
166+
167+
#define QUAD_ENABLE() \
168+
/* TODO: add implementation */ \
169+
return QSPI_STATUS_OK
170+
171+
172+
#define QUAD_DISABLE() \
173+
/* TODO: add implementation */ \
174+
return QSPI_STATUS_OK
175+
176+
177+
#define FAST_MODE_ENABLE() \
178+
/* TODO: add implementation */ \
179+
return QSPI_STATUS_OK
180+
181+
182+
#endif // MBED_QSPI_FLASH_N25Q128A_H

0 commit comments

Comments
 (0)