Skip to content

Commit b4b9c2f

Browse files
committed
hal/spi: Add missing hal_spi_init_hw function
hal_spi_init_hw function is needed by spi_hal driver Signed-off-by: Jerzy Kasenberg <[email protected]> Signed-off-by: Jerzy Kasenberg <[email protected]>
1 parent 0abde83 commit b4b9c2f

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

hw/mcu/stm/stm32_common/src/hal_spi.c

+28-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct stm32_hal_spi {
6868
uint8_t tx_in_prog:1; /* slave: tx'ing user data not def */
6969
uint8_t selected:1; /* slave: if we see SS */
7070
uint8_t def_char[4]; /* slave: default data to tx */
71-
struct stm32_hal_spi_cfg *cfg;
71+
struct stm32_hal_spi_cfg cfg;
7272
hal_spi_txrx_cb txrx_cb_func; /* callback function */
7373
void *txrx_cb_arg; /* callback arguments */
7474
};
@@ -282,7 +282,7 @@ spi_ss_isr(void *arg)
282282
uint16_t reg;
283283

284284
spi_stat.ss_irq++;
285-
ss = hal_gpio_read(spi->cfg->ss_pin);
285+
ss = hal_gpio_read(spi->cfg.ss_pin);
286286
if (ss == 0 && !spi->selected) {
287287
/*
288288
* We're now seeing chip select. Enable SPI, SPI interrupts.
@@ -450,7 +450,7 @@ hal_spi_init(int spi_num, void *usercfg, uint8_t spi_type)
450450
*/
451451
STM32_HAL_SPI_RESOLVE(spi_num, spi);
452452

453-
spi->cfg = usercfg;
453+
spi->cfg = *(struct stm32_hal_spi_cfg *)usercfg;
454454
spi->slave = (spi_type == HAL_SPI_TYPE_SLAVE);
455455
switch (spi_num) {
456456
#if SPI_0_ENABLED
@@ -638,7 +638,7 @@ hal_spi_config(int spi_num, struct hal_spi_settings *settings)
638638

639639
init = &spi->handle.Init;
640640

641-
cfg = spi->cfg;
641+
cfg = &spi->cfg;
642642

643643
if (!spi->slave) {
644644
spi->handle.Init.NSS = SPI_NSS_HARD_OUTPUT;
@@ -1040,7 +1040,7 @@ hal_spi_txrx(int spi_num, void *txbuf, void *rxbuf, int len)
10401040
}
10411041
__HAL_DISABLE_INTERRUPTS(sr);
10421042
spi_stat.tx++;
1043-
__HAL_SPI_ENABLE(&spi->handle);
1043+
__HAL_ENABLE_INTERRUPTS(sr);
10441044
if (rxbuf) {
10451045
rc = HAL_SPI_TransmitReceive(&spi->handle, (uint8_t *)txbuf,
10461046
(uint8_t *)rxbuf, len,
@@ -1049,7 +1049,6 @@ hal_spi_txrx(int spi_num, void *txbuf, void *rxbuf, int len)
10491049
rc = HAL_SPI_Transmit(&spi->handle, (uint8_t *)txbuf,
10501050
len, STM32_HAL_SPI_TIMEOUT);
10511051
}
1052-
__HAL_ENABLE_INTERRUPTS(sr);
10531052
if (rc != HAL_OK) {
10541053
rc = -1;
10551054
goto err;
@@ -1079,3 +1078,26 @@ hal_spi_abort(int spi_num)
10791078
err:
10801079
return rc;
10811080
}
1081+
1082+
int
1083+
hal_spi_init_hw(uint8_t spi_num, uint8_t spi_type,
1084+
const struct hal_spi_hw_settings *cfg)
1085+
{
1086+
int rc = SYS_EINVAL;
1087+
struct stm32_hal_spi *spi;
1088+
struct stm32_hal_spi_cfg hal_cfg;
1089+
1090+
STM32_HAL_SPI_RESOLVE(spi_num, spi);
1091+
if (spi->slave) {
1092+
rc = SYS_ENOTSUP;
1093+
goto err;
1094+
}
1095+
hal_cfg.sck_pin = cfg->pin_sck;
1096+
hal_cfg.mosi_pin = cfg->pin_mosi;
1097+
hal_cfg.miso_pin = cfg->pin_miso;
1098+
hal_cfg.ss_pin = cfg->pin_ss;
1099+
hal_cfg.irq_prio = 2;
1100+
rc = hal_spi_init(spi_num, &hal_cfg, spi_type);
1101+
err:
1102+
return rc;
1103+
}

0 commit comments

Comments
 (0)