Browse Source

[arduino][stm32l475 pandora] fullly support analog output(PWM) and analog input(ADC) (#5690)

Man, Jianting (Meco) 3 years ago
parent
commit
9ee5940f25

+ 1 - 1
bsp/stm32/libraries/HAL_Drivers/drv_gpio.c

@@ -279,7 +279,7 @@ static void stm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
 
 rt_inline rt_int32_t bit2bitno(rt_uint32_t bit)
 {
-    int i;
+    rt_uint8_t i;
     for (i = 0; i < 32; i++)
     {
         if ((0x01 << i) == bit)

+ 29 - 28
bsp/stm32/stm32f072-st-nucleo/applications/arduino/pins_arduino.c

@@ -11,36 +11,37 @@
 #include <board.h>
 #include "pins_arduino.h"
 
+/*
+    {Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
+    [] means optional
+    Digital pins must NOT give the device name and channel.
+    Analog pins MUST give the device name and channel(ADC or PWM).
+    Arduino Pin must keep in sequence.
+*/
 const pin_map_t pin_map_table[]=
 {
-    /*
-        {Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
-        [] means optional
-        Digital pins must NOT give the device name and channel.
-        Analog pins MUST give the device name and channel(ADC or PWM).
-    */
-    {0, GET_PIN(A,3)},  /* D0, RX */
-    {1, GET_PIN(A,2)},  /* D1, TX */
-    {2, GET_PIN(A,10)}, /* D2 */
-    {3, GET_PIN(B,3), "pwm2", 2},   /* D3, PWM */
-    {4, GET_PIN(B,5)},  /* D4 */
-    {5, GET_PIN(B,4), "pwm3", 1},   /* D5, PWM */
-    {6, GET_PIN(B,10), "pwm2", 3},  /* D6, PWM */
-    {7, GET_PIN(A,8)},  /* D7 */
-    {8, GET_PIN(A,9)},  /* D8 */
-    {9, GET_PIN(C,7), "pwm3", 2},   /* D9, PWM */
-    {10, GET_PIN(B,6)}, /* D10 */
-    {11, GET_PIN(A,7)}, /* D11 */
-    {12, GET_PIN(A,6)}, /* D12 */
-    {13, GET_PIN(A,5)}, /* D13 */
-    {14, GET_PIN(B,9)}, /* D14 */
-    {15, GET_PIN(B,8)}, /* D15 */
-    {16, GET_PIN(A,0), "adc1", 0},  /* A0 */
-    {17, GET_PIN(A,1), "adc1", 1},  /* A1 */
-    {18, GET_PIN(A,4), "adc1", 4},  /* A2 */
-    {19, GET_PIN(B,0), "adc1", 8},  /* A3 */
-    {20, GET_PIN(C,1), "adc1", 11}, /* A4 */
-    {21, GET_PIN(C,0), "adc1", 10}  /* A5 */
+    {D0, GET_PIN(A,3)}, /* RX */
+    {D1, GET_PIN(A,2)}, /* TX */
+    {D2, GET_PIN(A,10)},
+    {D3, GET_PIN(B,3), "pwm2", 2}, /* PWM */
+    {D4, GET_PIN(B,5)},  /* D4 */
+    {D5, GET_PIN(B,4), "pwm3", 1}, /* PWM */
+    {D6, GET_PIN(B,10), "pwm2", 3}, /* PWM */
+    {D7, GET_PIN(A,8)},
+    {D8, GET_PIN(A,9)},
+    {D9, GET_PIN(C,7), "pwm3", 2}, /* PWM */
+    {D10, GET_PIN(B,6)},
+    {D11, GET_PIN(A,7)},
+    {D12, GET_PIN(A,6)},
+    {D13, GET_PIN(A,5)},
+    {D14, GET_PIN(B,9)},
+    {D15, GET_PIN(B,8)},
+    {A0, GET_PIN(A,0), "adc1", 0},
+    {A1, GET_PIN(A,1), "adc1", 1},
+    {A2, GET_PIN(A,4), "adc1", 4},
+    {A3, GET_PIN(B,0), "adc1", 8},
+    {A4, GET_PIN(C,1), "adc1", 11},
+    {A5, GET_PIN(C,0), "adc1", 10}
 };
 
 /* initialization for BSP; maybe a blank function  */

+ 8 - 10
bsp/stm32/stm32f072-st-nucleo/applications/arduino/pins_arduino.h

@@ -10,16 +10,7 @@
 #ifndef Pins_Arduino_h
 #define Pins_Arduino_h
 
-#define LED_BUILTIN  13 /* Built-in LED */
-
-#define ARDUINO_PWM_HZ 500 /* Arduino UNO's PWM is around 500Hz */
-
-#define ARDUINO_PINOUT_ADC_MAX  6  /* Arduino UNO has 6 ADC pins */
-#define ARDUINO_PINOUT_PWM_MAX  5  /* Arduino UNO has 5 PWM pins */
-
-#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
-
-/* pins alias */
+/* pins alias. Must keep in sequence */
 #define D0   (0)
 #define D1   (1)
 #define D2   (2)
@@ -43,4 +34,11 @@
 #define A4   (20)
 #define A5   (21)
 
+#define LED_BUILTIN  D13 /* Built-in LED */
+
+#define ARDUINO_PINOUT_PWM_MAX  5  /* This Arduino variant has 5 PWM pins */
+#define ARDUINO_PWM_HZ 500 /* Arduino UNO's PWM is around 500Hz */
+
+#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
+
 #endif /* Pins_Arduino_h */

+ 38 - 27
bsp/stm32/stm32l475-atk-pandora/applications/arduino/pins_arduino.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -11,34 +11,45 @@
 #include <board.h>
 #include "pins_arduino.h"
 
+/*
+    {Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
+    [] means optional
+    Digital pins must NOT give the device name and channel.
+    Analog pins MUST give the device name and channel(ADC or PWM).
+    Arduino Pin must keep in sequence.
+*/
 const pin_map_t pin_map_table[]=
 {
-    /*
-        {Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
-        [] means optional
-        Digital pins must NOT give the device name and channel.
-        Analog pins MUST give the device name and channel(ADC or PWM).
-    */
-    {0}, /* D0, RX */
-    {1}, /* D1, TX */
-    {2, GET_PIN(D,10)}, /* D2, BSP:KEY0 */
-    {3}, /* D3, PWM */
-    {4, GET_PIN(D,9)}, /* D4, BSP:KEY1 */
-    {5, GET_PIN(D,8)}, /* D5, BSP:KEY2 */
-    {6}, /* D6, PWM */
-    {7}, /* D7 */
-    {8, GET_PIN(E,7)}, /* D8, BSP: RED-LED */
-    {9}, /* D9, PWM */
-    {10, GET_PIN(E,9), "pwm1", 1}, /* D10, PWM, BSP: BLUE-LED */
-    {11, GET_PIN(B,8), "pwm4", 3}, /* D11, PWM */
-    {12, GET_PIN(B,2)}, /* D12, BSP: BEEP */
-    {13, GET_PIN(E,8)}, /* D13, LED_BUILTIN, BSP: GREEN-LED */
-    {14, GET_PIN(C,2), "adc1", 3}, /* D14, A0 */
-    {15}, /* A1 */
-    {16}, /* A2 */
-    {17}, /* A3 */
-    {18}, /* A4 */
-    {19} /*  A5 */
+    {D0}, /* RX */
+    {D1}, /* TX */
+    {D2, GET_PIN(B,9)},
+    {D3, GET_PIN(D,15), "pwm4", 4}, /* PWM */
+    {D4, GET_PIN(A,8)},
+    {D5, GET_PIN(D,14)},
+    {D6, GET_PIN(B,11), "pwm2", 4}, /* PWM */
+    {D7, GET_PIN(B,14)},
+    {D8, GET_PIN(B,12)},
+    {D9, GET_PIN(D,12), "pwm4", 1}, /* PWM */
+    {D10, GET_PIN(B,10), "pwm2", 3}, /* PWM */
+    {D11, GET_PIN(B,8), "pwm4", 3}, /* PWM */
+    {D12, GET_PIN(B,15)},
+    {D13, GET_PIN(B,13)},
+    {D14, GET_PIN(A,1)}, /* BSP: MOTOR-A */
+    {D15, GET_PIN(A,0)}, /* BSP: MOTOR-B */
+    {D16, GET_PIN(B,2)}, /* BSP: BEEP */
+    {D17, GET_PIN(D,10)}, /* BSP: KEY0 */
+    {D18, GET_PIN(D,9)}, /* BSP: KEY1 */
+    {D19, GET_PIN(D,8)}, /* BSP: KEY2 */
+    {D20, GET_PIN(C,13)}, /* BSP: KEY-WKUP */
+    {D21, GET_PIN(E,7)}, /* BSP: RED-LED */
+    {D22, GET_PIN(E,8)}, /* LED_BUILTIN, BSP: GREEN-LED */
+    {D23, GET_PIN(E,9), "pwm1", 1}, /* PWM, BSP: BLUE-LED */
+    {A0, GET_PIN(C,2), "adc1", 3},
+    {A1, GET_PIN(C,4), "adc1", 13},
+    {A2},
+    {A3},
+    {A4},
+    {A5}
 };
 
 /* initialization for BSP; maybe a blank function  */

+ 25 - 16
bsp/stm32/stm32l475-atk-pandora/applications/arduino/pins_arduino.h

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006-2021, RT-Thread Development Team
+ * Copyright (c) 2006-2022, RT-Thread Development Team
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -10,15 +10,7 @@
 #ifndef Pins_Arduino_h
 #define Pins_Arduino_h
 
-#define LED_BUILTIN  13 /* Built-in LED */
-
-#define ARDUINO_PWM_HZ 500 /* Arduino UNO's PWM is around 500Hz */
-
-#define ARDUINO_PINOUT_ADC_MAX  6  /* Arduino UNO has 6 ADC pins */
-#define ARDUINO_PINOUT_PWM_MAX  5  /* Arduino UNO has 5 PWM pins */
-
-#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
-
+/* pins alias. Must keep in sequence */
 #define D0   (0)
 #define D1   (1)
 #define D2   (2)
@@ -33,11 +25,28 @@
 #define D11  (11)
 #define D12  (12)
 #define D13  (13)
-#define A0   (14)
-#define A1   (15)
-#define A2   (16)
-#define A3   (17)
-#define A4   (18)
-#define A5   (19)
+#define D14  (14)
+#define D15  (15)
+#define D16  (16)
+#define D17  (17)
+#define D18  (18)
+#define D19  (19)
+#define D20  (20)
+#define D21  (21)
+#define D22  (22)
+#define D23  (23)
+#define A0   (24)
+#define A1   (25)
+#define A2   (26)
+#define A3   (27)
+#define A4   (28)
+#define A5   (29)
+
+#define LED_BUILTIN  D22 /* Built-in LED */
+
+#define ARDUINO_PINOUT_PWM_MAX  6  /* This Arduino variant has 6 PWM pins */
+#define ARDUINO_PWM_HZ 500 /* Arduino UNO's PWM is around 500Hz */
+
+#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
 
 #endif /* Pins_Arduino_h */

File diff suppressed because it is too large
+ 0 - 0
bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/.mxproject


+ 0 - 2
bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/Inc/main.h

@@ -89,5 +89,3 @@ void Error_Handler(void);
 #endif
 
 #endif /* __MAIN_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 7 - 8
bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/Inc/stm32l4xx_hal_conf.h

@@ -1,3 +1,4 @@
+/* USER CODE BEGIN Header */
 /**
   ******************************************************************************
   * @file    stm32l4xx_hal_conf.h
@@ -8,16 +9,16 @@
   ******************************************************************************
   * @attention
   *
-  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
-  * All rights reserved.</center></h2>
+  * Copyright (c) 2017 STMicroelectronics.
+  * All rights reserved.
   *
-  * This software component is licensed by ST under BSD 3-Clause license,
-  * the "License"; You may not use this file except in compliance with the
-  * License. You may obtain a copy of the License at:
-  *                        opensource.org/licenses/BSD-3-Clause
+  * This software is licensed under terms that can be found in the LICENSE file
+  * in the root directory of this software component.
+  * If no LICENSE file comes with this software, it is provided AS-IS.
   *
   ******************************************************************************
   */
+/* USER CODE END Header */
 
 /* Define to prevent recursive inclusion -------------------------------------*/
 #ifndef STM32L4xx_HAL_CONF_H
@@ -479,5 +480,3 @@
 #endif
 
 #endif /* STM32L4xx_HAL_CONF_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 2
bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/Inc/stm32l4xx_it.h

@@ -81,5 +81,3 @@ void OTG_FS_IRQHandler(void);
 #endif
 
 #endif /* __STM32L4xx_IT_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 51 - 38
bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/STM32L475VE.ioc

@@ -1,5 +1,5 @@
 #MicroXplorer Configuration settings - do not modify
-ADC1.Channel-15\#ChannelRegularConversion=ADC_CHANNEL_14
+ADC1.Channel-15\#ChannelRegularConversion=ADC_CHANNEL_3
 ADC1.IPParameters=Rank-15\#ChannelRegularConversion,Channel-15\#ChannelRegularConversion,SamplingTime-15\#ChannelRegularConversion,OffsetNumber-15\#ChannelRegularConversion,NbrOfConversionFlag,master
 ADC1.NbrOfConversionFlag=1
 ADC1.OffsetNumber-15\#ChannelRegularConversion=ADC_OFFSET_NONE
@@ -44,7 +44,7 @@ Mcu.Pin12=PA4
 Mcu.Pin13=PA5
 Mcu.Pin14=PA6
 Mcu.Pin15=PA7
-Mcu.Pin16=PC5
+Mcu.Pin16=PC4
 Mcu.Pin17=PE9
 Mcu.Pin18=PE10
 Mcu.Pin19=PE11
@@ -58,47 +58,49 @@ Mcu.Pin25=PB11
 Mcu.Pin26=PB13
 Mcu.Pin27=PB14
 Mcu.Pin28=PB15
-Mcu.Pin29=PC8
+Mcu.Pin29=PD12
 Mcu.Pin3=PE5
-Mcu.Pin30=PC9
-Mcu.Pin31=PA9
-Mcu.Pin32=PA10
-Mcu.Pin33=PA11
-Mcu.Pin34=PA12
-Mcu.Pin35=PA13 (JTMS-SWDIO)
-Mcu.Pin36=PA14 (JTCK-SWCLK)
-Mcu.Pin37=PC10
-Mcu.Pin38=PC11
-Mcu.Pin39=PC12
+Mcu.Pin30=PD15
+Mcu.Pin31=PC8
+Mcu.Pin32=PC9
+Mcu.Pin33=PA9
+Mcu.Pin34=PA10
+Mcu.Pin35=PA11
+Mcu.Pin36=PA12
+Mcu.Pin37=PA13 (JTMS-SWDIO)
+Mcu.Pin38=PA14 (JTCK-SWCLK)
+Mcu.Pin39=PC10
 Mcu.Pin4=PE6
-Mcu.Pin40=PD2
-Mcu.Pin41=PB3 (JTDO-TRACESWO)
-Mcu.Pin42=PB5
-Mcu.Pin43=PB7
-Mcu.Pin44=PB8
-Mcu.Pin45=VP_IWDG_VS_IWDG
-Mcu.Pin46=VP_LPTIM1_VS_LPTIM_counterModeInternalClock
-Mcu.Pin47=VP_RTC_VS_RTC_Activate
-Mcu.Pin48=VP_SAI1_VP_$IpInstance_SAIA_SAI_BASIC
-Mcu.Pin49=VP_SAI1_VP_$IpInstance_SAIB_SAI_BASIC
+Mcu.Pin40=PC11
+Mcu.Pin41=PC12
+Mcu.Pin42=PD2
+Mcu.Pin43=PB3 (JTDO-TRACESWO)
+Mcu.Pin44=PB5
+Mcu.Pin45=PB7
+Mcu.Pin46=PB8
+Mcu.Pin47=VP_IWDG_VS_IWDG
+Mcu.Pin48=VP_LPTIM1_VS_LPTIM_counterModeInternalClock
+Mcu.Pin49=VP_RTC_VS_RTC_Activate
 Mcu.Pin5=PC14-OSC32_IN (PC14)
-Mcu.Pin50=VP_SYS_VS_Systick
-Mcu.Pin51=VP_TIM1_VS_ClockSourceINT
-Mcu.Pin52=VP_TIM2_VS_ClockSourceINT
-Mcu.Pin53=VP_TIM4_VS_ClockSourceINT
-Mcu.Pin54=VP_TIM15_VS_ClockSourceINT
-Mcu.Pin55=VP_TIM16_VS_ClockSourceINT
-Mcu.Pin56=VP_TIM17_VS_ClockSourceINT
+Mcu.Pin50=VP_SAI1_VP_$IpInstance_SAIA_SAI_BASIC
+Mcu.Pin51=VP_SAI1_VP_$IpInstance_SAIB_SAI_BASIC
+Mcu.Pin52=VP_SYS_VS_Systick
+Mcu.Pin53=VP_TIM1_VS_ClockSourceINT
+Mcu.Pin54=VP_TIM2_VS_ClockSourceINT
+Mcu.Pin55=VP_TIM4_VS_ClockSourceINT
+Mcu.Pin56=VP_TIM15_VS_ClockSourceINT
+Mcu.Pin57=VP_TIM16_VS_ClockSourceINT
+Mcu.Pin58=VP_TIM17_VS_ClockSourceINT
 Mcu.Pin6=PC15-OSC32_OUT (PC15)
 Mcu.Pin7=PH0-OSC_IN (PH0)
 Mcu.Pin8=PH1-OSC_OUT (PH1)
 Mcu.Pin9=PC2
-Mcu.PinsNb=57
+Mcu.PinsNb=59
 Mcu.ThirdPartyNb=0
 Mcu.UserConstants=
 Mcu.UserName=STM32L475VETx
-MxCube.Version=6.4.0
-MxDb.Version=DB.6.0.40
+MxCube.Version=6.5.0
+MxDb.Version=DB.6.0.50
 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
 NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
 NVIC.ForceEnableDMAVector=true
@@ -175,11 +177,16 @@ PC15-OSC32_OUT\ (PC15).Mode=LSE-External-Oscillator
 PC15-OSC32_OUT\ (PC15).Signal=RCC_OSC32_OUT
 PC2.Locked=true
 PC2.Signal=ADCx_IN3
-PC5.Signal=ADCx_IN14
+PC4.Locked=true
+PC4.Signal=ADCx_IN13
 PC8.Mode=SD_4_bits_Wide_bus
 PC8.Signal=SDMMC1_D0
 PC9.Mode=SD_4_bits_Wide_bus
 PC9.Signal=SDMMC1_D1
+PD12.Locked=true
+PD12.Signal=S_TIM4_CH1
+PD15.Locked=true
+PD15.Signal=S_TIM4_CH4
 PD2.Mode=SD_4_bits_Wide_bus
 PD2.Signal=SDMMC1_CMD
 PE10.Mode=Single Bank
@@ -223,7 +230,7 @@ ProjectManager.CustomerFirmwarePackage=
 ProjectManager.DefaultFWLocation=true
 ProjectManager.DeletePrevious=true
 ProjectManager.DeviceId=STM32L475VETx
-ProjectManager.FirmwarePackage=STM32Cube FW_L4 V1.17.0
+ProjectManager.FirmwarePackage=STM32Cube FW_L4 V1.17.1
 ProjectManager.FreePins=false
 ProjectManager.HalAssertFull=false
 ProjectManager.HeapSize=0x200
@@ -311,8 +318,8 @@ SAI1.VirtualMode-SAI_A_MasterWithClock=VM_MASTER
 SAI1.VirtualMode-SAI_B_SyncSlave=VM_SLAVE
 SAI1.VirtualProtocol-SAI_A_BASIC=VM_BASIC_PROTOCOL
 SAI1.VirtualProtocol-SAI_B_BASIC=VM_BASIC_PROTOCOL
-SH.ADCx_IN14.0=ADC1_IN14,IN14-Single-Ended
-SH.ADCx_IN14.ConfNb=1
+SH.ADCx_IN13.0=ADC1_IN13,IN13-Single-Ended
+SH.ADCx_IN13.ConfNb=1
 SH.ADCx_IN3.0=ADC1_IN3,IN3-Single-Ended
 SH.ADCx_IN3.ConfNb=1
 SH.COMP_DAC11_group.0=DAC1_OUT1,DAC_OUT1
@@ -323,10 +330,14 @@ SH.S_TIM2_CH3.0=TIM2_CH3,PWM Generation3 CH3
 SH.S_TIM2_CH3.ConfNb=1
 SH.S_TIM2_CH4.0=TIM2_CH4,PWM Generation4 CH4
 SH.S_TIM2_CH4.ConfNb=1
+SH.S_TIM4_CH1.0=TIM4_CH1,PWM Generation1 CH1
+SH.S_TIM4_CH1.ConfNb=1
 SH.S_TIM4_CH2.0=TIM4_CH2,PWM Generation2 CH2
 SH.S_TIM4_CH2.ConfNb=1
 SH.S_TIM4_CH3.0=TIM4_CH3,PWM Generation3 CH3
 SH.S_TIM4_CH3.ConfNb=1
+SH.S_TIM4_CH4.0=TIM4_CH4,PWM Generation4 CH4
+SH.S_TIM4_CH4.ConfNb=1
 SPI1.CalculateBaudRate=40.0 MBits/s
 SPI1.Direction=SPI_DIRECTION_2LINES
 SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
@@ -347,9 +358,11 @@ TIM1.IPParameters=Channel-PWM Generation1 CH1
 TIM2.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
 TIM2.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
 TIM2.IPParameters=Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4
+TIM4.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
 TIM4.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
 TIM4.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
-TIM4.IPParameters=Channel-PWM Generation3 CH3,Channel-PWM Generation2 CH2
+TIM4.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
+TIM4.IPParameters=Channel-PWM Generation3 CH3,Channel-PWM Generation2 CH2,Channel-PWM Generation4 CH4,Channel-PWM Generation1 CH1
 USART1.IPParameters=VirtualMode-Asynchronous
 USART1.VirtualMode-Asynchronous=VM_ASYNC
 USART2.IPParameters=VirtualMode-Asynchronous

+ 19 - 3
bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/Src/main.c

@@ -61,7 +61,7 @@
 /* USER CODE END PM */
 
 /* Private variables ---------------------------------------------------------*/
-ADC_HandleTypeDef hadc1;
+ ADC_HandleTypeDef hadc1;
 
 DAC_HandleTypeDef hdac1;
 
@@ -216,10 +216,12 @@ void SystemClock_Config(void)
   {
     Error_Handler();
   }
+
   /** Configure LSE Drive Capability
   */
   HAL_PWR_EnableBkUpAccess();
   __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
+
   /** Initializes the RCC Oscillators according to the specified parameters
   * in the RCC_OscInitTypeDef structure.
   */
@@ -239,6 +241,7 @@ void SystemClock_Config(void)
   {
     Error_Handler();
   }
+
   /** Initializes the CPU, AHB and APB buses clocks
   */
   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
@@ -302,6 +305,7 @@ static void MX_ADC1_Init(void)
   /* USER CODE BEGIN ADC1_Init 1 */
 
   /* USER CODE END ADC1_Init 1 */
+
   /** Common config
   */
   hadc1.Instance = ADC1;
@@ -323,6 +327,7 @@ static void MX_ADC1_Init(void)
   {
     Error_Handler();
   }
+
   /** Configure the ADC multi-mode
   */
   multimode.Mode = ADC_MODE_INDEPENDENT;
@@ -330,9 +335,10 @@ static void MX_ADC1_Init(void)
   {
     Error_Handler();
   }
+
   /** Configure Regular Channel
   */
-  sConfig.Channel = ADC_CHANNEL_14;
+  sConfig.Channel = ADC_CHANNEL_3;
   sConfig.Rank = ADC_REGULAR_RANK_1;
   sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
   sConfig.SingleDiff = ADC_SINGLE_ENDED;
@@ -365,6 +371,7 @@ static void MX_DAC1_Init(void)
   /* USER CODE BEGIN DAC1_Init 1 */
 
   /* USER CODE END DAC1_Init 1 */
+
   /** DAC Initialization
   */
   hdac1.Instance = DAC1;
@@ -372,6 +379,7 @@ static void MX_DAC1_Init(void)
   {
     Error_Handler();
   }
+
   /** DAC channel OUT1 config
   */
   sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
@@ -500,6 +508,7 @@ static void MX_RTC_Init(void)
   /* USER CODE BEGIN RTC_Init 1 */
 
   /* USER CODE END RTC_Init 1 */
+
   /** Initialize RTC Only
   */
   hrtc.Instance = RTC;
@@ -916,6 +925,10 @@ static void MX_TIM4_Init(void)
   sConfigOC.Pulse = 0;
   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
+  if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
+  {
+    Error_Handler();
+  }
   if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
   {
     Error_Handler();
@@ -924,6 +937,10 @@ static void MX_TIM4_Init(void)
   {
     Error_Handler();
   }
+  if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
+  {
+    Error_Handler();
+  }
   /* USER CODE BEGIN TIM4_Init 2 */
 
   /* USER CODE END TIM4_Init 2 */
@@ -1198,4 +1215,3 @@ void assert_failed(uint8_t *file, uint32_t line)
   /* USER CODE END 6 */
 }
 #endif /* USE_FULL_ASSERT */
-

+ 58 - 6
bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/Src/stm32l4xx_hal_msp.c

@@ -41,6 +41,7 @@
 
 /* Includes ------------------------------------------------------------------*/
 #include "main.h"
+#include <drv_common.h>
 /* USER CODE BEGIN Includes */
 
 /* USER CODE END Includes */
@@ -119,9 +120,9 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
     __HAL_RCC_GPIOC_CLK_ENABLE();
     /**ADC1 GPIO Configuration
     PC2     ------> ADC1_IN3
-    PC5     ------> ADC1_IN14
+    PC4     ------> ADC1_IN13
     */
-    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_5;
+    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_4;
     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
@@ -151,9 +152,9 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
 
     /**ADC1 GPIO Configuration
     PC2     ------> ADC1_IN3
-    PC5     ------> ADC1_IN14
+    PC4     ------> ADC1_IN13
     */
-    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_5);
+    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_4);
 
   /* USER CODE BEGIN ADC1_MspDeInit 1 */
 
@@ -231,11 +232,22 @@ void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
 */
 void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef* hlptim)
 {
+  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
   if(hlptim->Instance==LPTIM1)
   {
   /* USER CODE BEGIN LPTIM1_MspInit 0 */
 
   /* USER CODE END LPTIM1_MspInit 0 */
+
+  /** Initializes the peripherals clock
+  */
+    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;
+    PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_PCLK;
+    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
     /* Peripheral clock enable */
     __HAL_RCC_LPTIM1_CLK_ENABLE();
   /* USER CODE BEGIN LPTIM1_MspInit 1 */
@@ -350,11 +362,22 @@ void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
 */
 void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
 {
+  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
   if(hrtc->Instance==RTC)
   {
   /* USER CODE BEGIN RTC_MspInit 0 */
 
   /* USER CODE END RTC_MspInit 0 */
+
+  /** Initializes the peripherals clock
+  */
+    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
+    PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
+    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
     /* Peripheral clock enable */
     __HAL_RCC_RTC_ENABLE();
   /* USER CODE BEGIN RTC_MspInit 1 */
@@ -752,11 +775,21 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
 
   /* USER CODE END TIM4_MspPostInit 0 */
 
+    __HAL_RCC_GPIOD_CLK_ENABLE();
     __HAL_RCC_GPIOB_CLK_ENABLE();
     /**TIM4 GPIO Configuration
+    PD12     ------> TIM4_CH1
+    PD15     ------> TIM4_CH4
     PB7     ------> TIM4_CH2
     PB8     ------> TIM4_CH3
     */
+    GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_15;
+    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+    GPIO_InitStruct.Alternate = GPIO_AF2_TIM4;
+    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+
     GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
@@ -856,11 +889,22 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
 void HAL_UART_MspInit(UART_HandleTypeDef* huart)
 {
   GPIO_InitTypeDef GPIO_InitStruct = {0};
+  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
   if(huart->Instance==USART1)
   {
   /* USER CODE BEGIN USART1_MspInit 0 */
 
   /* USER CODE END USART1_MspInit 0 */
+
+  /** Initializes the peripherals clock
+  */
+    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
+    PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
+    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
     /* Peripheral clock enable */
     __HAL_RCC_USART1_CLK_ENABLE();
 
@@ -885,6 +929,16 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
   /* USER CODE BEGIN USART2_MspInit 0 */
 
   /* USER CODE END USART2_MspInit 0 */
+
+  /** Initializes the peripherals clock
+  */
+    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
+    PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
+    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
+    {
+      Error_Handler();
+    }
+
     /* Peripheral clock enable */
     __HAL_RCC_USART2_CLK_ENABLE();
 
@@ -1141,5 +1195,3 @@ void HAL_SAI_MspDeInit(SAI_HandleTypeDef* hsai)
 /* USER CODE BEGIN 1 */
 
 /* USER CODE END 1 */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 0 - 1
bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/Src/stm32l4xx_it.c

@@ -229,4 +229,3 @@ void OTG_FS_IRQHandler(void)
 /* USER CODE BEGIN 1 */
 
 /* USER CODE END 1 */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 17 - 4
bsp/stm32/stm32l475-atk-pandora/board/Kconfig

@@ -25,8 +25,13 @@ menu "Onboard Peripheral Drivers"
         select BSP_USING_PWM
         select BSP_USING_PWM1
         select BSP_USING_PWM1_CH1
+        select BSP_USING_PWM2
+        select BSP_USING_PWM2_CH3
+        select BSP_USING_PWM2_CH4
         select BSP_USING_PWM4
+        select BSP_USING_PWM4_CH1
         select BSP_USING_PWM4_CH3
+        select BSP_USING_PWM4_CH4
         select BSP_USING_ADC
         select BSP_USING_ADC1
         select BSP_USING_I2C
@@ -365,12 +370,12 @@ menu "On-chip Peripheral Drivers"
         endif
 
     menuconfig BSP_USING_PWM
-        bool "Enable pwm"
+        bool "Enable PWM"
         default n
         select RT_USING_PWM
         if BSP_USING_PWM
         menuconfig BSP_USING_PWM1
-            bool "Enable timer1 output pwm"
+            bool "Enable timer1 output PWM"
             default n
             if BSP_USING_PWM1
                 config BSP_USING_PWM1_CH1
@@ -379,7 +384,7 @@ menu "On-chip Peripheral Drivers"
             endif
 
         menuconfig BSP_USING_PWM2
-            bool "Enable timer2 output pwm"
+            bool "Enable timer2 output PWM"
             default n
             if BSP_USING_PWM2
                 config BSP_USING_PWM2_CH3
@@ -392,9 +397,13 @@ menu "On-chip Peripheral Drivers"
             endif
 
         menuconfig BSP_USING_PWM4
-            bool "Enable timer4 output pwm"
+            bool "Enable timer4 output PWM"
             default n
             if BSP_USING_PWM4
+                config BSP_USING_PWM4_CH1
+                    bool "Enable PWM4 channel1"
+                    default n
+
                 config BSP_USING_PWM4_CH2
                     bool "Enable PWM4 channel2"
                     default n
@@ -402,6 +411,10 @@ menu "On-chip Peripheral Drivers"
                 config BSP_USING_PWM4_CH3
                     bool "Enable PWM4 channel3"
                     default n
+
+                config BSP_USING_PWM4_CH4
+                    bool "Enable PWM4 channel4"
+                    default n
             endif
         endif
 

Some files were not shown because too many files changed in this diff