未验证 提交 2be0c598 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #4460 from OpenNuvoton/nuvoton

[nuvoton] Update BSP.
# 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 |
\ No newline at end of file
| [numaker-m2354](numaker-m2354) | Nuvoton NuMaker-M2354 |
| [nk-rtu980](nk-rtu980) | Nuvoton NK-RTU980 |
\ No newline at end of file
......@@ -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>
......
......@@ -14,7 +14,7 @@
#if defined(BSP_USING_HSOTG)
#include <rtdevice.h>
#include <rtdbg.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* This delay must be at least 10 us */
......
......@@ -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)
......
......@@ -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)
......
......@@ -15,7 +15,7 @@
#include <rtdevice.h>
#include <sys/time.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
......
......@@ -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>
......
......@@ -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)
......
......@@ -19,7 +19,7 @@
defined(BSP_USING_TIMER3_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"
......
......@@ -17,7 +17,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 */
......
......@@ -88,10 +88,10 @@ static int I2C_WriteNAU88L25(uint16_t u16addr, uint16_t u16data)
static int I2C_ReadNAU88L25(uint16_t u16addr, uint16_t *pu16data)
{
struct rt_i2c_msg msgs[2];
uint16_t u16data = 0;
char au8TxData[2];
RT_ASSERT(g_I2cBusDev != NULL);
RT_ASSERT(pu16data != NULL);
au8TxData[0] = (uint8_t)((u16addr >> 8) & 0x00FF); //addr [15:8]
au8TxData[1] = (uint8_t)(u16addr & 0x00FF); //addr [ 7:0]
......@@ -103,8 +103,8 @@ static int I2C_ReadNAU88L25(uint16_t u16addr, uint16_t *pu16data)
msgs[1].addr = DEF_NAU88L25_ADDR; /* Slave address */
msgs[1].flags = RT_I2C_RD; /* Read flag */
msgs[1].buf = (rt_uint8_t *)&u16data; /* Read data pointer */
msgs[1].len = sizeof(u16data); /* Number of bytes read */
msgs[1].buf = (rt_uint8_t *)pu16data; /* Read data pointer */
msgs[1].len = sizeof(uint16_t); /* Number of bytes read */
if (rt_i2c_transfer(g_I2cBusDev, &msgs[0], 2) != 2)
{
......
......@@ -26,6 +26,8 @@
static int audio_test(int argc, char **argv)
{
#define DEF_MAX_ARGV_NUM 8
#define DEF_MAX_TEST_SECOND 5
int smplrate[] = {8000, 16000, 44100, 48000};
int smplbit[] = {16};
int chnum[] = {1, 2};
......@@ -54,9 +56,9 @@ static int audio_test(int argc, char **argv)
info.samplebits = smplbit[j];
info.channels = chnum[k];
wavrecorder_start(&info);
rt_thread_mdelay(10000);
rt_thread_mdelay(DEF_MAX_TEST_SECOND * 1000);
wavrecorder_stop();
rt_thread_mdelay(1000);
rt_thread_mdelay(DEF_MAX_TEST_SECOND * 1000);
}
else
{
......@@ -68,7 +70,7 @@ static int audio_test(int argc, char **argv)
rt_kprintf("Replay file at %s\n", strbuf);
wavplayer_play(strbuf);
rt_thread_mdelay(10000);
rt_thread_mdelay(DEF_MAX_TEST_SECOND * 1000);
wavplayer_stop();
}
} // k
......
......@@ -30,21 +30,6 @@ config SOC_SERIES_NUC980
select RT_USING_PIN
default y
menuconfig BSP_USING_CLK
bool "Enable Clock Controller(CLK)"
select RT_USING_PM
select BSP_USING_TMR
default y
help
Choose this option if you need CLK/PM function.
Notice: Enable the option will hold timer3 resource
if BSP_USING_CLK
config NU_CLK_INVOKE_WKTMR
bool "Enable SPD1 and DPD mode wakeup timer. (About 6.6 Secs)"
default y
endif
menuconfig BSP_USING_EMAC
bool "Enable Ethernet MAC Controller(EMAC)"
select RT_USING_LWIP
......
......@@ -14,7 +14,7 @@
#if defined(BSP_USING_ADC)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_sys.h>
/* Private define ---------------------------------------------------------------*/
......
......@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_sys.h>
/* Private Define ---------------------------------------------------------------*/
......
......@@ -13,7 +13,7 @@
#define __DRV_EBI_H___
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#define MAX_BANK EBI_BANK2
......
......@@ -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>
......@@ -117,7 +117,7 @@ static struct nu_emac nu_emac_arr[] =
.name = "e1",
.memmgr.psEmac = (EMAC_T *)EMC1_BA,
.irqn_tx = IRQ_EMC1_TX,
.irqn_rx = IRQ_EMC1_RX
.irqn_rx = IRQ_EMC1_RX,
.rstidx = EMAC1RST,
.clkidx = EMAC1CKEN,
},
......
......@@ -15,7 +15,7 @@
#if defined(BSP_USING_TIMER) && defined(RT_USING_HWTIMER)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_sys.h>
/* Private define ---------------------------------------------------------------*/
......
......@@ -15,7 +15,7 @@
#if defined(BSP_USING_TIMER_CAPTURE)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_sys.h>
/* Private define ---------------------------------------------------------------*/
......
......@@ -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>
......
......@@ -15,7 +15,7 @@
#if defined( BSP_USING_I2C)
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_i2c.h>
#include <drv_sys.h>
......
......@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <drv_i2s.h>
#include <NuMicro.h>
#include "NuMicro.h"
/* Private define ---------------------------------------------------------------*/
#define DBG_ENABLE
......
......@@ -15,7 +15,7 @@
#include <rtthread.h>
#include <drv_sys.h>
#include <NuMicro.h>
#include "NuMicro.h"
#if !defined(NU_I2S_DMA_FIFO_SIZE)
#define NU_I2S_DMA_FIFO_SIZE (2048)
......
......@@ -15,7 +15,7 @@
#include <rtconfig.h>
#include <rtthread.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <board.h>
#define NU_PDMA_CAP_NONE (0 << 0)
......
......@@ -15,7 +15,7 @@
#include <rtdevice.h>
#include <sys/time.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_sys.h>
/* Private define ---------------------------------------------------------------*/
......
......@@ -12,12 +12,9 @@
#include <rtconfig.h>
#define BSP_USING_SCUART
#define BSP_USING_SCUART0
#if defined(BSP_USING_SCUART)
#include <NuMicro.h>
#include "NuMicro.h"
#include <rtdevice.h>
#include <rthw.h>
#include <drv_sys.h>
......
......@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <string.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_pdma.h>
#include <drv_sys.h>
......
......@@ -17,7 +17,7 @@
#include <rtthread.h>
#include <rthw.h>
#include <rtdevice.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include "drv_sys.h"
/* Private define ---------------------------------------------------------------*/
......@@ -106,7 +106,7 @@ static const struct rt_i2c_bit_ops nu_soft_i2c_bit_ops =
*/
static void nu_soft_i2c_udelay(rt_uint32_t us)
{
nu_systick_udelay(us);
rt_hw_us_delay(us);
}
/**
......
......@@ -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)
......
......@@ -348,4 +348,22 @@ int nu_clocks(int argc, char **argv)
MSH_CMD_EXPORT(nu_clocks, Get all system clocks);
#endif
#ifdef RT_USING_INTERRUPT_INFO
int list_interrupt(int argc, char **argv)
{
int i;
for (i = 1; i <= SYS_MAX_INT_SOURCE; i++)
{
if (irq_desc[i].handler != rt_hw_interrupt_dummy_handler)
{
rt_kprintf("[%d] %s: %d\n", i, irq_desc[i].name, irq_desc[i].counter);
}
}
return 0;
}
MSH_CMD_EXPORT(list_interrupt, list registered interrupts);
#endif
#endif
......@@ -49,13 +49,13 @@ void rt_hw_systick_init(void)
ETIMER_Start(USE_TIMER);
} /* rt_hw_systick_init */
void nu_systick_udelay(uint32_t delay_us)
void rt_hw_us_delay(rt_uint32_t us)
{
rt_uint32_t ticks;
rt_uint32_t told, tnow, tcnt = 0;
rt_uint32_t cmp = ETIMER_GetCompareData(USE_TIMER);
ticks = delay_us * cmp / (1000000 / RT_TICK_PER_SECOND);
ticks = us * cmp / (1000000 / RT_TICK_PER_SECOND);
told = ETIMER_GetCounter(USE_TIMER);
while (1)
{
......@@ -82,5 +82,4 @@ void nu_systick_udelay(uint32_t delay_us)
}
}
}
} /* nu_systick_udelay */
} /* rt_hw_us_delay */
......@@ -16,7 +16,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_uart.h>
#include <drv_sys.h>
......@@ -25,6 +25,7 @@
#endif
/* Private define ---------------------------------------------------------------*/
enum
{
UART_START = -1,
......@@ -70,6 +71,7 @@ struct nu_uart
IRQn_Type irqn;
E_SYS_IPRST rstidx;
E_SYS_IPCLK clkidx;
#if defined(RT_SERIAL_USING_DMA)
uint32_t dma_flag;
int16_t pdma_perp_tx;
......@@ -81,7 +83,6 @@ struct nu_uart
int32_t rxdma_trigger_len;
nu_pdma_desc_t pdma_rx_desc;
#endif
};
......@@ -395,6 +396,34 @@ static void nu_uart_isr(int vector, void *param)
uart_base->FIFOSTS = u32FIFOSts;
}
/**
* Set RS-485 AUD mode
*/
void nu_uart_set_rs485aud(struct rt_serial_device *serial, rt_bool_t bRTSActiveLowLevel)
{
UART_T *uart_base;
RT_ASSERT(serial != RT_NULL);
/* Get base address of uart register */
uart_base = ((nu_uart_t)serial)->uart_base;
/* Set RTS as RS-485 phy direction controlling ping. */
UART_SelectRS485Mode(uart_base, UART_ALTCTL_RS485AUD_Msk, 0);
if (bRTSActiveLowLevel)
{
/* Set direction pin as active-low. */
uart_base->MODEM |= UART_MODEM_RTSACTLV_Msk;
}
else
{
/* Set direction pin as active-high. */
uart_base->MODEM &= ~UART_MODEM_RTSACTLV_Msk;
}
rt_kprintf("Set %s to RS-485 AUD function mode. ActiveLowLevel-%s\n", ((nu_uart_t)serial)->name, bRTSActiveLowLevel ? "YES" : "NO");
}
/**
* Configure uart port
*/
......
......@@ -16,5 +16,6 @@
#include <rtdevice.h>
rt_err_t rt_hw_uart_init(void);
void nu_uart_set_rs485aud(struct rt_serial_device *serial, rt_bool_t bRTSActiveLowLevel);
#endif /* __DRV_UART_H__ */
......@@ -829,7 +829,7 @@ static rt_err_t _init(rt_device_t device)
nu_sys_ip_reset(nu_usbd.rstidx);
nu_systick_udelay(1000);
rt_hw_us_delay(1000);
/* USBD Open */
USBD_ENABLE_USB();
......
......@@ -15,7 +15,7 @@
#include <rtdevice.h>
#include <rthw.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include "usb.h"
#include "usbh_lib.h"
......
......@@ -16,7 +16,7 @@
#include <rthw.h>
#include <rtdevice.h>
#include <rtdbg.h>
#include <NuMicro.h>
#include "NuMicro.h"
#include <drv_sys.h>
/* Private define ---------------------------------------------------------------*/
......
......@@ -13,7 +13,7 @@
#ifndef __BOARD_H__
#define __BOARD_H__
#include <NuMicro.h>
#include "NuMicro.h"
#include "drv_sys.h"
#if defined(__CC_ARM)
......
此差异已折叠。
mainmenu "RT-Thread Configuration"
config BSP_DIR
string
option env="BSP_ROOT"
default "."
config RTT_DIR
string
option env="RTT_ROOT"
default "../../.."
# you can change the RTT_ROOT default "../../.." to your rtthread_root,
# example : default "F:/git_repositories/rt-thread"
config PKGS_DIR
string
option env="PKGS_ROOT"
default "packages"
config NU_PKGS_DIR
string
option env="NU_PKGS_ROOT"
default "../libraries/nu_packages"
source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "$NU_PKGS_DIR/Kconfig"
source "$BSP_DIR/board/Kconfig"
# NK-RTU980
## 1. Introduction
NuMaker-RTU-NUC980, also known as Chili, is a Nuvoton’s development platform that uses NUC980DR61YC microprocessor with a 64-pin package on a 50 mm x 50 mm dimension PCB. Chili board provides a high-end hardware features including a NUC980DR61YC ARM926EJ-S processor with 64 MB DRAM, 32MB SPI NOR Flash, 10/100 Ethernet MAC interface, USB 2.0 High Speed host/device connector, CAN bus, RS-485 and five GPIOs. Crypto engine supports RSA2048, AES256, ECC, SHA512 algorithm and a Pseudo Random Number Generator for communication security protection.
[![NK-RTU980](https://i.imgur.com/gCKG4PN.png "NK-RTU980")](https://i.imgur.com/gCKG4PN.png "NK-RTU980")
### 1.1 MCU specification
| | Features |
| -- | -- |
| Part NO. | NUC980DR61YC |
| CPU ARCH. | 32-bit ARM926EJ-STM |
| Operation frequency | 300 MHz |
| Embedded SDRAM size | Built-in 64MB |
| Crypto engine | AES, RSA, ECC, HMAC and SHA crypto accelerator |
| RMII interface | 10/100 Mbps x1 |
| USB 2.0 | High Speed Host x1, High Speed Host/Device x1 |
| Extern storage | 32 MB SPI-NOR Flash |
### 1.2 Interface
| Interface |
| -- |
| Arduino UNO |
| A RJ45 Ethernet |
| An USB 2.0 HS port |
| An USB 2.0 HS OTG port |
| A RS-485 |
| A CAN bus |
| An ICE connector |
### 1.3 On-board devices
| Device | Description | Driver supporting status |
| -- | -- | -- |
|Ethernet PHY | IP101GR | Supported |
|Button | | Supported |
|LEDs | | Supported |
|USB Device | VCOM + MStorage | Supported |
|USB Host | MStorage | Supported |
|SPI NOR flash | W25Q256F | Supported |
|VCOM | For console | Ready.(Need to install VCOM driver) |
## 2. Supported compiler
Support GCC, MDK4 and MDK5 IDE/compilers. More information of these compiler version as following:
| IDE/Compiler | Tested version |
| ---------- | ---------------------------- |
| MDK4 | 4.76 |
| MDK5 | 5.26.2 |
| GCC | GCC 5.4.1 20160919 (release) |
Notice: Please install ICE driver for development.
## 3. Program firmware
### 3.1 SDRAM Downloading using NuWriter
You can use NuWriter to download rtthread.bin into SDRAM, then run it.
[![SDRAM Downloading using NuWriter](https://i.imgur.com/NvbzsRp.gif "SDRAM Downloading using NuWriter")](https://i.imgur.com/NvbzsRp.gif "SDRAM Downloading using NuWriter")
<br>
Choose type: DDR/SRAM<br>
<< Press Re-Connect >><br>
Choose file: Specify your rtthread.bin file.<br>
Execute Address: 0x0<br>
Option: Download and run<br>
<< Press Download >><br>
Enjoy!! <br>
<br>
### 3.2 SPI NOR flash using NuWriter
You can use NuWriter to program rtthread.bin into SPI NOR flash.
[![SPI NOR flash](https://i.imgur.com/8OtXGSQ.gif "SPI NOR flash")](https://i.imgur.com/8OtXGSQ.gif "SPI NOR flash using NuWriter")
<br>
Choose type: SPI<br>
<< Press Re-Connect >><br>
Choose file: Specify your rtthread.bin file.<br>
Image Type: Loader<br>
Execute Address: 0x0<br>
<< Press Program >><br>
<< Press OK & Wait it down >><br>
<< Set Power-on setting to SPI NOR booting >><br>
<< Press Reset button on board >><br>
Enjoy!! <br>
<br>
## 4. Test
You can use Tera Term terminate emulator (or other software) to type commands of RTT. All parameters of serial communication are shown in below image. Here, you can find out the corresponding port number of Nuvoton Virtual Com Port in window device manager.
[![Serial settings](https://i.imgur.com/5NYuSNM.png "Serial settings")](https://i.imgur.com/5NYuSNM.png "Serial settings")
## 5. Purchase
* [Nuvoton Direct][1]
## 6. Resources
* [Download Board Schematics][2]
* [Download NK-RTU980 Quick Start Guide][3]
* [Download TRM][4]
* [Download NuWriter][5]
[1]: https://direct.nuvoton.com/tw/numaker-rtu-nuc980
[2]: https://www.nuvoton.com/resource-download.jsp?tp_GUID=HL1020200508155209
[3]: https://www.nuvoton.com/resource-download.jsp?tp_GUID=UG1320200623183237
[4]: https://www.nuvoton.com/resource-download.jsp?tp_GUID=DA05-NUC980-1
[5]: https://github.com/OpenNuvoton/NUC980_NuWriter
\ No newline at end of file
# for module compiling
import os
Import('RTT_ROOT')
cwd = str(Dir('#'))
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')
import os
import sys
import rtconfig
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
Export('RTT_ROOT')
Export('rtconfig')
SDK_ROOT = os.path.abspath('./')
if os.path.exists(SDK_ROOT + '/libraries'):
libraries_path_prefix = SDK_ROOT + '/libraries'
else:
libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/libraries'
SDK_LIB = libraries_path_prefix
Export('SDK_LIB')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
nuvoton_library = 'nuc980'
rtconfig.BSP_LIBRARY_TYPE = nuvoton_library
# include libraries
objs.extend(SConscript(os.path.join(libraries_path_prefix, nuvoton_library, 'SConscript')))
# include nu_pkgs
objs.extend(SConscript(os.path.join(libraries_path_prefix, 'nu_packages', 'SConscript')))
# make a building
DoBuilding(TARGET, objs)
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd, str(Dir('#'))]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/**************************************************************************//**
*
* @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-12-12 Wayne First version
*
******************************************************************************/
#include <rtconfig.h>
#include <rtdevice.h>
#if defined(RT_USING_PIN)
#include <drv_gpio.h>
/* defined the LED_G1 pin: PC3 */
#define LED_G1 NU_GET_PININDEX(NU_PC, 3)
/* defined the LED_G2 pin: PC11 */
#define LED_G2 NU_GET_PININDEX(NU_PC, 11)
/* defined the BUTTON pin: PC15 */
#define BUTTON NU_GET_PININDEX(NU_PC, 15)
static uint32_t u32Button = BUTTON;
void nu_button_cb(void *args)
{
static int u32ToggleFlag = 0;
uint32_t u32Key = *((uint32_t *)(args));
switch (u32Key)
{
case BUTTON:
u32ToggleFlag = ~u32ToggleFlag;
rt_pin_write(LED_G1, u32ToggleFlag);
break;
}
}
#endif
int main(int argc, char **argv)
{
#if defined(RT_USING_PIN)
int counter = 1000;
/* set LED_G1 pin mode to output */
rt_pin_mode(LED_G1, PIN_MODE_OUTPUT);
/* set LED_G2 pin mode to output */
rt_pin_mode(LED_G2, PIN_MODE_OUTPUT);
/* set BUTTON pin mode to input */
rt_pin_mode(BUTTON, PIN_MODE_INPUT_PULLUP);
rt_pin_attach_irq(BUTTON, PIN_IRQ_MODE_FALLING, nu_button_cb, &u32Button);
rt_pin_irq_enable(BUTTON, PIN_IRQ_ENABLE);
while (counter--)
{
rt_pin_write(LED_G2, PIN_HIGH);
rt_thread_mdelay(200);
rt_pin_write(LED_G2, PIN_LOW);
rt_thread_mdelay(200);
}
#endif
return 0;
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册