Skip to content

Commit 0715a46

Browse files
author
Cruz Monrreal
authored
Merge pull request #7325 from maciejbocianski/qspi_tests
hal-qspi test
2 parents 2fe18db + af90f2c commit 0715a46

File tree

12 files changed

+1308
-60
lines changed

12 files changed

+1308
-60
lines changed
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_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_IMPLEMENTATION() \
112+
\
113+
uint8_t reg_data[QSPI_STATUS_REG_SIZE]; \
114+
\
115+
reg_data[0] = STATUS_BIT_QE; \
116+
qspi.cmd.build(QSPI_CMD_WRSR); \
117+
\
118+
if (qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
119+
reg_data, QSPI_STATUS_REG_SIZE, NULL, 0) != QSPI_STATUS_OK) { \
120+
return QSPI_STATUS_ERROR; \
121+
} \
122+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
123+
\
124+
memset(reg_data, 0, QSPI_STATUS_REG_SIZE); \
125+
if (read_register(STATUS_REG, reg_data, \
126+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
127+
return QSPI_STATUS_ERROR; \
128+
} \
129+
\
130+
return ((reg_data[0] & STATUS_BIT_QE) != 0 ? \
131+
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
132+
133+
134+
135+
#define QUAD_DISABLE_IMPLEMENTATION() \
136+
\
137+
uint8_t reg_data[QSPI_STATUS_REG_SIZE]; \
138+
\
139+
reg_data[0] = 0; \
140+
qspi.cmd.build(QSPI_CMD_WRSR); \
141+
\
142+
if (qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
143+
reg_data, QSPI_STATUS_REG_SIZE, NULL, 0) != QSPI_STATUS_OK) { \
144+
return QSPI_STATUS_ERROR; \
145+
} \
146+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
147+
\
148+
reg_data[0] = 0; \
149+
if (read_register(STATUS_REG, reg_data, \
150+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
151+
return QSPI_STATUS_ERROR; \
152+
} \
153+
\
154+
return ((reg_data[0] & STATUS_BIT_QE) == 0 ? \
155+
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
156+
157+
158+
159+
#define FAST_MODE_ENABLE_IMPLEMENTATION() \
160+
\
161+
qspi_status_t ret; \
162+
const int32_t reg_size = QSPI_STATUS_REG_SIZE + QSPI_CONFIG_REG_0_SIZE; \
163+
uint8_t reg_data[reg_size]; \
164+
\
165+
if (read_register(STATUS_REG, reg_data, \
166+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
167+
return QSPI_STATUS_ERROR; \
168+
} \
169+
if (read_register(CONFIG_REG0, reg_data + QSPI_STATUS_REG_SIZE, \
170+
QSPI_CONFIG_REG_0_SIZE, qspi) != QSPI_STATUS_OK) { \
171+
return QSPI_STATUS_ERROR; \
172+
} \
173+
\
174+
reg_data[2] |= CONFIG1_BIT_LH; \
175+
qspi.cmd.build(QSPI_CMD_WRSR); \
176+
\
177+
return qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
178+
reg_data, reg_size, NULL, 0)
179+
180+
181+
182+
#endif // MBED_QSPI_FLASH_MX25R6435F_H
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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_CONFIG_H
17+
#define MBED_QSPI_FLASH_CONFIG_H
18+
19+
#include "../../MX25R6435F_config.h"
20+
21+
// NRF doesn't uses read/write opcodes, instead it uses commands id's.
22+
// Before sending it to H/W opcodes are mapped to id's in Mbed hal qspi implementation
23+
//
24+
// for more details see:
25+
// targets\TARGET_NORDIC\TARGET_NRF5x\TARGET_SDK_14_2\device\nrf52840_bitfields.h
26+
// targets\TARGET_NORDIC\TARGET_NRF5x\qspi_api.c
27+
28+
// NRF doesn't support read 1IO (opcode 0x03)
29+
#undef QSPI_CMD_READ_1IO
30+
#define QSPI_CMD_READ_1IO QSPI_CMD_READ_1IO_FAST
31+
32+
33+
#endif // MBED_QSPI_FLASH_CONFIG_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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_CONFIG_H
17+
#define MBED_QSPI_FLASH_CONFIG_H
18+
19+
#include "../../MX25R6435F_config.h"
20+
21+
// TODO: remove when fixed
22+
// when perform 4IO write, when memory indicates write finish (changing WIP bit in status register)
23+
// but actually write is still in progress and we have to wait a bit more before reading
24+
#define STM_WRITE_4IO_BUG_WORKAROUND
25+
26+
#endif // MBED_QSPI_FLASH_CONFIG_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
17+
#ifndef MBED_FLASH_CONFIGS_H
18+
#define MBED_FLASH_CONFIGS_H
19+
20+
#if defined(TARGET_DISCO_L475VG_IOT01A)
21+
#include "STM/DISCO_L475VG_IOT01A/flash_config.h"
22+
#elif defined(TARGET_NRF52840)
23+
#include "NORDIC/NRF52840_DK/flash_config.h"
24+
#endif
25+
26+
#endif // MBED_FLASH_CONFIGS_H

0 commit comments

Comments
 (0)