Bläddra i källkod

feat(bsp/gd32): 添加PWM和更多硬件定时器支持

- 在Kconfig中添加BSP_USING_PWM和BSP_USING_HWTIMER配置项
- 修正PWM时钟获取逻辑,使其能正确得到APB1/APB2上的定时器时钟源频率,添加在pwm结构体通道引脚资源配置项
- 修改硬件定时器初始化逻辑,修正定时器中断处理函数,适配GD32F4xx系列
- 在main.c中添加hwtimer_test和pwm_test测试函数
- 修复PWM和硬件定时器的依赖关系配置
石鸿超 1 månad sedan
förälder
incheckning
4851ea2eee

+ 16 - 3
bsp/gd32/arm/gd32405rg/.config

@@ -254,7 +254,7 @@ CONFIG_RT_USING_I2C_BITOPS=y
 # CONFIG_RT_USING_NULL is not set
 # CONFIG_RT_USING_NULL is not set
 # CONFIG_RT_USING_ZERO is not set
 # CONFIG_RT_USING_ZERO is not set
 # CONFIG_RT_USING_RANDOM is not set
 # CONFIG_RT_USING_RANDOM is not set
-# CONFIG_RT_USING_PWM is not set
+CONFIG_RT_USING_PWM=y
 # CONFIG_RT_USING_PULSE_ENCODER is not set
 # CONFIG_RT_USING_PULSE_ENCODER is not set
 # CONFIG_RT_USING_INPUT_CAPTURE is not set
 # CONFIG_RT_USING_INPUT_CAPTURE is not set
 # CONFIG_RT_USING_MTD_NOR is not set
 # CONFIG_RT_USING_MTD_NOR is not set
@@ -274,7 +274,7 @@ CONFIG_RT_USING_I2C_BITOPS=y
 # CONFIG_RT_USING_VIRTIO is not set
 # CONFIG_RT_USING_VIRTIO is not set
 CONFIG_RT_USING_PIN=y
 CONFIG_RT_USING_PIN=y
 # CONFIG_RT_USING_KTIME is not set
 # CONFIG_RT_USING_KTIME is not set
-# CONFIG_RT_USING_HWTIMER is not set
+CONFIG_RT_USING_HWTIMER=y
 # CONFIG_RT_USING_CHERRYUSB is not set
 # CONFIG_RT_USING_CHERRYUSB is not set
 # end of Device Drivers
 # end of Device Drivers
 
 
@@ -1442,7 +1442,20 @@ CONFIG_BSP_USING_UART0=y
 # CONFIG_BSP_USING_UART5 is not set
 # CONFIG_BSP_USING_UART5 is not set
 # CONFIG_BSP_USING_SPI is not set
 # CONFIG_BSP_USING_SPI is not set
 # CONFIG_BSP_USING_ADC is not set
 # CONFIG_BSP_USING_ADC is not set
-# CONFIG_BSP_USING_TIM is not set
+# CONFIG_BSP_USING_HWTIMER is not set
+CONFIG_BSP_USING_PWM=y
+CONFIG_BSP_USING_PWM0=y
+CONFIG_BSP_USING_PWM1=y
+CONFIG_BSP_USING_PWM2=y
+CONFIG_BSP_USING_PWM3=y
+CONFIG_BSP_USING_PWM4=y
+CONFIG_BSP_USING_PWM7=y
+CONFIG_BSP_USING_PWM8=y
+CONFIG_BSP_USING_PWM9=y
+CONFIG_BSP_USING_PWM10=y
+CONFIG_BSP_USING_PWM11=y
+CONFIG_BSP_USING_PWM12=y
+CONFIG_BSP_USING_PWM13=y
 # CONFIG_BSP_USING_ONCHIP_RTC is not set
 # CONFIG_BSP_USING_ONCHIP_RTC is not set
 # CONFIG_BSP_USING_WDT is not set
 # CONFIG_BSP_USING_WDT is not set
 # CONFIG_BSP_USING_SDIO is not set
 # CONFIG_BSP_USING_SDIO is not set

+ 102 - 0
bsp/gd32/arm/gd32405rg/applications/main.c

@@ -33,3 +33,105 @@ int main(void)
 
 
     return RT_EOK;
     return RT_EOK;
 }
 }
+
+#ifdef BSP_USING_HWTIMER
+/* hwtimer callback function */
+static rt_err_t hwtimer_test_cb(rt_device_t dev, rt_size_t size)
+{
+    rt_kprintf("this is hwtimer timeout callback fucntion!\n");
+    rt_kprintf("tick is :%d !\n", rt_tick_get());
+    
+    return 0;
+}
+
+#define HWTIMER_DEV_NAME "timer13"
+
+/* hwtimer test */
+static void hwtimer_test(void)
+{ 
+    rt_err_t ret = RT_EOK;
+    rt_hwtimerval_t timeout_s;      /* 定时器超时值 */
+    rt_device_t hw_dev = RT_NULL;   /* 定时器设备句柄 */
+    rt_hwtimer_mode_t mode;         /* 定时器模式 */
+    rt_uint32_t freq = 10000;               /* 计数频率 */
+
+    /* 查找定时器设备 */
+    hw_dev = rt_device_find(HWTIMER_DEV_NAME);
+    if (hw_dev == RT_NULL)
+    {
+        rt_kprintf("hwtimer sample run failed! can't find %s device!\n", HWTIMER_DEV_NAME);
+        return;
+    }
+
+    /* 以读写方式打开设备 */
+    ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
+    if (ret != RT_EOK)
+    {
+        rt_kprintf("open %s device failed!\n", HWTIMER_DEV_NAME);
+        return;
+    }
+
+    /* 设置超时回调函数 */
+    rt_device_set_rx_indicate(hw_dev, hwtimer_test_cb);
+    
+    /* 设置计数频率(若未设置该项,默认为1Mhz 或 支持的最小计数频率) */
+    rt_device_control(hw_dev, HWTIMER_CTRL_FREQ_SET, &freq);
+    /* 设置模式为周期性定时器(若未设置,默认是HWTIMER_MODE_ONESHOT)*/
+    mode = HWTIMER_MODE_PERIOD;
+    ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
+    if (ret != RT_EOK)
+    {
+        rt_kprintf("set mode failed! ret is :%d\n", ret);
+        return;
+    }
+    
+    /* 设置定时器超时值为5s并启动定时器 */
+    timeout_s.sec = 5;      /* 秒 */
+    timeout_s.usec = 0;     /* 微秒 */
+    if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
+    {
+        rt_kprintf("set timeout value failed\n");
+        return;
+    }
+}
+MSH_CMD_EXPORT(hwtimer_test, hwtimer test);
+#endif //BSP_USING_HWTIMER
+
+#ifdef BSP_USING_PWM
+
+/* pwm test */
+static void pwm_test(void)
+{
+    rt_err_t ret = RT_EOK;
+    struct rt_device_pwm *pwm2 = RT_NULL, *pwm8 = RT_NULL, *pwm1 = RT_NULL, *pwm4 = RT_NULL;
+    rt_uint32_t period = 1000;      /* 周期 */
+    rt_uint32_t pulse = 500;        /* 占空比 */
+
+    /* 查找PWM设备 */
+    pwm2 = (struct rt_device_pwm *)rt_device_find("pwm2");
+    if (pwm2 == RT_NULL)
+    {
+        rt_kprintf("pwm sample run failed! can't find %s device!\n", "pwm2");
+        return;
+    }
+    rt_pwm_set(pwm2, 3, period, pulse);
+    rt_pwm_enable(pwm2, 3);
+    rt_pwm_set(pwm2, 4, period, pulse);
+    rt_pwm_enable(pwm2, 4);
+
+    pwm8 = (struct rt_device_pwm *)rt_device_find("pwm8");
+    rt_pwm_set(pwm8, 2, period, pulse);
+    rt_pwm_enable(pwm8, 2);
+
+    pwm1 = (struct rt_device_pwm *)rt_device_find("pwm1");
+    rt_pwm_set(pwm1, 3, period, pulse);
+    rt_pwm_enable(pwm1, 3);
+
+    pwm4 = (struct rt_device_pwm *)rt_device_find("pwm4");
+    rt_pwm_set(pwm4, 1, period, pulse);
+    rt_pwm_enable(pwm4, 1);
+    rt_pwm_set(pwm4, 2, period, pulse);
+    rt_pwm_enable(pwm4, 2);
+}
+MSH_CMD_EXPORT(pwm_test, pwm test);
+#endif // BSP_USING_PWM

+ 115 - 5
bsp/gd32/arm/gd32405rg/board/Kconfig

@@ -271,24 +271,134 @@ menu "On-chip Peripheral Drivers"
                 default n
                 default n
         endif
         endif
 
 
-    menuconfig BSP_USING_TIM
+    menuconfig BSP_USING_HWTIMER
         bool "Enable timer"
         bool "Enable timer"
         default n
         default n
         select RT_USING_HWTIMER
         select RT_USING_HWTIMER
-        if BSP_USING_TIM
-            config BSP_USING_TIM10
+        if BSP_USING_HWTIMER
+            config BSP_USING_HWTIMER0
+                bool "Enable TIM0"
+                default n
+
+            config BSP_USING_HWTIMER1
+                bool "Enable TIM1"
+                default n
+
+            config BSP_USING_HWTIMER2
+                bool "Enable TIM2"
+                default n
+
+            config BSP_USING_HWTIMER3
+                bool "Enable TIM3"
+                default n
+
+            config BSP_USING_HWTIMER4
+                bool "Enable TIM4"
+                default n
+
+            config BSP_USING_HWTIMER5
+                bool "Enable TIM5"
+                default n
+
+            config BSP_USING_HWTIMER6
+                bool "Enable TIM6"
+                default y
+
+            config BSP_USING_HWTIMER7
+                bool "Enable TIM7"
+                default n
+
+            config BSP_USING_HWTIMER8
+                bool "Enable TIM8"
+                default n
+            
+            config BSP_USING_HWTIMER9
+                bool "Enable TIM9"
+                default n
+
+            config BSP_USING_HWTIMER10
                 bool "Enable TIM10"
                 bool "Enable TIM10"
                 default n
                 default n
 
 
-            config BSP_USING_TIM11
+            config BSP_USING_HWTIMER11
                 bool "Enable TIM11"
                 bool "Enable TIM11"
                 default n
                 default n
 
 
-            config BSP_USING_TIM12
+            config BSP_USING_HWTIMER12
+                bool "Enable TIM12"
+                default n
+
+            config BSP_USING_HWTIMER13
                 bool "Enable TIM13"
                 bool "Enable TIM13"
                 default n
                 default n
         endif
         endif
 
 
