@@ -241,23 +241,30 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
241
241
{
242
242
qspi_status_t status = QSPI_STATUS_OK ;
243
243
244
- if (rx_size > 4 ) {
245
- return QSPI_STATUS_INVALID_PARAMETER ;
246
- }
247
-
248
- QSPI_CommandTypeDef st_command ;
249
- qspi_prepare_command (command , & st_command );
250
-
251
- QSPI_AutoPollingTypeDef s_config ;
252
- s_config .Match = 0 ;
253
- s_config .Mask = 0 ;
254
- s_config .MatchMode = QSPI_MATCH_MODE_OR ;
255
- s_config .StatusBytesSize = rx_size ;
256
- s_config .Interval = 0x10 ;
257
- s_config .AutomaticStop = QSPI_AUTOMATIC_STOP_ENABLE ; // or QSPI_AUTOMATIC_STOP_DISABLE ?
258
-
259
- if (HAL_QSPI_AutoPolling (& obj -> handle , & st_command , & s_config , HAL_QPSI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
260
- status = QSPI_STATUS_ERROR ;
244
+ if ((tx_data == NULL || tx_size == 0 ) && (rx_data == NULL || rx_size == 0 )) {
245
+ // only command, no rx or tx
246
+ QSPI_CommandTypeDef st_command ;
247
+ qspi_prepare_command (command , & st_command );
248
+
249
+ st_command .NbData = 1 ;
250
+ if (HAL_QSPI_Command (& obj -> handle , & st_command , HAL_QPSI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
251
+ status = QSPI_STATUS_ERROR ;
252
+ return status ;
253
+ }
254
+ } else {
255
+ // often just read a register, check if we need to transmit anything prior reading
256
+ if (tx_data != NULL && tx_size ) {
257
+ size_t tx_length = tx_size ;
258
+ status = qspi_write (obj , command , tx_data , & tx_length );
259
+ if (status != QSPI_STATUS_OK ) {
260
+ return status ;
261
+ }
262
+ }
263
+
264
+ if (rx_data != NULL && rx_size ) {
265
+ size_t rx_length = rx_size ;
266
+ status = qspi_read (obj , command , rx_data , & rx_length );
267
+ }
261
268
}
262
269
return status ;
263
270
}
0 commit comments