42
42
/* hence 2^(31+1), then FLASH_SIZE_DEFAULT = 1<<31 */
43
43
#define QSPI_FLASH_SIZE_DEFAULT 0x80000000
44
44
45
+ #if defined(OCTOSPI1 )
46
+ static uint32_t get_alt_bytes_size (const uint32_t num_bytes )
47
+ {
48
+ switch (num_bytes ) {
49
+ case 1 :
50
+ return HAL_OSPI_ALTERNATE_BYTES_8_BITS ;
51
+ case 2 :
52
+ return HAL_OSPI_ALTERNATE_BYTES_16_BITS ;
53
+ case 3 :
54
+ return HAL_OSPI_ALTERNATE_BYTES_24_BITS ;
55
+ case 4 :
56
+ return HAL_OSPI_ALTERNATE_BYTES_32_BITS ;
57
+ }
58
+ error ("Invalid alt bytes size" );
59
+ return 0xFFFFFFFF ;
60
+ }
61
+ #else /* OCTOSPI1 */
62
+ static uint32_t get_alt_bytes_size (const uint32_t num_bytes )
63
+ {
64
+ switch (num_bytes ) {
65
+ case 1 :
66
+ return QSPI_ALTERNATE_BYTES_8_BITS ;
67
+ case 2 :
68
+ return QSPI_ALTERNATE_BYTES_16_BITS ;
69
+ case 3 :
70
+ return QSPI_ALTERNATE_BYTES_24_BITS ;
71
+ case 4 :
72
+ return QSPI_ALTERNATE_BYTES_32_BITS ;
73
+ }
74
+ error ("Invalid alt bytes size" );
75
+ return 0xFFFFFFFF ;
76
+ }
77
+ #endif /* OCTOSPI1 */
78
+
45
79
#if defined(OCTOSPI1 )
46
80
qspi_status_t qspi_prepare_command (const qspi_command_t * command , OSPI_RegularCmdTypeDef * st_command )
47
81
{
@@ -151,15 +185,15 @@ qspi_status_t qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCm
151
185
}
152
186
153
187
// Round up to nearest byte - unused parts of byte act as dummy cycles
154
- uint32_t rounded_size = ((command -> alt .size - 1 ) >> 3 ) + 1 ;
188
+ uint32_t alt_bytes = ((command -> alt .size - 1 ) >> 3 ) + 1 ;
155
189
// Maximum of 4 alt bytes
156
- if (rounded_size > 4 ) {
190
+ if (alt_bytes > 4 ) {
157
191
error ("Command param error: alt size exceeds maximum of 32 bits\n" );
158
192
return QSPI_STATUS_ERROR ;
159
193
}
160
194
161
195
// Unused bits in most significant byte of alt
162
- uint8_t leftover_bits = (rounded_size << 3 ) - command -> alt .size ;
196
+ uint8_t leftover_bits = (alt_bytes << 3 ) - command -> alt .size ;
163
197
if (leftover_bits != 0 ) {
164
198
// Account for dummy cycles that will be spent in the alt portion of the command
165
199
uint8_t integrated_dummy_cycles = leftover_bits / alt_lines ;
@@ -176,9 +210,7 @@ qspi_status_t qspi_prepare_command(const qspi_command_t *command, OSPI_RegularCm
176
210
st_command -> AlternateBytes = command -> alt .value ;
177
211
}
178
212
179
- /* command->AlternateBytesSize needs to be shifted by OCTOSPI_CCR_ABSIZE_Pos */
180
- // 0b00 = 1 byte, 0b01 = 2 bytes, 0b10 = 3 bytes, 0b11 = 4 bytes
181
- st_command -> AlternateBytesSize = ((rounded_size - 1 ) << OCTOSPI_CCR_ABSIZE_Pos ) & OCTOSPI_CCR_ABSIZE_Msk ;
213
+ st_command -> AlternateBytesSize = get_alt_bytes_size (alt_bytes );
182
214
}
183
215
184
216
switch (command -> data .bus_width ) {
@@ -283,14 +315,14 @@ qspi_status_t qspi_prepare_command(const qspi_command_t *command, QSPI_CommandTy
283
315
}
284
316
285
317
// Round up to nearest byte - unused parts of byte act as dummy cycles
286
- uint32_t rounded_size = ((command -> alt .size - 1 ) >> 3 ) + 1 ;
318
+ uint32_t alt_bytes = ((command -> alt .size - 1 ) >> 3 ) + 1 ;
287
319
// Maximum of 4 alt bytes
288
- if (rounded_size > 4 ) {
320
+ if (alt_bytes > 4 ) {
289
321
return QSPI_STATUS_ERROR ;
290
322
}
291
323
292
324
// Unused bits in most significant byte of alt
293
- uint8_t leftover_bits = (rounded_size << 3 ) - command -> alt .size ;
325
+ uint8_t leftover_bits = (alt_bytes << 3 ) - command -> alt .size ;
294
326
if (leftover_bits != 0 ) {
295
327
// Account for dummy cycles that will be spent in the alt portion of the command
296
328
uint8_t integrated_dummy_cycles = leftover_bits / alt_lines ;
@@ -306,9 +338,7 @@ qspi_status_t qspi_prepare_command(const qspi_command_t *command, QSPI_CommandTy
306
338
st_command -> AlternateBytes = command -> alt .value ;
307
339
}
308
340
309
- /* command->AlternateBytesSize needs to be shifted by QUADSPI_CCR_ABSIZE_Pos */
310
- // 0b00 = 1 byte, 0b01 = 2 bytes, 0b10 = 3 bytes, 0b11 = 4 bytes
311
- st_command -> AlternateBytesSize = ((rounded_size - 1 ) << QUADSPI_CCR_ABSIZE_Pos ) & QUADSPI_CCR_ABSIZE_Msk ;
341
+ st_command -> AlternateBytesSize = get_alt_bytes_size (alt_bytes );
312
342
}
313
343
314
344
switch (command -> data .bus_width ) {
0 commit comments