Skip to content

Commit 2e336f8

Browse files
maciejbocianski0xc0170
authored andcommitted
hal-qspi test: add F413ZH support
1 parent 72227e2 commit 2e336f8

File tree

6 files changed

+227
-5
lines changed

6 files changed

+227
-5
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_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
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 "../../N25Q128A_config.h"
20+
21+
22+
#endif // MBED_QSPI_FLASH_CONFIG_H

TESTS/mbed_hal/qspi/flash_configs/flash_configs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "STM/DISCO_L475VG_IOT01A/flash_config.h"
2222
#elif defined(TARGET_NRF52840)
2323
#include "NORDIC/NRF52840_DK/flash_config.h"
24+
#elif defined(TARGET_DISCO_F413ZH)
25+
#include "STM/DISCO_F413ZH/flash_config.h"
2426
#endif
2527

2628
#endif // MBED_FLASH_CONFIGS_H

TESTS/mbed_hal/qspi/main.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
17+
#if !DEVICE_QSPI
18+
#error [NOT_SUPPORTED] QSPI not supported for this target
19+
#endif
20+
1621
#include "utest/utest.h"
1722
#include "unity/unity.h"
1823
#include "greentea-client/test_env.h"
@@ -23,8 +28,8 @@
2328
#include "qspi_api.h"
2429

2530

26-
#if !DEVICE_QSPI || !defined(QSPI_FLASH_CHIP_STRING)
27-
#error [NOT_SUPPORTED] QSPI not supported for this target
31+
#if !defined(QSPI_FLASH_CHIP_STRING)
32+
#error [NOT_SUPPORTED] QSPI test not supported for this target
2833
#endif
2934

3035
using namespace utest::v1;
@@ -278,9 +283,6 @@ void qspi_write_read_test(void)
278283
}
279284

280285

281-
282-
283-
284286
void qspi_init_free_test(void)
285287
{
286288
Qspi qspi;

TESTS/mbed_hal/qspi/qspi_test_utils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ qspi_status_t read_register(uint32_t cmd, uint8_t *buf, uint32_t size, Qspi &q)
7474
return qspi_command_transfer(&q.handle, q.cmd.get(), NULL, 0, buf, size);
7575
}
7676

77+
qspi_status_t write_register(uint32_t cmd, uint8_t *buf, uint32_t size, Qspi &q)
78+
{
79+
q.cmd.build(cmd);
80+
return qspi_command_transfer(&q.handle, q.cmd.get(), buf, size, NULL, 0);
81+
}
82+
7783

7884
QspiStatus flash_wait_for(uint32_t time_us, Qspi &qspi)
7985
{

TESTS/mbed_hal/qspi/qspi_test_utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ struct Qspi {
8484
#ifdef QSPI_CMD_RDCR1
8585
#define CONFIG_REG1 QSPI_CMD_RDCR1
8686
#endif
87+
#ifdef QSPI_CMD_RDCR2
88+
#define CONFIG_REG2 QSPI_CMD_RDCR2
89+
#endif
8790
#define SECURITY_REG QSPI_CMD_RDSCUR
8891

8992
#ifndef QSPI_CONFIG_REG_1_SIZE
9093
#define QSPI_CONFIG_REG_1_SIZE 0
9194
#endif
9295

96+
#ifndef QSPI_CONFIG_REG_2_SIZE
97+
#define QSPI_CONFIG_REG_2_SIZE 0
98+
#endif
99+
93100

94101
#define SECTOR_ERASE QSPI_CMD_ERASE_SECTOR
95102
#define BLOCK_ERASE QSPI_CMD_ERASE_BLOCK_64
@@ -105,6 +112,7 @@ struct Qspi {
105112

106113

107114
qspi_status_t read_register(uint32_t cmd, uint8_t *buf, uint32_t size, Qspi &q);
115+
qspi_status_t write_register(uint32_t cmd, uint8_t *buf, uint32_t size, Qspi &q);
108116

109117
QspiStatus flash_wait_for(uint32_t time_us, Qspi &qspi);
110118

0 commit comments

Comments
 (0)