1
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
31
32
45
46
51
52
53
54
55
56
57
58
59
60
61
62
63
67
68
69
77
78
82
83
84
85
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
108
109
110
111
112
113
114
115
116
117
118
119
126
127
128
129
130
131
132
136
137
138
139
143
144
149
153
154
155
156
157
158
159
166
167
168
169
170
171
175
176
177
178
182
183
188
192
193
194
195
196
197
198
199
200
201
202
206
207
211
215
216
217
218
219
220
221
222
223
227
228
232
236
237
238
239
240
...
#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;
/* ... */
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;
}{ ... }
/* ... */
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) { ... }
nor_flash->lx_nor_flash_base_address = 0;
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
nor_flash->lx_nor_flash_sector_buffer = &qspi_sector_buffer[0];/* ... */
#endif
is_initialized = LX_TRUE;
}if (is_initialized == LX_FALSE) { ... }
LX_STM32_QSPI_POST_INIT();
return LX_SUCCESS;
}{ ... }
/* ... */
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;
}{ ... }
/* ... */
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;
}{ ... }