Merge pull request #28 from RT-Thread/master

pr
This commit is contained in:
Meco Jianting Man
2021-03-17 02:32:02 +08:00
committed by GitHub
744 changed files with 10033 additions and 64240 deletions
+4 -3
View File
@@ -68,6 +68,8 @@ ab32vg1-prougen 是 中科蓝讯(Bluetrum) 推出的一款基于 RISC-V 内核
本 BSP 为开发者提供 GCC 开发环境。下面介绍如何将系统运行起来。
教学视频:https://www.bilibili.com/video/BV1RV411v75P/
#### 硬件连接
使用数据线连接开发板到 PC,打开电源开关。
@@ -94,13 +96,12 @@ msh >
此 BSP 默认只开启了 GPIO 和 串口0 的功能,如果需使用 SD 卡、Flash 等更多高级功能,需要利用 ENV 工具对BSP 进行配置,步骤如下:
1. 在 bsp 下打开 env 工具。
2. 输入`menuconfig`命令配置工程,配置好之后保存退出。
3. 输入`pkgs --update`命令更新软件包。
4. 输入`scons` 命令重新编译工程。
更多细节请参见使用指南:https://ab32vg1-example.readthedocs.io/zh/latest/introduction.html
## 注意事项
波特率默认为 1.5M,需要使用 [Downloader](https://github.com/BLUETRUM/Downloader) 下载 `.dcf` 到芯片,需要编译后自动下载,需要在 `Downloader` 中的下载的下拉窗中选择 `自动`;目前暂时屏蔽 uart1 打印
@@ -15,4 +15,6 @@
#include <rthw.h>
#include <rtdevice.h>
#define GET_PIN(PORTx,PIN) (uint8_t)__AB32_GET_PIN_##PORTx(PIN)
#endif // DRV_COMMON_H__
@@ -15,6 +15,10 @@
#include "board.h"
#define __AB32_PORT(port) GPIO##port
#define __AB32_GET_PIN_A(PIN) PIN
#define __AB32_GET_PIN_B(PIN) 8 + PIN
#define __AB32_GET_PIN_E(PIN) 13 + PIN
#define __AB32_GET_PIN_F(PIN) 21 + PIN
int rt_hw_pin_init(void);
+3 -2
View File
@@ -1,4 +1,4 @@
# Nuvoton BSP descriptions
ï»? Nuvoton BSP descriptions
Current supported BSP shown in below table:
| **BSP folder** | **Board name** |
@@ -6,4 +6,5 @@ Current supported BSP shown in below table:
| [numaker-iot-m487](numaker-iot-m487) | Nuvoton NuMaker-IoT-M487 |
| [numaker-pfm-m487](numaker-pfm-m487) | Nuvoton NuMaker-PFM-M487 |
| [nk-980iot](nk-980iot) | Nuvoton NK-980IOT |
| [numaker-m2354](numaker-m2354) | Nuvoton NuMaker-M2354 |
| [numaker-m2354](numaker-m2354) | Nuvoton NuMaker-M2354 |
| [nk-rtu980](nk-rtu980) | Nuvoton NK-RTU980 |
@@ -9,6 +9,7 @@
#ifndef __NUMICRO_H__
#define __NUMICRO_H__
#include "nutool_clkcfg.h"
#include "M2354.h"
#endif /* __NUMICRO_H__ */
@@ -49,11 +49,21 @@ extern "C" {
/*----------------------------------------------------------------------------
Define SYSCLK
*----------------------------------------------------------------------------*/
#ifndef __HXT
#define __HXT (12000000UL) /*!< External Crystal Clock Frequency */
#endif
#define __LIRC (32000UL) /*!< Internal 32K RC Oscillator Frequency */
#define __HIRC (12000000UL) /*!< Internal 12M RC Oscillator Frequency */
#ifndef __LXT
#define __LXT (32768UL) /*!< External Crystal Clock Frequency 32.768KHz */
#endif
#ifndef __HSI
#define __HSI (48000000UL) /*!< PLL Output Clock Frequency */
#endif
#define __HIRC48 (48000000UL) /*!< Internal 48M RC Oscillator Frequency */
#define __LIRC32 (32000UL) /*!< Internal 32K RC Oscillator Frequency */
#define __MIRC (4000000UL) /*!< Internal 4M RC Oscillator Frequency */
@@ -93,7 +103,7 @@ extern uint32_t __PC(void); /*!< Return the current program counter valu
*/
#define ASSERT_PARAM(expr) { if (!(expr)) { AssertError((uint8_t*)__FILE__, __LINE__); } }
void AssertError(uint8_t* file, uint32_t line);
void AssertError(uint8_t *file, uint32_t line);
#else
#define ASSERT_PARAM(expr)
#endif
@@ -348,6 +348,7 @@
<state>$PROJ_DIR$\..\..\Device\Nuvoton\M2354\Include</state>
<state>$PROJ_DIR$\..\..\CMSIS\Include</state>
<state>$PROJ_DIR$\..\inc</state>
<state>$PROJ_DIR$</state>
</option>
<option>
<name>CCStdIncCheck</name>
@@ -1385,6 +1386,7 @@
<state>$PROJ_DIR$\..\..\Device\Nuvoton\M2354\Include</state>
<state>$PROJ_DIR$\..\..\CMSIS\Include</state>
<state>$PROJ_DIR$\..\inc</state>
<state>$PROJ_DIR$</state>
</option>
<option>
<name>CCStdIncCheck</name>
@@ -338,7 +338,7 @@
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath>..\inc;..\..\CMSIS\Include;..\..\Device\Nuvoton\M2354\Include</IncludePath>
<IncludePath>..\inc;..\..\CMSIS\Include;..\..\Device\Nuvoton\M2354\Include;.</IncludePath>
</VariousControls>
</Cads>
<Aads>
@@ -14,7 +14,7 @@
#if defined(BSP_USING_BPWM_CAPTURE)
#if ((BSP_USING_BPWM0_CAPTURE_CHMSK+BSP_USING_BPWM1_CAPTURE_CHMSK)!=0)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private typedef --------------------------------------------------------------*/
typedef struct _bpwm_dev
@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private Define ---------------------------------------------------------------*/
#define RX_MSG_ID_INDEX 16
@@ -18,7 +18,7 @@
#include <rtdbg.h>
#include <stdint.h>
#include <string.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
@@ -12,7 +12,7 @@
#include <rtconfig.h>
#include <rtthread.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <nu_bitutil.h>
#include "drv_uart.h"
#include "board.h"
@@ -24,7 +24,7 @@
/**
* This function will initial M487 board.
*/
void rt_hw_board_init(void)
RT_WEAK void rt_hw_board_init(void)
{
/* Init System/modules clock */
nutool_modclkcfg_init();
@@ -67,6 +67,41 @@ void rt_hw_board_init(void)
#endif
}
/**
* The time delay function.
*
* @param microseconds.
*/
void rt_hw_us_delay(rt_uint32_t us)
{
rt_uint32_t ticks;
rt_uint32_t told, tnow, tcnt = 0;
rt_uint32_t reload = SysTick->LOAD;
ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
told = SysTick->VAL;
while (1)
{
tnow = SysTick->VAL;
if (tnow != told)
{
if (tnow < told)
{
tcnt += told - tnow;
}
else
{
tcnt += reload - tnow + told;
}
told = tnow;
if (tcnt >= ticks)
{
break;
}
}
}
}
/**
* This is the timer interrupt service routine.
*
@@ -11,7 +11,7 @@
#include <rtconfig.h>
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#ifdef BSP_USING_EADC
@@ -13,7 +13,7 @@
#define __DRV_EBI_H___
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/**
* @brief Initialize EBI for specify Bank
@@ -14,7 +14,7 @@
#if defined(BSP_USING_ECAP)
#if ((BSP_USING_ECAP0_CHMSK+BSP_USING_ECAP1_CHMSK)!=0)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#define ECAP_CH0_POS (0)
#define ECAP_CH1_POS (1)
@@ -14,7 +14,7 @@
#if defined(BSP_USING_EPWM_CAPTURE)
#if ((BSP_USING_EPWM0_CAPTURE_CHMSK+BSP_USING_EPWM1_CAPTURE_CHMSK)!=0)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#define EPWM_CH0CH1_POS (0)
#define EPWM_CH2CH3_POS (2)
@@ -14,7 +14,7 @@
#define __DRV_FMC_H__
#include <rtthread.h>
#include <NuMicro.h>
#include "NuMicro.h"
int nu_fmc_read(long offset, uint8_t *buf, size_t size);
int nu_fmc_write(long offset, const uint8_t *buf, size_t size);
@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <nu_bitutil.h>
#include <drv_gpio.h>
#include <stdlib.h>
@@ -14,7 +14,7 @@
#ifdef BSP_USING_I2C
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
#define LOG_TAG "drv.i2c"
@@ -220,7 +220,8 @@ static rt_err_t nu_i2s_dai_setup(nu_i2s_t psNuI2s, struct rt_audio_configure *pc
}
/* Set MCLK and enable MCLK */
I2S_EnableMCLK(psNuI2s->i2s_base, __HXT);
/* The target MCLK is related to audio codec setting. */
I2S_EnableMCLK(psNuI2s->i2s_base, 12000000);
/* Set unmute */
if (pNuACodecOps->nu_acodec_mixer_control)
@@ -14,7 +14,7 @@
#define __DRV_I2S_H__
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_pdma.h>
#if !defined(NU_I2S_DMA_FIFO_SIZE)
@@ -14,7 +14,7 @@
#if defined(BSP_USING_OTG)
#include <rtdevice.h>
#include <rtdbg.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* This delay must be at least 10 us */
static void _usb_init_delay(void)
@@ -15,7 +15,7 @@
#include <rtconfig.h>
#include <rtthread.h>
#include <NuMicro.h>
#include "NuMicro.h"
#ifndef NU_PDMA_SGTBL_POOL_SIZE
#define NU_PDMA_SGTBL_POOL_SIZE (16)
@@ -14,7 +14,8 @@
#if defined (BSP_USING_RTC)
#include <rtdevice.h>
#include <NuMicro.h>
#include <sys/time.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
@@ -184,8 +185,8 @@ static rt_err_t nu_rtc_is_date_valid(const time_t *const t)
if (!initialised)
{
t_upper = mktime((struct tm *)&tm_upper);
t_lower = mktime((struct tm *)&tm_lower);
t_upper = timegm((struct tm *)&tm_upper);
t_lower = timegm((struct tm *)&tm_lower);
initialised = RT_TRUE;
}
@@ -226,13 +227,13 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
tm_out.tm_hour = hw_time.u32Hour;
tm_out.tm_min = hw_time.u32Minute;
tm_out.tm_sec = hw_time.u32Second;
*time = mktime(&tm_out);
*time = timegm(&tm_out);
break;
case RT_DEVICE_CTRL_RTC_SET_TIME:
time = (time_t *) args;
tm_in = localtime(time);
tm_in = gmtime(time);
if (nu_rtc_is_date_valid(time) != RT_EOK)
return RT_ERROR;
@@ -14,7 +14,7 @@
#if defined(BSP_USING_SCUART)
#include <NuMicro.h>
#include "NuMicro.h"
#include <rtdevice.h>
#include <rthw.h>
@@ -15,7 +15,7 @@
#if defined(BSP_USING_SDH)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_pdma.h>
#include <string.h>
@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_slcd.h>
/* Private define ---------------------------------------------------------------*/
@@ -14,7 +14,7 @@
#define __DRV_SLCD_H__
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
struct nu_slcd_pixel
{
@@ -17,7 +17,7 @@
#include <rtthread.h>
#include <rthw.h>
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
#define LOG_TAG "drv.softi2c"
@@ -65,7 +65,6 @@ struct nu_soft_i2c
};
/* Private functions ------------------------------------------------------------*/
static void nu_soft_i2c_udelay(rt_uint32_t us);
static void nu_soft_i2c_set_sda(void *data, rt_int32_t state);
static void nu_soft_i2c_set_scl(void *data, rt_int32_t state);
static rt_int32_t nu_soft_i2c_get_sda(void *data);
@@ -91,48 +90,13 @@ static const struct rt_i2c_bit_ops nu_soft_i2c_bit_ops =
.set_scl = nu_soft_i2c_set_scl,
.get_sda = nu_soft_i2c_get_sda,
.get_scl = nu_soft_i2c_get_scl,
.udelay = nu_soft_i2c_udelay,
.udelay = rt_hw_us_delay,
.delay_us = 1,
.timeout = 100
};
/* Functions define ------------------------------------------------------------*/
/**
* The time delay function.
*
* @param microseconds.
*/
static void nu_soft_i2c_udelay(rt_uint32_t us)
{
rt_uint32_t ticks;
rt_uint32_t told, tnow, tcnt = 0;
rt_uint32_t reload = SysTick->LOAD;
ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
told = SysTick->VAL;
while (1)
{
tnow = SysTick->VAL;
if (tnow != told)
{
if (tnow < told)
{
tcnt += told - tnow;
}
else
{
tcnt += reload - tnow + told;
}
told = tnow;
if (tcnt >= ticks)
{
break;
}
}
}
}
/**
* This function initializes the soft i2c pin.
*
@@ -163,9 +127,9 @@ static rt_err_t nu_soft_i2c_bus_unlock(const struct nu_soft_i2c_config *cfg)
while (i++ < 9)
{
rt_pin_write(cfg->scl, PIN_HIGH);
nu_soft_i2c_udelay(100);
rt_hw_us_delay(100);
rt_pin_write(cfg->scl, PIN_LOW);
nu_soft_i2c_udelay(100);
rt_hw_us_delay(100);
}
}
if (PIN_LOW == rt_pin_read(cfg->sda))
@@ -16,7 +16,7 @@
#include <rtconfig.h>
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <nu_bitutil.h>
#if defined(BSP_USING_SPI_PDMA)
@@ -282,7 +282,8 @@ static rt_err_t nu_spii2s_dai_setup(nu_i2s_t psNuSPII2s, struct rt_audio_configu
LOG_I("Open SPII2S.");
/* Set MCLK and enable MCLK */
SPII2S_EnableMCLK(spii2s_base, __HXT);
/* The target MCLK is related to audio codec setting. */
SPII2S_EnableMCLK(spii2s_base, 12000000);
/* Set un-mute */
if (pNuACodecOps->nu_acodec_mixer_control)
@@ -15,7 +15,7 @@
#if (defined(BSP_USING_TIMER) && defined(RT_USING_HWTIMER))
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
#define NU_TIMER_DEVICE(timer) (nu_timer_t *)(timer)
@@ -21,7 +21,7 @@
defined(BSP_USING_TIMER5_CAPTURE)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private typedef --------------------------------------------------------------*/
typedef struct _timer
@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_uart.h>
#if defined(RT_SERIAL_USING_DMA)
@@ -15,7 +15,7 @@
#if (defined(BSP_USING_UI2C) && defined(RT_USING_I2C))
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
#define LOG_TAG "drv.ui2c"
@@ -15,7 +15,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include "usb.h"
#include "usbh_lib.h"
@@ -24,7 +24,7 @@
#include <rtdevice.h>
#include <rtdef.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <nu_bitutil.h>
#if defined(BSP_USING_USPI_PDMA)
@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#if defined(RT_SERIAL_USING_DMA)
#include <drv_pdma.h>
@@ -16,7 +16,7 @@
#include <rthw.h>
#include <rtdevice.h>
#include <rtdbg.h>
#include <NuMicro.h>
#include "NuMicro.h"
/*-------------------------------------------------------------------------------*/
/* watchdog timer timeout look up table */
@@ -14,7 +14,7 @@
#if defined(BSP_USING_BPWM_CAPTURE)
#if ((BSP_USING_BPWM0_CAPTURE_CHMSK+BSP_USING_BPWM1_CAPTURE_CHMSK)!=0)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private typedef --------------------------------------------------------------*/
typedef struct _bpwm_dev
@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private Define ---------------------------------------------------------------*/
#define RX_MSG_ID_INDEX 16
@@ -18,7 +18,7 @@
#include <rtdbg.h>
#include <stdint.h>
#include <string.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
@@ -12,7 +12,7 @@
#include <rtconfig.h>
#include <rtthread.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include "drv_uart.h"
#include "board.h"
#include "nutool_pincfg.h"
@@ -20,9 +20,9 @@
/**
* This function will initial M487 board.
* This function will initial.
*/
void rt_hw_board_init(void)
RT_WEAK void rt_hw_board_init(void)
{
/* Init System/modules clock */
nutool_modclkcfg_init();
@@ -67,6 +67,41 @@ void rt_hw_board_init(void)
#endif
}
/**
* The time delay function.
*
* @param microseconds.
*/
void rt_hw_us_delay(rt_uint32_t us)
{
rt_uint32_t ticks;
rt_uint32_t told, tnow, tcnt = 0;
rt_uint32_t reload = SysTick->LOAD;
ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
told = SysTick->VAL;
while (1)
{
tnow = SysTick->VAL;
if (tnow != told)
{
if (tnow < told)
{
tcnt += told - tnow;
}
else
{
tcnt += reload - tnow + told;
}
told = tnow;
if (tcnt >= ticks)
{
break;
}
}
}
}
/**
* This is the timer interrupt service routine.
*
@@ -89,7 +124,7 @@ void rt_hw_cpu_reset(void)
SYS->IPRST0 |= SYS_IPRST0_CHIPRST_Msk;
}
int reboot(int argc, char** argv)
int reboot(int argc, char **argv)
{
rt_hw_cpu_reset();
return 0;
@@ -11,7 +11,7 @@
#include <rtconfig.h>
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#ifdef BSP_USING_EADC
@@ -13,7 +13,7 @@
#define __DRV_EBI_H___
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
/**
* @brief Initialize EBI for specify Bank
@@ -14,7 +14,7 @@
#if defined(BSP_USING_ECAP)
#if ((BSP_USING_ECAP0_CHMSK+BSP_USING_ECAP1_CHMSK)!=0)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#define ECAP_CH0_POS (0)
#define ECAP_CH1_POS (1)
@@ -17,7 +17,7 @@
#if defined(RT_USING_LWIP)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <netif/ethernetif.h>
#include <netif/etharp.h>
#include <lwip/icmp.h>
@@ -14,7 +14,7 @@
#if defined(BSP_USING_EPWM_CAPTURE)
#if ((BSP_USING_EPWM0_CAPTURE_CHMSK+BSP_USING_EPWM1_CAPTURE_CHMSK)!=0)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#define EPWM_CH0CH1_POS (0)
#define EPWM_CH2CH3_POS (2)
@@ -14,7 +14,7 @@
#define __DRV_FMC_H__
#include <rtthread.h>
#include <NuMicro.h>
#include "NuMicro.h"
int nu_fmc_read(long offset, uint8_t *buf, size_t size);
int nu_fmc_write(long offset, const uint8_t *buf, size_t size);
@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <nu_bitutil.h>
#include <drv_gpio.h>
#include <stdlib.h>

Some files were not shown because too many files have changed in this diff Show More