Mistake on this page?
Report an issue in GitHub or email us
qspi_api.h
1 
2 /** \addtogroup hal */
3 /** @{*/
4 /* mbed Microcontroller Library
5  * Copyright (c) 2017 ARM Limited
6  * SPDX-License-Identifier: Apache-2.0
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef MBED_QSPI_API_H
21 #define MBED_QSPI_API_H
22 
23 #include "device.h"
24 #include "pinmap.h"
25 #include <stdbool.h>
26 
27 #if DEVICE_QSPI
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /**
34  * \defgroup hal_qspi QSPI HAL
35  * @{
36  */
37 
38 /** QSPI HAL object
39  */
40 typedef struct qspi_s qspi_t;
41 
42 /** QSPI Bus width
43  *
44  * Some parts of commands provide variable bus width
45  */
46 typedef enum qspi_bus_width {
47  QSPI_CFG_BUS_SINGLE,
48  QSPI_CFG_BUS_DUAL,
49  QSPI_CFG_BUS_QUAD,
51 
52 /** Address size in bits
53  */
54 typedef enum qspi_address_size {
55  QSPI_CFG_ADDR_SIZE_8,
56  QSPI_CFG_ADDR_SIZE_16,
57  QSPI_CFG_ADDR_SIZE_24,
58  QSPI_CFG_ADDR_SIZE_32,
60 
61 /** Alternative size in bits
62  */
63 typedef uint8_t qspi_alt_size_t;
64 
65 // The following defines are provided for backwards compatibilty. New code should explicitly
66 // specify the required number of alt bits.
67 #define QSPI_CFG_ALT_SIZE_8 8u
68 #define QSPI_CFG_ALT_SIZE_16 16u
69 #define QSPI_CFG_ALT_SIZE_24 24u
70 #define QSPI_CFG_ALT_SIZE_32 32u
71 
72 /** QSPI command
73  *
74  * Defines a frame format. It consists of instruction, address, alternative, dummy count and data
75  */
76 typedef struct qspi_command {
77  struct {
78  qspi_bus_width_t bus_width; /**< Bus width for the instruction >*/
79  uint8_t value; /**< Instruction value >*/
80  bool disabled; /**< Instruction phase skipped if disabled is set to true >*/
81  } instruction;
82  struct {
83  qspi_bus_width_t bus_width; /**< Bus width for the address >*/
84  qspi_address_size_t size; /**< Address size >*/
85  uint32_t value; /**< Address value >*/
86  bool disabled; /**< Address phase skipped if disabled is set to true >*/
87  } address;
88  struct {
89  qspi_bus_width_t bus_width; /**< Bus width for alternative >*/
90  qspi_alt_size_t size; /**< Alternative size >*/
91  uint32_t value; /**< Alternative value >*/
92  bool disabled; /**< Alternative phase skipped if disabled is set to true >*/
93  } alt;
94  uint8_t dummy_count; /**< Dummy cycles count >*/
95  struct {
96  qspi_bus_width_t bus_width; /**< Bus width for data >*/
97  } data;
99 
100 /** QSPI return status
101  */
102 typedef enum qspi_status {
103  QSPI_STATUS_ERROR = -1, /**< Generic error >*/
104  QSPI_STATUS_INVALID_PARAMETER = -2, /**< The parameter is invalid >*/
105  QSPI_STATUS_OK = 0, /**< Function executed sucessfully >*/
106 } qspi_status_t;
107 
108 /** Initialize QSPI peripheral.
109  *
110  * It should initialize QSPI pins (io0-io3, sclk and ssel), set frequency, clock polarity and phase mode. The clock for the peripheral should be enabled
111  *
112  * @param obj QSPI object
113  * @param io0 Data pin 0
114  * @param io1 Data pin 1
115  * @param io2 Data pin 2
116  * @param io3 Data pin 3
117  * @param sclk The clock pin
118  * @param ssel The chip select pin
119  * @param hz The bus frequency
120  * @param mode Clock polarity and phase mode (0 - 3)
121  * @return QSPI_STATUS_OK if initialisation successfully executed
122  QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
123  QSPI_STATUS_ERROR otherwise
124  */
125 qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel, uint32_t hz, uint8_t mode);
126 
127 /** Deinitilize QSPI peripheral
128  *
129  * It should release pins that are associated with the QSPI object, and disable clocks for QSPI peripheral module that was associated with the object
130  *
131  * @param obj QSPI object
132  * @return QSPI_STATUS_OK if deinitialisation successfully executed
133  QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
134  QSPI_STATUS_ERROR otherwise
135  */
137 
138 /** Set the QSPI baud rate
139  *
140  * Actual frequency may differ from the desired frequency due to available dividers and the bus clock
141  * Configures the QSPI peripheral's baud rate
142  * @param obj The SPI object to configure
143  * @param hz The baud rate in Hz
144  * @return QSPI_STATUS_OK if frequency was set
145  QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
146  QSPI_STATUS_ERROR otherwise
147  */
148 qspi_status_t qspi_frequency(qspi_t *obj, int hz);
149 
150 /** Send a command and block of data
151  *
152  * @param obj QSPI object
153  * @param command QSPI command
154  * @param data TX buffer
155  * @param[in,out] length in - TX buffer length in bytes, out - number of bytes written
156  * @return QSPI_STATUS_OK if the data has been succesfully sent
157  QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
158  QSPI_STATUS_ERROR otherwise
159  */
160 qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void *data, size_t *length);
161 
162 /** Send a command (and optionally data) and get the response. Can be used to send/receive device specific commands
163  *
164  * @param obj QSPI object
165  * @param command QSPI command
166  * @param tx_data TX buffer
167  * @param tx_size TX buffer length in bytes
168  * @param rx_data RX buffer
169  * @param rx_size RX buffer length in bytes
170  * @return QSPI_STATUS_OK if the data has been succesfully sent
171  QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
172  QSPI_STATUS_ERROR otherwise
173  */
174 qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command, const void *tx_data, size_t tx_size, void *rx_data, size_t rx_size);
175 
176 /** Receive a command and block of data
177  *
178  * @param obj QSPI object
179  * @param command QSPI command
180  * @param data RX buffer
181  * @param[in,out] length in - RX buffer length in bytes, out - number of bytes read
182  * @return QSPI_STATUS_OK if data has been succesfully received
183  QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
184  QSPI_STATUS_ERROR otherwise
185  */
186 qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data, size_t *length);
187 
188 /** Get the pins that support QSPI SCLK
189  *
190  * Return a PinMap array of pins that support QSPI SCLK in
191  * master mode. The array is terminated with {NC, NC, 0}.
192  *
193  * @return PinMap array
194  */
195 const PinMap *qspi_master_sclk_pinmap(void);
196 
197 /** Get the pins that support QSPI SSEL
198  *
199  * Return a PinMap array of pins that support QSPI SSEL in
200  * master mode. The array is terminated with {NC, NC, 0}.
201  *
202  * @return PinMap array
203  */
204 const PinMap *qspi_master_ssel_pinmap(void);
205 
206 /** Get the pins that support QSPI DATA0
207  *
208  * Return a PinMap array of pins that support QSPI DATA0 in
209  * master mode. The array is terminated with {NC, NC, 0}.
210  *
211  * @return PinMap array
212  */
213 const PinMap *qspi_master_data0_pinmap(void);
214 
215 /** Get the pins that support QSPI DATA1
216  *
217  * Return a PinMap array of pins that support QSPI DATA1 in
218  * master mode. The array is terminated with {NC, NC, 0}.
219  *
220  * @return PinMap array
221  */
222 const PinMap *qspi_master_data1_pinmap(void);
223 
224 /** Get the pins that support QSPI DATA2
225  *
226  * Return a PinMap array of pins that support QSPI DATA2 in
227  * master mode. The array is terminated with {NC, NC, 0}.
228  *
229  * @return PinMap array
230  */
231 const PinMap *qspi_master_data2_pinmap(void);
232 
233 /** Get the pins that support QSPI DATA3
234  *
235  * Return a PinMap array of pins that support QSPI DATA3 in
236  * master mode. The array is terminated with {NC, NC, 0}.
237  *
238  * @return PinMap array
239  */
240 const PinMap *qspi_master_data3_pinmap(void);
241 
242 /**@}*/
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 #endif
249 
250 #endif
251 
252 /** @}*/
qspi_status_t qspi_frequency(qspi_t *obj, int hz)
Set the QSPI baud rate.
QSPI command.
Definition: qspi_api.h:76
const PinMap * qspi_master_data0_pinmap(void)
Get the pins that support QSPI DATA0.
struct qspi_command qspi_command_t
QSPI command.
uint8_t dummy_count
Dummy cycles count >
Definition: qspi_api.h:94
struct qspi_s qspi_t
QSPI HAL object.
Definition: qspi_api.h:40
const PinMap * qspi_master_ssel_pinmap(void)
Get the pins that support QSPI SSEL.
qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data, size_t *length)
Receive a command and block of data.
uint32_t value
Address value >
Definition: qspi_api.h:85
Generic error >
Definition: qspi_api.h:103
const PinMap * qspi_master_data1_pinmap(void)
Get the pins that support QSPI DATA1.
The parameter is invalid >
Definition: qspi_api.h:104
qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void *data, size_t *length)
Send a command and block of data.
bool disabled
Instruction phase skipped if disabled is set to true >
Definition: qspi_api.h:80
qspi_status
QSPI return status.
Definition: qspi_api.h:102
qspi_bus_width_t bus_width
Bus width for the instruction >
Definition: qspi_api.h:78
qspi_alt_size_t size
Alternative size >
Definition: qspi_api.h:90
qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command, const void *tx_data, size_t tx_size, void *rx_data, size_t rx_size)
Send a command (and optionally data) and get the response.
enum qspi_address_size qspi_address_size_t
Address size in bits.
qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel, uint32_t hz, uint8_t mode)
Initialize QSPI peripheral.
Definition: pinmap.h:30
const PinMap * qspi_master_data2_pinmap(void)
Get the pins that support QSPI DATA2.
const PinMap * qspi_master_sclk_pinmap(void)
Get the pins that support QSPI SCLK.
uint8_t qspi_alt_size_t
Alternative size in bits.
Definition: qspi_api.h:63
qspi_address_size_t size
Address size >
Definition: qspi_api.h:84
enum qspi_bus_width qspi_bus_width_t
QSPI Bus width.
qspi_address_size
Address size in bits.
Definition: qspi_api.h:54
qspi_bus_width
QSPI Bus width.
Definition: qspi_api.h:46
uint8_t value
Instruction value >
Definition: qspi_api.h:79
Function executed sucessfully >
Definition: qspi_api.h:105
enum qspi_status qspi_status_t
QSPI return status.
const PinMap * qspi_master_data3_pinmap(void)
Get the pins that support QSPI DATA3.
qspi_status_t qspi_free(qspi_t *obj)
Deinitilize QSPI peripheral.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.