Skip to content

Commit 774031a

Browse files
Blues-JiangBernardXiong
authored andcommitted
[bsp/n32g452xx] Unified header file definition. "GPIO_H__" to "DRV_GPIO_H". "USART_H" to "DRV_USART_H"
[bsp/n32g452xx] In drv_pwm.c, variable meaning is different with RT-Thread interface definition. Fixed and tested. [bsp/n32g452xx] Add support for UART4/UART5. [bsp/n32g452xx] In drv_gpio.c Modify "N32F10X_PIN_NUMBERS" to "N32G45X_PIN_NUMBERS".
1 parent 09f439b commit 774031a

File tree

7 files changed

+101
-20
lines changed

7 files changed

+101
-20
lines changed

bsp/n32g452xx/Libraries/rt_drivers/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ src += ['drv_clk.c']
1515
if GetDepend(['BSP_USING_GPIO']):
1616
src += ['drv_gpio.c']
1717

18-
if GetDepend(['BSP_USING_UART']):
18+
if GetDepend(['RT_USING_WDT']):
1919
src += ['drv_wdt.c']
2020

2121
if GetDepend(['BSP_USING_UART']):

bsp/n32g452xx/Libraries/rt_drivers/drv_gpio.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#ifdef RT_USING_PIN
1717

18-
#define N32F10X_PIN_NUMBERS 64 //[48, 64, 100, 144 ]
18+
#define N32G45X_PIN_NUMBERS 64 //[48, 64, 100, 144 ]
1919

