@@ -241,7 +241,6 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
241
241
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 )
242
242
{
243
243
ret_code_t ret_code ;
244
- uint32_t i ;
245
244
uint8_t data [8 ];
246
245
uint32_t data_size = tx_size + rx_size ;
247
246
@@ -252,24 +251,35 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
252
251
qspi_cinstr_config .wipwait = false;
253
252
qspi_cinstr_config .wren = false;
254
253
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 ) {
256
267
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
+ }
257
272
} else {
258
273
return QSPI_STATUS_ERROR ;
259
274
}
260
275
261
- // preparing data to send
262
- for (i = 0 ; i < tx_size ; ++ i ) {
263
- data [i ] = ((uint8_t * )tx_data )[i ];
264
- }
265
-
266
276
ret_code = nrf_drv_qspi_cinstr_xfer (& qspi_cinstr_config , data , data );
267
277
if (ret_code != NRF_SUCCESS ) {
268
278
return QSPI_STATUS_ERROR ;
269
279
}
270
280
271
281
// preparing received data
272
- for (i = 0 ; i < rx_size ; ++ i ) {
282
+ for (uint32_t i = 0 ; i < rx_size ; ++ i ) {
273
283
// Data is sending as a normal SPI transmission so there is one buffer to send and receive data.
274
284
((uint8_t * )rx_data )[i ] = data [i ];
275
285
}
0 commit comments