Skip to content

Commit 3baf58e

Browse files
committed
[bsp] add n32 pwm driver
1 parent 9a6d515 commit 3baf58e

40 files changed

Lines changed: 3890 additions & 1010 deletions

File tree

bsp/n32/libraries/n32_drivers/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ if GetDepend(['RT_USING_RTC']):
4545
if GetDepend(['RT_USING_WDT']):
4646
src += ['drv_wdt.c']
4747

48+
if GetDepend('BSP_USING_PWM'):
49+
src += ['drv_base.c']
50+
51+
if GetDepend(['BSP_USING_PWM']):
52+
src += ['drv_pwm.c']
53+
4854
path = [cwd]
4955
path += [cwd + '/config']
5056

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright (c) 2006-2020, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-12-02 Bernard car (1085582540@qq.com)
9+
10+
*/
11+
#include <rtthread.h>
12+
13+
14+
#define DBG_TAG "PWM"
15+
#define DBG_LEVEL DBG_LOG
16+
#include <rtdbg.h>
17+
#include "board.h"
18+
/**
19+
* @brief enable gpio rcc
20+
*
21+
* @param gpio_grp
22+
*/
23+
void n32_gpio_rcc_enable(GPIO_Module *gpio_grp)
24+
{
25+
assert_param(IS_GPIO_ALL_PERIPH(gpio_grp));
26+
if (GPIOA == gpio_grp)
27+
{
28+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
29+
LOG_D("enable gpio rcc GPIOA");
30+
}
31+
else if (GPIOB == gpio_grp)
32+
{
33+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
34+
LOG_D("enable gpio rcc GPIOB");
35+
}
36+
else if (GPIOC == gpio_grp)
37+
{
38+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC, ENABLE);
39+
LOG_D("enable gpio rcc GPIOC");
40+
}
41+
else if (GPIOD == gpio_grp)
42+
{
43+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOD, ENABLE);
44+
LOG_D("enable gpio rcc GPIOD");
45+
}
46+
#if defined(SOC_N32G45X) || defined(SOC_N32WB452) || defined(SOC_N32G4FR)
47+
else if (GPIOE == gpio_grp)
48+
{
49+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOE, ENABLE);
50+
}
51+
#if defined(SOC_N32G45X)
52+
else if (GPIOF == gpio_grp)
53+
{
54+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOF, ENABLE);
55+
}
56+
else if (GPIOG == gpio_grp)
57+
{
58+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOG, ENABLE);
59+
}
60+
#endif
61+
#endif
62+
}
63+
64+
/**
65+
* @brief
66+
*
67+
* @param gpio_grp
68+
* @param pin
69+
*
70+
* The pin of Timer 2 involves the debug pin of SWD-JTAG. When reusing, it is necessary to first set the reuse of jSWD-JTAG
71+
JTMS/SWDIO PA13-----------swd
72+
JTCK/SWCLK A14------------swd
73+
JTDI PA15
74+
JTDO PB3
75+
NJTRST PB4
76+
77+
* GPIO_ConfigPinRemap(GPIO_RMP_SW_JTAG_SW_ENABLE,ENABLE);
78+
*/
79+
void gpio_remap_JTAGOFF_SWDON(GPIO_Module *gpio_grp, uint16_t pin)
80+
{
81+
#if defined(SOC_N32G45X) || defined(SOC_N32WB452) || defined(SOC_N32G4FR)
82+
83+
if ((GPIOA == gpio_grp && GPIO_PIN_15) ||
84+
(GPIOB == gpio_grp && GPIO_PIN_3) ||
85+
(GPIOB == gpio_grp && GPIO_PIN_4))
86+
{
87+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE);
88+
GPIO_ConfigPinRemap(GPIO_RMP_SW_JTAG_SW_ENABLE, ENABLE);
89+
}
90+
#endif
91+
}
92+
93+
/**
94+
* @brief enable time rcc
95+
*/
96+
void n32_time_rcc_config(TIM_Module *htim)
97+
{
98+
RT_ASSERT(TIM1 == htim || TIM2 == htim || TIM3 == htim || TIM4 == htim || TIM5 == htim || TIM8 == htim
99+
#if defined(SOC_N32G45X) || defined(SOC_N32WB452) || defined(SOC_N32G4FR)
100+
);
101+
#else
102+
|| TIM9 == htim);
103+
#endif
104+
105+
if (TIM1 == htim)
106+
{
107+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1, ENABLE);
108+
}
109+
else if (TIM2 == htim)
110+
{
111+
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM2, ENABLE);
112+
}
113+
else if (TIM3 == htim)
114+
{
115+
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM3, ENABLE);
116+
}
117+
else if (TIM4 == htim)
118+
{
119+
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM4, ENABLE);
120+
}
121+
else if (TIM5 == htim)
122+
{
123+
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM5, ENABLE);
124+
}
125+
else if (TIM8 == htim)
126+
{
127+
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM8, ENABLE);
128+
}
129+
#if defined(SOC_N32L43X) || defined(SOC_N32L40X) || defined(SOC_N32G43X)
130+
else if (TIM9 == htim)
131+
{
132+
RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_TIM9, ENABLE);
133+
}
134+
#endif
135+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef __DRV_BASE__
2+
#define __DRV_BASE__
3+
#include "board.h"
4+
5+
void n32_gpio_rcc_enable(GPIO_Module *gpio_grp);
6+
7+
8+
void n32_time_rcc_config(TIM_Module *htim);
9+
10+
void gpio_remap_JTAGOFF_SWDON(GPIO_Module *gpio_grp, uint16_t pin);
11+
#endif

0 commit comments

Comments
 (0)