Merge pull request #2424 from wangyq2018/es32f0654

[bsp/es32f0654] add pwm drivers
This commit is contained in:
Bernard Xiong 2019-03-13 08:58:45 +08:00 committed by GitHub
commit f165b9cb3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 282 additions and 55 deletions

View File

@ -338,6 +338,14 @@ CONFIG_BSP_USING_UART2=y
# CONFIG_BSP_USING_I2C0 is not set
# CONFIG_BSP_USING_I2C1 is not set
#
# PWM Drivers
#
# CONFIG_BSP_USING_PWM0 is not set
# CONFIG_BSP_USING_PWM1 is not set
# CONFIG_BSP_USING_PWM2 is not set
# CONFIG_BSP_USING_PWM3 is not set
#
# Onboard Peripheral Drivers
#

View File

@ -42,8 +42,7 @@ ES-PDS-ES32F0654-V1.0
| UART | 支持 | UART0/1/2/3 |
| SPI | 支持 | SPI0/1 |
| I2C | 支持 | I2C0/1 |
| **扩展模块** | **支持情况** | **备注** |
| PWM | 支持 | PWM0/1/2/3 |
更多详细信息请咨询[上海东软载波微电子技术支持](http://www.essemi.com/)

View File

@ -53,6 +53,27 @@ menu "Hardware Drivers Config"
default n
endmenu
menu "PWM Drivers"
config BSP_USING_PWM0
bool "Using PWM0 PA08/PA09/PA10/PA11"
select RT_USING_PWM
default n
config BSP_USING_PWM1
bool "Using PWM1 PB06/PB07/PB08/PB09"
select RT_USING_PWM
default n
config BSP_USING_PWM2
bool "Using PWM2 PA00/PA01"
select RT_USING_PWM
default n
config BSP_USING_PWM3
bool "Using PWM3 PC06/PC07"
select RT_USING_PWM
default n
endmenu
endmenu
menu "Onboard Peripheral Drivers"

View File

@ -27,6 +27,10 @@ if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1'):
if GetDepend('BSP_USING_SPI_FLASH'):
src += ['drv_spiflash.c']
# add pwm driver code
if GetDepend('BSP_USING_PWM0') or GetDepend('BSP_USING_PWM1') or GetDepend('BSP_USING_PWM2') or GetDepend('BSP_USING_PWM3'):
src += ['drv_pwm.c']
CPPPATH = [cwd]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)

View File

@ -58,14 +58,8 @@ void SystemClock_Config(void)
*******************************************************************************/
void SysTick_Configuration(void)
{
rt_uint32_t _mclk;
rt_uint32_t _sys_div = READ_BITS(CMU->CFGR, CMU_CFGR_SYSDIV_MSK, CMU_CFGR_SYSDIV_POSS);
/* get hrc clock*/
_mclk = cmu_get_clock();
/* SYSCLK = MCLK/SYSDIV */
SysTick_Config(_mclk / (RT_TICK_PER_SECOND << _sys_div));
/* ticks = sysclk / RT_TICK_PER_SECOND */
SysTick_Config(cmu_get_sys_clock() / RT_TICK_PER_SECOND);
}
/**
@ -108,3 +102,20 @@ void rt_hw_board_init(void)
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
}
/**
* This function will delay for some us.
*
* @param us the delay time of us
*/
void rt_hw_us_delay(rt_uint32_t us)
{
unsigned int start, now, delta, reload, us_tick;
start = SysTick->VAL;
reload = SysTick->LOAD;
us_tick = cmu_get_sys_clock() / 1000000UL;
do{
now = SysTick->VAL;
delta = start > now ? start - now : reload + start - now;
} while(delta < us_tick * us);
}

View File

