diff --git a/bsp/stm32/stm32f401-st-nucleo/applications/arduino_pinout/pins_arduino.c b/bsp/stm32/stm32f401-st-nucleo/applications/arduino_pinout/pins_arduino.c index 8548402ac6..f4a2c69347 100644 --- a/bsp/stm32/stm32f401-st-nucleo/applications/arduino_pinout/pins_arduino.c +++ b/bsp/stm32/stm32f401-st-nucleo/applications/arduino_pinout/pins_arduino.c @@ -62,9 +62,7 @@ void switchToSPI(const char *bus_name) __HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); /**SPI1 GPIO Configuration PA5 ------> SPI1_SCK @@ -78,7 +76,7 @@ void switchToSPI(const char *bus_name) GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - LOG_W("D11, D12 and D13 will switch from PWM to SPI"); + LOG_I("D11, D12 and D13 will switch from PWM to SPI"); } } #endif /* RTDUINO_USING_SPI */ diff --git a/bsp/stm32/stm32f411-st-nucleo/applications/arduino_pinout/pins_arduino.c b/bsp/stm32/stm32f411-st-nucleo/applications/arduino_pinout/pins_arduino.c index f5620fe2d3..716fd2318c 100644 --- a/bsp/stm32/stm32f411-st-nucleo/applications/arduino_pinout/pins_arduino.c +++ b/bsp/stm32/stm32f411-st-nucleo/applications/arduino_pinout/pins_arduino.c @@ -62,9 +62,7 @@ void switchToSPI(const char *bus_name) __HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); /**SPI1 GPIO Configuration PA5 ------> SPI1_SCK @@ -78,7 +76,7 @@ void switchToSPI(const char *bus_name) GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - LOG_W("D11, D12 and D13 will switch from PWM to SPI"); + LOG_I("D11, D12 and D13 will switch from PWM to SPI"); } } #endif /* RTDUINO_USING_SPI */ diff --git a/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/pins_arduino.c b/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/pins_arduino.c index cd299653f6..8af913a392 100644 --- a/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/pins_arduino.c +++ b/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/pins_arduino.c @@ -65,9 +65,7 @@ void switchToSPI(const char *bus_name) __HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6); - HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7); + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7); /**SPI1 GPIO Configuration PA5 ------> SPI1_SCK @@ -81,7 +79,7 @@ void switchToSPI(const char *bus_name) GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - LOG_W("D11, D12 and D13 will switch from PWM to SPI"); + LOG_I("D11, D12 and D13 will switch from PWM to SPI"); } } #endif /* RTDUINO_USING_SPI */ diff --git a/bsp/stm32/stm32f469-st-disco/applications/arduino_pinout/pins_arduino.c b/bsp/stm32/stm32f469-st-disco/applications/arduino_pinout/pins_arduino.c index ff578abce4..2488e18729 100644 --- a/bsp/stm32/stm32f469-st-disco/applications/arduino_pinout/pins_arduino.c +++ b/bsp/stm32/stm32f469-st-disco/applications/arduino_pinout/pins_arduino.c @@ -12,6 +12,10 @@ #include "pins_arduino.h" #include +#define DBG_TAG "RTduino.pins_arduino" +#define DBG_LVL DBG_INFO +#include + /* * {Arduino Pin, RT-Thread Pin [, Device Name, Channel]} * [] means optional @@ -51,3 +55,42 @@ const pin_map_t pin_map_table[]= {A6, RT_NULL, "adc1", RT_ADC_INTERN_CH_VREF}, /* ADC, On-Chip: internal reference voltage */ {A7, RT_NULL, "adc1", RT_ADC_INTERN_CH_TEMPER}, /* ADC, On-Chip: internal temperature sensor */ }; + +#ifdef RTDUINO_USING_SPI +void switchToSPI(const char *bus_name) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + if(!rt_strcmp(bus_name, "spi2")) + { + __HAL_RCC_SPI2_CLK_ENABLE(); + + __HAL_RCC_GPIOD_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + + HAL_GPIO_DeInit(GPIOD, GPIO_PIN_3); + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14 | GPIO_PIN_15); + + /**SPI2 GPIO Configuration + PD3 ------> SPI2_SCK + PB14 ------> SPI2_MISO + PB15 ------> SPI2_MOSI + */ + GPIO_InitStruct.Pin = GPIO_PIN_3; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + LOG_I("D11, D12 and D13 will switch from PWM to SPI"); + } +} +#endif /* RTDUINO_USING_SPI */ diff --git a/bsp/stm32/stm32f469-st-disco/applications/arduino_pinout/pins_arduino.h b/bsp/stm32/stm32f469-st-disco/applications/arduino_pinout/pins_arduino.h index 6513f0d6f3..ad1360cd07 100644 --- a/bsp/stm32/stm32f469-st-disco/applications/arduino_pinout/pins_arduino.h +++ b/bsp/stm32/stm32f469-st-disco/applications/arduino_pinout/pins_arduino.h @@ -51,6 +51,9 @@ /* i2c1 : PB9-SDA PB8-SCL */ #define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c1" +#define SS D10 +#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi2" + #define RTDUINO_TONE_HWTIMER_DEVICE_NAME "timer6" #endif /* Pins_Arduino_h */ diff --git a/bsp/stm32/stm32f469-st-disco/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h b/bsp/stm32/stm32f469-st-disco/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h index 89f4af032f..d01568b91a 100644 --- a/bsp/stm32/stm32f469-st-disco/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h +++ b/bsp/stm32/stm32f469-st-disco/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h @@ -73,7 +73,7 @@ /* #define HAL_SAI_MODULE_ENABLED */ #define HAL_SD_MODULE_ENABLED /* #define HAL_MMC_MODULE_ENABLED */ -/* #define HAL_SPI_MODULE_ENABLED */ +#define HAL_SPI_MODULE_ENABLED #define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /* #define HAL_USART_MODULE_ENABLED */ @@ -83,7 +83,6 @@ #define HAL_PCD_MODULE_ENABLED /* #define HAL_HCD_MODULE_ENABLED */ #define HAL_DSI_MODULE_ENABLED -/* #define HAL_QSPI_MODULE_ENABLED */ #define HAL_QSPI_MODULE_ENABLED /* #define HAL_CEC_MODULE_ENABLED */ /* #define HAL_FMPI2C_MODULE_ENABLED */ diff --git a/bsp/stm32/stm32f469-st-disco/board/Kconfig b/bsp/stm32/stm32f469-st-disco/board/Kconfig index 544aae2b45..f1e76d08f1 100644 --- a/bsp/stm32/stm32f469-st-disco/board/Kconfig +++ b/bsp/stm32/stm32f469-st-disco/board/Kconfig @@ -42,6 +42,8 @@ menu "Onboard Peripheral Drivers" select BSP_USING_PWM12_CH2 select BSP_USING_I2C select BSP_USING_I2C1 + select BSP_USING_SPI + select BSP_USING_SPI2 imply RTDUINO_USING_SERVO imply RTDUINO_USING_WIRE default n @@ -223,6 +225,21 @@ menu "On-chip Peripheral Drivers" select RT_USING_SPI default n if BSP_USING_SPI + config BSP_USING_SPI2 + bool "Enable SPI2 Bus" + default n + + config BSP_SPI2_TX_USING_DMA + bool "Enable SPI2 TX DMA" + depends on BSP_USING_SPI2 + default n + + config BSP_SPI2_RX_USING_DMA + bool "Enable SPI2 RX DMA" + depends on BSP_USING_SPI2 + select BSP_SPI2_TX_USING_DMA + default n + config BSP_USING_SPI3 bool "Enable SPI3 BUS" default n diff --git a/bsp/stm32/stm32l476-st-nucleo/applications/arduino_pinout/pins_arduino.c b/bsp/stm32/stm32l476-st-nucleo/applications/arduino_pinout/pins_arduino.c index 0a9798202d..a61610fcd6 100644 --- a/bsp/stm32/stm32l476-st-nucleo/applications/arduino_pinout/pins_arduino.c +++ b/bsp/stm32/stm32l476-st-nucleo/applications/arduino_pinout/pins_arduino.c @@ -78,7 +78,7 @@ void switchToSPI(const char *bus_name) GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - LOG_W("D11, D12 and D13 will switch from PWM to SPI"); + LOG_I("D11, D12 and D13 will switch from PWM to SPI"); } } #endif /* RTDUINO_USING_SPI */