Skip to content

Commit 0db8960

Browse files
author
Cruz Monrreal
authored
Merge pull request #8485 from NXPmicro/feature-qspi-kinetis
Feature qspi kinetis
2 parents cd55994 + 86ae041 commit 0db8960

File tree

24 files changed

+1241
-94
lines changed

24 files changed

+1241
-94
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 "../../MX25RXX35F_config.h"
20+
21+
/* Fast mode not supported in MX25U3235F */
22+
#undef FAST_MODE_ENABLE
23+
#undef FAST_MODE_DISABLE
24+
25+
#ifdef QSPI_SECTOR_COUNT
26+
#undef QSPI_SECTOR_COUNT
27+
#define QSPI_SECTOR_COUNT 1024 // for MX25U3235F
28+
#endif
29+
30+
/* The values for MX25U3235F are different, specify this here */
31+
#undef QSPI_COMMON_MAX_FREQUENCY
32+
#undef QSPI_WRSR_MAX_TIME
33+
#undef QSPI_PAGE_PROG_MAX_TIME
34+
#undef QSPI_ERASE_SECTOR_MAX_TIME
35+
#undef QSPI_ERASE_BLOCK_32_MAX_TIME
36+
#undef QSPI_ERASE_BLOCK_64_MAX_TIME
37+
38+
/* Implementation of these macros are slightly different for MX25U3235F */
39+
#undef EXTENDED_SPI_ENABLE
40+
#undef EXTENDED_SPI_DISABLE
41+
42+
/* Max frequency for basic rw operation in MX25U3235F */
43+
#define QSPI_COMMON_MAX_FREQUENCY 54000000
44+
45+
/* WRSR operations max time [us] (datasheet max time + 15%) */
46+
#define QSPI_WRSR_MAX_TIME 46000 // 40ms
47+
48+
/* Write operations max time [us] (datasheet max time + 15%) */
49+
#define QSPI_PAGE_PROG_MAX_TIME 3450 // 3ms
50+
51+
/* erase operations max time [us] (datasheet max time + 15%) */
52+
#define QSPI_ERASE_SECTOR_MAX_TIME 230000 // 200 ms
53+
#define QSPI_ERASE_BLOCK_32_MAX_TIME 1150000 // 1s
54+
#define QSPI_ERASE_BLOCK_64_MAX_TIME 2300000 // 2s
55+
56+
#define EXTENDED_SPI_ENABLE() \
57+
\
58+
const int32_t reg_size = QSPI_STATUS_REG_SIZE; \
59+
uint8_t reg_data[reg_size] = { 0 }; \
60+
\
61+
if (read_register(STATUS_REG, reg_data, \
62+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
63+
return QSPI_STATUS_ERROR; \
64+
} \
65+
if (write_enable(qspi) != QSPI_STATUS_OK) { \
66+
return QSPI_STATUS_ERROR; \
67+
} \
68+
\
69+
reg_data[0] = STATUS_BIT_QE; \
70+
if (write_register(QSPI_CMD_WRSR, reg_data, \
71+
reg_size, qspi) != QSPI_STATUS_OK) { \
72+
return QSPI_STATUS_ERROR; \
73+
} \
74+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
75+
\
76+
memset(reg_data, 0, QSPI_STATUS_REG_SIZE); \
77+
if (read_register(STATUS_REG, reg_data, \
78+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
79+
return QSPI_STATUS_ERROR; \
80+
} \
81+
\
82+
return ((reg_data[0] & STATUS_BIT_QE) != 0 ? \
83+
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
84+
85+
86+
87+
#define EXTENDED_SPI_DISABLE() \
88+
\
89+
const int32_t reg_size = QSPI_STATUS_REG_SIZE; \
90+
uint8_t reg_data[reg_size] = { 0 }; \
91+
\
92+
if (read_register(STATUS_REG, reg_data, \
93+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
94+
return QSPI_STATUS_ERROR; \
95+
} \
96+
\
97+
if (write_enable(qspi) != QSPI_STATUS_OK) { \
98+
return QSPI_STATUS_ERROR; \
99+
} \
100+
\
101+
reg_data[0] &= ~(STATUS_BIT_QE); \
102+
\
103+
if (write_register(QSPI_CMD_WRSR, reg_data, \
104+
reg_size, qspi) != QSPI_STATUS_OK) { \
105+
return QSPI_STATUS_ERROR; \
106+
} \
107+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
108+
\
109+
reg_data[0] = 0; \
110+
if (read_register(STATUS_REG, reg_data, \
111+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
112+
return QSPI_STATUS_ERROR; \
113+
} \
114+
\
115+
return ((reg_data[0] & STATUS_BIT_QE) == 0 ? \
116+
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
117+
118+
#endif // MBED_QSPI_FLASH_CONFIG_H
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 "../../MX25RXX35F_config.h"
20+
21+
/* Fast mode not supported in MX25L12845G */
22+
#undef FAST_MODE_ENABLE
23+
#undef FAST_MODE_DISABLE
24+
25+
#ifdef QSPI_SECTOR_COUNT
26+
#undef QSPI_SECTOR_COUNT
27+
#define QSPI_SECTOR_COUNT 4096 // for MX25L12845G
28+
#endif
29+
30+
/* The values for MX25U3235F are different, specify this here */
31+
#undef QSPI_COMMON_MAX_FREQUENCY
32+
#undef QSPI_WRSR_MAX_TIME
33+
#undef QSPI_PAGE_PROG_MAX_TIME
34+
#undef QSPI_ERASE_SECTOR_MAX_TIME
35+
#undef QSPI_ERASE_BLOCK_32_MAX_TIME
36+
#undef QSPI_ERASE_BLOCK_64_MAX_TIME
37+
38+
/* Implementation of these macros are slightly different for MX25L12845G */
39+
#undef EXTENDED_SPI_ENABLE
40+
#undef EXTENDED_SPI_DISABLE
41+
42+
/* Max frequency for basic rw operation based on max bus frequency of 24MHz */
43+
#define QSPI_COMMON_MAX_FREQUENCY 23000000
44+
45+
/* WRSR operations max time [us] (datasheet max time + 15%) */
46+
#define QSPI_WRSR_MAX_TIME 46000 // 40ms
47+
48+
/* Write operations max time [us] (datasheet max time + 15%) */
49+
#define QSPI_PAGE_PROG_MAX_TIME 1000 // 0.75ms
50+
51+
/* erase operations max time [us] (datasheet max time + 15%) */
52+
#define QSPI_ERASE_SECTOR_MAX_TIME 460000 // 400 ms
53+
#define QSPI_ERASE_BLOCK_32_MAX_TIME 1150000 // 1s
54+
#define QSPI_ERASE_BLOCK_64_MAX_TIME 2300000 // 2s
55+
56+
#define EXTENDED_SPI_ENABLE() \
57+
\
58+
const int32_t reg_size = QSPI_STATUS_REG_SIZE; \
59+
uint8_t reg_data[reg_size] = { 0 }; \
60+
\
61+
if (read_register(STATUS_REG, reg_data, \
62+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
63+
return QSPI_STATUS_ERROR; \
64+
} \
65+
if (write_enable(qspi) != QSPI_STATUS_OK) { \
66+
return QSPI_STATUS_ERROR; \
67+
} \
68+
\
69+
reg_data[0] = STATUS_BIT_QE; \
70+
if (write_register(QSPI_CMD_WRSR, reg_data, \
71+
reg_size, qspi) != QSPI_STATUS_OK) { \
72+
return QSPI_STATUS_ERROR; \
73+
} \
74+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
75+
\
76+
memset(reg_data, 0, QSPI_STATUS_REG_SIZE); \
77+
if (read_register(STATUS_REG, reg_data, \
78+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
79+
return QSPI_STATUS_ERROR; \
80+
} \
81+
\
82+
return ((reg_data[0] & STATUS_BIT_QE) != 0 ? \
83+
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
84+
85+
86+
87+
#define EXTENDED_SPI_DISABLE() \
88+
\
89+
const int32_t reg_size = QSPI_STATUS_REG_SIZE; \
90+
uint8_t reg_data[reg_size] = { 0 }; \
91+
\
92+
if (read_register(STATUS_REG, reg_data, \
93+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
94+
return QSPI_STATUS_ERROR; \
95+
} \
96+
\
97+
if (write_enable(qspi) != QSPI_STATUS_OK) { \
98+
return QSPI_STATUS_ERROR; \
99+
} \
100+
\
101+
reg_data[0] &= ~(STATUS_BIT_QE); \
102+
\
103+
if (write_register(QSPI_CMD_WRSR, reg_data, \
104+
reg_size, qspi) != QSPI_STATUS_OK) { \
105+
return QSPI_STATUS_ERROR; \
106+
} \
107+
WAIT_FOR(WRSR_MAX_TIME, qspi); \
108+
\
109+
reg_data[0] = 0; \
110+
if (read_register(STATUS_REG, reg_data, \
111+
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
112+
return QSPI_STATUS_ERROR; \
113+
} \
114+
\
115+
return ((reg_data[0] & STATUS_BIT_QE) == 0 ? \
116+
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
117+
118+
#endif // MBED_QSPI_FLASH_CONFIG_H

TESTS/mbed_hal/qspi/flash_configs/flash_configs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include "STM/DISCO_F413ZH/flash_config.h"
2626
#elif defined(TARGET_EFM32GG11_STK3701)
2727
#include "SiliconLabs/EFM32GG11_STK3701/flash_config.h"
28+
#elif defined(TARGET_K82F)
29+
#include "Freescale/K82F/flash_config.h"
30+
#elif defined(TARGET_KL82Z)
31+
#include "Freescale/KL82Z/flash_config.h"
2832
#endif
2933

3034
#endif // MBED_FLASH_CONFIGS_H

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/TARGET_FRDM/PeripheralNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ typedef enum {
106106
SPI_2 = 2,
107107
} SPIName;
108108

109+
typedef enum {
110+
QSPI_0 = 0
111+
} QSPIName;
112+
109113
#ifdef __cplusplus
110114
}
111115
#endif

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/TARGET_FRDM/PeripheralPins.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,29 @@ const PinMap PinMap_PWM[] = {
265265

266266
{NC , NC , 0}
267267
};
268+
269+
const PinMap PinMap_QSPI_DATA[] = {
270+
{PTE0, QSPI_0, 5},
271+
{PTE2, QSPI_0, 5},
272+
{PTE3, QSPI_0, 5},
273+
{PTE4, QSPI_0, 5},
274+
{PTE6, QSPI_0, 5},
275+
{PTE7, QSPI_0, 5},
276+
{PTE8, QSPI_0, 5},
277+
{PTE9, QSPI_0, 5},
278+
{PTE10, QSPI_0, 5},
279+
{NC , NC , 0}
280+
};
281+
282+
const PinMap PinMap_QSPI_SCLK[] = {
283+
{PTE1, QSPI_0, 5},
284+
{PTE7, QSPI_0, 5},
285+
{NC , NC , 0}
286+
};
287+
288+
const PinMap PinMap_QSPI_SSEL[] = {
289+
{PTE5, QSPI_0, 5},
290+
{PTE11, QSPI_0, 5},
291+
{NC , NC , 0}
292+
};
293+

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/TARGET_FRDM/PinNames.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ typedef enum {
178178
SPI_SCK = PTE1,
179179
SPI_PERSISTENT_MEM_CS = PTE5,
180180

181+
/**** QSPI FLASH pins ****/
182+
QSPI_FLASH1_IO0 = PTE2,
183+
QSPI_FLASH1_IO1 = PTE4,
184+
QSPI_FLASH1_IO2 = PTE3,
185+
QSPI_FLASH1_IO3 = PTE0,
186+
QSPI_FLASH1_SCK = PTE1,
187+
QSPI_FLASH1_CSN = PTE5,
188+
181189
// Not connected
182190
NC = (int)0xFFFFFFFF
183191
} PinName;

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/TARGET_FRDM/device.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,9 @@
1818
#ifndef MBED_DEVICE_H
1919
#define MBED_DEVICE_H
2020

21+
#include "objects.h"
2122

23+
#define DEVICE_ID_LENGTH 24
2224

2325

24-
25-
26-
27-
28-
29-
30-
31-
#define DEVICE_ID_LENGTH 24
32-
33-
34-
35-
36-
37-
#include "objects.h"
38-
3926
#endif

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/TARGET_FRDM/mbed_overrides.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ void serial_clock_init(void)
6262
CLOCK_SetLpuartClock(2U);
6363
}
6464

65+
// Get the QSPI clock frequency
66+
uint32_t qspi_get_freq(void)
67+
{
68+
return CLOCK_GetFreq(kCLOCK_McgPll0Clk);
69+
}
70+

0 commit comments

Comments
 (0)