[bsp][stm32f072-nucleo][RTduino] support SPI

This commit is contained in:
Meco Man 2024-03-15 22:21:59 -04:00
parent 59231a4276
commit 7218127a83
4 changed files with 43 additions and 2 deletions

View File

@ -12,6 +12,10 @@
#include "pins_arduino.h"
#include <drv_gpio.h>
#define DBG_TAG "RTduino.pins_arduino"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
/*
* {Arduino Pin, RT-Thread Pin [, Device Name, Channel]}
* [] means optional
@ -47,3 +51,32 @@ 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 | GPIO_PIN_6 | 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_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
LOG_I("D11, D12 and D13 will switch from PWM to SPI");
}
}
#endif /* RTDUINO_USING_SPI */

View File

@ -47,4 +47,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 */

View File

@ -48,7 +48,7 @@
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_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 */

View File

@ -27,8 +27,13 @@ menu "Onboard Peripheral Drivers"
select BSP_USING_PWM17_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
select RTDUINO_USING_WIRE
select RTDUINO_USING_SPI
imply RTDUINO_USING_SERVO
imply RTDUINO_USING_WIRE
default n
endmenu