+    menuconfig BSP_USING_PWM
+        bool "Enable pwm"
+        select RT_USING_PWM
+        default n
+        if BSP_USING_PWM
+            config BSP_USING_PWM0
+                bool "Enable PWM0"
+                depends on !BSP_USING_HWTIMER0
+                default n
+
+            config BSP_USING_PWM1
+                bool "Enable PWM1"
+                depends on !BSP_USING_HWTIMER1
+                default n
+            
+            config BSP_USING_PWM2
+                bool "Enable PWM2"
+                depends on !BSP_USING_HWTIMER2
+                default n
+            
+            config BSP_USING_PWM3
+                bool "Enable PWM3"
+                depends on !BSP_USING_HWTIMER3
+                default n
+
+            config BSP_USING_PWM4
+                bool "Enable PWM4"
+                depends on !BSP_USING_HWTIMER4
+                default n
+
+            config BSP_USING_PWM7
+                bool "Enable PWM7"
+                depends on !BSP_USING_HWTIMER7
+                default n
+
+            config BSP_USING_PWM8
+                bool "Enable PWM8"
+                depends on !BSP_USING_HWTIMER8
+                default n
+
+            config BSP_USING_PWM9
+                bool "Enable PWM9"
+                depends on !BSP_USING_HWTIMER9
+                default n
+
+            config BSP_USING_PWM10
+                bool "Enable PWM10"
+                depends on !BSP_USING_HWTIMER10
+                default n
+
+            config BSP_USING_PWM11
+                bool "Enable PWM11"
+                depends on !BSP_USING_HWTIMER11
+                default n
+
+            config BSP_USING_PWM12
+                bool "Enable PWM12"
+                depends on !BSP_USING_HWTIMER12
+                default n
+
+            config BSP_USING_PWM13
+                bool "Enable PWM13"
+                depends on !BSP_USING_HWTIMER13
+                default n
+        endif
+
     menuconfig BSP_USING_ONCHIP_RTC
     menuconfig BSP_USING_ONCHIP_RTC
         bool "Enable RTC"
         bool "Enable RTC"
         select RT_USING_RTC
         select RT_USING_RTC

+ 139 - 75
bsp/gd32/arm/gd32405rg/project.uvoptx

@@ -193,9 +193,13 @@
       <pMultCmdsp></pMultCmdsp>
       <pMultCmdsp></pMultCmdsp>
       <SystemViewers>
       <SystemViewers>
         <Entry>
         <Entry>
-          <Name>System Viewer\RCU</Name>
+          <Name>System Viewer\TIMER1</Name>
           <WinId>35905</WinId>
           <WinId>35905</WinId>
         </Entry>
         </Entry>
+        <Entry>
+          <Name>System Viewer\TIMER2</Name>
+          <WinId>35904</WinId>
+        </Entry>
       </SystemViewers>
       </SystemViewers>
     </TargetOption>
     </TargetOption>
   </Target>
   </Target>
@@ -349,6 +353,18 @@
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
+      <PathWithFileName>..\..\..\..\components\drivers\hwtimer\hwtimer.c</PathWithFileName>
+      <FilenameWithoutPath>hwtimer.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>12</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
       <PathWithFileName>..\..\..\..\components\drivers\i2c\dev_i2c_bit_ops.c</PathWithFileName>
       <PathWithFileName>..\..\..\..\components\drivers\i2c\dev_i2c_bit_ops.c</PathWithFileName>
       <FilenameWithoutPath>dev_i2c_bit_ops.c</FilenameWithoutPath>
       <FilenameWithoutPath>dev_i2c_bit_ops.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
@@ -356,7 +372,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>12</FileNumber>
+      <FileNumber>13</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -368,7 +384,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>13</FileNumber>
+      <FileNumber>14</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -380,7 +396,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>14</FileNumber>
+      <FileNumber>15</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -392,7 +408,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>15</FileNumber>
+      <FileNumber>16</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -404,7 +420,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>16</FileNumber>
+      <FileNumber>17</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -416,7 +432,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>17</FileNumber>
+      <FileNumber>18</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -428,7 +444,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>18</FileNumber>
+      <FileNumber>19</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -440,7 +456,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>19</FileNumber>
+      <FileNumber>20</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -452,7 +468,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>20</FileNumber>
+      <FileNumber>21</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -464,7 +480,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>21</FileNumber>
+      <FileNumber>22</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -476,7 +492,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>22</FileNumber>
+      <FileNumber>23</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -488,7 +504,19 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>23</FileNumber>
+      <FileNumber>24</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\..\..\..\components\drivers\misc\rt_drv_pwm.c</PathWithFileName>
+      <FilenameWithoutPath>rt_drv_pwm.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>25</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -500,7 +528,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>3</GroupNumber>
       <GroupNumber>3</GroupNumber>
-      <FileNumber>24</FileNumber>
+      <FileNumber>26</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -520,7 +548,7 @@
     <RteFlg>0</RteFlg>
     <RteFlg>0</RteFlg>
     <File>
     <File>
       <GroupNumber>4</GroupNumber>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>25</FileNumber>
+      <FileNumber>27</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -532,7 +560,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>4</GroupNumber>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>26</FileNumber>
+      <FileNumber>28</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -544,7 +572,31 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>4</GroupNumber>
       <GroupNumber>4</GroupNumber>
-      <FileNumber>27</FileNumber>
+      <FileNumber>29</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\libraries\gd32_drivers\drv_hwtimer.c</PathWithFileName>
+      <FilenameWithoutPath>drv_hwtimer.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>4</GroupNumber>
+      <FileNumber>30</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\libraries\gd32_drivers\drv_pwm.c</PathWithFileName>
+      <FilenameWithoutPath>drv_pwm.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>4</GroupNumber>
+      <FileNumber>31</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -564,49 +616,49 @@
     <RteFlg>0</RteFlg>
     <RteFlg>0</RteFlg>
     <File>
     <File>
       <GroupNumber>5</GroupNumber>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>28</FileNumber>
+      <FileNumber>32</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\components\finsh\shell.c</PathWithFileName>
-      <FilenameWithoutPath>shell.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\components\finsh\msh_parse.c</PathWithFileName>
+      <FilenameWithoutPath>msh_parse.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>5</GroupNumber>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>29</FileNumber>
+      <FileNumber>33</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\components\finsh\msh.c</PathWithFileName>
-      <FilenameWithoutPath>msh.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\components\finsh\shell.c</PathWithFileName>
+      <FilenameWithoutPath>shell.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>5</GroupNumber>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>30</FileNumber>
+      <FileNumber>34</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\components\finsh\cmd.c</PathWithFileName>
-      <FilenameWithoutPath>cmd.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\components\finsh\msh.c</PathWithFileName>
+      <FilenameWithoutPath>msh.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>5</GroupNumber>
       <GroupNumber>5</GroupNumber>
-      <FileNumber>31</FileNumber>
+      <FileNumber>35</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\components\finsh\msh_parse.c</PathWithFileName>
-      <FilenameWithoutPath>msh_parse.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\components\finsh\cmd.c</PathWithFileName>
+      <FilenameWithoutPath>cmd.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
@@ -620,7 +672,7 @@
     <RteFlg>0</RteFlg>
     <RteFlg>0</RteFlg>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>32</FileNumber>
+      <FileNumber>36</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -632,7 +684,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>33</FileNumber>
+      <FileNumber>37</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -644,7 +696,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>34</FileNumber>
+      <FileNumber>38</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -656,7 +708,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>35</FileNumber>
+      <FileNumber>39</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -668,7 +720,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>36</FileNumber>
+      <FileNumber>40</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -680,7 +732,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>37</FileNumber>
+      <FileNumber>41</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -692,7 +744,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>38</FileNumber>
+      <FileNumber>42</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -704,7 +756,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>39</FileNumber>
+      <FileNumber>43</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -716,7 +768,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>40</FileNumber>
+      <FileNumber>44</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -728,7 +780,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>41</FileNumber>
+      <FileNumber>45</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -740,7 +792,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>42</FileNumber>
+      <FileNumber>46</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -752,7 +804,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>43</FileNumber>
+      <FileNumber>47</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -764,7 +816,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>44</FileNumber>
+      <FileNumber>48</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -776,7 +828,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>45</FileNumber>
+      <FileNumber>49</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -788,7 +840,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>6</GroupNumber>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>46</FileNumber>
+      <FileNumber>50</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -808,61 +860,61 @@
     <RteFlg>0</RteFlg>
     <RteFlg>0</RteFlg>
     <File>
     <File>
       <GroupNumber>7</GroupNumber>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>47</FileNumber>
+      <FileNumber>51</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\src\klibc\kstdio.c</PathWithFileName>
-      <FilenameWithoutPath>kstdio.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\src\klibc\kstring.c</PathWithFileName>
+      <FilenameWithoutPath>kstring.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>7</GroupNumber>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>48</FileNumber>
+      <FileNumber>52</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\src\klibc\rt_vsnprintf_tiny.c</PathWithFileName>
-      <FilenameWithoutPath>rt_vsnprintf_tiny.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\src\klibc\rt_vsscanf.c</PathWithFileName>
+      <FilenameWithoutPath>rt_vsscanf.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>7</GroupNumber>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>49</FileNumber>
+      <FileNumber>53</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\src\klibc\kstring.c</PathWithFileName>
-      <FilenameWithoutPath>kstring.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\src\klibc\kerrno.c</PathWithFileName>
+      <FilenameWithoutPath>kerrno.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>7</GroupNumber>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>50</FileNumber>
+      <FileNumber>54</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\src\klibc\rt_vsscanf.c</PathWithFileName>
-      <FilenameWithoutPath>rt_vsscanf.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\src\klibc\kstdio.c</PathWithFileName>
+      <FilenameWithoutPath>kstdio.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>7</GroupNumber>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>51</FileNumber>
+      <FileNumber>55</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <bDave2>0</bDave2>
-      <PathWithFileName>..\..\..\..\src\klibc\kerrno.c</PathWithFileName>
-      <FilenameWithoutPath>kerrno.c</FilenameWithoutPath>
+      <PathWithFileName>..\..\..\..\src\klibc\rt_vsnprintf_tiny.c</PathWithFileName>
+      <FilenameWithoutPath>rt_vsnprintf_tiny.c</FilenameWithoutPath>
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
@@ -876,7 +928,7 @@
     <RteFlg>0</RteFlg>
     <RteFlg>0</RteFlg>
     <File>
     <File>
       <GroupNumber>8</GroupNumber>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>52</FileNumber>
+      <FileNumber>56</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -888,7 +940,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>8</GroupNumber>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>53</FileNumber>
+      <FileNumber>57</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -900,7 +952,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>8</GroupNumber>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>54</FileNumber>
+      <FileNumber>58</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -912,7 +964,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>8</GroupNumber>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>55</FileNumber>
+      <FileNumber>59</FileNumber>
       <FileType>2</FileType>
       <FileType>2</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -924,7 +976,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>8</GroupNumber>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>56</FileNumber>
+      <FileNumber>60</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -938,13 +990,13 @@
 
 
   <Group>
   <Group>
     <GroupName>Libraries</GroupName>
     <GroupName>Libraries</GroupName>
-    <tvExp>0</tvExp>
+    <tvExp>1</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>
     <RteFlg>0</RteFlg>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>57</FileNumber>
+      <FileNumber>61</FileNumber>
       <FileType>2</FileType>
       <FileType>2</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -956,7 +1008,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>58</FileNumber>
+      <FileNumber>62</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -968,7 +1020,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>59</FileNumber>
+      <FileNumber>63</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -980,7 +1032,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>60</FileNumber>
+      <FileNumber>64</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -992,7 +1044,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>61</FileNumber>
+      <FileNumber>65</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1004,7 +1056,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>62</FileNumber>
+      <FileNumber>66</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1016,7 +1068,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>63</FileNumber>
+      <FileNumber>67</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1028,7 +1080,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>64</FileNumber>
+      <FileNumber>68</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1040,7 +1092,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>65</FileNumber>
+      <FileNumber>69</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1052,7 +1104,7 @@
     </File>
     </File>
     <File>
     <File>
       <GroupNumber>9</GroupNumber>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>66</FileNumber>
+      <FileNumber>70</FileNumber>
       <FileType>1</FileType>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1062,6 +1114,18 @@
       <RteFlg>0</RteFlg>
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
       <bShared>0</bShared>
     </File>
     </File>
+    <File>
+      <GroupNumber>9</GroupNumber>
+      <FileNumber>71</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>.\packages\gd32-arm-series-latest\GD32F4xx\GD32F4xx_standard_peripheral\Source\gd32f4xx_timer.c</PathWithFileName>
+      <FilenameWithoutPath>gd32f4xx_timer.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
   </Group>
   </Group>
 
 
   <Group>
   <Group>

