From e639054d89b1b76a95a94c208c7c9a133cd397da Mon Sep 17 00:00:00 2001
From: a1012112796 <1012112796@qq.com>
Date: Fri, 6 Jan 2023 15:25:18 +0800
Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E7=94=A8=20pwm=20=E8=AE=BE=E5=A4=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: a1012112796 <1012112796@qq.com>
---
.config | 14 +-
board/Kconfig | 37 +++++-
board/board.c | 3 +
libraries/HAL_Drivers/drv_pwm.c | 4 +-
project.uvoptx | 218 ++++++++++++++++++++------------
project.uvprojx | 51 ++++++--
rtconfig.h | 12 ++
7 files changed, 238 insertions(+), 101 deletions(-)
diff --git a/.config b/.config
index 94bc8d5..f9073be 100644
--- a/.config
+++ b/.config
@@ -137,7 +137,7 @@ CONFIG_RT_USING_CAN=y
CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_ADC is not set
# CONFIG_RT_USING_DAC is not set
-# CONFIG_RT_USING_PWM is not set
+CONFIG_RT_USING_PWM=y
# CONFIG_RT_USING_MTD_NOR is not set
# CONFIG_RT_USING_MTD_NAND is not set
# CONFIG_RT_USING_PM is not set
@@ -1039,7 +1039,17 @@ CONFIG_BSP_USING_CAN3=y
# CONFIG_BSP_USING_SPI is not set
# CONFIG_BSP_USING_I2C1 is not set
# CONFIG_BSP_USING_TIM is not set
-# CONFIG_BSP_USING_PWM is not set
+CONFIG_BSP_USING_PWM=y
+CONFIG_BSP_USING_PWM3=y
+CONFIG_BSP_USING_PWM3_CH1=y
+CONFIG_BSP_USING_PWM3_CH2=y
+CONFIG_BSP_USING_PWM3_CH3=y
+CONFIG_BSP_USING_PWM3_CH4=y
+CONFIG_BSP_USING_PWM4=y
+CONFIG_BSP_USING_PWM4_CH1=y
+CONFIG_BSP_USING_PWM4_CH2=y
+CONFIG_BSP_USING_PWM4_CH3=y
+CONFIG_BSP_USING_PWM4_CH4=y
# CONFIG_BSP_USING_ADC is not set
# CONFIG_BSP_USING_ONCHIP_RTC is not set
# CONFIG_BSP_USING_WDT is not set
diff --git a/board/Kconfig b/board/Kconfig
index ec05dde..28108ac 100644
--- a/board/Kconfig
+++ b/board/Kconfig
@@ -238,12 +238,39 @@ menu "On-chip Peripheral Drivers"
default n
select RT_USING_PWM
if BSP_USING_PWM
- menuconfig BSP_USING_PWM2
- bool "Enable timer2 output PWM"
+ menuconfig BSP_USING_PWM3
+ bool "Enable timer3 output PWM"
default n
- if BSP_USING_PWM2
- config BSP_USING_PWM2_CH4
- bool "Enable PWM2 channel4"
+ if BSP_USING_PWM3
+ config BSP_USING_PWM3_CH1
+ bool "Enable PWM3 channel1"
+ default n
+ config BSP_USING_PWM3_CH2
+ bool "Enable PWM3 channel2"
+ default n
+ config BSP_USING_PWM3_CH3
+ bool "Enable PWM3 channel3"
+ default n
+ config BSP_USING_PWM3_CH4
+ bool "Enable PWM3 channel4"
+ default n
+ endif
+
+ menuconfig BSP_USING_PWM4
+ 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
+ config BSP_USING_PWM4_CH3
+ bool "Enable PWM4 channel3"
+ default n
+ config BSP_USING_PWM4_CH4
+ bool "Enable PWM4 channel4"
default n
endif
endif
diff --git a/board/board.c b/board/board.c
index f4a5139..da912f6 100644
--- a/board/board.c
+++ b/board/board.c
@@ -98,3 +98,6 @@ INIT_PREV_EXPORT(ulog_console_backend_init);
extern int rt_hw_can_init(void);
INIT_BOARD_EXPORT(rt_hw_can_init);
+
+extern int stm32_pwm_init(void);
+INIT_DEVICE_EXPORT(stm32_pwm_init);
diff --git a/libraries/HAL_Drivers/drv_pwm.c b/libraries/HAL_Drivers/drv_pwm.c
index b74428d..ccdc477 100644
--- a/libraries/HAL_Drivers/drv_pwm.c
+++ b/libraries/HAL_Drivers/drv_pwm.c
@@ -639,7 +639,7 @@ static void pwm_get_channel(void)
#endif
}
-static int stm32_pwm_init(void)
+int stm32_pwm_init(void)
{
int i = 0;
int result = RT_EOK;
@@ -675,5 +675,5 @@ static int stm32_pwm_init(void)
__exit:
return result;
}
-INIT_DEVICE_EXPORT(stm32_pwm_init);
+//INIT_DEVICE_EXPORT(stm32_pwm_init);
#endif /* RT_USING_PWM */
diff --git a/project.uvoptx b/project.uvoptx
index 237fb5e..845e525 100644
--- a/project.uvoptx
+++ b/project.uvoptx
@@ -315,8 +315,8 @@
0
0
0
- rt-thread\components\libc\cplusplus\cxx_Semaphore.cpp
- cxx_Semaphore.cpp
+ rt-thread\components\libc\cplusplus\cxx_crt.cpp
+ cxx_crt.cpp
0
0
@@ -327,8 +327,8 @@
0
0
0
- rt-thread\components\libc\cplusplus\cxx_Thread.cpp
- cxx_Thread.cpp
+ rt-thread\components\libc\cplusplus\cxx_Semaphore.cpp
+ cxx_Semaphore.cpp
0
0
@@ -339,8 +339,8 @@
0
0
0
- rt-thread\components\libc\cplusplus\cxx_crt.cpp
- cxx_crt.cpp
+ rt-thread\components\libc\cplusplus\cxx_Thread.cpp
+ cxx_Thread.cpp
0
0
@@ -547,6 +547,18 @@
0
0
0
+ rt-thread\components\drivers\misc\rt_drv_pwm.c
+ rt_drv_pwm.c
+ 0
+ 0
+
+
+ 4
+ 29
+ 1
+ 0
+ 0
+ 0
rt-thread\components\drivers\serial\serial.c
serial.c
0
@@ -554,7 +566,7 @@
4
- 29
+ 30
1
0
0
@@ -568,13 +580,13 @@
Drivers
- 0
+ 1
0
0
0
5
- 30
+ 31
1
0
0
@@ -586,7 +598,7 @@
5
- 31
+ 32
1
0
0
@@ -598,7 +610,7 @@
5
- 32
+ 33
2
0
0
@@ -610,7 +622,7 @@
5
- 33
+ 34
1
0
0
@@ -622,7 +634,7 @@
5
- 34
+ 35
1
0
0
@@ -634,7 +646,7 @@
5
- 35
+ 36
1
0
0
@@ -646,7 +658,7 @@
5
- 36
+ 37
1
0
0
@@ -658,7 +670,19 @@
5
- 37
+ 38
+ 1
+ 0
+ 0
+ 0
+ libraries\HAL_Drivers\drv_pwm.c
+ drv_pwm.c
+ 0
+ 0
+
+
+ 5
+ 39
1
0
0
@@ -678,7 +702,7 @@
0
6
- 38
+ 40
1
0
0
@@ -690,7 +714,7 @@
6
- 39
+ 41
1
0
0
@@ -702,19 +726,7 @@
6
- 40
- 1
- 0
- 0
- 0
- rt-thread\components\fal\src\fal.c
- fal.c
- 0
- 0
-
-
- 6
- 41
+ 42
1
0
0
@@ -724,6 +736,18 @@
0
0
+
+ 6
+ 43
+ 1
+ 0
+ 0
+ 0
+ rt-thread\components\fal\src\fal.c
+ fal.c
+ 0
+ 0
+
@@ -734,7 +758,7 @@
0
7
- 42
+ 44
1
0
0
@@ -746,7 +770,7 @@
7
- 43
+ 45
1
0
0
@@ -758,7 +782,7 @@
7
- 44
+ 46
1
0
0
@@ -770,7 +794,7 @@
7
- 45
+ 47
1
0
0
@@ -790,7 +814,7 @@
0
8
- 46
+ 48
1
0
0
@@ -810,7 +834,7 @@
0
9
- 47
+ 49
1
0
0
@@ -822,7 +846,7 @@
9
- 48
+ 50
1
0
0
@@ -834,7 +858,7 @@
9
- 49
+ 51
1
0
0
@@ -846,7 +870,7 @@
9
- 50
+ 52
1
0
0
@@ -858,7 +882,7 @@
9
- 51
+ 53
1
0
0
@@ -870,7 +894,7 @@
9
- 52
+ 54
1
0
0
@@ -882,7 +906,7 @@
9
- 53
+ 55
1
0
0
@@ -894,7 +918,7 @@
9
- 54
+ 56
1
0
0
@@ -906,7 +930,7 @@
9
- 55
+ 57
1
0
0
@@ -918,7 +942,7 @@
9
- 56
+ 58
1
0
0
@@ -930,7 +954,7 @@
9
- 57
+ 59
1
0
0
@@ -942,7 +966,7 @@
9
- 58
+ 60
1
0
0
@@ -954,7 +978,7 @@
9
- 59
+ 61
1
0
0
@@ -974,7 +998,19 @@
0
10
- 60
+ 62
+ 1
+ 0
+ 0
+ 0
+ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_lptim.c
+ stm32f4xx_hal_lptim.c
+ 0
+ 0
+
+
+ 10
+ 63
1
0
0
@@ -986,7 +1022,7 @@
10
- 61
+ 64
1
0
0
@@ -998,7 +1034,19 @@
10
- 62
+ 65
+ 1
+ 0
+ 0
+ 0
+ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c
+ stm32f4xx_hal_tim_ex.c
+ 0
+ 0
+
+
+ 10
+ 66
1
0
0
@@ -1010,19 +1058,19 @@
10
- 63
+ 67
1
0
0
0
- libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_crc.c
- stm32f4xx_hal_crc.c
+ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c
+ stm32f4xx_hal_tim.c
0
0
10
- 64
+ 68
1
0
0
@@ -1034,7 +1082,7 @@
10
- 65
+ 69
1
0
0
@@ -1046,7 +1094,7 @@
10
- 66
+ 70
1
0
0
@@ -1058,7 +1106,7 @@
10
- 67
+ 71
1
0
0
@@ -1070,7 +1118,19 @@
10
- 68
+ 72
+ 1
+ 0
+ 0
+ 0
+ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_crc.c
+ stm32f4xx_hal_crc.c
+ 0
+ 0
+
+
+ 10
+ 73
1
0
0
@@ -1082,7 +1142,7 @@
10
- 69
+ 74
1
0
0
@@ -1094,7 +1154,7 @@
10
- 70
+ 75
1
0
0
@@ -1106,7 +1166,7 @@
10
- 71
+ 76
1
0
0
@@ -1118,7 +1178,7 @@
10
- 72
+ 77
1
0
0
@@ -1130,7 +1190,7 @@
10
- 73
+ 78
1
0
0
@@ -1142,7 +1202,7 @@
10
- 74
+ 79
1
0
0
@@ -1154,7 +1214,7 @@
10
- 75
+ 80
1
0
0
@@ -1166,7 +1226,7 @@
10
- 76
+ 81
1
0
0
@@ -1178,7 +1238,7 @@
10
- 77
+ 82
1
0
0
@@ -1190,7 +1250,7 @@
10
- 78
+ 83
1
0
0
@@ -1202,7 +1262,7 @@
10
- 79
+ 84
1
0
0
@@ -1214,7 +1274,7 @@
10
- 80
+ 85
1
0
0
@@ -1226,7 +1286,7 @@
10
- 81
+ 86
1
0
0
@@ -1238,7 +1298,7 @@
10
- 82
+ 87
1
0
0
@@ -1258,7 +1318,7 @@
0
11
- 83
+ 88
1
0
0
@@ -1272,13 +1332,13 @@
Utilities
- 1
+ 0
0
0
0
12
- 84
+ 89
1
0
0
@@ -1290,7 +1350,7 @@
12
- 85
+ 90
1
0
0
@@ -1302,7 +1362,7 @@
12
- 86
+ 91
1
0
0
diff --git a/project.uvprojx b/project.uvprojx
index 792e52b..648857b 100644
--- a/project.uvprojx
+++ b/project.uvprojx
@@ -54,7 +54,7 @@
1
0
1
- 0
+ 1
.\build\keil\List\
1
0
@@ -433,6 +433,11 @@
8
rt-thread\components\libc\cplusplus\cxx_Mutex.cpp
+
+ cxx_crt.cpp
+ 8
+ rt-thread\components\libc\cplusplus\cxx_crt.cpp
+
cxx_Semaphore.cpp
8
@@ -443,11 +448,6 @@
8
rt-thread\components\libc\cplusplus\cxx_Thread.cpp
-
- cxx_crt.cpp
- 8
- rt-thread\components\libc\cplusplus\cxx_crt.cpp
-
cxx_crt_init.c
1
@@ -533,6 +533,11 @@
1
rt-thread\components\drivers\misc\pin.c
+
+ rt_drv_pwm.c
+ 1
+ rt-thread\components\drivers\misc\rt_drv_pwm.c
+
serial.c
1
@@ -583,6 +588,11 @@
1
libraries\HAL_Drivers\drv_gpio.c
+
+ drv_pwm.c
+ 1
+ libraries\HAL_Drivers\drv_pwm.c
+
drv_usart.c
1
@@ -603,16 +613,16 @@
1
rt-thread\components\fal\src\fal_rtt.c
-
- fal.c
- 1
- rt-thread\components\fal\src\fal.c
-
fal_flash.c
1
rt-thread\components\fal\src\fal_flash.c
+
+ fal.c
+ 1
+ rt-thread\components\fal\src\fal.c
+
@@ -723,6 +733,11 @@
Libraries
+
+ stm32f4xx_hal_lptim.c
+ 1
+ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_lptim.c
+
stm32f4xx_hal_flash_ex.c
1
@@ -733,15 +748,20 @@
1
libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c
+
+ stm32f4xx_hal_tim_ex.c
+ 1
+ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c
+
stm32f4xx_hal_rcc_ex.c
1
libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c
- stm32f4xx_hal_crc.c
+ stm32f4xx_hal_tim.c
1
- libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_crc.c
+ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c
stm32f4xx_hal_cryp_ex.c
@@ -763,6 +783,11 @@
1
libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_usart.c
+
+ stm32f4xx_hal_crc.c
+ 1
+ libraries\STM32F4xx_HAL\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_crc.c
+
stm32f4xx_hal_pwr.c
1
diff --git a/rtconfig.h b/rtconfig.h
index a915ab7..f8cada8 100644
--- a/rtconfig.h
+++ b/rtconfig.h
@@ -85,6 +85,7 @@
#define RT_SERIAL_RB_BUFSZ 64
#define RT_USING_CAN
#define RT_USING_PIN
+#define RT_USING_PWM
#define RT_USING_WDT
/* Using USB */
@@ -291,6 +292,17 @@
#define BSP_USING_CAN1
#define BSP_USING_CAN2
#define BSP_USING_CAN3
+#define BSP_USING_PWM
+#define BSP_USING_PWM3
+#define BSP_USING_PWM3_CH1
+#define BSP_USING_PWM3_CH2
+#define BSP_USING_PWM3_CH3
+#define BSP_USING_PWM3_CH4
+#define BSP_USING_PWM4
+#define BSP_USING_PWM4_CH1
+#define BSP_USING_PWM4_CH2
+#define BSP_USING_PWM4_CH3
+#define BSP_USING_PWM4_CH4
#define BSP_USING_ON_CHIP_FLASH
/* Board extended module Drivers */