Select one of the symbols to view example projects that use it.
 
Outline
...
#include "lx_stm32_qspi_driver.h"
is_initialized
check_status()
lx_stm32_qspi_initialize(LX_NOR_FLASH *)
lx_qspi_driver_read_sector(ULONG *, ULONG *, ULONG)
lx_qspi_driver_write_sector(ULONG *, ULONG *, ULONG)
lx_qspi_driver_erase_block(ULONG, ULONG)
lx_qspi_driver_block_erased_verify(ULONG)
lx_qspi_driver_system_error(UINT)
Files
loading...
CodeScopeSTM32 Libraries and Sampleslevelxcommon/drivers/lx_stm32_qspi_driver.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ #include "lx_stm32_qspi_driver.h" static UINT lx_qspi_driver_read_sector(ULONG *flash_address, ULONG *destination, ULONG words); static UINT lx_qspi_driver_write_sector(ULONG *flash_address, ULONG *source, ULONG words); static UINT lx_qspi_driver_erase_block(ULONG block, ULONG erase_count); static UINT lx_qspi_driver_block_erased_verify(ULONG block); #ifndef LX_DIRECT_READ extern ULONG qspi_sector_buffer[LX_STM32_QSPI_SECTOR_SIZE/sizeof(ULONG)]; #endif static UINT is_initialized = LX_FALSE; /** * @brief check the status of the octospi memory. * @param none * @retval LX_SUCCESS if the octospi is ready, LX_ERROR otherwise *//* ... */ static UINT check_status(void) { ULONG start = LX_STM32_QSPI_CURRENT_TIME(); while (LX_STM32_QSPI_CURRENT_TIME() - start < LX_STM32_QSPI_DEFAULT_TIMEOUT) { if (lx_stm32_qspi_get_status(LX_STM32_QSPI_INSTANCE) == 0) { return LX_SUCCESS; }if (lx_stm32_qspi_get_status(LX_STM32_QSPI_INSTANCE) == 0) { ... } }while (LX_STM32_QSPI_CURRENT_TIME() - start < LX_STM32_QSPI_DEFAULT_TIMEOUT) { ... } return LX_ERROR; }{ ... } /** * @brief initialize the OctoSPI memory * @param LX_NOR_FLASH * the levelx NOR flash main instance. * @retval LX_SUCCESS if the octospi is ready, LX_ERROR otherwise *//* ... */ UINT lx_stm32_qspi_initialize(LX_NOR_FLASH *nor_flash) { INT ret; ULONG block_size; ULONG total_blocks; if (is_initialized == LX_FALSE) { ret = lx_stm32_qspi_lowlevel_init(LX_STM32_QSPI_INSTANCE); if (ret != 0) { return LX_ERROR; }if (ret != 0) { ... } #if (LX_STM32_QSPI_ERASE == 1) ret = lx_stm32_qspi_erase(LX_STM32_QSPI_INSTANCE, (ULONG)0, (ULONG)0, 1); if (ret != 0) { return LX_ERROR; }if (ret != 0) { ... } /* ... */#endif if (check_status() != LX_SUCCESS) { return LX_ERROR; }if (check_status() != LX_SUCCESS) { ... } ret = lx_stm32_qspi_get_info(LX_STM32_QSPI_INSTANCE, &block_size, &total_blocks); if (ret != 0) { return LX_ERROR; }if (ret != 0) { ... } /* Setup the base address of the flash memory. */ nor_flash->lx_nor_flash_base_address = 0; /* Setup geometry of the flash. */ nor_flash->lx_nor_flash_total_blocks = total_blocks; nor_flash->lx_nor_flash_words_per_block = block_size / sizeof(ULONG); nor_flash->lx_nor_flash_driver_read = lx_qspi_driver_read_sector; nor_flash->lx_nor_flash_driver_write = lx_qspi_driver_write_sector; nor_flash->lx_nor_flash_driver_block_erase = lx_qspi_driver_erase_block; nor_flash->lx_nor_flash_driver_block_erased_verify = lx_qspi_driver_block_erased_verify; nor_flash->lx_nor_flash_driver_system_error = lx_qspi_driver_system_error; #ifndef LX_DIRECT_READ /* Setup local buffer for NOR flash operation. This buffer must be the sector size of the NOR flash memory. */ nor_flash->lx_nor_flash_sector_buffer = &qspi_sector_buffer[0];/* ... */ #endif is_initialized = LX_TRUE; }if (is_initialized == LX_FALSE) { ... } /* call post init routine*/ LX_STM32_QSPI_POST_INIT(); /* Return success. */ return LX_SUCCESS; }{ ... } /** * @brief read data from flash memory address into a destination buffer * @param ULONG* flash_address the flash address to read from * @param ULONG* destination the buffer to hold the read data * @param ULONG words the number of words to read * @retval LX_SUCCESS if data is read correctly, LX_ERROR on errors *//* ... */ static UINT lx_qspi_driver_read_sector(ULONG *flash_address, ULONG *destination, ULONG words) { UINT status = LX_SUCCESS; if (check_status() != LX_SUCCESS) { return LX_ERROR; }if (check_status() != LX_SUCCESS) { ... } LX_STM32_QSPI_PRE_READ_TRANSFER(status); if (status != LX_SUCCESS) { return status; }if (status != LX_SUCCESS) { ... } if (lx_stm32_qspi_read(LX_STM32_QSPI_INSTANCE, flash_address, destination, words) != 0) { status = LX_ERROR; LX_STM32_QSPI_READ_TRANSFER_ERROR(status); }if (lx_stm32_qspi_read(LX_STM32_QSPI_INSTANCE, flash_address, destination, words) != 0) { ... } else { LX_STM32_QSPI_READ_CPLT_NOTIFY(status); }else { ... } LX_STM32_QSPI_POST_READ_TRANSFER(status); return status; }{ ... } /** * @brief write source buffer into flash memory address * @param ULONG* flash_address the flash address to write into * @param ULONG* source the data buffer to be written * @param ULONG words the number of words to write * @retval LX_SUCCESS if data is written correctly, LX_ERROR on errors *//* ... */ static UINT lx_qspi_driver_write_sector(ULONG *flash_address, ULONG *source, ULONG words) { UINT status = LX_SUCCESS; if (check_status() != LX_SUCCESS) { return LX_ERROR; }if (check_status() != LX_SUCCESS) { ... } LX_STM32_QSPI_PRE_WRITE_TRANSFER(status); if (status != LX_SUCCESS) { return status; }if (status != LX_SUCCESS) { ... } if (lx_stm32_qspi_write(LX_STM32_QSPI_INSTANCE, flash_address, source, words) != 0) { status = LX_ERROR; LX_STM32_QSPI_WRITE_TRANSFER_ERROR(status); }if (lx_stm32_qspi_write(LX_STM32_QSPI_INSTANCE, flash_address, source, words) != 0) { ... } else { LX_STM32_QSPI_WRITE_CPLT_NOTIFY(status); }else { ... } LX_STM32_QSPI_POST_WRITE_TRANSFER(status); return status; }{ ... } static UINT lx_qspi_driver_erase_block(ULONG block, ULONG erase_count) { UINT status; if (check_status() != LX_SUCCESS) { return LX_ERROR; }if (check_status() != LX_SUCCESS) { ... } if (lx_stm32_qspi_erase(LX_STM32_QSPI_INSTANCE, block, erase_count, 0) != 0) { status = LX_ERROR; }if (lx_stm32_qspi_erase(LX_STM32_QSPI_INSTANCE, block, erase_count, 0) != 0) { ... } else { status = check_status(); }else { ... } return status; }{ ... } static UINT lx_qspi_driver_block_erased_verify(ULONG block) { UINT status; if (check_status() != LX_SUCCESS) { return LX_ERROR; }if (check_status() != LX_SUCCESS) { ... } if (lx_stm32_qspi_is_block_erased(LX_STM32_QSPI_INSTANCE, block) == 0) { status = LX_SUCCESS; }if (lx_stm32_qspi_is_block_erased(LX_STM32_QSPI_INSTANCE, block) == 0) { ... } else { status = LX_ERROR; }else { ... } return status; }{ ... } __WEAK UINT lx_qspi_driver_system_error(UINT error_code) { LX_PARAMETER_NOT_USED(error_code); return LX_ERROR; }{ ... }