+ 145 - 18
bsp/gd32/arm/gd32405rg/project.uvprojx

@@ -338,9 +338,9 @@
             <v6Rtti>0</v6Rtti>
             <v6Rtti>0</v6Rtti>
             <VariousControls>
             <VariousControls>
               <MiscControls></MiscControls>
               <MiscControls></MiscControls>
-              <Define>GD32F405, __CLK_TCK=RT_TICK_PER_SECOND, HXTAL_VALUE=8000000, RT_USING_LIBC, USE_STDPERIPH_DRIVER, __STDC_LIMIT_MACROS, RT_USING_ARMLIBC, __RTTHREAD__</Define>
+              <Define>RT_USING_LIBC, HXTAL_VALUE=8000000U, RT_USING_ARMLIBC, USE_STDPERIPH_DRIVER, __RTTHREAD__, __CLK_TCK=RT_TICK_PER_SECOND, GD32F405, __STDC_LIMIT_MACROS</Define>
               <Undefine></Undefine>
               <Undefine></Undefine>
-              <IncludePath>applications;..\..\..\..\components\drivers\include;..\..\..\..\components\libc\posix\io\epoll;..\..\..\..\components\libc\compilers\common\extension\fcntl\octal;..\..\..\..\components\drivers\phy;..\..\..\..\components\libc\compilers\common\extension;.;..\..\..\..\components\finsh;..\..\..\..\components\drivers\include;..\..\..\..\components\libc\posix\ipc;..\..\..\..\components\net\utest;..\..\..\..\include;..\..\..\..\components\drivers\include;board;..\..\..\..\components\libc\posix\io\eventfd;..\..\..\..\components\drivers\smp_call;packages\gd32-arm-cmsis-latest\GD32F4xx;..\..\..\..\components\libc\posix\io\poll;..\..\..\..\components\drivers\include;..\libraries\gd32_drivers;..\..\..\..\components\drivers\include;packages\gd32-arm-series-latest\GD32F4xx\GD32F4xx_standard_peripheral\Include;..\..\..\..\components\libc\compilers\common\include;..\..\..\..\libcpu\arm\cortex-m4;..\..\..\..\libcpu\arm\common;packages\gd32-arm-cmsis-latest\GD32F4xx\GD\GD32F4xx\Include;..\..\..\..\components\drivers\include</IncludePath>
+              <IncludePath>packages\gd32-arm-cmsis-latest\GD32F4xx\GD\GD32F4xx\Include;packages\gd32-arm-cmsis-latest\GD32F4xx;.;..\..\..\..\components\drivers\include;..\..\..\..\components\libc\compilers\common\extension\fcntl\octal;..\..\..\..\components\drivers\smp_call;..\..\..\..\components\libc\posix\io\poll;..\..\..\..\components\net\utest;applications;..\..\..\..\components\libc\compilers\common\extension;..\..\..\..\components\libc\posix\io\epoll;..\..\..\..\components\libc\compilers\common\include;..\..\..\..\components\libc\posix\ipc;..\..\..\..\components\drivers\include;packages\gd32-arm-series-latest\GD32F4xx\GD32F4xx_standard_peripheral\Include;..\..\..\..\components\drivers\phy;..\..\..\..\components\drivers\include;..\..\..\..\components\drivers\include;board;..\..\..\..\libcpu\arm\cortex-m4;..\..\..\..\libcpu\arm\common;..\..\..\..\include;..\..\..\..\components\drivers\include;..\..\..\..\components\drivers\include;..\..\..\..\components\finsh;..\..\..\..\components\drivers\include;..\libraries\gd32_drivers;..\..\..\..\components\drivers\include;..\..\..\..\components\libc\posix\io\eventfd</IncludePath>
             </VariousControls>
             </VariousControls>
           </Cads>
           </Cads>
           <Aads>
           <Aads>
@@ -371,7 +371,7 @@
             <TextAddressRange>0x08000000</TextAddressRange>
             <TextAddressRange>0x08000000</TextAddressRange>
             <DataAddressRange>0x20000000</DataAddressRange>
             <DataAddressRange>0x20000000</DataAddressRange>
             <pXoBase></pXoBase>
             <pXoBase></pXoBase>
-            <ScatterFile>.\board\linker_scripts\link.sct</ScatterFile>
+            <ScatterFile>.\gd32_rom.ld</ScatterFile>
             <IncludeLibs></IncludeLibs>
             <IncludeLibs></IncludeLibs>
             <IncludeLibsPath></IncludeLibsPath>
             <IncludeLibsPath></IncludeLibsPath>
             <Misc></Misc>
             <Misc></Misc>
@@ -495,6 +495,62 @@
                 </FileArmAds>
                 </FileArmAds>
               </FileOption>
               </FileOption>
             </File>
             </File>
+            <File>
+              <FileName>hwtimer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\components\drivers\hwtimer\hwtimer.c</FilePath>
+              <FileOption>
+                <CommonProperty>
+                  <UseCPPCompiler>2</UseCPPCompiler>
+                  <RVCTCodeConst>0</RVCTCodeConst>
+                  <RVCTZI>0</RVCTZI>
+                  <RVCTOtherData>0</RVCTOtherData>
+                  <ModuleSelection>0</ModuleSelection>
+                  <IncludeInBuild>1</IncludeInBuild>
+                  <AlwaysBuild>0</AlwaysBuild>
+                  <GenerateAssemblyFile>0</GenerateAssemblyFile>
+                  <AssembleAssemblyFile>0</AssembleAssemblyFile>
+                  <PublicsOnly>0</PublicsOnly>
+                  <StopOnExitCode>3</StopOnExitCode>
+                  <CustomArgument></CustomArgument>
+                  <IncludeLibraryModules></IncludeLibraryModules>
+                  <ComprImg>1</ComprImg>
+                </CommonProperty>
+                <FileArmAds>
+                  <Cads>
+                    <interw>2</interw>
+                    <Optim>0</Optim>
+                    <oTime>2</oTime>
+                    <SplitLS>2</SplitLS>
+                    <OneElfS>2</OneElfS>
+                    <Strict>2</Strict>
+                    <EnumInt>2</EnumInt>
+                    <PlainCh>2</PlainCh>
+                    <Ropi>2</Ropi>
+                    <Rwpi>2</Rwpi>
+                    <wLevel>0</wLevel>
+                    <uThumb>2</uThumb>
+                    <uSurpInc>2</uSurpInc>
+                    <uC99>2</uC99>
+                    <uGnu>2</uGnu>
+                    <useXO>2</useXO>
+                    <v6Lang>0</v6Lang>
+                    <v6LangP>0</v6LangP>
+                    <vShortEn>2</vShortEn>
+                    <vShortWch>2</vShortWch>
+                    <v6Lto>2</v6Lto>
+                    <v6WtE>2</v6WtE>
+                    <v6Rtti>2</v6Rtti>
+                    <VariousControls>
+                      <MiscControls> </MiscControls>
+                      <Define>__RT_IPC_SOURCE__</Define>
+                      <Undefine> </Undefine>
+                      <IncludePath></IncludePath>
+                    </VariousControls>
+                  </Cads>
+                </FileArmAds>
+              </FileOption>
+            </File>
             <File>
             <File>
               <FileName>dev_i2c_bit_ops.c</FileName>
               <FileName>dev_i2c_bit_ops.c</FileName>
               <FileType>1</FileType>
               <FileType>1</FileType>
@@ -1167,6 +1223,62 @@
                 </FileArmAds>
                 </FileArmAds>
               </FileOption>
               </FileOption>
             </File>
             </File>
+            <File>
+              <FileName>rt_drv_pwm.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\components\drivers\misc\rt_drv_pwm.c</FilePath>
+              <FileOption>
+                <CommonProperty>
+                  <UseCPPCompiler>2</UseCPPCompiler>
+                  <RVCTCodeConst>0</RVCTCodeConst>
+                  <RVCTZI>0</RVCTZI>
+                  <RVCTOtherData>0</RVCTOtherData>
+                  <ModuleSelection>0</ModuleSelection>
+                  <IncludeInBuild>1</IncludeInBuild>
+                  <AlwaysBuild>0</AlwaysBuild>
+                  <GenerateAssemblyFile>0</GenerateAssemblyFile>
+                  <AssembleAssemblyFile>0</AssembleAssemblyFile>
+                  <PublicsOnly>0</PublicsOnly>
+                  <StopOnExitCode>3</StopOnExitCode>
+                  <CustomArgument></CustomArgument>
+                  <IncludeLibraryModules></IncludeLibraryModules>
+                  <ComprImg>1</ComprImg>
+                </CommonProperty>
+                <FileArmAds>
+                  <Cads>
+                    <interw>2</interw>
+                    <Optim>0</Optim>
+                    <oTime>2</oTime>
+                    <SplitLS>2</SplitLS>
+                    <OneElfS>2</OneElfS>
+                    <Strict>2</Strict>
+                    <EnumInt>2</EnumInt>
+                    <PlainCh>2</PlainCh>
+                    <Ropi>2</Ropi>
+                    <Rwpi>2</Rwpi>
+                    <wLevel>0</wLevel>
+                    <uThumb>2</uThumb>
+                    <uSurpInc>2</uSurpInc>
+                    <uC99>2</uC99>
+                    <uGnu>2</uGnu>
+                    <useXO>2</useXO>
+                    <v6Lang>0</v6Lang>
+                    <v6LangP>0</v6LangP>
+                    <vShortEn>2</vShortEn>
+                    <vShortWch>2</vShortWch>
+                    <v6Lto>2</v6Lto>
+                    <v6WtE>2</v6WtE>
+                    <v6Rtti>2</v6Rtti>
+                    <VariousControls>
+                      <MiscControls> </MiscControls>
+                      <Define>__RT_IPC_SOURCE__</Define>
+                      <Undefine> </Undefine>
+                      <IncludePath></IncludePath>
+                    </VariousControls>
+                  </Cads>
+                </FileArmAds>
+              </FileOption>
+            </File>
             <File>
             <File>
               <FileName>dev_pin.c</FileName>
               <FileName>dev_pin.c</FileName>
               <FileType>1</FileType>
               <FileType>1</FileType>
@@ -1294,6 +1406,16 @@
               <FileType>1</FileType>
               <FileType>1</FileType>
               <FilePath>..\libraries\gd32_drivers\drv_gpio.c</FilePath>
               <FilePath>..\libraries\gd32_drivers\drv_gpio.c</FilePath>
             </File>
             </File>
+            <File>
+              <FileName>drv_hwtimer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\libraries\gd32_drivers\drv_hwtimer.c</FilePath>
+            </File>
+            <File>
+              <FileName>drv_pwm.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\libraries\gd32_drivers\drv_pwm.c</FilePath>
+            </File>
             <File>
             <File>
               <FileName>drv_usart.c</FileName>
               <FileName>drv_usart.c</FileName>
               <FileType>1</FileType>
               <FileType>1</FileType>
@@ -1304,6 +1426,11 @@
         <Group>
         <Group>
           <GroupName>Finsh</GroupName>
           <GroupName>Finsh</GroupName>
           <Files>
           <Files>
+            <File>
+              <FileName>msh_parse.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\components\finsh\msh_parse.c</FilePath>
+            </File>
             <File>
             <File>
               <FileName>shell.c</FileName>
               <FileName>shell.c</FileName>
               <FileType>1</FileType>
               <FileType>1</FileType>
