[bsp][stm32l476][RTduino] support PWM switch to SPI

This commit is contained in:
Meco Man 2023-07-09 17:55:59 -04:00 committed by Man, Jianting (Meco)
parent 673d1dcaf0
commit 325ddd2ab7
4 changed files with 48 additions and 20 deletions

View File

@ -11,6 +11,10 @@
#include <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]}
* [] means optional
@ -46,3 +50,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 */

View File

@ -43,7 +43,10 @@
#define F_CPU 80000000L /* CPU:80MHz */
/* 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 "spi1"
#define RTDUINO_TONE_HWTIMER_DEVICE_NAME "timer7"

View File

@ -64,8 +64,8 @@ Mcu.PinsNb=28
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32L476RGTx
MxCube.Version=6.8.0
MxDb.Version=DB.6.0.80
MxCube.Version=6.8.1
MxDb.Version=DB.6.0.81
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.ForceEnableDMAVector=true
@ -149,7 +149,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=MDK-ARM V5
ProjectManager.ToolChainLocation=
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_RTC_Init-RTC-false-HAL-true,5-MX_SPI3_Init-SPI3-false-HAL-true,6-MX_TIM15_Init-TIM15-false-HAL-true,7-MX_TIM16_Init-TIM16-false-HAL-true,8-MX_TIM17_Init-TIM17-false-HAL-true,9-MX_ADC1_Init-ADC1-false-HAL-true,10-MX_LPTIM1_Init-LPTIM1-false-HAL-true,11-MX_TIM2_Init-TIM2-false-HAL-true,12-MX_TIM3_Init-TIM3-false-HAL-true,13-MX_TIM4_Init-TIM4-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_RTC_Init-RTC-false-HAL-true,5-MX_SPI3_Init-SPI3-false-HAL-true,6-MX_TIM15_Init-TIM15-false-HAL-true,7-MX_TIM16_Init-TIM16-false-HAL-true,8-MX_TIM17_Init-TIM17-false-HAL-true,9-MX_ADC1_Init-ADC1-false-HAL-true,10-MX_LPTIM1_Init-LPTIM1-false-HAL-true,11-MX_TIM2_Init-TIM2-false-HAL-true,12-MX_TIM3_Init-TIM3-false-HAL-true,13-MX_TIM4_Init-TIM4-false-HAL-true,14-MX_TIM7_Init-TIM7-false-HAL-true
RCC.ADCFreq_Value=64000000
RCC.AHBFreq_Value=80000000
RCC.APB1Freq_Value=80000000

View File

@ -37,8 +37,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
@ -142,21 +147,6 @@ menu "On-chip Peripheral Drivers"
select BSP_SPI1_TX_USING_DMA
default n
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