diff --git a/os/hal/hal.mk b/os/hal/hal.mk index a456cdd1d..905dbfd5d 100644 --- a/os/hal/hal.mk +++ b/os/hal/hal.mk @@ -44,7 +44,7 @@ endif ifneq ($(findstring HAL_USE_PWM TRUE,$(HALCONF)),) HALSRC += $(CHIBIOS)/os/hal/src/hal_pwm.c endif -ifneq ($(findstring HAL_USE_PWM TRUE,$(HALCONF)),) +ifneq ($(findstring HAL_USE_QSPI TRUE,$(HALCONF)),) HALSRC += $(CHIBIOS)/os/hal/src/hal_qspi.c endif ifneq ($(findstring HAL_USE_RTC TRUE,$(HALCONF)),) diff --git a/os/hal/include/hal_qspi.h b/os/hal/include/hal_qspi.h index 0fe1e79fb..67fc7ad10 100644 --- a/os/hal/include/hal_qspi.h +++ b/os/hal/include/hal_qspi.h @@ -141,16 +141,16 @@ typedef struct { * @post At the end of the operation the configured callback is invoked. * * @param[in] qspip pointer to the @p QSPIDriver object - * @param[in] cmd pointer to the command descriptor + * @param[in] cmdp pointer to the command descriptor * * @iclass */ -#define qspiCommandI(qspip, cmd) { \ - osalDbgAssert(((cmd)->cfg & QSPI_CFG_DATA_MODE_MASK) == \ +#define qspiStartCommandI(qspip, cmdp) { \ + osalDbgAssert(((cmdp)->cfg & QSPI_CFG_DATA_MODE_MASK) == \ QSPI_CFG_DATA_MODE_NONE, \ "data mode specified"); \ (qspip)->state = QSPI_ACTIVE; \ - qspi_lld_command(qspip, cmd, n, txbuf); \ + qspi_lld_command(qspip, cmdp); \ } /** @@ -159,18 +159,18 @@ typedef struct { * @post At the end of the operation the configured callback is invoked. * * @param[in] qspip pointer to the @p QSPIDriver object - * @param[in] cmd pointer to the command descriptor + * @param[in] cmdp pointer to the command descriptor * @param[in] n number of bytes to send or zero if no data phase * @param[in] txbuf the pointer to the transmit buffer * * @iclass */ -#define qspiStartSendI(qspip, cmd, n, txbuf) { \ - osalDbgAssert(((cmd)->cfg & QSPI_CFG_DATA_MODE_MASK) != \ +#define qspiStartSendI(qspip, cmdp, n, txbuf) { \ + osalDbgAssert(((cmdp)->cfg & QSPI_CFG_DATA_MODE_MASK) != \ QSPI_CFG_DATA_MODE_NONE, \ "data mode required"); \ (qspip)->state = QSPI_ACTIVE; \ - qspi_lld_send(qspip, cmd, n, txbuf); \ + qspi_lld_send(qspip, cmdp, n, txbuf); \ } /** @@ -179,18 +179,18 @@ typedef struct { * @post At the end of the operation the configured callback is invoked. * * @param[in] qspip pointer to the @p QSPIDriver object - * @param[in] cmd pointer to the command descriptor + * @param[in] cmdp pointer to the command descriptor * @param[in] n number of bytes to receive or zero if no data phase * @param[out] rxbuf the pointer to the receive buffer * * @iclass */ -#define qspiStartReceiveI(qspip, cmd, n, rxbuf) { \ - osalDbgAssert(((cmd)->cfg & QSPI_CFG_DATA_MODE_MASK) != \ +#define qspiStartReceiveI(qspip, cmdp, n, rxbuf) { \ + osalDbgAssert(((cmdp)->cfg & QSPI_CFG_DATA_MODE_MASK) != \ QSPI_CFG_DATA_MODE_NONE, \ "data mode required"); \ (qspip)->state = QSPI_ACTIVE; \ - qspi_lld_receive(qspip, cmd, n, rxbuf); \ + qspi_lld_receive(qspip, cmdp, n, rxbuf); \ } /** @} */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index 04cd0b2c5..583702bdc 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -94,6 +94,9 @@ void halInit(void) { #if (HAL_USE_PWM == TRUE) || defined(__DOXYGEN__) pwmInit(); #endif +#if (HAL_USE_QSPI == TRUE) || defined(__DOXYGEN__) + qspiInit(); +#endif #if (HAL_USE_SERIAL == TRUE) || defined(__DOXYGEN__) sdInit(); #endif diff --git a/os/hal/src/hal_qspi.c b/os/hal/src/hal_qspi.c index 6fdb0c3a0..240e1b93e 100644 --- a/os/hal/src/hal_qspi.c +++ b/os/hal/src/hal_qspi.c @@ -137,7 +137,7 @@ void qspiStartCommand(QSPIDriver *qspip, const qspi_command_t *cmdp) { osalSysLock(); osalDbgAssert(qspip->state == QSPI_READY, "not ready"); - qspiStartCommandI(qspip, cmd); + qspiStartCommandI(qspip, cmdp); osalSysUnlock(); } @@ -160,7 +160,7 @@ void qspiStartSend(QSPIDriver *qspip, const qspi_command_t *cmdp, osalSysLock(); osalDbgAssert(qspip->state == QSPI_READY, "not ready"); - qspiStartSendI(qspip, cmd, n, txbuf); + qspiStartSendI(qspip, cmdp, n, txbuf); osalSysUnlock(); } @@ -183,7 +183,7 @@ void qspiStartReceive(QSPIDriver *qspip, const qspi_command_t *cmdp, osalSysLock(); osalDbgAssert(qspip->state == QSPI_READY, "not ready"); - qspiStartReceiveI(qspip, cmd, n, rxbuf); + qspiStartReceiveI(qspip, cmdp, n, rxbuf); osalSysUnlock(); } @@ -196,7 +196,7 @@ void qspiStartReceive(QSPIDriver *qspip, const qspi_command_t *cmdp, * without callbacks (@p end_cb = @p NULL). * * @param[in] qspip pointer to the @p QSPIDriver object - * @param[in] cmd pointer to the command descriptor + * @param[in] cmdp pointer to the command descriptor * * @api */ @@ -207,7 +207,7 @@ void qspiCommand(QSPIDriver *qspip, const qspi_command_t *cmdp) { osalSysLock(); osalDbgAssert(qspip->state == QSPI_READY, "not ready"); osalDbgAssert(qspip->config->end_cb == NULL, "has callback"); - qspiStartCommandI(qspip, cmd, n, txbuf); + qspiStartCommandI(qspip, cmdp); (void) osalThreadSuspendS(&qspip->thread); osalSysUnlock(); } @@ -220,7 +220,7 @@ void qspiCommand(QSPIDriver *qspip, const qspi_command_t *cmdp) { * without callbacks (@p end_cb = @p NULL). * * @param[in] qspip pointer to the @p QSPIDriver object - * @param[in] cmd pointer to the command descriptor + * @param[in] cmdp pointer to the command descriptor * @param[in] n number of bytes to send * @param[in] txbuf the pointer to the transmit buffer * @@ -235,7 +235,7 @@ void qspiSend(QSPIDriver *qspip, const qspi_command_t *cmdp, osalSysLock(); osalDbgAssert(qspip->state == QSPI_READY, "not ready"); osalDbgAssert(qspip->config->end_cb == NULL, "has callback"); - qspiStartSendI(qspip, cmd, n, txbuf); + qspiStartSendI(qspip, cmdp, n, txbuf); (void) osalThreadSuspendS(&qspip->thread); osalSysUnlock(); } @@ -248,7 +248,7 @@ void qspiSend(QSPIDriver *qspip, const qspi_command_t *cmdp, * without callbacks (@p end_cb = @p NULL). * * @param[in] qspip pointer to the @p QSPIDriver object - * @param[in] cmd pointer to the command descriptor + * @param[in] cmdp pointer to the command descriptor * @param[in] n number of bytes to send * @param[out] rxbuf the pointer to the receive buffer * @@ -263,7 +263,7 @@ void qspiReceive(QSPIDriver *qspip, const qspi_command_t *cmdp, osalSysLock(); osalDbgAssert(qspip->state == QSPI_READY, "not ready"); osalDbgAssert(qspip->config->end_cb == NULL, "has callback"); - qspiStartReceiveI(qspip, cmd, n, rxbuf); + qspiStartReceiveI(qspip, cmdp, n, rxbuf); (void) osalThreadSuspendS(&qspip->thread); osalSysUnlock(); } diff --git a/testhal/STM32/STM32L4xx/DSPI-N25Q128/main.c b/testhal/STM32/STM32L4xx/DSPI-N25Q128/main.c index 42a3984a4..942629734 100644 --- a/testhal/STM32/STM32L4xx/DSPI-N25Q128/main.c +++ b/testhal/STM32/STM32L4xx/DSPI-N25Q128/main.c @@ -17,6 +17,23 @@ #include "ch.h" #include "hal.h" +QSPIConfig qspicfg1 = { + NULL, + 0 +}; + +qspi_command_t cmd_read_id = { + QSPI_CFG_CMD(0x9E) | QSPI_CFG_CMD_MODE_ONE_LINE | + QSPI_CFG_ADDR_MODE_NONE | + QSPI_CFG_ALT_MODE_NONE | + QSPI_CFG_DUMMY_CYCLES(0) | + QSPI_CFG_DATA_MODE_ONE_LINE, + 0, + 0 +}; + +uint8_t buffer[512]; + /* * LED blinker thread, times are in milliseconds. */ @@ -58,6 +75,12 @@ int main(void) { */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL); + /* + * Starting QSPI driver 1. + */ + qspiStart(&QSPID1, &qspicfg1); + qspiReceive(&QSPID1, &cmd_read_id, 17, buffer); + /* * Normal main() thread activity, in this demo it does nothing. */