@@ -1319,11 +1446,6 @@
               <FileType>1</FileType>
               <FileType>1</FileType>
               <FilePath>..\..\..\..\components\finsh\cmd.c</FilePath>
               <FilePath>..\..\..\..\components\finsh\cmd.c</FilePath>
             </File>
             </File>
-            <File>
-              <FileName>msh_parse.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\..\..\components\finsh\msh_parse.c</FilePath>
-            </File>
           </Files>
           </Files>
         </Group>
         </Group>
         <Group>
         <Group>
@@ -2174,16 +2296,6 @@
         <Group>
         <Group>
           <GroupName>klibc</GroupName>
           <GroupName>klibc</GroupName>
           <Files>
           <Files>
-            <File>
-              <FileName>kstdio.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\..\..\src\klibc\kstdio.c</FilePath>
-            </File>
-            <File>
-              <FileName>rt_vsnprintf_tiny.c</FileName>
-              <FileType>1</FileType>
-              <FilePath>..\..\..\..\src\klibc\rt_vsnprintf_tiny.c</FilePath>
-            </File>
             <File>
             <File>
               <FileName>kstring.c</FileName>
               <FileName>kstring.c</FileName>
               <FileType>1</FileType>
               <FileType>1</FileType>
@@ -2199,6 +2311,16 @@
               <FileType>1</FileType>
               <FileType>1</FileType>
               <FilePath>..\..\..\..\src\klibc\kerrno.c</FilePath>
               <FilePath>..\..\..\..\src\klibc\kerrno.c</FilePath>
             </File>
             </File>
+            <File>
+              <FileName>kstdio.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\src\klibc\kstdio.c</FilePath>
+            </File>
+            <File>
+              <FileName>rt_vsnprintf_tiny.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\..\..\..\src\klibc\rt_vsnprintf_tiny.c</FilePath>
+            </File>
           </Files>
           </Files>
         </Group>
         </Group>
         <Group>
         <Group>
@@ -2284,6 +2406,11 @@
               <FileType>1</FileType>
               <FileType>1</FileType>
               <FilePath>packages\gd32-arm-series-latest\GD32F4xx\GD32F4xx_standard_peripheral\Source\gd32f4xx_usart.c</FilePath>
               <FilePath>packages\gd32-arm-series-latest\GD32F4xx\GD32F4xx_standard_peripheral\Source\gd32f4xx_usart.c</FilePath>
             </File>
             </File>
+            <File>
+              <FileName>gd32f4xx_timer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>.\packages\gd32-arm-series-latest\GD32F4xx\GD32F4xx_standard_peripheral\Source\gd32f4xx_timer.c</FilePath>
+            </File>
           </Files>
           </Files>
         </Group>
         </Group>
         <Group>
         <Group>

+ 15 - 0
bsp/gd32/arm/gd32405rg/rtconfig.h

@@ -149,7 +149,9 @@
 #define RT_SERIAL_RB_BUFSZ 64
 #define RT_SERIAL_RB_BUFSZ 64
 #define RT_USING_I2C
 #define RT_USING_I2C
 #define RT_USING_I2C_BITOPS
 #define RT_USING_I2C_BITOPS
+#define RT_USING_PWM
 #define RT_USING_PIN
 #define RT_USING_PIN
+#define RT_USING_HWTIMER
 /* end of Device Drivers */
 /* end of Device Drivers */
 
 
 /* C/C++ and POSIX layer */
 /* C/C++ and POSIX layer */
@@ -420,6 +422,19 @@
 #define BSP_USING_GPIO
 #define BSP_USING_GPIO
 #define BSP_USING_UART
 #define BSP_USING_UART
 #define BSP_USING_UART0
 #define BSP_USING_UART0
+#define BSP_USING_PWM
+#define BSP_USING_PWM0
+#define BSP_USING_PWM1
+#define BSP_USING_PWM2
+#define BSP_USING_PWM3
+#define BSP_USING_PWM4
+#define BSP_USING_PWM7
+#define BSP_USING_PWM8
+#define BSP_USING_PWM9
+#define BSP_USING_PWM10
+#define BSP_USING_PWM11
+#define BSP_USING_PWM12
+#define BSP_USING_PWM13
 #define BSP_USING_GD_DBG
 #define BSP_USING_GD_DBG
 /* end of On-chip Peripheral Drivers */
 /* end of On-chip Peripheral Drivers */
 
 

+ 168 - 6
bsp/gd32/arm/libraries/gd32_drivers/drv_hwtimer.c

@@ -6,6 +6,10 @@
  * Change Logs:
  * Change Logs:
  * Date           Author            Notes
  * Date           Author            Notes
  * 2021-02-25     iysheng           first version
  * 2021-02-25     iysheng           first version
+ * 2025-12-26     shihongchao       Configure GD32F4xx chips interrupt handlers, 
+ *                                  relocate clock and interrupt initialization 
+ *                                  to the _init function, and implement deinit 
+ *                                  functionality
  */
  */
 
 
 #include <board.h>
 #include <board.h>
@@ -114,16 +118,30 @@ static void __set_timerx_freq(uint32_t timerx, uint32_t freq)
 static void gd32_hwtimer_init(struct rt_hwtimer_device *timer, rt_uint32_t state)
 static void gd32_hwtimer_init(struct rt_hwtimer_device *timer, rt_uint32_t state)
 {
 {
     uint32_t timer_base = (uint32_t)timer->parent.user_data;
     uint32_t timer_base = (uint32_t)timer->parent.user_data;
+    gd32_hwtimer_device *hwtimer = rt_container_of(timer, gd32_hwtimer_device, hwtimer_dev);
     timer_parameter_struct initpara;
     timer_parameter_struct initpara;
 
 
     if (state)
     if (state)
     {
     {
+        rcu_periph_clock_enable(hwtimer->hw_data.rcu);
+        NVIC_SetPriority(hwtimer->hw_data.irqn, 0);
+        NVIC_EnableIRQ(hwtimer->hw_data.irqn);
+        timer_interrupt_enable(timer_base, TIMER_INT_UP);
+
         timer_internal_clock_config(timer_base);
         timer_internal_clock_config(timer_base);
         timer_struct_para_init(&initpara);
         timer_struct_para_init(&initpara);
         initpara.period =  timer->info->maxcnt;
         initpara.period =  timer->info->maxcnt;
         timer_init(timer_base, &initpara);
         timer_init(timer_base, &initpara);
         __set_timerx_freq(timer_base, timer->info->maxfreq);
         __set_timerx_freq(timer_base, timer->info->maxfreq);
     }
     }
+    else
+    {
+        rcu_periph_clock_disable(hwtimer->hw_data.rcu);
+        NVIC_DisableIRQ(hwtimer->hw_data.irqn);
+        timer_interrupt_disable(timer_base, TIMER_INT_UP);
+
+        timer_disable(timer_base);
+    }
 }
 }
 
 
 static rt_err_t gd32_hwtimer_start(struct rt_hwtimer_device *timer, \
 static rt_err_t gd32_hwtimer_start(struct rt_hwtimer_device *timer, \
@@ -200,7 +218,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer0",
         "timer0",
         {
         {
              TIMER0,
              TIMER0,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER0_UP_TIMER9_IRQn,
+#else
              TIMER0_UP_IRQn,
              TIMER0_UP_IRQn,
+#endif
              RCU_TIMER0,
              RCU_TIMER0,
         },
         },
         {0},
         {0},
@@ -285,7 +307,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer5",
         "timer5",
         {
         {
              TIMER5,
              TIMER5,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER5_DAC_IRQn,
+#else
              TIMER5_IRQn,
              TIMER5_IRQn,
+#endif
              RCU_TIMER5,
              RCU_TIMER5,
         },
         },
         {0},
         {0},
@@ -319,7 +345,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer7",
         "timer7",
         {
         {
              TIMER7,
              TIMER7,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER7_UP_TIMER12_IRQn,
+#else
              TIMER7_UP_IRQn,
              TIMER7_UP_IRQn,
+#endif
              RCU_TIMER7,
              RCU_TIMER7,
         },
         },
         {0},
         {0},
@@ -336,7 +366,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer8",
         "timer8",
         {
         {
              TIMER8,
              TIMER8,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER0_BRK_TIMER8_IRQn,
+#else
              TIMER8_IRQn,
              TIMER8_IRQn,
+#endif
              RCU_TIMER8,
              RCU_TIMER8,
         },
         },
         {0},
         {0},
@@ -353,7 +387,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer9",
         "timer9",
         {
         {
              TIMER9,
              TIMER9,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER0_UP_TIMER9_IRQn,
+#else
              TIMER9_IRQn,
              TIMER9_IRQn,
+#endif
              RCU_TIMER9,
              RCU_TIMER9,
         },
         },
         {0},
         {0},
@@ -370,7 +408,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer10",
         "timer10",
         {
         {
              TIMER10,
              TIMER10,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER0_TRG_CMT_TIMER10_IRQn,
+#else
              TIMER10_IRQn,
              TIMER10_IRQn,
+#endif
              RCU_TIMER10,
              RCU_TIMER10,
         },
         },
         {0},
         {0},
@@ -387,7 +429,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer11",
         "timer11",
         {
         {
              TIMER11,
              TIMER11,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER7_BRK_TIMER11_IRQn,
+#else
              TIMER11_IRQn,
              TIMER11_IRQn,
+#endif
              RCU_TIMER11,
              RCU_TIMER11,
         },
         },
         {0},
         {0},
@@ -404,7 +450,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer12",
         "timer12",
         {
         {
              TIMER12,
              TIMER12,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER7_UP_TIMER12_IRQn,
+#else
              TIMER12_IRQn,
              TIMER12_IRQn,
+#endif
              RCU_TIMER12,
              RCU_TIMER12,
         },
         },
         {0},
         {0},
@@ -421,7 +471,11 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
         "timer13",
         "timer13",
         {
         {
              TIMER13,
              TIMER13,
+#ifdef SOC_SERIES_GD32F4xx
+            TIMER7_TRG_CMT_TIMER13_IRQn,
+#else
              TIMER13_IRQn,
              TIMER13_IRQn,
+#endif
              RCU_TIMER13,
              RCU_TIMER13,
         },
         },
         {0},
         {0},
@@ -436,12 +490,31 @@ static gd32_hwtimer_device g_gd32_hwtimer[] = {
 };
 };
 
 
 #ifdef BSP_USING_HWTIMER0
 #ifdef BSP_USING_HWTIMER0
+#ifdef SOC_SERIES_GD32F4xx
+void TIMER0_UP_TIMER9_IRQHandler(void)
+#else
 void TIMER0_UP_IRQHandler(void)
 void TIMER0_UP_IRQHandler(void)
+#endif
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
-    rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM0_INDEX].hwtimer_dev);
-    timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM0_INDEX].hwtimer_dev.parent.user_data, \
+#ifdef BSP_USING_HWTIMER0
+    if(timer_interrupt_flag_get((uint32_t)g_gd32_hwtimer[TIM0_INDEX].hwtimer_dev.parent.user_data, \
+        TIMER_INT_UP))
+    {
+        rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM0_INDEX].hwtimer_dev);
+        timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM0_INDEX].hwtimer_dev.parent.user_data, \
+            TIMER_INT_UP);
+    }
+#endif
+#ifdef BSP_USING_HWTIMER9
+    if(timer_interrupt_flag_get((uint32_t)g_gd32_hwtimer[TIM9_INDEX].hwtimer_dev.parent.user_data, \
+        TIMER_INT_UP))
+    {
+        rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM9_INDEX].hwtimer_dev);
+        timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM9_INDEX].hwtimer_dev.parent.user_data, \
         TIMER_INT_UP);
         TIMER_INT_UP);
