Merge pull request #2469 from wangyq2018/es32f0334

[bsp/es32f0334] add spi/i2c/pwm drivers
This commit is contained in:
Bernard Xiong authored and GitHub committed 2019-03-20 21:05:14 +08:00
commit c6ed9fb284
19 files changed
+906 -32

No files matched your search

+21
View File
@@ -324,9 +324,30 @@ CONFIG_BSP_USING_GPIO=y
# CONFIG_BSP_USING_UART0 is not set
CONFIG_BSP_USING_UART1=y
#
# SPI Drivers
#
# CONFIG_BSP_USING_SPI0 is not set
# CONFIG_BSP_USING_SPI1 is not set
#
# I2C Drivers
#
# 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
#
# CONFIG_BSP_USING_SPI_FLASH is not set
#
# Offboard Peripheral Drivers
+5 -5
View File
@@ -20,7 +20,7 @@ ES-PDS-ES32F0334-V1.1
该开发板常用 **板载资源** 如下:
- MCU:ES32F0334LT,主频 48MHz,32KB SRAM,256KB FLASH,54 GPIOs
- 外部 FLASH:MX25L64(SPI,16MB)、EEPROM(24c04)
- 外部模块:SPI FLASH (MX25L64,8MB)、I2C EEPROM (M24C04,512B)
- 常用外设
- LED:2个,(PA12/PC12)
- 液晶屏:1个
@@ -35,13 +35,13 @@ ES-PDS-ES32F0334-V1.1
| **板载外设** | **支持情况** | **备注** |
| :---------------- | :----------: | :------------------------------------|
| SPI FLASH | 支持 | SPI0 |
| **片上外设** | **支持情况** | **备注** |
| :---------------- | :----------: | :------------------------------------|
| GPIO | 支持 | 54 GPIOs |
| UART | 支持 | UART0/1 |
| **扩展模块** | **支持情况** | **备注** |
| SPI | 支持 | SPI0/1 |
| I2C | 支持 | I2C0/1 |
| PWM | 支持 | PWM0/1/2/3 |
更多详细信息请咨询[上海东软载波微电子技术支持](http://www.essemi.com/)
+54
View File
@@ -19,10 +19,64 @@ menu "Hardware Drivers Config"
endmenu
menu "SPI Drivers"
config BSP_USING_SPI0
bool "Enable SPI0 BUS PB03/PB04/PB05(CLK/MISO/MOSI)"
select RT_USING_SPI
select RT_USING_PIN
default n
config BSP_USING_SPI1
bool "Enable SPI1 BUS PB13/PB14/PB15(CLK/MISO/MOSI)"
select RT_USING_SPI
select RT_USING_PIN
default n
endmenu
menu "I2C Drivers"
config BSP_USING_I2C0
bool "Enable I2C0 BUS PB08/PB09(SCL/SDA)"
select RT_USING_I2C
default n
config BSP_USING_I2C1
bool "Enable I2C1 BUS PB10/PB11(SCL/SDA)"
select RT_USING_I2C
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"
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"
config BSP_USING_SPI_FLASH
bool "Enable SPI FLASH (W25Q64 spi0)"
select BSP_USING_SPI
select BSP_USING_SPI0
select RT_USING_SFUD
select RT_SFUD_USING_SFDP
default n
endmenu
menu "Offboard Peripheral Drivers"
+16
View File
@@ -15,6 +15,22 @@ if GetDepend('RT_USING_PIN'):
if GetDepend('BSP_USING_UART0') or GetDepend('BSP_USING_UART1'):
src += ['drv_uart.c']
# add spi driver code
if GetDepend('BSP_USING_SPI0') or GetDepend('BSP_USING_SPI1'):
src += ['drv_spi.c']
# add i2c driver code
if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1'):
src += ['drv_i2c.c']
# add spi flash driver code
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)
+22 -9
View File
@@ -45,7 +45,7 @@ void SystemClock_Config(void)
/* hosc 12MHz, from hosc/3 pll to 48MHz */
cmu_pll1_config(CMU_PLL1_INPUT_HOSC_3, CMU_PLL1_OUTPUT_48M);
/* MCLK 48MHz*/
/* MCLK 48MHz */
cmu_clock_config(CMU_CLOCK_PLL1, 48000000);
}
@@ -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,22 @@ 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);
}
+4 -4
View File
@@ -257,7 +257,7 @@ rt_err_t es32f0_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
{
return RT_ENOSYS;
}
/**pin no. convert to dec no.**/
/* pin no. convert to dec no. */
for (irqindex = 0; irqindex < 16; irqindex++)
{
if ((0x01 << irqindex) == index->pin)
@@ -327,7 +327,7 @@ rt_err_t es32f0_pin_irq_enable(struct rt_device *device, rt_base_t pin,
const struct pin_irq_map *irqmap;
rt_base_t level;
rt_int32_t irqindex = -1;
/*Configure GPIO_InitStructure & EXTI_InitStructure*/
/* Configure GPIO_InitStructure & EXTI_InitStructure */
gpio_init_t gpio_initstruct;
exti_init_t exti_initstruct;
exti_initstruct.filter = DISABLE;
@@ -341,7 +341,7 @@ rt_err_t es32f0_pin_irq_enable(struct rt_device *device, rt_base_t pin,
}
if (enabled == PIN_IRQ_ENABLE)
{
/**pin no. convert to dec no.**/
/* pin no. convert to dec no. */
for (irqindex = 0; irqindex < 16; irqindex++)
{
if ((0x01 << irqindex) == index->pin)
@@ -421,7 +421,7 @@ INIT_BOARD_EXPORT(rt_hw_pin_init);
rt_inline void pin_irq_hdr(uint16_t GPIO_Pin)
{
uint16_t irqno;
/**pin no. convert to dec no.**/
/* pin no. convert to dec no. */
for (irqno = 0; irqno < 16; irqno++)
{
if ((0x01 << irqno) == GPIO_Pin)
+141
View File
@@ -0,0 +1,141 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-19 wangyq the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_i2c.h"
#include <ald_i2c.h>
#include <ald_gpio.h>
#ifdef RT_USING_I2C
#define TIMEOUT 0x0FFF
/* I2C struct definition */
static i2c_handle_t _h_i2c0, _h_i2c1;
static void _i2c_init(void)
{
gpio_init_t gpio_instruct;
/* Initialize I2C Pin */
gpio_instruct.mode = GPIO_MODE_OUTPUT;
gpio_instruct.odos = GPIO_PUSH_PULL;
gpio_instruct.pupd = GPIO_PUSH_UP;
gpio_instruct.odrv = GPIO_OUT_DRIVE_NORMAL;
gpio_instruct.flt = GPIO_FILTER_DISABLE;
gpio_instruct.type = GPIO_TYPE_CMOS;
gpio_instruct.func = GPIO_FUNC_5;
#ifdef BSP_USING_I2C0
/* Initialize I2C Function */
_h_i2c0.perh = I2C0;
_h_i2c0.init.clk_speed = 100000;
_h_i2c0.init.duty = I2C_DUTYCYCLE_2;
_h_i2c0.init.own_addr1 = 0x0A;
_h_i2c0.init.addr_mode = I2C_ADDR_7BIT;
_h_i2c0.init.general_call = I2C_GENERALCALL_DISABLE;
_h_i2c0.init.no_stretch = I2C_NOSTRETCH_ENABLE;
i2c_reset(&_h_i2c0);
i2c_init(&_h_i2c0);
/* I2C0_SCL->PB8, I2C0_SDA->PB9 */
gpio_init(GPIOB, GPIO_PIN_8 | GPIO_PIN_9, &gpio_instruct);
#endif
#ifdef BSP_USING_I2C1
/* Initialize i2c function */
_h_i2c1.perh = I2C1;
_h_i2c1.init.clk_speed = 100000;
_h_i2c1.init.duty = I2C_DUTYCYCLE_2;
_h_i2c1.init.own_addr1 = 0xA0;
_h_i2c1.init.addr_mode = I2C_ADDR_7BIT;
_h_i2c1.init.general_call = I2C_GENERALCALL_DISABLE;
_h_i2c1.init.no_stretch = I2C_NOSTRETCH_ENABLE;
i2c_reset(&_h_i2c1);
i2c_init(&_h_i2c1);
/* I2C1_SCL->PB10, I2C1_SDA->PB11 */
gpio_init(GPIOB, GPIO_PIN_10 | GPIO_PIN_11, &gpio_instruct);
#endif
}
static rt_size_t es32f0_master_xfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num)
{
struct rt_i2c_msg *msg;
rt_uint32_t i;
rt_err_t ret = RT_ERROR;
for (i = 0; i < num; i++)
{
msg = &msgs[i];
if (msg->flags & RT_I2C_RD)
{
if (i2c_master_recv(bus->priv, msg->addr << 1, msg->buf, msg->len, TIMEOUT) != 0)
{
i2c_dbg("i2c bus write failed,i2c bus stop!\n");
goto out;
}
}
else
{
if (i2c_master_send(bus->priv, msg->addr << 1, msg->buf, msg->len, TIMEOUT) != 0)
{
i2c_dbg("i2c bus write failed,i2c bus stop!\n");
goto out;
}
}
}
ret = i;
out:
i2c_dbg("send stop condition\n");
return ret;
}
const struct rt_i2c_bus_device_ops es32f0_i2c_ops =
{
es32f0_master_xfer,
RT_NULL,
RT_NULL,
};
int rt_hw_i2c_init(void)
{
_i2c_init();
#ifdef BSP_USING_I2C0
/* define i2c Instance */
static struct rt_i2c_bus_device _i2c_device0;
rt_memset((void *)&_i2c_device0, 0, sizeof(struct rt_i2c_bus_device));
_i2c_device0.ops = &es32f0_i2c_ops;
_i2c_device0.priv = &_h_i2c0;
rt_i2c_bus_device_register(&_i2c_device0, "i2c0");
#endif
#ifdef BSP_USING_I2C1
/* define i2c Instance */
static struct rt_i2c_bus_device _i2c_device1;
rt_memset((void *)&_i2c_device1, 0, sizeof(struct rt_i2c_bus_device));
_i2c_device1.ops = &es32f0_i2c_ops;
_i2c_device1.priv = &_h_i2c1;
rt_i2c_bus_device_register(&_i2c_device1, "i2c1");
#endif
return RT_EOK;
}
INIT_DEVICE_EXPORT(rt_hw_i2c_init);
#endif
+16
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-19 wangyq the first version
*/
#ifndef DRV_I2C_H__
#define DRV_I2C_H__
int rt_hw_i2c_init(void);
#endif
File diff suppressed because it is too large. Load diff
+16
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-19 wangyq the first version
*/
#ifndef DRV_PWM_H__
#define DRV_PWM_H__
int rt_hw_pwm_init(void);
#endif
File diff suppressed because it is too large. Load diff
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-19 wangyq the first version
*/
#ifndef DRV_SPI_H__
#define DRV_SPI_H__
#include <rtthread.h>
#include <rthw.h>
#include <rtdevice.h>
struct es32f0_hw_spi_cs
{
rt_uint32_t pin;
};
/* cannot be used before completion init */
rt_err_t es32f0_spi_device_attach(rt_uint32_t pin, const char *bus_name, const char *device_name);
int rt_hw_spi_init(void);
#endif
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-19 wangyq the first version
*/
#include <rtthread.h>
#include "spi_flash.h"
#include "drv_spiflash.h"
#include "spi_flash_sfud.h"
#include "drv_spi.h"
#if defined(BSP_USING_SPI_FLASH)
static int rt_hw_spi_flash_init(void)
{
es32f0_spi_device_attach(50, "spi0", "spi00");
if (RT_NULL == rt_sfud_flash_probe("W25Q64", "spi00"))
{
return -RT_ERROR;
};
return RT_EOK;
}
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
#endif
+16
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-19 wangyq the first version
*/
#ifndef DRV_NOR_FLASH_H__
#define DRV_NOR_FLASH_H__
int rt_hw_spi_flash_init(void);
#endif
+4 -9
View File
@@ -45,13 +45,10 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
gpio_init_initstructure.func = GPIO_FUNC_3;
gpio_init(GPIOB, GPIO_PIN_10, &gpio_init_initstructure);
/* Initialize rx pin ,the same as txpin except mode*/
/* 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);
#endif /* uart0 gpio init */
#endif
#ifdef BSP_USING_UART1
/* Initialize tx pin */
@@ -61,9 +58,7 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
/* 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);
#endif /* uart1 gpio init */
#endif
uart->huart.init.mode = UART_MODE_UART;
uart->huart.init.baud = cfg->baud_rate;
@@ -90,7 +85,7 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
UART_DATA_INV_DISABLE(&uart->huart);
}
/*enable rx int*/
/* enable rx int */
uart_interrupt_config(&uart->huart, UART_IT_RXRD, ENABLE);
return RT_EOK;
+7 -2
View File
@@ -101,7 +101,7 @@
<sRunDeb>0</sRunDeb>
<sLrtime>0</sLrtime>
<bEvRecOn>1</bEvRecOn>
<nTsel>3</nTsel>
<nTsel>2</nTsel>
<sDll></sDll>
<sDllPa></sDllPa>
<sDlgDll></sDlgDll>
@@ -112,9 +112,14 @@
<tDlgDll></tDlgDll>
<tDlgPa></tDlgPa>
<tIfile></tIfile>
<pMon>Segger\JL2CM3.dll</pMon>
<pMon>BIN\CMSIS_AGDI.dll</pMon>
</DebugOpt>
<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 -FF0ES32F033x.FLM -FS00 -FL040000 -FP0($$Device:ES32F0334LT$Flash\ES32F033x.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>JL2CM3</Key>
+1 -1
View File
@@ -365,7 +365,7 @@
<ScatterFile />
<IncludeLibs />
<IncludeLibsPath />
<Misc> --keep *.o(.rti_fn.*) --keep *.o(FSymTab)</Misc>
<Misc />
<LinkerInputFile />
<DisabledWarnings />
</LDads>
+10
View File
@@ -163,8 +163,18 @@
#define BSP_USING_UART1
/* SPI Drivers */
/* I2C Drivers */
/* PWM Drivers */
/* Onboard Peripheral Drivers */
/* Offboard Peripheral Drivers */
+7 -2
View File
@@ -101,7 +101,7 @@
<sRunDeb>0</sRunDeb>
<sLrtime>0</sLrtime>
<bEvRecOn>1</bEvRecOn>
<nTsel>3</nTsel>
<nTsel>2</nTsel>
<sDll></sDll>
<sDllPa></sDllPa>
<sDlgDll></sDlgDll>
@@ -112,9 +112,14 @@
<tDlgDll></tDlgDll>
<tDlgPa></tDlgPa>
<tIfile></tIfile>
<pMon>Segger\JL2CM3.dll</pMon>
<pMon>BIN\CMSIS_AGDI.dll</pMon>
</DebugOpt>
<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 -FF0ES32F033x.FLM -FS00 -FL040000 -FP0($$Device:ES32F0334LT$Flash\ES32F033x.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>JL2CM3</Key>