diff --git a/drivers/sdhc/imx_usdhc.c b/drivers/sdhc/imx_usdhc.c index 88684e04d0..73c1342bd8 100644 --- a/drivers/sdhc/imx_usdhc.c +++ b/drivers/sdhc/imx_usdhc.c @@ -586,7 +586,7 @@ static int imx_usdhc_request(const struct device *dev, struct sdhc_command *cmd, host_cmd.index = cmd->opcode; host_cmd.argument = cmd->arg; /* Mask out part of response type field used for SPI commands */ - host_cmd.responseType = (cmd->response_type & 0xF); + host_cmd.responseType = (cmd->response_type & SDHC_NATIVE_RESPONSE_MASK); transfer.command = &host_cmd; if (cmd->timeout_ms == SDHC_TIMEOUT_FOREVER) { request.command_timeout = K_FOREVER; @@ -711,8 +711,10 @@ static int imx_usdhc_request(const struct device *dev, struct sdhc_command *cmd, k_mutex_unlock(&dev_data->access_mutex); /* Record command response */ memcpy(cmd->response, host_cmd.response, sizeof(cmd->response)); - /* Record number of bytes xfered */ - data->bytes_xfered = dev_data->transfer_handle.transferredWords; + if (data) { + /* Record number of bytes xfered */ + data->bytes_xfered = dev_data->transfer_handle.transferredWords; + } return ret; } diff --git a/drivers/sdhc/sdhc_spi.c b/drivers/sdhc/sdhc_spi.c index 2d64da2cad..b5c8fab1e9 100644 --- a/drivers/sdhc/sdhc_spi.c +++ b/drivers/sdhc/sdhc_spi.c @@ -231,7 +231,7 @@ static int sdhc_spi_response_get(const struct device *dev, struct sdhc_command * } /* else IDLE_STATE bit is set, which is not an error, card is just resetting */ } - switch ((cmd->response_type & 0xF0)) { + switch ((cmd->response_type & SDHC_SPI_RESPONSE_TYPE_MASK)) { case SD_SPI_RSP_TYPE_R1: /* R1 response - one byte*/ break; diff --git a/include/zephyr/drivers/sdhc.h b/include/zephyr/drivers/sdhc.h index 1cb33e1c6b..f0368f3a56 100644 --- a/include/zephyr/drivers/sdhc.h +++ b/include/zephyr/drivers/sdhc.h @@ -48,6 +48,9 @@ struct sdhc_command { int timeout_ms; /*!< Command timeout in milliseconds */ }; +#define SDHC_NATIVE_RESPONSE_MASK 0xF +#define SDHC_SPI_RESPONSE_TYPE_MASK 0xF0 + /** * @brief SD host controller data structure *