+    }
+#endif
     rt_interrupt_leave();
     rt_interrupt_leave();
 }
 }
 #endif
 #endif
@@ -491,7 +564,11 @@ void TIMER4_IRQHandler(void)
 #endif
 #endif
 
 
 #ifdef BSP_USING_HWTIMER5
 #ifdef BSP_USING_HWTIMER5
+#ifdef SOC_SERIES_GD32F4xx
+void TIMER5_DAC_IRQHandler(void)
+#else
 void TIMER5_IRQHandler(void)
 void TIMER5_IRQHandler(void)
+#endif
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
     rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM5_INDEX].hwtimer_dev);
     rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM5_INDEX].hwtimer_dev);
@@ -512,7 +589,34 @@ void TIMER6_IRQHandler(void)
 }
 }
 #endif
 #endif
 
 
+#ifdef SOC_SERIES_GD32F4xx
+#if defined(BSP_USING_HWTIMER7) || defined(BSP_USING_HWTIMER12)
+void TIMER7_UP_TIMER12_IRQHandler(void)
+{
+    rt_interrupt_enter();
 #ifdef BSP_USING_HWTIMER7
 #ifdef BSP_USING_HWTIMER7
+    if(timer_interrupt_flag_get((uint32_t)g_gd32_hwtimer[TIM7_INDEX].hwtimer_dev.parent.user_data, \
+        TIMER_INT_UP))
+    {
+        rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM7_INDEX].hwtimer_dev);
+        timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM7_INDEX].hwtimer_dev.parent.user_data, \
+            TIMER_INT_UP);
+    }
+#endif
+#ifdef BSP_USING_HWTIMER12
+    if(timer_interrupt_flag_get((uint32_t)g_gd32_hwtimer[TIM12_INDEX].hwtimer_dev.parent.user_data, \
+        TIMER_INT_UP))
+    {
+        rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM12_INDEX].hwtimer_dev);
+        timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM12_INDEX].hwtimer_dev.parent.user_data, \
+            TIMER_INT_UP);
+    }
+#endif
+    rt_interrupt_leave();
+}
+#endif
+#else
+#if defined(BSP_USING_HWTIMER7)
 void TIMER7_UP_IRQHandler(void)
 void TIMER7_UP_IRQHandler(void)
 {
 {
     rt_interrupt_enter();
     rt_interrupt_enter();
@@ -522,6 +626,68 @@ void TIMER7_UP_IRQHandler(void)
     rt_interrupt_leave();
     rt_interrupt_leave();
 }
 }
 #endif
 #endif
+#endif
+
+
+#ifdef BSP_USING_HWTIMER8
+#ifdef SOC_SERIES_GD32F4xx
+void TIMER0_BRK_TIMER8_IRQHandler(void)
+#else
+void TIMER8_UP_IRQHandler(void)
+#endif
+{
+    rt_interrupt_enter();
+    rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM8_INDEX].hwtimer_dev);
+    timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM8_INDEX].hwtimer_dev.parent.user_data, \
+        TIMER_INT_UP);
+    rt_interrupt_leave();
+}
+#endif
+
+#ifdef BSP_USING_HWTIMER10
+#ifdef SOC_SERIES_GD32F4xx
+void TIMER0_TRG_CMT_TIMER10_IRQHandler(void)
+#else
+void TIMER10_IRQHandler(void)
+#endif
+{
+    rt_interrupt_enter();
+    rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM10_INDEX].hwtimer_dev);
+    timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM10_INDEX].hwtimer_dev.parent.user_data, \
+        TIMER_INT_UP);
+    rt_interrupt_leave();
+}
+#endif
+
+#ifdef BSP_USING_HWTIMER11
+#ifdef SOC_SERIES_GD32F4xx
+void TIMER7_BRK_TIMER11_IRQHandler(void)
+#else
+void TIMER10_IRQHandler(void)
+#endif
+{
+    rt_interrupt_enter();
+    rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM11_INDEX].hwtimer_dev);
+    timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM11_INDEX].hwtimer_dev.parent.user_data, \
+        TIMER_INT_UP);
+    rt_interrupt_leave();
+}
+#endif
+
+#ifdef BSP_USING_HWTIMER13
+#ifdef SOC_SERIES_GD32F4xx
+void TIMER7_TRG_CMT_TIMER13_IRQHandler(void)
+#else
+void TIMER10_IRQHandler(void)
+#endif
+{
+    rt_interrupt_enter();
+    rt_device_hwtimer_isr(&g_gd32_hwtimer[TIM13_INDEX].hwtimer_dev);
+    timer_flag_clear((uint32_t)g_gd32_hwtimer[TIM13_INDEX].hwtimer_dev.parent.user_data, \
+        TIMER_INT_UP);
+    rt_interrupt_leave();
+}
+#endif
 
 
 static int rt_hwtimer_init(void)
 static int rt_hwtimer_init(void)
 {
 {
@@ -532,10 +698,6 @@ static int rt_hwtimer_init(void)
         g_gd32_hwtimer[i].hwtimer_dev.ops = &g_gd32_hwtimer_ops;
         g_gd32_hwtimer[i].hwtimer_dev.ops = &g_gd32_hwtimer_ops;
         g_gd32_hwtimer[i].hwtimer_dev.info = &g_gd32_hwtimer[i].hwtimer_info;
         g_gd32_hwtimer[i].hwtimer_dev.info = &g_gd32_hwtimer[i].hwtimer_info;
 
 
-        rcu_periph_clock_enable(g_gd32_hwtimer[i].hw_data.rcu);
-        NVIC_SetPriority(g_gd32_hwtimer[i].hw_data.irqn, 0);
-        NVIC_EnableIRQ(g_gd32_hwtimer[i].hw_data.irqn);
-        timer_interrupt_enable(g_gd32_hwtimer[i].hw_data.reg_base, TIMER_INT_UP);
         ret = rt_device_hwtimer_register(&g_gd32_hwtimer[i].hwtimer_dev, \
         ret = rt_device_hwtimer_register(&g_gd32_hwtimer[i].hwtimer_dev, \
             g_gd32_hwtimer[i].dev_name, (void *)g_gd32_hwtimer[i].hw_data.reg_base);
             g_gd32_hwtimer[i].dev_name, (void *)g_gd32_hwtimer[i].hw_data.reg_base);
         if (RT_EOK != ret)
         if (RT_EOK != ret)

+ 364 - 288
bsp/gd32/arm/libraries/gd32_drivers/drv_pwm.c

@@ -6,15 +6,21 @@
  * Change Logs:
  * Change Logs:
  * Date           Author            Notes
  * Date           Author            Notes
  * 2023-06-05     zengjianwei       first version
  * 2023-06-05     zengjianwei       first version
- * 2025-06-23     Yucai Liu         Support for non-complementary PWM output with advanced timers
+ * 2025-06-23     Yucai Liu         Support for non-complementary PWM output with 
+ *                                  advanced timers
+ * 2025-12-26     shihongchao       Optimize the timer clock frequency acquisition 
+ *                                  method; optimize the gd32_pwm structure to make 
+ *                                  it easier to configure; optimize the RCU enable 
+ *                                  logic; optimize GPIO configuration to maintain 
+ *                                  floating input mode when channels are disabled, 
+ *                                  reducing power consumption.
  */
  */
 
 
 #include <board.h>
 #include <board.h>
-#include <gd32f30x.h>
 #include <rtdevice.h>
 #include <rtdevice.h>
 #include <rtthread.h>
 #include <rtthread.h>
 
 
-#ifdef RT_USING_PWM
+#ifdef BSP_USING_PWM
 
 
 /* #define DRV_DEBUG */
 /* #define DRV_DEBUG */
 #define LOG_TAG "drv.pwm"
 #define LOG_TAG "drv.pwm"
@@ -24,208 +30,186 @@
 #define MIN_PERIOD 3
 #define MIN_PERIOD 3
 #define MIN_PULSE  2
 #define MIN_PULSE  2
 
 
-typedef struct
-{
-    rt_int8_t   TimerIndex; /* timer index:0~13 */
-    rt_uint32_t Port;       /* gpio port:GPIOA/GPIOB/GPIOC/... */
-    rt_uint32_t pin;        /* gpio pin:GPIO_PIN_0~GPIO_PIN_15 */
-    /* timer channel: -2 is ch_1n, -1 is ch_0n, 0 is ch0, 1 is ch1 */
-    rt_int16_t channel;
-    char      *name;
-} TIMER_PORT_CHANNEL_MAP_S;
+typedef struct{
+    uint32_t gpio_port;
+    uint32_t gpio_af;
+    uint16_t gpio_pin;
+}channel_type;
 
 
 struct gd32_pwm
 struct gd32_pwm
 {
 {
-    struct rt_device_pwm     pwm_device;
-    TIMER_PORT_CHANNEL_MAP_S tim_handle;
+    struct rt_device_pwm       pwm_device;   /* 继承pwm设备 */
+           char                *name;        /* 设备名称 */
+           uint32_t            timerx;       /* PWM依赖的的硬件定时器 */
+           rcu_clock_freq_enum apb_of;       /* TIMER从属的APB总线 */
+           channel_type        channels[4];  /* PWM通道 */
+           channel_type        nchannels[3]; /* PWM反相通道, 只有高级定时器支持 */
 };
 };
 
 
 static struct gd32_pwm gd32_pwm_obj[] = {
 static struct gd32_pwm gd32_pwm_obj[] = {
-#ifdef RT_USING_PWM1
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm1"}},
-#endif
-
-#ifdef RT_USING_PWM2
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm2"}},
-#endif
-
-#ifdef RT_USING_PWM3
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm3"}},
+#ifdef BSP_USING_PWM0
+    {
+        .name = "pwm0",
+        .timerx = TIMER0,
+        .apb_of = CK_APB2,
+        .channels = {
+            {GPIOC, GPIO_AF_1, GPIO_PIN_0},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_1},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_2},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_3},
+        },
+        .nchannels = {
+            {GPIOB, GPIO_AF_1, GPIO_PIN_13},
+            {GPIOB, GPIO_AF_1, GPIO_PIN_14},
+            {GPIOB, GPIO_AF_1, GPIO_PIN_15},
+        }
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM4
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm4"}},
+#ifdef BSP_USING_PWM1
+    {
+        .name = "pwm1",
+        .timerx = TIMER1,
+        .apb_of = CK_APB1,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_0},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_1},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_2},
+            {GPIOB, GPIO_AF_1, GPIO_PIN_2},
+        },
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM5
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm5"}},
+#ifdef BSP_USING_PWM2
+    {
+        .name = "pwm2",
+        .timerx = TIMER2,
+        .apb_of = CK_APB1,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_6},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_7},
+            {GPIOB, GPIO_AF_2, GPIO_PIN_0},
+            {GPIOB, GPIO_AF_2, GPIO_PIN_1},
+        },
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM6
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm6"}},
+#ifdef BSP_USING_PWM3
+    {
+        .name = "pwm3",
+        .timerx = TIMER3,
+        .apb_of = CK_APB1,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_0},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_1},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_2},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_3},
+        },
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM7
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm7"}},
+#ifdef BSP_USING_PWM4
+    {
+        .name = "pwm4",
+        .timerx = TIMER4,
+        .apb_of = CK_APB1,
+        .channels = {
+            {GPIOA, GPIO_AF_2, GPIO_PIN_0},
+            {GPIOA, GPIO_AF_2, GPIO_PIN_1},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_2},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_3},
+        },
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM8
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm8"}},
+#ifdef BSP_USING_PWM7
+    {
+        .name = "pwm7",
+        .timerx = TIMER7,
+        .apb_of = CK_APB2,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_0},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_1},
+            {GPIOC, GPIO_AF_1, GPIO_PIN_8},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_3},
+        },
+        .nchannels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_5},
+            {GPIOB, GPIO_AF_1, GPIO_PIN_0},
+            {GPIOB, GPIO_AF_1, GPIO_PIN_1},
+        }
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM9
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm9"}},
+#ifdef BSP_USING_PWM8
+    {
+        .name = "pwm8",
+        .timerx = TIMER8,
+        .apb_of = CK_APB2,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_2},
+            {GPIOA, GPIO_AF_3, GPIO_PIN_3},
+        }, // L1通用定时器为两通道定时器
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM10
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm10"}},
+#ifdef BSP_USING_PWM9
+    {
+        .name = "pwm9",
+        .timerx = TIMER9,
+        .apb_of = CK_APB2,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_0},
+        }, // L2通用定时器为单通道定时器
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM11
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm11"}},
+#ifdef BSP_USING_PWM10
+    {
+        .name = "pwm10",
+        .timerx = TIMER10,
+        .apb_of = CK_APB2,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_0},
+        }, // L2通用定时器为单通道定时器
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM12
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm12"}},
+#ifdef BSP_USING_PWM11
+    {
+        .name = "pwm11",
+        .timerx = TIMER11,
+        .apb_of = CK_APB1,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_0},
+            {GPIOA, GPIO_AF_1, GPIO_PIN_1},
+        }, // L1通用定时器为两通道定时器
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM13
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm13"}},
+#ifdef BSP_USING_PWM12
+    {
+        .name = "pwm12",
+        .timerx = TIMER12,
+        .apb_of = CK_APB1,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_0},
+        }, // L2通用定时器为单通道定时器
+    },
 #endif
 #endif
 
 