@ -0,0 +1,178 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-11 wangyq the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <ald_timer.h>
#include <ald_gpio.h>
static rt_err_t es32f0_pwm_control(struct rt_device_pwm *device, int cmd, void *arg)
{
rt_err_t ret = RT_EOK;
timer_channel_t pwm_channel;
timer_oc_init_t tim_ocinit;
timer_handle_t *timer_initstruct = (timer_handle_t *)device->parent.user_data;
struct rt_pwm_configuration *cfg = (struct rt_pwm_configuration *)arg;
RT_ASSERT(timer_initstruct != RT_NULL);
tim_ocinit.oc_mode = TIMER_OC_MODE_PWM1;
tim_ocinit.oc_polarity = TIMER_OC_POLARITY_HIGH;
tim_ocinit.oc_fast_en = DISABLE;
tim_ocinit.ocn_polarity = TIMER_OCN_POLARITY_HIGH;
tim_ocinit.ocn_idle = TIMER_OCN_IDLE_RESET;
tim_ocinit.oc_idle = TIMER_OC_IDLE_RESET;
/* select pwm output channel */
if (0 == cfg->channel)
{
pwm_channel = TIMER_CHANNEL_1;
}
else if (1 == cfg->channel)
{
pwm_channel = TIMER_CHANNEL_2;
}
else if (2 == cfg->channel)
{
if (timer_initstruct->perh == GP16C2T0 || timer_initstruct->perh == GP16C2T1)
return RT_EINVAL;
pwm_channel = TIMER_CHANNEL_3;
}
else if (3 == cfg->channel)
{
if (timer_initstruct->perh == GP16C2T0 || timer_initstruct->perh == GP16C2T1)
return RT_EINVAL;
pwm_channel = TIMER_CHANNEL_4;
}
else
{
return RT_EINVAL;
}
switch (cmd)
{
case PWM_CMD_ENABLE:
timer_pwm_start(timer_initstruct, pwm_channel);
break;
case PWM_CMD_DISABLE:
timer_pwm_stop(timer_initstruct, pwm_channel);
break;
case PWM_CMD_SET:
/* count registers max 0xFFFF, auto adjust prescaler*/
do
{
timer_pwm_set_freq(timer_initstruct, 1000000000 / cfg->period);
timer_initstruct->init.prescaler ++;
}
while (timer_initstruct->init.period > 0xFFFF);
/* update prescaler */
WRITE_REG(timer_initstruct->perh->PRES, -- timer_initstruct->init.prescaler);
timer_oc_config_channel(timer_initstruct, &tim_ocinit, pwm_channel);
timer_pwm_set_duty(timer_initstruct, pwm_channel, cfg->pulse * 100 / cfg->period);
break;
case PWM_CMD_GET:
cfg->pulse = timer_read_capture_value(timer_initstruct, pwm_channel) * 100 / READ_REG(timer_initstruct->perh->AR);
break;
default:
break;
}
return ret;
}
const static struct rt_pwm_ops es32f0_pwm_ops =
{
es32f0_pwm_control
};
int rt_hw_pwm_init(void)
{
rt_err_t ret = RT_EOK;
gpio_init_t gpio_initstructure;
gpio_initstructure.mode = GPIO_MODE_OUTPUT;
gpio_initstructure.odos = GPIO_PUSH_PULL;
gpio_initstructure.pupd = GPIO_PUSH_UP;
gpio_initstructure.odrv = GPIO_OUT_DRIVE_NORMAL;
gpio_initstructure.flt = GPIO_FILTER_DISABLE;
gpio_initstructure.type = GPIO_TYPE_TTL;
#ifdef BSP_USING_PWM0 /* 4 channels */
static struct rt_device_pwm pwm_dev0;
static timer_handle_t timer_initstruct0;
timer_initstruct0.perh = AD16C4T0;
timer_pwm_init(&timer_initstruct0);
/* gpio initialization */
gpio_initstructure.func = GPIO_FUNC_2;
gpio_init(GPIOA, GPIO_PIN_8, &gpio_initstructure);
gpio_init(GPIOA, GPIO_PIN_9, &gpio_initstructure);
gpio_init(GPIOA, GPIO_PIN_10, &gpio_initstructure);
gpio_init(GPIOA, GPIO_PIN_11, &gpio_initstructure);
ret = rt_device_pwm_register(&pwm_dev0, "pwm0", &es32f0_pwm_ops, &timer_initstruct0);
#endif
#ifdef BSP_USING_PWM1 /* 4 channels */
static struct rt_device_pwm pwm_dev1;
static timer_handle_t timer_initstruct1;
timer_initstruct1.perh = GP16C4T0;
timer_pwm_init(&timer_initstruct1);
/* gpio initialization */
gpio_initstructure.func = GPIO_FUNC_2;
gpio_init(GPIOB, GPIO_PIN_6, &gpio_initstructure);
gpio_init(GPIOB, GPIO_PIN_7, &gpio_initstructure);
gpio_init(GPIOB, GPIO_PIN_8, &gpio_initstructure);
gpio_init(GPIOB, GPIO_PIN_9, &gpio_initstructure);
ret = rt_device_pwm_register(&pwm_dev1, "pwm1", &es32f0_pwm_ops, &timer_initstruct1);
#endif
#ifdef BSP_USING_PWM2 /* 2 channels */
static struct rt_device_pwm pwm_dev2;
static timer_handle_t timer_initstruct2;
timer_initstruct2.perh = GP16C2T0;
timer_pwm_init(&timer_initstruct2);
/* gpio initialization */
gpio_initstructure.func = GPIO_FUNC_2;
gpio_init(GPIOA, GPIO_PIN_0, &gpio_initstructure);
gpio_init(GPIOA, GPIO_PIN_1, &gpio_initstructure);
ret = rt_device_pwm_register(&pwm_dev2, "pwm2", &es32f0_pwm_ops, &timer_initstruct2);
#endif
#ifdef BSP_USING_PWM3 /* 2 channels */
static struct rt_device_pwm pwm_dev3;
static timer_handle_t timer_initstruct3;
timer_initstruct3.perh = GP16C2T1;
timer_pwm_init(&timer_initstruct3);
/* gpio initialization */
gpio_initstructure.func = GPIO_FUNC_3;
gpio_init(GPIOC, GPIO_PIN_6, &gpio_initstructure);
gpio_init(GPIOC, GPIO_PIN_7, &gpio_initstructure);
ret = rt_device_pwm_register(&pwm_dev3, "pwm3", &es32f0_pwm_ops, &timer_initstruct3);
#endif
return ret;
}
INIT_DEVICE_EXPORT(rt_hw_pwm_init);

