[RTduino][stm32-f411nucleo] 支持对接引脚的功能切换 (#7798)

This commit is contained in:
liYangYang 2023-07-09 12:19:11 +08:00 committed by GitHub
parent a87b399848
commit 3660db39a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 240 additions and 71 deletions

View File

@ -11,6 +11,10 @@
#include <Arduino.h> #include <Arduino.h>
#include "pins_arduino.h" #include "pins_arduino.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
@ -46,3 +50,29 @@ 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 */
}; };
void pins_switch_to_spi(const char *bus_name)
{
if(!rt_strcmp(bus_name, "spi1"))
{
__HAL_RCC_TIM1_CLK_DISABLE();
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7);
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**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");
}
}

View File

@ -47,4 +47,7 @@
/* 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 D7
#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi1"
#endif /* Pins_Arduino_h */ #endif /* Pins_Arduino_h */

File diff suppressed because one or more lines are too long

View File

@ -5,23 +5,27 @@ ADC1.NbrOfConversionFlag=1
ADC1.Rank-0\#ChannelRegularConversion=1 ADC1.Rank-0\#ChannelRegularConversion=1
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_3CYCLES ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_3CYCLES
ADC1.master=1 ADC1.master=1
CAD.formats=
CAD.pinconfig=
CAD.provider=
File.Version=6 File.Version=6
KeepUserPlacement=true KeepUserPlacement=true
Mcu.CPN=STM32F411RET6 Mcu.CPN=STM32F411RET6
Mcu.Family=STM32F4 Mcu.Family=STM32F4
Mcu.IP0=ADC1 Mcu.IP0=ADC1
Mcu.IP1=IWDG Mcu.IP1=IWDG
Mcu.IP10=USART2 Mcu.IP10=TIM4
Mcu.IP11=USART6 Mcu.IP11=USART2
Mcu.IP12=USART6
Mcu.IP2=NVIC Mcu.IP2=NVIC
Mcu.IP3=RCC Mcu.IP3=RCC
Mcu.IP4=RTC Mcu.IP4=RTC
Mcu.IP5=SYS Mcu.IP5=SPI3
Mcu.IP6=TIM1 Mcu.IP6=SYS
Mcu.IP7=TIM2 Mcu.IP7=TIM1
Mcu.IP8=TIM3 Mcu.IP8=TIM2
Mcu.IP9=TIM4 Mcu.IP9=TIM3
Mcu.IPNb=12 Mcu.IPNb=13
Mcu.Name=STM32F411R(C-E)Tx Mcu.Name=STM32F411R(C-E)Tx
Mcu.Package=LQFP64 Mcu.Package=LQFP64
Mcu.Pin0=PC14-OSC32_IN Mcu.Pin0=PC14-OSC32_IN
@ -31,35 +35,38 @@ Mcu.Pin11=PA7
Mcu.Pin12=PB0 Mcu.Pin12=PB0
Mcu.Pin13=PB1 Mcu.Pin13=PB1
Mcu.Pin14=PB10 Mcu.Pin14=PB10
Mcu.Pin15=PC7 Mcu.Pin15=PB12
Mcu.Pin16=PA11 Mcu.Pin16=PC7
Mcu.Pin17=PA12 Mcu.Pin17=PA11
Mcu.Pin18=PA13 Mcu.Pin18=PA12
Mcu.Pin19=PA14 Mcu.Pin19=PA13
Mcu.Pin2=PH0 - OSC_IN Mcu.Pin2=PH0 - OSC_IN
Mcu.Pin20=PB3 Mcu.Pin20=PA14
Mcu.Pin21=PB4 Mcu.Pin21=PC11
Mcu.Pin22=PB6 Mcu.Pin22=PC12
Mcu.Pin23=VP_IWDG_VS_IWDG Mcu.Pin23=PB3
Mcu.Pin24=VP_RTC_VS_RTC_Activate Mcu.Pin24=PB4
Mcu.Pin25=VP_SYS_VS_Systick Mcu.Pin25=PB6
Mcu.Pin26=VP_TIM1_VS_ClockSourceINT Mcu.Pin26=VP_IWDG_VS_IWDG
Mcu.Pin27=VP_TIM2_VS_ClockSourceINT Mcu.Pin27=VP_RTC_VS_RTC_Activate
Mcu.Pin28=VP_TIM3_VS_ClockSourceINT Mcu.Pin28=VP_SYS_VS_Systick
Mcu.Pin29=VP_TIM4_VS_ClockSourceINT Mcu.Pin29=VP_TIM1_VS_ClockSourceINT
Mcu.Pin3=PH1 - OSC_OUT Mcu.Pin3=PH1 - OSC_OUT
Mcu.Pin30=VP_TIM2_VS_ClockSourceINT
Mcu.Pin31=VP_TIM3_VS_ClockSourceINT
Mcu.Pin32=VP_TIM4_VS_ClockSourceINT
Mcu.Pin4=PC0 Mcu.Pin4=PC0
Mcu.Pin5=PC1 Mcu.Pin5=PC1
Mcu.Pin6=PA0-WKUP Mcu.Pin6=PA0-WKUP
Mcu.Pin7=PA1 Mcu.Pin7=PA1
Mcu.Pin8=PA2 Mcu.Pin8=PA2
Mcu.Pin9=PA3 Mcu.Pin9=PA3
Mcu.PinsNb=30 Mcu.PinsNb=33
Mcu.ThirdPartyNb=0 Mcu.ThirdPartyNb=0
Mcu.UserConstants= Mcu.UserConstants=
Mcu.UserName=STM32F411RETx Mcu.UserName=STM32F411RETx
MxCube.Version=6.6.1 MxCube.Version=6.7.0
MxDb.Version=DB.6.0.60 MxDb.Version=DB.6.0.70
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
NVIC.ForceEnableDMAVector=true NVIC.ForceEnableDMAVector=true
@ -99,6 +106,8 @@ PB1.Locked=true
PB1.Signal=S_TIM3_CH4 PB1.Signal=S_TIM3_CH4
PB10.Locked=true PB10.Locked=true
PB10.Signal=S_TIM2_CH3 PB10.Signal=S_TIM2_CH3
PB12.Mode=Full_Duplex_Master
PB12.Signal=SPI3_SCK
PB3.Locked=true PB3.Locked=true
PB3.Signal=S_TIM2_CH2 PB3.Signal=S_TIM2_CH2
PB4.Locked=true PB4.Locked=true
@ -109,6 +118,10 @@ PC0.Locked=true
PC0.Signal=ADCx_IN10 PC0.Signal=ADCx_IN10
PC1.Locked=true PC1.Locked=true
PC1.Signal=ADCx_IN11 PC1.Signal=ADCx_IN11
PC11.Mode=Full_Duplex_Master
PC11.Signal=SPI3_MISO
PC12.Mode=Full_Duplex_Master
PC12.Signal=SPI3_MOSI
PC14-OSC32_IN.Mode=LSE-External-Oscillator PC14-OSC32_IN.Mode=LSE-External-Oscillator
PC14-OSC32_IN.Signal=RCC_OSC32_IN PC14-OSC32_IN.Signal=RCC_OSC32_IN
PC15-OSC32_OUT.Mode=LSE-External-Oscillator PC15-OSC32_OUT.Mode=LSE-External-Oscillator
@ -147,7 +160,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=MDK-ARM V5 ProjectManager.TargetToolchain=MDK-ARM V5
ProjectManager.ToolChainLocation= ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_TIM3_Init-TIM3-false-HAL-true,5-MX_ADC1_Init-ADC1-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true,7-MX_TIM2_Init-TIM2-false-HAL-true,8-MX_TIM4_Init-TIM4-false-HAL-true,9-MX_RTC_Init-RTC-false-HAL-true,10-MX_SPI1_Init-SPI1-false-HAL-true,11-MX_USART6_UART_Init-USART6-false-HAL-true ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_TIM3_Init-TIM3-false-HAL-true,5-MX_ADC1_Init-ADC1-false-HAL-true,6-MX_TIM1_Init-TIM1-false-HAL-true,7-MX_TIM2_Init-TIM2-false-HAL-true,8-MX_TIM4_Init-TIM4-false-HAL-true,9-MX_RTC_Init-RTC-false-HAL-true,10-MX_USART6_UART_Init-USART6-false-HAL-true,11-MX_IWDG_Init-IWDG-false-HAL-true
RCC.48MHZClocksFreq_Value=42000000 RCC.48MHZClocksFreq_Value=42000000
RCC.AHBFreq_Value=84000000 RCC.AHBFreq_Value=84000000
RCC.APB1CLKDivider=RCC_HCLK_DIV2 RCC.APB1CLKDivider=RCC_HCLK_DIV2
@ -205,6 +218,11 @@ SH.S_TIM3_CH4.0=TIM3_CH4,PWM Generation4 CH4
SH.S_TIM3_CH4.ConfNb=1 SH.S_TIM3_CH4.ConfNb=1
SH.S_TIM4_CH1.0=TIM4_CH1,PWM Generation1 CH1 SH.S_TIM4_CH1.0=TIM4_CH1,PWM Generation1 CH1
SH.S_TIM4_CH1.ConfNb=1 SH.S_TIM4_CH1.ConfNb=1
SPI3.CalculateBaudRate=21.0 MBits/s
SPI3.Direction=SPI_DIRECTION_2LINES
SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
SPI3.Mode=SPI_MODE_MASTER
SPI3.VirtualType=VM_MASTER
TIM1.Channel-PWM\ Generation1\ CH1N=TIM_CHANNEL_1 TIM1.Channel-PWM\ Generation1\ CH1N=TIM_CHANNEL_1
TIM1.IPParameters=Channel-PWM Generation1 CH1N TIM1.IPParameters=Channel-PWM Generation1 CH1N
TIM2.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2 TIM2.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2