-#ifdef RT_USING_PWM14
-    {.tim_handle = {3, GPIOB, GPIO_PIN_8, 2, "pwm14"}},
+#ifdef BSP_USING_PWM13
+    {
+        .name = "pwm13",
+        .timerx = TIMER13,
+        .apb_of = CK_APB1,
+        .channels = {
+            {GPIOA, GPIO_AF_1, GPIO_PIN_7},
+        }, // L2通用定时器为单通道定时器
+    },
 #endif
 #endif
 };
 };
 
 
-typedef struct
-{
-    rt_uint32_t Port[7];
-    rt_int8_t   TimerIndex[14];
-} TIMER_PERIPH_LIST_S;
-
-static TIMER_PERIPH_LIST_S gd32_timer_periph_list = {
-    .Port       = {0, 0, 0, 0, 0, 0, 0},
-    .TimerIndex = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
-};
-
-/*
- * 将所有用到的 gpio port 和 timer 不重复地列举出来,以方便后面不重复地初始化
- */
-static rt_err_t pwm_find_timer_periph(void)
-{
-    rt_int16_t i, j, k;
-
-    /* find gpio port of defined table */
-    for (i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); ++i)
-    {
-        /* find -1 of gd32_periph_list's member of Port */
-        for (j = 0; j < sizeof(gd32_timer_periph_list.Port) / sizeof(gd32_timer_periph_list.Port[0]); ++j)
-        {
-            if (0 == gd32_timer_periph_list.Port[j])
-            {
-                break;
-            }
-        }
-
-        if (j >= sizeof(gd32_timer_periph_list.Port) / sizeof(gd32_timer_periph_list.Port[0]))
-        {
-            LOG_E("Can not find -1 of gd32_periph_list's member of Port!\n");
-            break;
-        }
-
-        /* find the different of Port */
-        for (k = 0; k < j; ++k)
-        {
-            if (gd32_pwm_obj[i].tim_handle.Port == gd32_timer_periph_list.Port[k])
-            {
-                break;
-            }
-        }
-
-        /* if can not find the same Port */
-        if (k == j)
-        {
-            gd32_timer_periph_list.Port[j] = gd32_pwm_obj[i].tim_handle.Port;
-        }
-    }
-
-    /* find timer periph of defined table */
-    for (i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); ++i)
-    {
-        /* find -1 of gd32_periph_list's member of TimerIndex */
-        for (j = 0; j < sizeof(gd32_timer_periph_list.TimerIndex) / sizeof(gd32_timer_periph_list.TimerIndex[0]); ++j)
-        {
-            if (-1 == gd32_timer_periph_list.TimerIndex[j])
-            {
-                break;
-            }
-        }
-
-        if (j >= sizeof(gd32_timer_periph_list.TimerIndex) / sizeof(gd32_timer_periph_list.TimerIndex[0]))
-        {
-            LOG_E("Can not find -1 of gd32_periph_list's member of TimerIndex!\n");
-            break;
-        }
-
-        /* find the different of TimerIndex */
-        for (k = 0; k < j; ++k)
-        {
-            if (gd32_pwm_obj[i].tim_handle.TimerIndex == gd32_timer_periph_list.TimerIndex[k])
-            {
-                break;
-            }
-        }
-
-        /* if can not find the same TimerIndex */
-        if (k == j)
-        {
-            gd32_timer_periph_list.TimerIndex[j] = gd32_pwm_obj[i].tim_handle.TimerIndex;
-        }
-    }
-
-    return RT_EOK;
-}
-
-static rt_uint32_t index_to_timer(rt_int8_t TimerIndex)
-{
-    switch (TimerIndex)
-    {
-    case 0:
-        return TIMER0;
-    case 1:
-        return TIMER1;
-    case 2:
-        return TIMER2;
-    case 3:
-        return TIMER3;
-    case 4:
-        return TIMER4;
-    case 5:
-        return TIMER5;
-    case 6:
-        return TIMER6;
-    case 7:
-        return TIMER7;
-    case 8:
-        return TIMER8;
-    case 9:
-        return TIMER9;
-    case 10:
-        return TIMER10;
-    case 11:
-        return TIMER11;
-    case 12:
-        return TIMER12;
-    case 13:
-        return TIMER13;
-
-    default:
-        LOG_E("Unsport timer periph!\n");
-    }
-    return TIMER0;
-}
-
 static void gpio_clock_enable(rt_uint32_t Port)
 static void gpio_clock_enable(rt_uint32_t Port)
 {
 {
     switch (Port)
     switch (Port)
@@ -257,54 +241,52 @@ static void gpio_clock_enable(rt_uint32_t Port)
     }
     }
 }
 }
 
 
-static void timer_clock_enable(rt_int8_t TimerIndex)
+static void timer_clock_enable(uint32_t timer)
 {
 {
-    switch (TimerIndex)
+    switch (timer)
     {
     {
-    case 0:
+    case TIMER0:
         rcu_periph_clock_enable(RCU_TIMER0);
         rcu_periph_clock_enable(RCU_TIMER0);
         break;
         break;
-    case 1:
+    case TIMER1:
         rcu_periph_clock_enable(RCU_TIMER1);
         rcu_periph_clock_enable(RCU_TIMER1);
         break;
         break;
-    case 2:
+    case TIMER2:
         rcu_periph_clock_enable(RCU_TIMER2);
         rcu_periph_clock_enable(RCU_TIMER2);
         break;
         break;
-    case 3:
+    case TIMER3:
         rcu_periph_clock_enable(RCU_TIMER3);
         rcu_periph_clock_enable(RCU_TIMER3);
         break;
         break;
-    case 4:
+    case TIMER4:
         rcu_periph_clock_enable(RCU_TIMER4);
         rcu_periph_clock_enable(RCU_TIMER4);
         break;
         break;
-    case 5:
+    case TIMER5:
         rcu_periph_clock_enable(RCU_TIMER5);
         rcu_periph_clock_enable(RCU_TIMER5);
         break;
         break;
-    case 6:
+    case TIMER6:
         rcu_periph_clock_enable(RCU_TIMER6);
         rcu_periph_clock_enable(RCU_TIMER6);
         break;
         break;
-    case 7:
+    case TIMER7:
         rcu_periph_clock_enable(RCU_TIMER7);
         rcu_periph_clock_enable(RCU_TIMER7);
         break;
         break;
-#ifndef GD32F30X_HD
-    case 8:
+    case TIMER8:
         rcu_periph_clock_enable(RCU_TIMER8);
         rcu_periph_clock_enable(RCU_TIMER8);
         break;
         break;
-    case 9:
+    case TIMER9:
         rcu_periph_clock_enable(RCU_TIMER9);
         rcu_periph_clock_enable(RCU_TIMER9);
         break;
         break;
-    case 10:
+    case TIMER10:
         rcu_periph_clock_enable(RCU_TIMER10);
         rcu_periph_clock_enable(RCU_TIMER10);
         break;
         break;
-    case 11:
+    case TIMER11:
         rcu_periph_clock_enable(RCU_TIMER11);
         rcu_periph_clock_enable(RCU_TIMER11);
         break;
         break;
-    case 12:
+    case TIMER12:
         rcu_periph_clock_enable(RCU_TIMER12);
         rcu_periph_clock_enable(RCU_TIMER12);
         break;
         break;
-    case 13:
+    case TIMER13:
         rcu_periph_clock_enable(RCU_TIMER13);
         rcu_periph_clock_enable(RCU_TIMER13);
         break;
         break;
-#endif
     default:
     default:
         LOG_E("Unsport timer periph!\n");
         LOG_E("Unsport timer periph!\n");
     }
     }
@@ -314,96 +296,168 @@ static void rcu_config(void)
 {
 {
     rt_int16_t i;
     rt_int16_t i;
 
 
-    for (i = 0; i < sizeof(gd32_timer_periph_list.Port) / sizeof(gd32_timer_periph_list.Port[0]); ++i)
+    for (i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); ++i)
     {
     {
-        if (0 == gd32_timer_periph_list.Port[i])
+        /* enable GPIO clock */
+        switch (gd32_pwm_obj[i].timerx)
         {
         {
+        /* 高级定时器 */
+        case TIMER0:
+        case TIMER7:
+            gpio_clock_enable(gd32_pwm_obj[i].nchannels[0].gpio_port);
+            gpio_clock_enable(gd32_pwm_obj[i].nchannels[1].gpio_port);
+            gpio_clock_enable(gd32_pwm_obj[i].nchannels[2].gpio_port);
+
+        /* L0 通用定时器 */
+        case TIMER1:
+        case TIMER2:
+        case TIMER3:
+        case TIMER4:
+            gpio_clock_enable(gd32_pwm_obj[i].channels[2].gpio_port);
+            gpio_clock_enable(gd32_pwm_obj[i].channels[3].gpio_port);
+        
+        /* L1 通用定时器 */
+        case TIMER8:
+        case TIMER11:
+            gpio_clock_enable(gd32_pwm_obj[i].channels[1].gpio_port);
+
+        /* L2 通用定时器 */
+        case TIMER9:
+        case TIMER10:
+        case TIMER12:
+        case TIMER13:
+            gpio_clock_enable(gd32_pwm_obj[i].channels[0].gpio_port);
+            break;
+        
+        default:
+            LOG_E("Unsport timer periph at rcu_config!\n");
             break;
             break;
         }
         }
-
-        /* enable GPIO clock */
-        gpio_clock_enable(gd32_timer_periph_list.Port[i]);
     }
     }
 
 
-    rcu_periph_clock_enable(RCU_AF);
-
-    for (i = 0; i < sizeof(gd32_timer_periph_list.TimerIndex) / sizeof(gd32_timer_periph_list.TimerIndex[0]); ++i)
+    for (i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); ++i)
     {
     {
-        if (-1 == gd32_timer_periph_list.TimerIndex[i])
-        {
-            break;
-        }
-
         /* enable timer clock */
         /* enable timer clock */
-        timer_clock_enable(gd32_timer_periph_list.TimerIndex[i]);
-        timer_deinit(index_to_timer(gd32_timer_periph_list.TimerIndex[i]));
+        timer_clock_enable(gd32_pwm_obj[i].timerx);
+        timer_deinit(gd32_pwm_obj[i].timerx);
     }
     }
 }
 }
 
 
