aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1052/drivers/fsl_romapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1052/drivers/fsl_romapi.c')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1052/drivers/fsl_romapi.c162
1 files changed, 162 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1052/drivers/fsl_romapi.c b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1052/drivers/fsl_romapi.c
new file mode 100644
index 000000000..b18534cb4
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/devices/MIMXRT1052/drivers/fsl_romapi.c
@@ -0,0 +1,162 @@
1/*
2 * Copyright 2017-2020 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#include "fsl_romapi.h"
9
10/*******************************************************************************
11 * Definitions
12 ******************************************************************************/
13
14/* Component ID definition, used by tools. */
15#ifndef FSL_COMPONENT_ID
16#define FSL_COMPONENT_ID "driver.romapi"
17#endif
18
19/*******************************************************************************
20 * Prototypes
21 ******************************************************************************/
22
23/*!
24 * @brief Interface for the ROM FLEXSPI NOR flash driver.
25 */
26typedef struct
27{
28 uint32_t version;
29 status_t (*init)(uint32_t instance, flexspi_nor_config_t *config);
30 status_t (*program)(uint32_t instance, flexspi_nor_config_t *config, uint32_t dst_addr, const uint32_t *src);
31 status_t (*erase_all)(uint32_t instance, flexspi_nor_config_t *config);
32 status_t (*erase)(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t lengthInBytes);
33 uint32_t reserved1;
34 void (*clear_cache)(uint32_t instance);
35 status_t (*xfer)(uint32_t instance, flexspi_xfer_t *xfer);
36 status_t (*update_lut)(uint32_t instance, uint32_t seqIndex, const uint32_t *lutBase, uint32_t seqNumber);
37 uint32_t reserved2;
38} flexspi_nor_driver_interface_t;
39
40/*!
41 * @brief Root of the bootloader api tree.
42 *
43 * An instance of this struct resides in read-only memory in the bootloader. It
44 * provides a user application access to APIs exported by the bootloader.
45 *
46 * @note The order of existing fields must not be changed.
47 */
48typedef struct
49{
50 void (*runBootloader)(void *arg); /*!< Function to start the bootloader executing */
51 const uint32_t version; /*!< Bootloader version number */
52 const uint8_t *copyright; /*!< Bootloader Copyright */
53 const uint32_t reserved0;
54 flexspi_nor_driver_interface_t *flexSpiNorDriver; /*!< FLEXSPI NOR flash api */
55} bootloader_api_entry_t;
56
57/*******************************************************************************
58 * Variables
59 ******************************************************************************/
60
61#define g_bootloaderTree ((bootloader_api_entry_t *)*(uint32_t *)0x0020001cU)
62
63#define api_flexspi_nor_erase_sector \
64 ((status_t(*)(uint32_t instance, flexspi_nor_config_t * config, uint32_t address))0x002106E7U)
65/*******************************************************************************
66 * Codes
67 ******************************************************************************/
68
69/*******************************************************************************
70 * ROM FLEXSPI NOR driver
71 ******************************************************************************/
72#if defined(FSL_FEATURE_BOOT_ROM_HAS_ROMAPI) && FSL_FEATURE_BOOT_ROM_HAS_ROMAPI
73
74/*!
75 * @brief Initialize Serial NOR flash via FLEXSPI.
76 *
77 * @param instance storge the instance of FLEXSPI.
78 * @param config A pointer to the storage for the driver runtime state.
79 */
80status_t ROM_FLEXSPI_NorFlash_Init(uint32_t instance, flexspi_nor_config_t *config)
81{
82 return g_bootloaderTree->flexSpiNorDriver->init(instance, config);
83}
84
85/*!
86 * @brief Program data to Serial NOR via FLEXSPI.
87 *
88 * @param instance storge the instance of FLEXSPI.
89 * @param config A pointer to the storage for the driver runtime state.
90 * @param dstAddr A pointer to the desired flash memory to be programmed.
91 * @param src A pointer to the source buffer of data that is to be programmed
92 * into the NOR flash.
93 */
94status_t ROM_FLEXSPI_NorFlash_ProgramPage(uint32_t instance,
95 flexspi_nor_config_t *config,
96 uint32_t dstAddr,
97 const uint32_t *src)
98{
99 return g_bootloaderTree->flexSpiNorDriver->program(instance, config, dstAddr, src);
100}
101
102/*!
103 * @brief Erase Flash Region specified by address and length.
104 *
105 * @param instance storge the index of FLEXSPI.
106 * @param config A pointer to the storage for the driver runtime state.
107 * @param start The start address of the desired NOR flash memory to be erased.
108 * @param length The length, given in bytes to be erased.
109 */
110status_t ROM_FLEXSPI_NorFlash_Erase(uint32_t instance, flexspi_nor_config_t *config, uint32_t start, uint32_t length)
111{
112 return g_bootloaderTree->flexSpiNorDriver->erase(instance, config, start, length);
113}
114
115#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR
116/*!
117 * @brief Erase one sector specified by address.
118 *
119 * @param instance storge the index of FLEXSPI.
120 * @param config A pointer to the storage for the driver runtime state.
121 * @param start The start address of the desired NOR flash memory to be erased.
122 */
123status_t ROM_FLEXSPI_NorFlash_EraseSector(uint32_t instance, flexspi_nor_config_t *config, uint32_t start)
124{
125 return api_flexspi_nor_erase_sector(instance, config, start);
126}
127#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_SECTOR */
128
129#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL
130/*! @brief Erase all the Serial NOR flash connected on FLEXSPI. */
131status_t ROM_FLEXSPI_NorFlash_EraseAll(uint32_t instance, flexspi_nor_config_t *config)
132{
133 return g_bootloaderTree->flexSpiNorDriver->erase_all(instance, config);
134}
135#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_ERASE_ALL */
136
137#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER
138/*! @brief FLEXSPI command */
139status_t ROM_FLEXSPI_NorFlash_CommandXfer(uint32_t instance, flexspi_xfer_t *xfer)
140{
141 return g_bootloaderTree->flexSpiNorDriver->xfer(instance, xfer);
142}
143#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_CMD_XFER */
144
145#if defined(FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT) && FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT
146/*! @brief Configure FLEXSPI Lookup table. */
147status_t ROM_FLEXSPI_NorFlash_UpdateLut(uint32_t instance,
148 uint32_t seqIndex,
149 const uint32_t *lutBase,
150 uint32_t seqNumber)
151{
152 return g_bootloaderTree->flexSpiNorDriver->update_lut(instance, seqIndex, lutBase, seqNumber);
153}
154#endif /* FSL_ROM_FLEXSPINOR_API_HAS_FEATURE_UPDATE_LUT */
155
156/*! @brief Software reset for the FLEXSPI logic. */
157void ROM_FLEXSPI_NorFlash_ClearCache(uint32_t instance)
158{
159 g_bootloaderTree->flexSpiNorDriver->clear_cache(instance);
160}
161
162#endif /* FSL_FEATURE_BOOT_ROM_HAS_ROMAPI */