View File

@ -80,6 +80,7 @@ void Error_Handler(void);
/* USER CODE END EFP */ /* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */ /* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */ /* USER CODE END Private defines */

View File

@ -37,12 +37,11 @@
*/ */
#define HAL_MODULE_ENABLED #define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
/* #define HAL_CRYP_MODULE_ENABLED */ /* #define HAL_CRYP_MODULE_ENABLED */
#define HAL_ADC_MODULE_ENABLED
/* #define HAL_CAN_MODULE_ENABLED */ /* #define HAL_CAN_MODULE_ENABLED */
/* #define HAL_CRC_MODULE_ENABLED */ /* #define HAL_CRC_MODULE_ENABLED */
/* #define HAL_CAN_LEGACY_MODULE_ENABLED */ /* #define HAL_CAN_LEGACY_MODULE_ENABLED */
/* #define HAL_CRYP_MODULE_ENABLED */
/* #define HAL_DAC_MODULE_ENABLED */ /* #define HAL_DAC_MODULE_ENABLED */
/* #define HAL_DCMI_MODULE_ENABLED */ /* #define HAL_DCMI_MODULE_ENABLED */
/* #define HAL_DMA2D_MODULE_ENABLED */ /* #define HAL_DMA2D_MODULE_ENABLED */
@ -62,7 +61,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 */
@ -214,7 +213,7 @@
#define MAC_ADDR5 0U #define MAC_ADDR5 0U
/* Definition of the Ethernet driver buffers size and count */ /* Definition of the Ethernet driver buffers size and count */
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ #define ETH_RX_BUF_SIZE /* buffer size for receive */
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
#define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ #define ETH_RXBUFNB 4U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ #define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */

