Skip to content

Commit fffb375

Browse files
committed
LPC546XX: Update the SPIFI SDK driver
Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 82f195c commit fffb375

File tree

3 files changed

+162
-73
lines changed

3 files changed

+162
-73
lines changed

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC546XX/drivers/fsl_reset.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ typedef enum _SYSCON_RSTn
220220
{ \
221221
kSHA_RST_SHIFT_RSTn \
222222
} /* Reset bits for SHA peripheral */
223+
#define SPIFI_RSTS \
224+
{ \
225+
kSPIFI_RST_SHIFT_RSTn \
226+
} /* Reset bits for SPIFI peripheral */
223227
#define USB0D_RST \
224228
{ \
225229
kUSB0D_RST_SHIFT_RSTn \
Lines changed: 105 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
/*
2-
* The Clear BSD License
32
* Copyright (c) 2016, Freescale Semiconductor, Inc.
43
* Copyright 2016-2017 NXP
54
* All rights reserved.
65
*
7-
* Redistribution and use in source and binary forms, with or without modification,
8-
* are permitted (subject to the limitations in the disclaimer below) provided
9-
* that the following conditions are met:
10-
*
11-
* o Redistributions of source code must retain the above copyright notice, this list
12-
* of conditions and the following disclaimer.
13-
*
14-
* o Redistributions in binary form must reproduce the above copyright notice, this
15-
* list of conditions and the following disclaimer in the documentation and/or
16-
* other materials provided with the distribution.
17-
*
18-
* o Neither the name of the copyright holder nor the names of its
19-
* contributors may be used to endorse or promote products derived from this
20-
* software without specific prior written permission.
21-
*
22-
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6+
* SPDX-License-Identifier: BSD-3-Clause
337
*/
348

359
#include "fsl_spifi.h"
@@ -38,18 +12,15 @@
3812
* Definitions
3913
******************************************************************************/
4014

15+
/* Component ID definition, used by tools. */
16+
#ifndef FSL_COMPONENT_ID
17+
#define FSL_COMPONENT_ID "platform.drivers.spifi"
18+
#endif
19+
4120
/*******************************************************************************
4221
* Prototypes
4322
******************************************************************************/
4423

45-
/*!
46-
* @brief Get the SPIFI instance from peripheral base address.
47-
*
48-
* @param base SPIFI peripheral base address.
49-
* @return SPIFI instance.
50-
*/
51-
uint32_t SPIFI_GetInstance(SPIFI_Type *base);
52-
5324
/*******************************************************************************
5425
* Variables
5526
******************************************************************************/
@@ -62,9 +33,19 @@ static SPIFI_Type *const s_spifiBases[] = SPIFI_BASE_PTRS;
6233
static const clock_ip_name_t s_spifiClock[] = SPIFI_CLOCKS;
6334
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
6435

36+
#if !(defined(FSL_FEATURE_SPIFI_HAS_NO_RESET) && FSL_FEATURE_SPIFI_HAS_NO_RESET)
37+
static const reset_ip_name_t s_spifiResets[] = SPIFI_RSTS;
38+
#endif
39+
6540
/*******************************************************************************
6641
* Code
6742
******************************************************************************/
43+
/*!
44+
* brief Get the SPIFI instance from peripheral base address.
45+
*
46+
* param base SPIFI peripheral base address.
47+
* return SPIFI instance.
48+
*/
6849
uint32_t SPIFI_GetInstance(SPIFI_Type *base)
6950
{
7051
uint32_t instance;
@@ -83,8 +64,16 @@ uint32_t SPIFI_GetInstance(SPIFI_Type *base)
8364
return instance;
8465
}
8566

67+
/*!
68+
* brief Get SPIFI default configure settings.
69+
*
70+
* param config SPIFI config structure pointer.
71+
*/
8672
void SPIFI_GetDefaultConfig(spifi_config_t *config)
8773
{
74+
/* Initializes the configure structure to zero. */
75+
memset(config, 0, sizeof(*config));
76+
8877
config->timeout = 0xFFFFU;
8978
config->csHighTime = 0xFU;
9079
config->disablePrefetch = false;
@@ -95,6 +84,14 @@ void SPIFI_GetDefaultConfig(spifi_config_t *config)
9584
config->dualMode = kSPIFI_QuadMode;
9685
}
9786

87+
/*!
88+
* brief Initializes the SPIFI with the user configuration structure.
89+
*
90+
* This function configures the SPIFI module with the user-defined configuration.
91+
*
92+
* param base SPIFI peripheral base address.
93+
* param config The pointer to the configuration structure.
94+
*/
9895
void SPIFI_Init(SPIFI_Type *base, const spifi_config_t *config)
9996
{
10097
assert(config);
@@ -104,6 +101,10 @@ void SPIFI_Init(SPIFI_Type *base, const spifi_config_t *config)
104101
CLOCK_EnableClock(s_spifiClock[SPIFI_GetInstance(base)]);
105102
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
106103

104+
#if !(defined(FSL_FEATURE_SPIFI_HAS_NO_RESET) && FSL_FEATURE_SPIFI_HAS_NO_RESET)
105+
RESET_PeripheralReset(s_spifiResets[SPIFI_GetInstance(base)]);
106+
#endif
107+
107108
/* Reset the Command register */
108109
SPIFI_ResetCommand(base);
109110

@@ -114,6 +115,11 @@ void SPIFI_Init(SPIFI_Type *base, const spifi_config_t *config)
114115
SPIFI_CTRL_RFCLK(config->isReadFullClockCycle) | SPIFI_CTRL_FBCLK(config->isFeedbackClock);
115116
}
116117

118+
/*!
119+
* brief Deinitializes the SPIFI regions.
120+
*
121+
* param base SPIFI peripheral base address.
122+
*/
117123
void SPIFI_Deinit(SPIFI_Type *base)
118124
{
119125
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
@@ -122,29 +128,84 @@ void SPIFI_Deinit(SPIFI_Type *base)
122128
#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
123129
}
124130

131+
/*!
132+
* brief Set SPIFI flash command.
133+
*
134+
* param base SPIFI peripheral base address.
135+
* param cmd SPIFI command structure pointer.
136+
*/
125137
void SPIFI_SetCommand(SPIFI_Type *base, spifi_command_t *cmd)
126138
{
127-
/* Wait for the CMD and MCINT flag all be 0 */
128-
while (SPIFI_GetStatusFlag(base) & (SPIFI_STAT_MCINIT_MASK | SPIFI_STAT_CMD_MASK))
139+
/* If SPIFI in memory mode, call reset function to abort memory mode */
140+
if (SPIFI_GetStatusFlag(base) & SPIFI_STAT_MCINIT_MASK)
129141
{
142+
SPIFI_ResetCommand(base);
130143
}
131-
base->CMD = SPIFI_CMD_DATALEN(cmd->dataLen) | SPIFI_CMD_POLL(cmd->isPollMode) | SPIFI_CMD_DOUT(cmd->direction) |
132-
SPIFI_CMD_INTLEN(cmd->intermediateBytes) | SPIFI_CMD_FIELDFORM(cmd->format) |
133-
SPIFI_CMD_FRAMEFORM(cmd->type) | SPIFI_CMD_OPCODE(cmd->opcode);
134144

135-
/* Wait for the command written */
136-
while ((base->STAT & SPIFI_STAT_CMD_MASK) == 0U)
145+
/* Wait for other command finished */
146+
while (SPIFI_GetStatusFlag(base) & SPIFI_STAT_CMD_MASK)
137147
{
138148
}
149+
150+
base->CMD = SPIFI_CMD_DATALEN(cmd->dataLen) | SPIFI_CMD_POLL(cmd->isPollMode) | SPIFI_CMD_DOUT(cmd->direction) |
151+
SPIFI_CMD_INTLEN(cmd->intermediateBytes) | SPIFI_CMD_FIELDFORM(cmd->format) |
152+
SPIFI_CMD_FRAMEFORM(cmd->type) | SPIFI_CMD_OPCODE(cmd->opcode);
139153
}
140154

155+
/*!
156+
* brief Set SPIFI flash AHB read command.
157+
*
158+
* Call this function means SPIFI enters to memory mode, while users need to use command, a SPIFI_ResetCommand shall
159+
* be called.
160+
*
161+
* param base SPIFI peripheral base address.
162+
* param cmd SPIFI command structure pointer.
163+
*/
141164
void SPIFI_SetMemoryCommand(SPIFI_Type *base, spifi_command_t *cmd)
142165
{
143-
/* Wait for the CMD and MCINT flag all be 0 */
144-
while (SPIFI_GetStatusFlag(base) & (SPIFI_STAT_MCINIT_MASK | SPIFI_STAT_CMD_MASK))
166+
/* Wait for the CMD flag be 0 */
167+
while (SPIFI_GetStatusFlag(base) & SPIFI_STAT_CMD_MASK)
145168
{
146169
}
147170

148171
base->MCMD = SPIFI_MCMD_POLL(0U) | SPIFI_MCMD_DOUT(0U) | SPIFI_MCMD_INTLEN(cmd->intermediateBytes) |
149172
SPIFI_MCMD_FIELDFORM(cmd->format) | SPIFI_MCMD_FRAMEFORM(cmd->type) | SPIFI_MCMD_OPCODE(cmd->opcode);
173+
174+
/* Wait for the command written */
175+
while ((base->STAT & SPIFI_STAT_MCINIT_MASK) == 0)
176+
{
177+
}
178+
}
179+
180+
/*!
181+
* brief Write a halfword data in address of SPIFI.
182+
*
183+
* Users can write a halfword data into SPIFI address.
184+
*
185+
* param base SPIFI peripheral base address.
186+
* param data Data need be write.
187+
*/
188+
void SPIFI_WriteDataHalfword(SPIFI_Type *base, uint16_t data)
189+
{
190+
volatile uint8_t *dataReg = ((volatile uint8_t *)(&(base->DATA)));
191+
192+
*dataReg = (data & 0xFFU);
193+
dataReg++;
194+
*dataReg = ((data >> 8U) & 0xFFU);
195+
}
196+
197+
/*!
198+
* brief Read a halfword data from serial flash.
199+
*
200+
* param base SPIFI peripheral base address.
201+
* return Data input from flash.
202+
*/
203+
uint16_t SPIFI_ReadDataHalfword(SPIFI_Type *base)
204+
{
205+
uint16_t val = 0;
206+
volatile uint8_t *dataReg = ((volatile uint8_t *)(&(base->DATA)));
207+
208+
val = ((*dataReg) | (uint16_t)((uint16_t)(*(dataReg + 1U)) << 8U));
209+
210+
return val;
150211
}

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC546XX/drivers/fsl_spifi.h

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
/*
2-
* The Clear BSD License
32
* Copyright (c) 2016, Freescale Semiconductor, Inc.
43
* Copyright 2016-2017 NXP
54
* All rights reserved.
65
*
7-
* Redistribution and use in source and binary forms, with or without modification,
8-
* are permitted (subject to the limitations in the disclaimer below) provided
9-
* that the following conditions are met:
10-
*
11-
* o Redistributions of source code must retain the above copyright notice, this list
12-
* of conditions and the following disclaimer.
13-
*
14-
* o Redistributions in binary form must reproduce the above copyright notice, this
15-
* list of conditions and the following disclaimer in the documentation and/or
16-
* other materials provided with the distribution.
17-
*
18-
* o Neither the name of the copyright holder nor the names of its
19-
* contributors may be used to endorse or promote products derived from this
20-
* software without specific prior written permission.
21-
*
22-
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27-
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30-
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6+
* SPDX-License-Identifier: BSD-3-Clause
337
*/
348
#ifndef _FSL_SPIFI_H_
359
#define _FSL_SPIFI_H_
@@ -47,8 +21,8 @@
4721

4822
/*! @name Driver version */
4923
/*@{*/
50-
/*! @brief SPIFI driver version 2.0.0. */
51-
#define FSL_SPIFI_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
24+
/*! @brief SPIFI driver version 2.0.2. */
25+
#define FSL_SPIFI_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
5226
/*@}*/
5327

5428
/*! @brief Status structure of SPIFI.*/
@@ -162,6 +136,14 @@ extern "C" {
162136
* @{
163137
*/
164138

139+
/*!
140+
* @brief Get the SPIFI instance from peripheral base address.
141+
*
142+
* @param base SPIFI peripheral base address.
143+
* @return SPIFI instance.
144+
*/
145+
uint32_t SPIFI_GetInstance(SPIFI_Type *base);
146+
165147
/*!
166148
* @brief Initializes the SPIFI with the user configuration structure.
167149
*
@@ -358,6 +340,29 @@ static inline void SPIFI_WriteData(SPIFI_Type *base, uint32_t data)
358340
base->DATA = data;
359341
}
360342

343+
/*!
344+
* @brief Write a byte data in address of SPIFI.
345+
*
346+
* Users can write a byte data into SPIFI address.
347+
*
348+
* @param base SPIFI peripheral base address.
349+
* @param data Data need be write.
350+
*/
351+
static inline void SPIFI_WriteDataByte(SPIFI_Type *base, uint8_t data)
352+
{
353+
*((volatile uint8_t *)(&(base->DATA))) = data;
354+
}
355+
356+
/*!
357+
* @brief Write a halfword data in address of SPIFI.
358+
*
359+
* Users can write a halfword data into SPIFI address.
360+
*
361+
* @param base SPIFI peripheral base address.
362+
* @param data Data need be write.
363+
*/
364+
void SPIFI_WriteDataHalfword(SPIFI_Type *base, uint16_t data);
365+
361366
/*!
362367
* @brief Read data from serial flash.
363368
*
@@ -372,6 +377,25 @@ static inline uint32_t SPIFI_ReadData(SPIFI_Type *base)
372377
return base->DATA;
373378
}
374379

380+
/*!
381+
* @brief Read a byte data from serial flash.
382+
*
383+
* @param base SPIFI peripheral base address.
384+
* @return Data input from flash.
385+
*/
386+
static inline uint8_t SPIFI_ReadDataByte(SPIFI_Type *base)
387+
{
388+
return *((volatile uint8_t *)(&(base->DATA)));
389+
}
390+
391+
/*!
392+
* @brief Read a halfword data from serial flash.
393+
*
394+
* @param base SPIFI peripheral base address.
395+
* @return Data input from flash.
396+
*/
397+
uint16_t SPIFI_ReadDataHalfword(SPIFI_Type *base);
398+
375399
/* @} */
376400

377401
#if defined(__cplusplus)

0 commit comments

Comments
 (0)