[bsp][stm32f469-disco] support RTduino SPI

This commit is contained in:
Meco Man 2024-03-09 12:54:44 -05:00
parent b85c4cade2
commit adaa44c911
8 changed files with 71 additions and 15 deletions

View File

@ -62,9 +62,7 @@ void switchToSPI(const char *bus_name)
__HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5); HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7);
/**SPI1 GPIO Configuration /**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK PA5 ------> SPI1_SCK
@ -78,7 +76,7 @@ void switchToSPI(const char *bus_name)
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 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 */ #endif /* RTDUINO_USING_SPI */

View File

@ -62,9 +62,7 @@ void switchToSPI(const char *bus_name)
__HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5); HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7);
/**SPI1 GPIO Configuration /**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK PA5 ------> SPI1_SCK
@ -78,7 +76,7 @@ void switchToSPI(const char *bus_name)
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 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 */ #endif /* RTDUINO_USING_SPI */

View File

@ -65,9 +65,7 @@ void switchToSPI(const char *bus_name)
__HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5); HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7);
/**SPI1 GPIO Configuration /**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK PA5 ------> SPI1_SCK
@ -81,7 +79,7 @@ void switchToSPI(const char *bus_name)
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 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 */ #endif /* RTDUINO_USING_SPI */

View File

@ -12,6 +12,10 @@
#include "pins_arduino.h" #include "pins_arduino.h"
#include <drv_gpio.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]} * {Arduino Pin, RT-Thread Pin [, Device Name, Channel]}
* [] means optional * [] 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 */ {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 */ {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 */

View File

@ -51,6 +51,9 @@
/* i2c1 : PB9-SDA PB8-SCL */ /* i2c1 : PB9-SDA PB8-SCL */
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c1" #define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c1"
#define SS D10
#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi2"
#define RTDUINO_TONE_HWTIMER_DEVICE_NAME "timer6" #define RTDUINO_TONE_HWTIMER_DEVICE_NAME "timer6"
#endif /* Pins_Arduino_h */ #endif /* Pins_Arduino_h */

View File

@ -73,7 +73,7 @@
/* #define HAL_SAI_MODULE_ENABLED */ /* #define HAL_SAI_MODULE_ENABLED */
#define HAL_SD_MODULE_ENABLED #define HAL_SD_MODULE_ENABLED
/* #define HAL_MMC_MODULE_ENABLED */ /* #define HAL_MMC_MODULE_ENABLED */
/* #define HAL_SPI_MODULE_ENABLED */ #define HAL_SPI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED #define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */ /* #define HAL_USART_MODULE_ENABLED */
@ -83,7 +83,6 @@
#define HAL_PCD_MODULE_ENABLED #define HAL_PCD_MODULE_ENABLED
/* #define HAL_HCD_MODULE_ENABLED */ /* #define HAL_HCD_MODULE_ENABLED */
#define HAL_DSI_MODULE_ENABLED #define HAL_DSI_MODULE_ENABLED
/* #define HAL_QSPI_MODULE_ENABLED */
#define HAL_QSPI_MODULE_ENABLED #define HAL_QSPI_MODULE_ENABLED
/* #define HAL_CEC_MODULE_ENABLED */ /* #define HAL_CEC_MODULE_ENABLED */
/* #define HAL_FMPI2C_MODULE_ENABLED */ /* #define HAL_FMPI2C_MODULE_ENABLED */

View File

@ -42,6 +42,8 @@ menu "Onboard Peripheral Drivers"
select BSP_USING_PWM12_CH2 select BSP_USING_PWM12_CH2
select BSP_USING_I2C select BSP_USING_I2C
select BSP_USING_I2C1 select BSP_USING_I2C1
select BSP_USING_SPI
select BSP_USING_SPI2
imply RTDUINO_USING_SERVO imply RTDUINO_USING_SERVO
imply RTDUINO_USING_WIRE imply RTDUINO_USING_WIRE
default n default n
@ -223,6 +225,21 @@ menu "On-chip Peripheral Drivers"
select RT_USING_SPI select RT_USING_SPI
default n default n
if BSP_USING_SPI 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 config BSP_USING_SPI3
bool "Enable SPI3 BUS" bool "Enable SPI3 BUS"
default n default n

View File

@ -78,7 +78,7 @@ void switchToSPI(const char *bus_name)
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 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 */ #endif /* RTDUINO_USING_SPI */