-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Description
I have discovered a bug with the nRF52840 QSPI hal driver while trying to get some examples to work. I was only seeing partial data being read back. The example was trying to write "hello\0", but when read back it would only product "hell"... as if the bug was trying to speak to me.
I narrowed it down to a fine print item in the nRF52840 datasheet concerning the length of QSPI read/writes (see attached screen captures):
Read/Write chunks must be multiples of 4 bytes. The current HAL driver simply populates this register from the user's input. In my toy case, this results in 6 being written to the READ.CNT and WRITE.CNT registers, where the nRF52840 ignores the lower bits and truncates the transfer lengths to 4 bytes.
See the functions here that call the underlying Nordic driver functions:
mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/qspi_api.c
Lines 248 to 277 in d30ae07
qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void *data, size_t *length) | |
{ | |
qspi_status_t status = qspi_prepare_command(obj, command, true); | |
if (status != QSPI_STATUS_OK) { | |
return status; | |
} | |
// write here does not return how much it transfered, we return transfered all | |
ret_code_t ret = nrf_drv_qspi_write(data, *length, command->address.value); | |
if (ret == NRF_SUCCESS ) { | |
return QSPI_STATUS_OK; | |
} else { | |
return QSPI_STATUS_ERROR; | |
} | |
} | |
qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data, size_t *length) | |
{ | |
qspi_status_t status = qspi_prepare_command(obj, command, false); | |
if (status != QSPI_STATUS_OK) { | |
return status; | |
} | |
ret_code_t ret = nrf_drv_qspi_read(data, *length, command->address.value); | |
if (ret == NRF_SUCCESS ) { | |
return QSPI_STATUS_OK; | |
} else { | |
return QSPI_STATUS_ERROR; | |
} | |
} |
If you need any other information or want me to upload my toy code, let me know.
Issue request type
[ ] Question
[ ] Enhancement
[x] Bug