ChibiOS/HAL  6.1.0
hal_jesd216_flash.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
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 /**
18  * @file hal_jesd216_flash.h
19  * @brief JESD216 compliant flash driver class header.
20  *
21  * @addtogroup HAL_JESD216_FLASH
22  * @{
23  */
24 
25 #ifndef HAL_JESD216_FLASH_H
26 #define HAL_JESD216_FLASH_H
27 
28 #include "hal_flash.h"
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /**
35  * @name Common command codes
36  * @{
37  */
38 #define JESD216_CMD_READ_ID 0x9FU
39 #define JESD216_CMD_READ 0x03U
40 #define JESD216_CMD_WRITE_ENABLE 0x06U
41 #define JESD216_CMD_WRITE_DISABLE 0x04U
42 #define JESD216_CMD_READ_STATUS_REGISTER 0x05U
43 #define JESD216_CMD_WRITE_STATUS_REGISTER 0x01U
44 #define JESD216_CMD_PAGE_PROGRAM 0x02U
45 #define JESD216_CMD_ERASE_4K 0x20U
46 #define JESD216_CMD_ERASE_BULK 0xC7U
47 #define JESD216_CMD_PROGRAM_ERASE_RESUME 0x7AU
48 #define JESD216_CMD_PROGRAM_ERASE_SUSPEND 0x75U
49 #define JESD216_CMD_READ_OTP_ARRAY 0x4BU
50 #define JESD216_CMD_PROGRAM_OTP_ARRAY 0x42U
51 /** @} */
52 
53 /**
54  * @name Command options
55  * @{
56  */
57 #define JESD216_CMD_EXTENDED_ADDRESSING 0x80000000U
58 /** @} */
59 
60 /**
61  * @name Bus interface.
62  * @{
63  */
64 #define JESD216_BUS_MODE_SPI 0U
65 #define JESD216_BUS_MODE_QSPI1L 1U
66 #define JESD216_BUS_MODE_QSPI2L 2U
67 #define JESD216_BUS_MODE_QSPI4L 4U
68 /** @} */
69 
70 /*===========================================================================*/
71 /* Driver pre-compile time settings. */
72 /*===========================================================================*/
73 
74 /**
75  * @name Configuration options
76  * @{
77  */
78 /**
79  * @brief Physical transport interface.
80  */
81 #if !defined(JESD216_BUS_MODE) || defined(__DOXYGEN__)
82 #define JESD216_BUS_MODE JESD216_BUS_MODE_QSPI4L
83 #endif
84 
85 /**
86  * @brief Shared bus switch.
87  * @details If set to @p TRUE the device acquires bus ownership
88  * on each transaction.
89  * @note Requires @p SPI_USE_MUTUAL_EXCLUSION or
90  * @p SPI_USE_MUTUAL_EXCLUSION.
91  */
92 #if !defined(JESD216_SHARED_BUS) || defined(__DOXYGEN__)
93 #define JESD216_SHARED_BUS TRUE
94 #endif
95 /** @} */
96 
97 /*===========================================================================*/
98 /* Derived constants and error checks. */
99 /*===========================================================================*/
100 
101 #if (JESD216_BUS_MODE == JESD216_BUS_MODE_SPI) && (HAL_USE_SPI == FALSE)
102 #error "JESD216_BUS_MODE_SPI requires HAL_USE_SPI"
103 #endif
104 
105 #if (JESD216_BUS_MODE != JESD216_BUS_MODE_SPI) && (HAL_USE_QSPI == FALSE)
106 #error "JESD216_BUS_MODE_QSPIxL requires HAL_USE_QSPI"
107 #endif
108 
109 #if (JESD216_BUS_MODE == JESD216_BUS_MODE_SPI) && \
110  (JESD216_SHARED_BUS == TRUE) && \
111  (SPI_USE_MUTUAL_EXCLUSION == FALSE)
112 #error "JESD216_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION"
113 #endif
114 
115 #if (JESD216_BUS_MODE != JESD216_BUS_MODE_SPI) && \
116  (JESD216_BUS_MODE != JESD216_BUS_MODE_QSPI1L) && \
117  (JESD216_BUS_MODE != JESD216_BUS_MODE_QSPI2L) && \
118  (JESD216_BUS_MODE != JESD216_BUS_MODE_QSPI4L)
119 #error "invalid JESD216_BUS_MODE selected"
120 #endif
121 
122 /*===========================================================================*/
123 /* Driver data structures and types. */
124 /*===========================================================================*/
125 
126 #if (JESD216_BUS_MODE != JESD216_BUS_MODE_SPI) || defined(__DOXYGEN__)
127 #define BUSConfig QSPIConfig
128 #define BUSDriver QSPIDriver
129 #else
130 #define BUSConfig SPIConfig
131 #define BUSDriver SPIDriver
132 #endif
133 
134 #define _jesd216_config \
135  BUSDriver *busp; \
136  const BUSConfig *buscfg;
137 
138 /**
139  * @brief @p JESD215Flash specific methods.
140  */
141 #define _jesd216_flash_methods_alone \
142  /* Read SFDP.*/ \
143  flash_error_t (*read_sfdp)(void *instance, \
144  flash_offset_t offset, \
145  size_t n, \
146  uint8_t *rp);
147 
148 /**
149  * @brief @p JESD215Flash specific methods with inherited ones.
150  */
151 #define _jesd216_flash_methods \
152  _base_flash_methods \
153  _jesd216_flash_methods_alone
154 
155 /**
156  * @brief @p JESD215Flash virtual methods table.
157  */
160 };
161 
162 /**
163  * @brief @p JESD215Flash specific data.
164  */
165 #define _jesd216_flash_data \
166  _base_flash_data
167 
168 /**
169  * @brief Base flash class.
170  */
171 typedef struct {
172  /** @brief Virtual Methods Table.*/
173  const struct JESD215FlashVMT *vmt;
175 } JESD215Flash;
176 
177 /*===========================================================================*/
178 /* Driver macros. */
179 /*===========================================================================*/
180 
181 /**
182  * @name Macro Functions (BaseFlash)
183  * @{
184  */
185 /** @} */
186 
187 /*===========================================================================*/
188 /* External declarations. */
189 /*===========================================================================*/
190 
191 #ifdef __cplusplus
192 extern "C" {
193 #endif
194  void jesd216_start(BUSDriver *busp, const BUSConfig *config);
195  void jesd216_stop(BUSDriver *busp);
196  void jesd216_cmd(BUSDriver *busp, uint32_t cmd);
197  void jesd216_cmd_receive(BUSDriver *busp, uint32_t cmd,
198  size_t n, uint8_t *p);
199  void jesd216_cmd_send(BUSDriver *busp, uint32_t cmd,
200  size_t n, const uint8_t *p);
201  void jesd216_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset);
202  void jesd216_cmd_addr_send(BUSDriver *busp, uint32_t cmd,
203  flash_offset_t offset, size_t n, const uint8_t *p);
204  void jesd216_cmd_addr_receive(BUSDriver *busp, uint32_t cmd,
205  flash_offset_t offset, size_t n, uint8_t *p);
206 #if JESD216_BUS_MODE != JESD216_BUS_MODE_SPI
207  void jesd216_cmd_addr_dummy_receive(BUSDriver *busp, uint32_t cmd,
208  flash_offset_t offset, uint8_t dummy,
209  size_t n, uint8_t *p);
210 #endif /* JESD216_BUS_MODE != JESD216_BUS_MODE_SPI */
211 #if JESD216_SHARED_BUS == TRUE
212  void jesd216_bus_acquire(BUSDriver *busp, const BUSConfig *config);
213  void jesd216_bus_release(BUSDriver *busp);
214 #endif
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif /* HAL_JESD216_FLASH_H */
220 
221 /** @} */
JESD215Flash virtual methods table.
#define _jesd216_flash_data
JESD215Flash specific data.
#define _jesd216_flash_methods
JESD215Flash specific methods with inherited ones.
uint32_t flash_offset_t
Type of a flash offset.
Definition: hal_flash.h:83
const struct JESD215FlashVMT * vmt
Virtual Methods Table.
Base flash class.
Generic flash driver class header.