-static void gpio_config(void)
+/**
+ * @brief 配置PWM输出引脚为pwm输出模式
+ * @param pwm pwm 对象
+ * @param configuration pwm驱动框架传递的配置信息
+ */
+static void gpio_config_pwmout(const struct gd32_pwm *pwm, 
+                               const struct rt_pwm_configuration *configuration)
 {
 {
-    rt_int16_t i;
-
-    /* config the GPIO as analog mode */
-    for (i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); ++i)
+    channel_type channel;
+    uint8_t channel_num = configuration->channel;
+    if(configuration->complementary)
     {
     {
-        gpio_init(gd32_pwm_obj[i].tim_handle.Port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, gd32_pwm_obj[i].tim_handle.pin);
+        if(channel_num > 3) channel_num = 3;
+        channel = pwm->nchannels[channel_num-1];
     }
     }
+    else
+    {
+        if(channel_num > 4) channel_num = 4;
+        channel = pwm->channels[channel_num-1];
+    }
+    gpio_mode_set(channel.gpio_port, GPIO_MODE_AF, GPIO_PUPD_NONE, channel.gpio_pin);
+    gpio_output_options_set(channel.gpio_port, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, channel.gpio_pin);
+    gpio_af_set(channel.gpio_port, channel.gpio_af, channel.gpio_pin);
 }
 }
 
 
-static void timer_init_para(timer_parameter_struct *initpara)
+/**
+ * @brief 配置PWM输出引脚为pwm浮空输入模式
+ * @param pwm pwm 对象
+ * @param configuration pwm驱动框架传递的配置信息
+ */
+static void gpio_config_input(const struct gd32_pwm *pwm, 
+                              const struct rt_pwm_configuration *configuration)
 {
 {
-    rt_int16_t i;
-
-    for (i = 0; i < sizeof(gd32_timer_periph_list.TimerIndex) / sizeof(gd32_timer_periph_list.TimerIndex[0]); ++i)
+    channel_type channel = {0};
+    uint8_t channel_num = configuration->channel;
+    if(configuration->complementary)
     {
     {
-        /* config timer */
-        if (-1 != gd32_timer_periph_list.TimerIndex[i])
-        {
-            timer_init(index_to_timer(gd32_timer_periph_list.TimerIndex[i]), initpara);
-        }
+        if(channel_num > 3) channel_num = 3;
+        channel = pwm->nchannels[channel_num-1];
+    }
+    else
+    {
+        if(channel_num > 4) channel_num = 4;
+        channel = pwm->channels[channel_num-1];
     }
     }
+    gpio_mode_set(channel.gpio_port, GPIO_MODE_INPUT, GPIO_PUPD_NONE, channel.gpio_pin);
 }
 }
 
 
-static void channel_output_config(timer_oc_parameter_struct *ocpara)
+static void channel_output_config(rt_uint32_t timer_periph, timer_oc_parameter_struct *ocpara)
 {
 {
     rt_int16_t  i;
     rt_int16_t  i;
-    rt_uint32_t timer_periph;
 
 
-    /* config the channel config */
-    for (i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); ++i)
+    switch (timer_periph)
     {
     {
-        if (gd32_pwm_obj[i].tim_handle.channel < 0)
-        {
-            ocpara->outputstate                = TIMER_CCX_DISABLE;
-            ocpara->outputnstate               = TIMER_CCXN_ENABLE;
-            gd32_pwm_obj[i].tim_handle.channel = -(gd32_pwm_obj[i].tim_handle.channel + 1);
-        }
-        timer_periph = index_to_timer(gd32_pwm_obj[i].tim_handle.TimerIndex);
-        timer_channel_output_config(timer_periph, gd32_pwm_obj[i].tim_handle.channel, ocpara);
+    /* 高级定时器 */
+    case TIMER0:
+    case TIMER7:
+        timer_primary_output_config(timer_periph, ENABLE);
+
+    /* L0通用定时器 */
+    case TIMER1:
+    case TIMER2:
+    case TIMER3:
+    case TIMER4:
+        timer_channel_output_config(timer_periph, TIMER_CH_2, ocpara);
+        timer_channel_output_pulse_value_config(timer_periph, TIMER_CH_2, 7999);
+        timer_channel_output_mode_config(timer_periph, TIMER_CH_2, TIMER_OC_MODE_PWM0);
+        timer_channel_output_shadow_config(timer_periph, TIMER_CH_2, TIMER_OC_SHADOW_DISABLE);
+        /* auto-reload preload shadow reg enable */
+        /* timer_auto_reload_shadow_enable(timer_periph); */
+        timer_channel_output_state_config(timer_periph, TIMER_CH_2, TIMER_CCX_DISABLE);
+        timer_channel_complementary_output_state_config(timer_periph, TIMER_CH_2, TIMER_CCXN_DISABLE);
 
 
-        timer_channel_output_pulse_value_config(timer_periph, gd32_pwm_obj[i].tim_handle.channel, 7999);
-        timer_channel_output_mode_config(timer_periph, gd32_pwm_obj[i].tim_handle.channel, TIMER_OC_MODE_PWM0);
-        timer_channel_output_shadow_config(timer_periph, gd32_pwm_obj[i].tim_handle.channel, TIMER_OC_SHADOW_DISABLE);
+        timer_channel_output_config(timer_periph, TIMER_CH_3, ocpara);
+        timer_channel_output_pulse_value_config(timer_periph, TIMER_CH_3, 7999);
+        timer_channel_output_mode_config(timer_periph, TIMER_CH_3, TIMER_OC_MODE_PWM0);
+        timer_channel_output_shadow_config(timer_periph, TIMER_CH_3, TIMER_OC_SHADOW_DISABLE);
         /* auto-reload preload shadow reg enable */
         /* auto-reload preload shadow reg enable */
         /* timer_auto_reload_shadow_enable(timer_periph); */
         /* timer_auto_reload_shadow_enable(timer_periph); */
-        timer_channel_output_state_config(timer_periph, gd32_pwm_obj[i].tim_handle.channel, TIMER_CCX_DISABLE);
-        timer_channel_complementary_output_state_config(timer_periph, gd32_pwm_obj[i].tim_handle.channel, TIMER_CCXN_DISABLE);
+        timer_channel_output_state_config(timer_periph, TIMER_CH_3, TIMER_CCX_DISABLE);
+        timer_channel_complementary_output_state_config(timer_periph, TIMER_CH_3, TIMER_CCXN_DISABLE);
+
+    /* L1通用定时器 */
+    case TIMER8:
+    case TIMER11:
+        timer_channel_output_config(timer_periph, TIMER_CH_1, ocpara);
+        timer_channel_output_pulse_value_config(timer_periph, TIMER_CH_1, 7999);
+        timer_channel_output_mode_config(timer_periph, TIMER_CH_1, TIMER_OC_MODE_PWM0);
+        timer_channel_output_shadow_config(timer_periph, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE);
+        /* auto-reload preload shadow reg enable */
+        /* timer_auto_reload_shadow_enable(timer_periph); */
+        timer_channel_output_state_config(timer_periph, TIMER_CH_1, TIMER_CCX_DISABLE);
+        timer_channel_complementary_output_state_config(timer_periph, TIMER_CH_1, TIMER_CCXN_DISABLE);
+
+    /* L2通用定时器 */
+    case TIMER9:
+    case TIMER10:
+    case TIMER12:
+    case TIMER13:
+        timer_channel_output_config(timer_periph, TIMER_CH_0, ocpara);
+        timer_channel_output_pulse_value_config(timer_periph, TIMER_CH_0, 7999);
+        timer_channel_output_mode_config(timer_periph, TIMER_CH_0, TIMER_OC_MODE_PWM0);
+        timer_channel_output_shadow_config(timer_periph, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
+        /* auto-reload preload shadow reg enable */
+        /* timer_auto_reload_shadow_enable(timer_periph); */
+        timer_channel_output_state_config(timer_periph, TIMER_CH_0, TIMER_CCX_DISABLE);
+        timer_channel_complementary_output_state_config(timer_periph, TIMER_CH_0, TIMER_CCXN_DISABLE);
+        break;
+    
+    default:
+        LOG_E("Unsport timer periph at channel_output_config!\n");
+        break;
     }
     }
 
 
-    /* enable timer */
-    for (i = 0; i < sizeof(gd32_timer_periph_list.TimerIndex) / sizeof(gd32_timer_periph_list.TimerIndex[0]); ++i)
-    {
-        if (-1 != gd32_timer_periph_list.TimerIndex[i])
-        {
-            timer_periph = index_to_timer(gd32_timer_periph_list.TimerIndex[i]);
-            if (timer_periph == TIMER0 || timer_periph == TIMER7)
-            {
-                timer_primary_output_config(timer_periph, ENABLE);
-            }
-            timer_enable(timer_periph);
-        }
-    }
+    timer_enable(timer_periph);
 }
 }
 
 
 static void timer_config(void)
 static void timer_config(void)
@@ -412,58 +466,76 @@ static void timer_config(void)
     timer_parameter_struct    timer_initpara;
     timer_parameter_struct    timer_initpara;
 
 
     /* TIMER configuration */
     /* TIMER configuration */
-    timer_initpara.prescaler         = 119;
+    timer_initpara.prescaler         = 199;
     timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
     timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
     timer_initpara.counterdirection  = TIMER_COUNTER_UP;
     timer_initpara.counterdirection  = TIMER_COUNTER_UP;
     timer_initpara.period            = 15999;
     timer_initpara.period            = 15999;
     timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
     timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
     timer_initpara.repetitioncounter = 0;
     timer_initpara.repetitioncounter = 0;
-    timer_init_para(&timer_initpara);
+    for (size_t i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); ++i)
+    {
+        timer_init(gd32_pwm_obj[i].timerx, &timer_initpara);
+    }
 
 
     /* CHX configuration in PWM mode */
     /* CHX configuration in PWM mode */
-    timer_ocintpara.outputstate  = TIMER_CCX_ENABLE;
+    timer_ocintpara.outputstate  = TIMER_CCX_DISABLE;
     timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
     timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
     timer_ocintpara.ocpolarity   = TIMER_OC_POLARITY_HIGH;
     timer_ocintpara.ocpolarity   = TIMER_OC_POLARITY_HIGH;
     timer_ocintpara.ocnpolarity  = TIMER_OCN_POLARITY_HIGH;
     timer_ocintpara.ocnpolarity  = TIMER_OCN_POLARITY_HIGH;
     timer_ocintpara.ocidlestate  = TIMER_OC_IDLE_STATE_LOW;
     timer_ocintpara.ocidlestate  = TIMER_OC_IDLE_STATE_LOW;
     timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
     timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
-    channel_output_config(&timer_ocintpara);
+    /* config the channel config */
+    for (size_t i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); ++i)
+    {
+        channel_output_config(gd32_pwm_obj[i].timerx, &timer_ocintpara);
+    }
 }
 }
 
 
