Skip to content

Commit cc7834a

Browse files
author
Cruz Monrreal
authored
Merge pull request #7218 from maciejbocianski/qspi_erase_fix_nordic
fix qspi command transfer for NORDIC
2 parents 544cd6e + 4fc5ff9 commit cc7834a

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/qspi_api.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
241241
qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command, const void *tx_data, size_t tx_size, void *rx_data, size_t rx_size)
242242
{
243243
ret_code_t ret_code;
244-
uint32_t i;
245244
uint8_t data[8];
246245
uint32_t data_size = tx_size + rx_size;
247246

@@ -252,24 +251,35 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
252251
qspi_cinstr_config.wipwait = false;
253252
qspi_cinstr_config.wren = false;
254253

255-
if (data_size < 9) {
254+
if(!command->address.disabled && data_size == 0) {
255+
// erase command with address
256+
if (command->address.size == QSPI_CFG_ADDR_SIZE_24) {
257+
qspi_cinstr_config.length = NRF_QSPI_CINSTR_LEN_4B;
258+
} else if (command->address.size == QSPI_CFG_ADDR_SIZE_32) {
259+
qspi_cinstr_config.length = NRF_QSPI_CINSTR_LEN_5B;
260+
} else {
261+
return QSPI_STATUS_INVALID_PARAMETER;
262+
}
263+
for (uint32_t i = 0; i < (uint32_t)qspi_cinstr_config.length - 1; ++i) {
264+
data[i] = ((uint8_t *)&command->address.value)[i];
265+
}
266+
} else if (data_size < 9) {
256267
qspi_cinstr_config.length = (nrf_qspi_cinstr_len_t)(NRF_QSPI_CINSTR_LEN_1B + data_size);
268+
// preparing data to send
269+
for (uint32_t i = 0; i < tx_size; ++i) {
270+
data[i] = ((uint8_t *)tx_data)[i];
271+
}
257272
} else {
258273
return QSPI_STATUS_ERROR;
259274
}
260275

261-
// preparing data to send
262-
for (i = 0; i < tx_size; ++i) {
263-
data[i] = ((uint8_t *)tx_data)[i];
264-
}
265-
266276
ret_code = nrf_drv_qspi_cinstr_xfer(&qspi_cinstr_config, data, data);
267277
if (ret_code != NRF_SUCCESS) {
268278
return QSPI_STATUS_ERROR;
269279
}
270280

271281
// preparing received data
272-
for (i = 0; i < rx_size; ++i) {
282+
for (uint32_t i = 0; i < rx_size; ++i) {
273283
// Data is sending as a normal SPI transmission so there is one buffer to send and receive data.
274284
((uint8_t *)rx_data)[i] = data[i];
275285
}

0 commit comments

Comments
 (0)