Skip to content

Commit fff2072

Browse files
0xc0170maciejbocianski
authored andcommitted
QSPI STM32: fix command transfer
use write/read from STM32 driver
1 parent 5038b38 commit fff2072

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

targets/TARGET_STM/qspi_api.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,30 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
241241
{
242242
qspi_status_t status = QSPI_STATUS_OK;
243243

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+
}
261268
}
262269
return status;
263270
}

0 commit comments

Comments
 (0)