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