Skip to content

Commit e0d033b

Browse files
committed
Allow unaligned input/output for QSPI
The code is written such that access to the data input/output happens word-by-word, and that means unaligned access is fine (though with a performance loss) on Cortex-M3/M4 devices.
1 parent 845a5be commit e0d033b

File tree

1 file changed

+8
-4
lines changed
  • targets/TARGET_Silicon_Labs/TARGET_EFM32

1 file changed

+8
-4
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/qspi_api.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void
163163
QSPI_WriteConfig_TypeDef cfg = QSPI_WRITECONFIG_DEFAULT;
164164
uint32_t to_write = *length;
165165

166-
// Enforce word-aligned and word-sized access
167-
if ((to_write & 0x3) != 0 || ((uint32_t)data & 0x3) != 0) {
166+
// Enforce word-sized access
167+
if ((to_write & 0x3) != 0) {
168168
return QSPI_STATUS_INVALID_PARAMETER;
169169
}
170170

@@ -216,6 +216,8 @@ qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void
216216
// Wait for the QSPI in case we're writing too fast
217217
while (((obj->instance->SRAMFILL & _QSPI_SRAMFILL_SRAMFILLINDACWRITE_MASK) >> _QSPI_SRAMFILL_SRAMFILLINDACWRITE_SHIFT) >= 126);
218218

219+
// Unaligned access is fine on CM3/CM4 provided we stick to LDR/STR
220+
// With the line below, the compiler can't really do anything else anyways
219221
*((uint32_t*)QSPI0_MEM_BASE) = ((uint32_t*)data)[i/4];
220222
}
221223

@@ -284,8 +286,8 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
284286
QSPI_ReadConfig_TypeDef cfg = QSPI_READCONFIG_DEFAULT;
285287
uint32_t to_read = *length;
286288

287-
// Enforce word-aligned and word-sized access
288-
if ((to_read & 0x3) != 0 || ((uint32_t)data & 0x3) != 0) {
289+
// Enforce word-sized access
290+
if ((to_read & 0x3) != 0) {
289291
return QSPI_STATUS_INVALID_PARAMETER;
290292
}
291293

@@ -353,6 +355,8 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
353355
// Wait for the FIFO in case we're reading too fast
354356
while ((obj->instance->SRAMFILL & _QSPI_SRAMFILL_SRAMFILLINDACREAD_MASK) >> _QSPI_SRAMFILL_SRAMFILLINDACREAD_SHIFT == 0);
355357

358+
// Unaligned access is fine on CM3/CM4 provided we stick to LDR/STR
359+
// With the line below, the compiler can't really do anything else anyways
356360
((uint32_t*)data)[i/4] = *((uint32_t*)QSPI0_MEM_BASE);
357361
}
358362

0 commit comments

Comments
 (0)