View File

@ -243,6 +243,83 @@ void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
} }
/**
* @brief SPI MSP Initialization
* This function configures the hardware resources used in this example
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hspi->Instance==SPI3)
{
/* USER CODE BEGIN SPI3_MspInit 0 */
/* USER CODE END SPI3_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI3_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
/**SPI3 GPIO Configuration
PB12 ------> SPI3_SCK
PC11 ------> SPI3_MISO
PC12 ------> SPI3_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_SPI3;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN SPI3_MspInit 1 */
/* USER CODE END SPI3_MspInit 1 */
}
}
/**
* @brief SPI MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
{
if(hspi->Instance==SPI3)
{
/* USER CODE BEGIN SPI3_MspDeInit 0 */
/* USER CODE END SPI3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI3_CLK_DISABLE();
/**SPI3 GPIO Configuration
PB12 ------> SPI3_SCK
PC11 ------> SPI3_MISO
PC12 ------> SPI3_MOSI
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_12);
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_11|GPIO_PIN_12);
/* USER CODE BEGIN SPI3_MspDeInit 1 */
/* USER CODE END SPI3_MspDeInit 1 */
}
}
/** /**
* @brief TIM_Base MSP Initialization * @brief TIM_Base MSP Initialization
* This function configures the hardware resources used in this example * This function configures the hardware resources used in this example

View File

@ -34,8 +34,13 @@ menu "Onboard Peripheral Drivers"
select BSP_USING_PWM1_CH1 select BSP_USING_PWM1_CH1
select BSP_USING_I2C select BSP_USING_I2C
select BSP_USING_I2C1 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_SERVO
imply RTDUINO_USING_WIRE
default n default n
endmenu endmenu
@ -180,6 +185,42 @@ menu "On-chip Peripheral Drivers"
select RT_USING_WDT select RT_USING_WDT
default n default n
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
config BSP_USING_SPI3
bool "Enable SPI3 Bus"
default n
config BSP_SPI3_TX_USING_DMA
bool "Enable SPI3 TX DMA"
depends on BSP_USING_SPI3
default n
config BSP_SPI3_RX_USING_DMA
bool "Enable SPI3 RX DMA"
depends on BSP_USING_SPI3
select BSP_SPI3_TX_USING_DMA
default n
endif
source "../libraries/HAL_Drivers/Kconfig" source "../libraries/HAL_Drivers/Kconfig"
endmenu endmenu