-static rt_err_t drv_pwm_enable(TIMER_PORT_CHANNEL_MAP_S *pstTimerMap, struct rt_pwm_configuration *configuration,
+static rt_err_t drv_pwm_enable(struct gd32_pwm *pwm, const struct rt_pwm_configuration *configuration,
                                rt_bool_t enable)
                                rt_bool_t enable)
 {
 {
     if (!enable)
     if (!enable)
     {
     {
-        timer_channel_output_state_config(index_to_timer(pstTimerMap->TimerIndex), configuration->channel,
-                                          TIMER_CCX_DISABLE);
+        gpio_config_input(pwm, configuration);
+        if (configuration->complementary == RT_TRUE)
+        {
+            timer_channel_complementary_output_state_config(pwm->timerx, configuration->channel-1, 
+                TIMER_CCXN_DISABLE);
+        }
+        else
+        {
+            timer_channel_output_state_config(pwm->timerx, configuration->channel-1, 
+                TIMER_CCX_DISABLE);
+        }
     }
     }
     else
     else
     {
     {
+        gpio_config_pwmout(pwm, configuration);
         if (configuration->complementary == RT_TRUE)
         if (configuration->complementary == RT_TRUE)
         {
         {
-            timer_channel_output_state_config(
-                index_to_timer(pstTimerMap->TimerIndex), configuration->channel - 1, TIMER_CCXN_ENABLE);
+            timer_channel_complementary_output_state_config(pwm->timerx, configuration->channel-1, 
+                TIMER_CCXN_ENABLE);
         }
         }
         else
         else
         {
         {
-            timer_channel_output_state_config(
-                index_to_timer(pstTimerMap->TimerIndex), configuration->channel, TIMER_CCX_ENABLE);
+            timer_channel_output_state_config(pwm->timerx, configuration->channel-1, 
+                TIMER_CCX_ENABLE);
         }
         }
     }
     }
 
 
     return RT_EOK;
     return RT_EOK;
 }
 }
 
 
-static rt_err_t drv_pwm_get(TIMER_PORT_CHANNEL_MAP_S *pstTimerMap, struct rt_pwm_configuration *configuration)
+static rt_err_t drv_pwm_get(const struct gd32_pwm *pwm, struct rt_pwm_configuration *configuration)
 {
 {
     rt_uint64_t tim_clock;
     rt_uint64_t tim_clock;
     rt_uint16_t psc;
     rt_uint16_t psc;
     rt_uint32_t chxcv;
     rt_uint32_t chxcv;
 
 
-    tim_clock = rcu_clock_freq_get(CK_SYS);
+    rt_uint8_t coef = (RCU_CFG1&RCU_CFG1_TIMERSEL)?4:2;
+    tim_clock = rcu_clock_freq_get(pwm->apb_of)*coef;
 
 
-    psc = timer_prescaler_read(index_to_timer(pstTimerMap->TimerIndex));
+    psc = timer_prescaler_read(pwm->timerx);
     if (psc == TIMER_CKDIV_DIV2)
     if (psc == TIMER_CKDIV_DIV2)
     {
     {
         tim_clock = tim_clock / 2;
         tim_clock = tim_clock / 2;
@@ -473,21 +545,22 @@ static rt_err_t drv_pwm_get(TIMER_PORT_CHANNEL_MAP_S *pstTimerMap, struct rt_pwm
         tim_clock = tim_clock / 4;
         tim_clock = tim_clock / 4;
     }
     }
 
 
-    chxcv = timer_channel_capture_value_register_read(index_to_timer(pstTimerMap->TimerIndex), configuration->channel);
+    chxcv = timer_channel_capture_value_register_read(pwm->timerx, configuration->channel-1);
     /* Convert nanosecond to frequency and duty cycle. 1s = 1 * 1000 * 1000 * 1000 ns */
     /* Convert nanosecond to frequency and duty cycle. 1s = 1 * 1000 * 1000 * 1000 ns */
     tim_clock             /= 1000000UL;
     tim_clock             /= 1000000UL;
-    configuration->period  = (TIMER_CAR(index_to_timer(pstTimerMap->TimerIndex)) + 1) * (psc + 1) * 1000UL / tim_clock;
+    configuration->period  = (TIMER_CAR(pwm->timerx) + 1) * (psc + 1) * 1000UL / tim_clock;
     configuration->pulse   = (chxcv + 1) * (psc + 1) * 1000UL / tim_clock;
     configuration->pulse   = (chxcv + 1) * (psc + 1) * 1000UL / tim_clock;
 
 
     return RT_EOK;
     return RT_EOK;
 }
 }
 
 
-static rt_err_t drv_pwm_set(TIMER_PORT_CHANNEL_MAP_S *pstTimerMap, struct rt_pwm_configuration *configuration)
+static rt_err_t drv_pwm_set(struct gd32_pwm *pwm, struct rt_pwm_configuration *configuration)
 {
 {
     rt_uint32_t period, pulse;
     rt_uint32_t period, pulse;
     rt_uint64_t tim_clock, psc;
     rt_uint64_t tim_clock, psc;
 
 
-    tim_clock = rcu_clock_freq_get(CK_SYS);
+    rt_uint8_t coef = (RCU_CFG1&RCU_CFG1_TIMERSEL)?4:2;
+    tim_clock = rcu_clock_freq_get(pwm->apb_of)*coef;
 
 
     /* Convert nanosecond to frequency and duty cycle. 1s = 1 * 1000 * 1000 * 1000 ns */
     /* Convert nanosecond to frequency and duty cycle. 1s = 1 * 1000 * 1000 * 1000 ns */
     tim_clock /= 1000000UL;
     tim_clock /= 1000000UL;
@@ -495,14 +568,14 @@ static rt_err_t drv_pwm_set(TIMER_PORT_CHANNEL_MAP_S *pstTimerMap, struct rt_pwm
     psc        = period / MAX_PERIOD + 1;
     psc        = period / MAX_PERIOD + 1;
     period     = period / psc;
     period     = period / psc;
 
 
-    timer_prescaler_config(index_to_timer(pstTimerMap->TimerIndex), psc - 1, TIMER_PSC_RELOAD_NOW);
+    timer_prescaler_config(pwm->timerx, psc - 1, TIMER_PSC_RELOAD_NOW);
 
 
     if (period < MIN_PERIOD)
     if (period < MIN_PERIOD)
     {
     {
         period = MIN_PERIOD;
         period = MIN_PERIOD;
     }
     }
 
 
-    timer_autoreload_value_config(index_to_timer(pstTimerMap->TimerIndex), period - 1);
+    timer_autoreload_value_config(pwm->timerx, period - 1);
 
 
     pulse = (unsigned long long)configuration->pulse * tim_clock / psc / 1000ULL;
     pulse = (unsigned long long)configuration->pulse * tim_clock / psc / 1000ULL;
     if (pulse < MIN_PULSE)
     if (pulse < MIN_PULSE)
@@ -514,11 +587,11 @@ static rt_err_t drv_pwm_set(TIMER_PORT_CHANNEL_MAP_S *pstTimerMap, struct rt_pwm
         pulse = period;
         pulse = period;
     }
     }
 
 
-    timer_channel_output_pulse_value_config(index_to_timer(pstTimerMap->TimerIndex), configuration->channel, pulse);
-    timer_counter_value_config(index_to_timer(pstTimerMap->TimerIndex), 0);
+    timer_channel_output_pulse_value_config(pwm->timerx, configuration->channel-1, pulse);
+    timer_counter_value_config(pwm->timerx, 0);
 
 
     /* Update frequency value */
     /* Update frequency value */
-    timer_event_software_generate(index_to_timer(pstTimerMap->TimerIndex), TIMER_EVENT_SRC_UPG);
+    timer_event_software_generate(pwm->timerx, TIMER_EVENT_SRC_UPG);
 
 
     return RT_EOK;
     return RT_EOK;
 }
 }
@@ -526,18 +599,18 @@ static rt_err_t drv_pwm_set(TIMER_PORT_CHANNEL_MAP_S *pstTimerMap, struct rt_pwm
 static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg)
 static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg)
 {
 {
     struct rt_pwm_configuration *configuration = (struct rt_pwm_configuration *)arg;
     struct rt_pwm_configuration *configuration = (struct rt_pwm_configuration *)arg;
-    TIMER_PORT_CHANNEL_MAP_S    *pstTimerMap   = (TIMER_PORT_CHANNEL_MAP_S *)device->parent.user_data;
+    struct gd32_pwm             *pwm   = (struct gd32_pwm *)device;
 
 
     switch (cmd)
     switch (cmd)
     {
     {
     case PWM_CMD_ENABLE:
     case PWM_CMD_ENABLE:
-        return drv_pwm_enable(pstTimerMap, configuration, RT_TRUE);
+        return drv_pwm_enable(pwm, configuration, RT_TRUE);
     case PWM_CMD_DISABLE:
     case PWM_CMD_DISABLE:
-        return drv_pwm_enable(pstTimerMap, configuration, RT_FALSE);
+        return drv_pwm_enable(pwm, configuration, RT_FALSE);
     case PWM_CMD_SET:
     case PWM_CMD_SET:
-        return drv_pwm_set(pstTimerMap, configuration);
+        return drv_pwm_set(pwm, configuration);
     case PWM_CMD_GET:
     case PWM_CMD_GET:
-        return drv_pwm_get(pstTimerMap, configuration);
+        return drv_pwm_get(pwm, configuration);
     default:
     default:
         return -RT_EINVAL;
         return -RT_EINVAL;
     }
     }
@@ -547,15 +620,18 @@ static struct rt_pwm_ops drv_ops = {drv_pwm_control};
 
 
 static rt_err_t gd32_hw_pwm_init(void)
 static rt_err_t gd32_hw_pwm_init(void)
 {
 {
-    pwm_find_timer_periph();
     rcu_config();
     rcu_config();
-    gpio_config();
     timer_config();
     timer_config();
 
 
+    /* 
+     * gpio 此处不配置,当pwm通道使能时会配置为pwmout,失能时会配置为浮空输入
+     * gpio 默认为浮空输入
+    */
+
     return RT_EOK;
     return RT_EOK;
 }
 }
 
 
-static int gd32_pwm_init(void)
+static int rt_hw_pwm_init(void)
 {
 {
     int i      = 0;
     int i      = 0;
     int result = RT_EOK;
     int result = RT_EOK;
@@ -573,14 +649,14 @@ static int gd32_pwm_init(void)
     for (i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); i++)
     for (i = 0; i < sizeof(gd32_pwm_obj) / sizeof(gd32_pwm_obj[0]); i++)
     {
     {
         /* register pwm device */
         /* register pwm device */
-        if (rt_device_pwm_register(&gd32_pwm_obj[i].pwm_device, gd32_pwm_obj[i].tim_handle.name, &drv_ops,
-                                   &gd32_pwm_obj[i].tim_handle)== RT_EOK )
+        if (rt_device_pwm_register(&gd32_pwm_obj[i].pwm_device, gd32_pwm_obj[i].name, &drv_ops,
+                                   RT_NULL)== RT_EOK )
         {
         {
-            LOG_D("%s register success", gd32_pwm_obj[i].tim_handle.name);
+            LOG_D("%s register success", gd32_pwm_obj[i].name);
         }
         }
         else
         else
         {
         {
-            LOG_E("%s register failed", gd32_pwm_obj[i].tim_handle.name);
+            LOG_E("%s register failed", gd32_pwm_obj[i].name);
             result = -RT_ERROR;
             result = -RT_ERROR;
         }
         }
     }
     }
@@ -588,6 +664,6 @@ static int gd32_pwm_init(void)
 __exit:
 __exit:
     return result;
     return result;
 }
 }
-INIT_DEVICE_EXPORT(gd32_pwm_init);
+INIT_DEVICE_EXPORT(rt_hw_pwm_init);
 #endif /* RT_USING_PWM */
 #endif /* RT_USING_PWM */