diff --git a/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/README.md b/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/README.md index 76083515f0..4e6219d32f 100644 --- a/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/README.md +++ b/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/README.md @@ -69,7 +69,7 @@ I2C bus is `SCL/D15` and `SDA/D14` pins. Users can directly include the `#includ ### 3.2 SPI Bus -This board doesn't support Arduino SPI header file and functions. +The SPI bus of the Nucleo board is the `CS/D10`, `MOSI/D11`, `MISO/D12` and `SCK/D13` pins printed on the board. These `D11`, `D12` and `D13` pins It is taken over by the RT-Thread SPI device framework and there is no need to directly control these pins. User needs to operate `D10` chip select pin. Directly quote `#include ` (Arduino official SPI header file) to use. After using the SPI function, the PWM function of `D10` and `D11` will be irreversibly disabled and converted to the SPI function. ### 3.3 Serial diff --git a/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/README_zh.md b/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/README_zh.md index 3ecb278f5a..11dc2f7e51 100644 --- a/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/README_zh.md +++ b/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/README_zh.md @@ -68,7 +68,7 @@ I2C总线是板上丝印的 `SCL/D15` 和 `SDA/D14` 引脚,这两个引脚默 ### 3.2 SPI总线 -目前本BSP不支持使用Arduino的SPI功能。 +Nucleo板的SPI总线是板上丝印的 `CS/D10`、`MOSI/D11`、`MISO/D12` 以及 `SCK/D13` 引脚,这`D11`、`D12` 以及 `D13` 引脚是被RT-Thread SPI设备框架接管的,不需要直接操控这些引脚。用户需要操作 `D10` 片选引脚。直接引用`#include `(Arduino官方SPI头文件)即可使用。在使用SPI功能后,`D10` 和 `D11` 的PWM功能将会不可逆失效,转为SPI功能。 ### 3.3 串口 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 09999642b4..cd299653f6 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 @@ -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 @@ -50,3 +54,34 @@ 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, "spi1")) + { + __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); + + /**SPI1 GPIO Configuration + PA5 ------> SPI1_SCK + PA6 ------> SPI1_MISO + PA7 ------> SPI1_MOSI + */ + GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; + 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_SPI1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + LOG_W("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.h b/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/pins_arduino.h index 8f5b6c0855..dcee3ff1f0 100644 --- a/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/pins_arduino.h +++ b/bsp/stm32/stm32f412-st-nucleo/applications/arduino_pinout/pins_arduino.h @@ -41,6 +41,8 @@ #define A6 (26) #define A7 (27) +#define RTDUINO_PIN_MAX_LIMIT A7 /* pin number max limit check */ + #define F_CPU 96000000L /* CPU:96MHz */ #define LED_BUILTIN D17 /* Default Built-in LED */ @@ -48,4 +50,7 @@ /* i2c1 : PB9-SDA PB8-SCL */ #define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c1" +#define SS D10 +#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi1" + #endif /* Pins_Arduino_h */ diff --git a/bsp/stm32/stm32f412-st-nucleo/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h b/bsp/stm32/stm32f412-st-nucleo/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h index 68d61c6667..23815e0a49 100644 --- a/bsp/stm32/stm32f412-st-nucleo/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h +++ b/bsp/stm32/stm32f412-st-nucleo/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h @@ -62,7 +62,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 */ diff --git a/bsp/stm32/stm32f412-st-nucleo/board/Kconfig b/bsp/stm32/stm32f412-st-nucleo/board/Kconfig index 547d6857e4..4a80bb5963 100644 --- a/bsp/stm32/stm32f412-st-nucleo/board/Kconfig +++ b/bsp/stm32/stm32f412-st-nucleo/board/Kconfig @@ -27,8 +27,13 @@ menu "Onboard Peripheral Drivers" select BSP_USING_PWM14_CH1 select BSP_USING_I2C select BSP_USING_I2C1 + select BSP_USING_SPI + select BSP_USING_SPI1 + select BSP_SPI1_TX_USING_DMA + select BSP_SPI1_RX_USING_DMA imply RTDUINO_USING_SERVO imply RTDUINO_USING_WIRE + imply RTDUINO_USING_SPI default n endmenu @@ -142,6 +147,27 @@ menu "On-chip Peripheral Drivers" endif endif + menuconfig BSP_USING_SPI + bool "Enable SPI BUS" + default n + select RT_USING_SPI + if BSP_USING_SPI + config BSP_USING_SPI1 + bool "Enable SPI1 BUS" + default n + + config BSP_SPI1_TX_USING_DMA + bool "Enable SPI1 TX DMA" + depends on BSP_USING_SPI1 + default n + + config BSP_SPI1_RX_USING_DMA + bool "Enable SPI1 RX DMA" + depends on BSP_USING_SPI1 + select BSP_SPI1_TX_USING_DMA + default n + endif + config BSP_USING_ON_CHIP_FLASH bool "Enable on-chip FLASH" default n diff --git a/bsp/stm32/stm32l476-st-nucleo/applications/arduino_pinout/README.md b/bsp/stm32/stm32l476-st-nucleo/applications/arduino_pinout/README.md index 814718aea4..1449118e72 100644 --- a/bsp/stm32/stm32l476-st-nucleo/applications/arduino_pinout/README.md +++ b/bsp/stm32/stm32l476-st-nucleo/applications/arduino_pinout/README.md @@ -62,11 +62,11 @@ Hardware Drivers Config ---> ### 3.1 I2C总线 -STM32F410 Nucleo板的I2C总线是板上丝印的 `SCL/D15` 和 `SDA/D14` 引脚,这两个引脚是被RT-Thread I2C设备框架接管的,不需要直接操控这两个引脚,直接引用`#include `(Arduino官方I2C头文件)即可使用。 +Nucleo板的I2C总线是板上丝印的 `SCL/D15` 和 `SDA/D14` 引脚,这两个引脚是被RT-Thread I2C设备框架接管的,不需要直接操控这两个引脚,直接引用`#include `(Arduino官方I2C头文件)即可使用。 ### 3.2 SPI总线 -目前本BSP不支持使用Arduino的SPI功能。 +Nucleo板的SPI总线是板上丝印的 `CS/D10`、`MOSI/D11`、`MISO/D12` 以及 `SCK/D13` 引脚,这`D11`、`D12` 以及 `D13` 引脚是被RT-Thread SPI设备框架接管的,不需要直接操控这些引脚。用户需要操作 `D10` 片选引脚。直接引用`#include `(Arduino官方SPI头文件)即可使用。在使用SPI功能后,`D10` 和 `D11` 的PWM功能将会不可逆失效,转为SPI功能。 ### 3.3 串口