2020
#define __N32_PIN(index, rcc, gpio, gpio_index) \
2121
{ \
@@ -37,7 +37,7 @@ struct pin_index
3737

3838
static const struct pin_index pins[] =
3939
{
40-
#if (N32F10X_PIN_NUMBERS == 48)
40+
#if (N32G45X_PIN_NUMBERS == 48)
4141
__N32_PIN_DEFAULT,
4242
__N32_PIN_DEFAULT,
4343
__N32_PIN(2, APB2, C, 13),
@@ -89,7 +89,7 @@ static const struct pin_index pins[] =
8989
__N32_PIN_DEFAULT,
9090

9191
#endif
92-
#if (N32F10X_PIN_NUMBERS == 64)
92+
#if (N32G45X_PIN_NUMBERS == 64)
9393
__N32_PIN_DEFAULT,
9494
__N32_PIN_DEFAULT,
9595
__N32_PIN(2, APB2, C, 13),
@@ -156,7 +156,7 @@ static const struct pin_index pins[] =
156156
__N32_PIN_DEFAULT,
157157
__N32_PIN_DEFAULT,
158158
#endif
159-
#if (N32F10X_PIN_NUMBERS == 100)
159+
#if (N32G45X_PIN_NUMBERS == 100)
160160
__N32_PIN_DEFAULT,
161161
__N32_PIN(1, APB2, E, 2),
162162
__N32_PIN(2, APB2, E, 3),
@@ -259,7 +259,7 @@ static const struct pin_index pins[] =
259259
__N32_PIN_DEFAULT,
260260
__N32_PIN_DEFAULT,
261261
#endif
262-
#if (N32F10X_PIN_NUMBERS == 144)
262+
#if (N32G45X_PIN_NUMBERS == 144)
263263
__N32_PIN_DEFAULT,
264264
__N32_PIN(1, APB2, E, 2),
265265
__N32_PIN(2, APB2, E, 3),

bsp/n32g452xx/Libraries/rt_drivers/drv_gpio.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
* Date Author Notes
88
* 2015-01-05 Bernard the first version
99
*/
10-
#ifndef GPIO_H__
11-
#define GPIO_H__
10+
#ifndef __DRV_GPIO_H__
11+
#define __DRV_GPIO_H__
1212

1313
int n32_hw_pin_init(void);
1414

15-
#endif
15+
16+
#endif /* __DRV_GPIO_H__ */

bsp/n32g452xx/Libraries/rt_drivers/drv_pwm.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#endif /* RT_USING_PWM */
3030

3131
#define MAX_PERIOD 65535
32+
#define MIN_PERIOD 3
3233

3334
#ifdef BSP_USING_PWM
3435

@@ -207,6 +208,9 @@ static rt_err_t drv_pwm_set(struct n32_pwm *pwm_dev, struct rt_pwm_configuration
207208
{
208209
TIM_Module *TIMx = pwm_dev->tim_handle;
209210
rt_uint32_t channel = configuration->channel;
211+
rt_uint32_t period;
212+
rt_uint64_t psc;
213+
rt_uint32_t pulse;
210214

211215
/* Init timer pin and enable clock */
212216
void n32_msp_tim_init(void *Instance);
@@ -228,25 +232,33 @@ static rt_err_t drv_pwm_set(struct n32_pwm *pwm_dev, struct rt_pwm_configuration
228232
input_clock = RCC_Clock.Pclk1Freq * 2;
229233
}
230234

235+
input_clock /= 1000000UL;
231236
/* Convert nanosecond to frequency and duty cycle. */
232-
rt_uint32_t period = (unsigned long long)configuration->period ;
233-
rt_uint64_t psc = period / MAX_PERIOD + 1;
237+
period = (unsigned long long)configuration->period * input_clock / 1000ULL;
238+
psc = period / MAX_PERIOD + 1;
234239
period = period / psc;
235-
psc = psc * (input_clock / 1000000);
236-
240+
if (period < MIN_PERIOD)
241+
{
242+
period = MIN_PERIOD;
243+
}
237244
if ((pwm_dev->period != period) || (pwm_dev->psc != psc))
238245
{
239-
/* TIMe base configuration */
246+
/* Tim base configuration */
240247
TIM_TimeBaseInitType TIM_TIMeBaseStructure;
241248
TIM_InitTimBaseStruct(&TIM_TIMeBaseStructure);
242-
TIM_TIMeBaseStructure.Period = period;
249+
TIM_TIMeBaseStructure.Period = period - 1;
243250
TIM_TIMeBaseStructure.Prescaler = psc - 1;
244251
TIM_TIMeBaseStructure.ClkDiv = 0;
245252
TIM_TIMeBaseStructure.CntMode = TIM_CNT_MODE_UP;
246253
TIM_InitTimeBase(TIMx, &TIM_TIMeBaseStructure);
247254
}
248255

249-
rt_uint32_t pulse = (unsigned long long)configuration->pulse;
256+
pulse = (unsigned long long)configuration->pulse * input_clock / psc / 1000ULL;
257+
if (pulse > period)
258+
{
259+
pulse = period;
260+
}
261+
250262
/* PWM1 Mode configuration: Channel1 */
251263
OCInitType TIM_OCInitStructure;
252264
TIM_InitOcStruct(&TIM_OCInitStructure);

bsp/n32g452xx/Libraries/rt_drivers/drv_usart.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,46 @@ void DMA2_Channel3_IRQHandler(void)
437437
rt_interrupt_enter();
438438

439439
dma_rx_done_isr(&serial4);
440-
441440
/* leave interrupt */
442441
rt_interrupt_leave();
443442
}
444443
#endif /* BSP_USING_UART4 */
445444

445+
#if defined(BSP_USING_UART5)
446+
/* UART5 device driver structure */
447+
struct n32_uart uart5 =
448+
{
449+
UART5,
450+
UART5_IRQn,
451+
{
452+
DMA1_CH8,
453+
DMA1,
454+
DMA1_FLAG_GL8,
455+
DMA1_Channel8_IRQn,
456+
0,
457+
},
458+
};
459+
struct rt_serial_device serial5;
460+
461+
void UART5_IRQHandler(void)
462+
{
463+
/* enter interrupt */
464+
rt_interrupt_enter();
465+
uart_isr(&serial5);
466+
/* leave interrupt */
467+
rt_interrupt_leave();
468+
}
469+
470+
void DMA1_Channel8_IRQHandler(void)
471+
{
472+
/* enter interrupt */
473+
rt_interrupt_enter();
474+
dma_rx_done_isr(&serial5);
475+
/* leave interrupt */
476+
rt_interrupt_leave();
477+
}
478+
#endif /* BSP_USING_UART5 */
479+
446480
static void NVIC_Configuration(struct n32_uart *uart)
447481
{
448482
NVIC_InitType NVIC_InitStructure;
@@ -552,6 +586,31 @@ int rt_hw_usart_init(void)
552586
uart);
553587
#endif /* BSP_USING_UART3 */
554588

589+
#if defined(BSP_USING_UART4)
590+
uart = &uart4;
591+
config.baud_rate = BAUD_RATE_115200;
592+
serial4.ops = &n32_uart_ops;
593+
serial4.config = config;
594+
NVIC_Configuration(uart);
595+
/* register UART3 device */
596+
rt_hw_serial_register(&serial4, "uart4",
597+
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX |
598+
RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_DMA_RX,
599+
uart);
600+
#endif /* BSP_USING_UART4 */
601+
602+
#if defined(BSP_USING_UART5)
603+
uart = &uart5;
604+
config.baud_rate = BAUD_RATE_115200;
605+
serial5.ops = &n32_uart_ops;
606+
serial5.config = config;
607+
NVIC_Configuration(uart);
608+
/* register UART3 device */
609+
rt_hw_serial_register(&serial5, "uart5",
610+
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX |
611+
RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_DMA_RX,
612+
uart);
613+
#endif /* BSP_USING_UART5 */
555614
return RT_EOK;
556615
}
557616

bsp/n32g452xx/Libraries/rt_drivers/drv_usart.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* 2009-01-05 Bernard the first version
99
*/
1010

11-
#ifndef __USART_H__
12-
#define __USART_H__
11+
#ifndef __DRV_USART_H__
12+
#define __DRV_USART_H__
1313

1414
int rt_hw_usart_init(void);
1515

16-
#endif
16+
#endif /* __DRV_USART_H__ */

bsp/n32g452xx/n32g452xx-mini-system/board/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ menu "On-chip Peripheral Drivers"
4949
config BSP_USING_UART3
5050
bool "Enable UART3"
5151
default n
52+
53+
config BSP_USING_UART4
54+
bool "Enable UART4"
55+
default n
56+
57+
config BSP_USING_UART5
58+
bool "Enable UART5"
59+
default n
60+
5261
endif
5362

5463
menuconfig BSP_USING_PWM

0 commit comments

Comments
 (0)