View File

@ -0,0 +1,16 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-11 wangyq the first version
*/
#ifndef DRV_PWM_H__
#define DRV_PWM_H__
int rt_hw_pwm_init(void);
#endif

View File

@ -27,62 +27,54 @@ struct es32_uart
static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
gpio_init_t gpio_init_initstructure;
gpio_init_t gpio_initstructure;
struct es32_uart *uart;
RT_ASSERT(serial != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
uart = (struct es32_uart *)serial->parent.user_data;
/* Initialize tx pin */
gpio_init_initstructure.mode = GPIO_MODE_OUTPUT;
gpio_init_initstructure.odos = GPIO_PUSH_PULL;
gpio_init_initstructure.pupd = GPIO_PUSH_UP;
gpio_init_initstructure.odrv = GPIO_OUT_DRIVE_NORMAL;
gpio_init_initstructure.flt = GPIO_FILTER_DISABLE;
gpio_init_initstructure.type = GPIO_TYPE_TTL;
gpio_initstructure.mode = GPIO_MODE_OUTPUT;
gpio_initstructure.odos = GPIO_PUSH_PULL;
gpio_initstructure.pupd = GPIO_PUSH_UP;
gpio_initstructure.odrv = GPIO_OUT_DRIVE_NORMAL;
gpio_initstructure.flt = GPIO_FILTER_DISABLE;
gpio_initstructure.type = GPIO_TYPE_TTL;
#ifdef BSP_USING_UART0
gpio_init_initstructure.func = GPIO_FUNC_3;
gpio_init(GPIOB, GPIO_PIN_10, &gpio_init_initstructure);
gpio_initstructure.func = GPIO_FUNC_3;
gpio_init(GPIOB, GPIO_PIN_10, &gpio_initstructure);
/* Initialize rx pin ,the same as txpin except mode*/
gpio_init_initstructure.mode = GPIO_MODE_INPUT;
gpio_init(GPIOB, GPIO_PIN_11, &gpio_init_initstructure);
NVIC_EnableIRQ(UART0_IRQn);
gpio_initstructure.mode = GPIO_MODE_INPUT;
gpio_init(GPIOB, GPIO_PIN_11, &gpio_initstructure);
#endif /* uart0 gpio init */
#ifdef BSP_USING_UART1
gpio_init_initstructure.func = GPIO_FUNC_3;
gpio_init(GPIOC, GPIO_PIN_10, &gpio_init_initstructure);
gpio_initstructure.func = GPIO_FUNC_3;
gpio_init(GPIOC, GPIO_PIN_10, &gpio_initstructure);
/* Initialize rx pin ,the same as txpin except mode*/
gpio_init_initstructure.mode = GPIO_MODE_INPUT;
gpio_init(GPIOC, GPIO_PIN_11, &gpio_init_initstructure);
NVIC_EnableIRQ(UART1_IRQn);
gpio_initstructure.mode = GPIO_MODE_INPUT;
gpio_init(GPIOC, GPIO_PIN_11, &gpio_initstructure);
#endif /* uart1 gpio init */
#ifdef BSP_USING_UART2
gpio_init_initstructure.func = GPIO_FUNC_5;
gpio_init(GPIOC, GPIO_PIN_12, &gpio_init_initstructure);
gpio_initstructure.func = GPIO_FUNC_5;
gpio_init(GPIOC, GPIO_PIN_12, &gpio_initstructure);
/* Initialize rx pin ,the same as txpin except mode*/
gpio_init_initstructure.mode = GPIO_MODE_INPUT;
gpio_init(GPIOD, GPIO_PIN_2, &gpio_init_initstructure);
NVIC_EnableIRQ(BS16T1_UART2_IRQn);
gpio_initstructure.mode = GPIO_MODE_INPUT;
gpio_init(GPIOD, GPIO_PIN_2, &gpio_initstructure);
#endif /* uart2 gpio init */
#ifdef BSP_USING_UART3
gpio_init_initstructure.func = GPIO_FUNC_4;
gpio_init(GPIOC, GPIO_PIN_4, &gpio_init_initstructure);
gpio_initstructure.func = GPIO_FUNC_4;
gpio_init(GPIOC, GPIO_PIN_4, &gpio_initstructure);
/* Initialize rx pin ,the same as txpin except mode*/
gpio_init_initstructure.mode = GPIO_MODE_INPUT;
gpio_init(GPIOC, GPIO_PIN_5, &gpio_init_initstructure);
NVIC_EnableIRQ(BS16T2_UART3_IRQn);
gpio_initstructure.mode = GPIO_MODE_INPUT;
gpio_init(GPIOC, GPIO_PIN_5, &gpio_initstructure);
#endif /* uart3 gpio init */
uart->huart.init.mode = UART_MODE_UART;

View File

@ -22,11 +22,11 @@
</DaveTm>
<Target>
<TargetName>rt-thread_es32f065x</TargetName>
<TargetName>rt-thread</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<TargetOption>
<CLKADS>24000000</CLKADS>
<CLKADS>12000000</CLKADS>
<OPTTT>
<gFlags>1</gFlags>
<BeepAtEnd>1</BeepAtEnd>
@ -73,11 +73,11 @@
<LExpSel>0</LExpSel>
</OPTXL>
<OPTFL>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget>
</OPTFL>
<CpuCode>255</CpuCode>
<CpuCode>0</CpuCode>
<DebugOpt>
<uSim>0</uSim>
<uTrg>1</uTrg>
@ -95,7 +95,7 @@
<tRmem>1</tRmem>
<tRfunc>0</tRfunc>
<tRbox>1</tRbox>
<tRtrace>0</tRtrace>
<tRtrace>1</tRtrace>
<sRSysVw>1</sRSysVw>
<tRSysVw>1</tRSysVw>
<sRunDeb>0</sRunDeb>
@ -117,18 +117,13 @@
<TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>CMSIS_AGDI</Key>
<Name>-X"Any" -UAny -O206 -S0 -C0 -P00 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0ES32F065x -FS00 -FL040000</Name>
<Key>JL2CM3</Key>
<Name>-U12345678 -O78 -S4 -ZTIFSpeedSel2000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BB11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC1000 -FN1 -FF0ES32F065x.FLM -FS00 -FL040000 -FP0($$Device:ES32F0654LT$Flash\ES32F065x.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>UL2CM3</Key>
<Name>UL2CM3(-S0 -C0 -P0 ) -FN1 -FC1000 -FD20000000 -FF0es32f0xx -FL040000 -FS00 -FP0($$Device:ES32F0654LT$Flash\es32f0xx.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>JL2CM3</Key>
<Name>-U12345678 -O78 -S4 -ZTIFSpeedSel2000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -TO18 -TC10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC1000 -FN1 -FF0ES32F065x -FS00 -FL040000</Name>
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0ES32F065x -FS00 -FL040000 -FP0($$Device:ES32F0654LT$Flash\ES32F065x.FLM))</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint/>

View File

@ -4,7 +4,7 @@
<Header>### uVision Project, (C) Keil Software</Header>
<Targets>
<Target>
<TargetName>rt-thread_es32f065x</TargetName>
<TargetName>rt-thread</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<TargetOption>

View File

@ -169,6 +169,9 @@
/* I2C Drivers */
/* PWM Drivers */
/* Onboard Peripheral Drivers */