Add uart driver and finsh function
This commit is contained in:
parent
d50ab16e6f
commit
3abf1fd5ba
|
@ -10,7 +10,7 @@
|
|||
; *
|
||||
; ******************************************************************************/
|
||||
|
||||
Stack_Size EQU 0x00000200
|
||||
Stack_Size EQU 0x00000100
|
||||
|
||||
AREA STACK, NOINIT, READWRITE, ALIGN=3
|
||||
Stack_Mem SPACE Stack_Size
|
||||
|
|
|
@ -56,7 +56,7 @@ static void rt_init_thread_entry(void* parameter)
|
|||
/* Create led thread */
|
||||
led_thread = rt_thread_create("led",
|
||||
led_thread_entry, RT_NULL,
|
||||
256, 20, 20);
|
||||
128, 20, 20);
|
||||
if(led_thread != RT_NULL)
|
||||
rt_thread_startup(led_thread);
|
||||
}
|
||||
|
|
|
@ -14,9 +14,8 @@
|
|||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#include "usart.h"
|
||||
/* RT_USING_COMPONENTS_INIT */
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
#include <components.h>
|
||||
|
@ -44,7 +43,7 @@ void NVIC_Configuration(void)
|
|||
* @param nCount: specifies the delay time length.
|
||||
* @retval None
|
||||
*/
|
||||
static void Delay(__IO uint32_t nCount)
|
||||
static void delay(__IO uint32_t nCount)
|
||||
{
|
||||
/* Decrement nCount value */
|
||||
while (nCount != 0)
|
||||
|
@ -53,6 +52,30 @@ static void Delay(__IO uint32_t nCount)
|
|||
}
|
||||
}
|
||||
|
||||
static void rt_hw_system_init(void)
|
||||
{
|
||||
/*---------------------------------------------------------------------------------------------------------*/
|
||||
/* Init System Clock */
|
||||
/*---------------------------------------------------------------------------------------------------------*/
|
||||
SYS_UnlockReg();
|
||||
/* Enable Internal RC 22.1184MHz clock */
|
||||
CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
|
||||
|
||||
/* Waiting for Internal RC clock ready */
|
||||
CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
|
||||
|
||||
/* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
|
||||
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
|
||||
|
||||
/* Set core clock as PLL_CLOCK from PLL */
|
||||
CLK_SetCoreClock(BOARD_PLL_CLOCK);
|
||||
|
||||
/* Set SysTick clock source to HCLK source divide 2 */
|
||||
CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLK_S_HCLK_DIV2);
|
||||
|
||||
SYS_LockReg();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the timer interrupt service routine.
|
||||
*
|
||||
|
@ -75,10 +98,13 @@ void rt_hw_board_init()
|
|||
/* NVIC Configuration */
|
||||
NVIC_Configuration();
|
||||
|
||||
/* Configure the system clock */
|
||||
rt_hw_system_init();
|
||||
/* Configure the SysTick */
|
||||
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
|
||||
|
||||
/* Initial usart deriver, and set console device */
|
||||
rt_hw_usart_init();
|
||||
#ifdef RT_USING_CONSOLE
|
||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include "M051Series.h"
|
||||
|
||||
#define BOARD_PLL_CLOCK 50000000
|
||||
|
||||
/* board configuration */
|
||||
// <o> Internal SRAM memory size[Kbytes]
|
||||
// <i>Default: 64
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* File : usart.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006-2014, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2014-11-29 Bright the first version
|
||||
*/
|
||||
|
||||
#include "M051Series.h"
|
||||
#include <rtdevice.h>
|
||||
#include "usart.h"
|
||||
|
||||
|
||||
static rt_err_t m05x_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
|
||||
{
|
||||
UART_T* uart;
|
||||
|
||||
uart = (UART_T *)serial->parent.user_data;
|
||||
#if defined(RT_USING_UART0)
|
||||
if (uart == UART0) {
|
||||
/* Enable UART module clock */
|
||||
CLK_EnableModuleClock(UART0_MODULE);
|
||||
/* Select UART module clock source */
|
||||
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
|
||||
|
||||
/* Set P3 multi-function pins for UART0 RXD and TXD */
|
||||
SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk);
|
||||
SYS->P3_MFP |= (SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0);
|
||||
|
||||
/* Reset IP */
|
||||
SYS_ResetModule(UART0_RST);
|
||||
/* Configure UART0 and set UART0 Baudrate */
|
||||
UART_Open(UART0, cfg->baud_rate);
|
||||
|
||||
/* Enable Interrupt */
|
||||
UART_EnableInt(UART0, UART_IER_RDA_IEN_Msk);
|
||||
}
|
||||
#endif /* RT_USING_UART0 */
|
||||
|
||||
#if defined(RT_USING_UART1)
|
||||
#endif /* RT_USING_UART1 */
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t m05x_control(struct rt_serial_device *serial, int cmd, void *arg)
|
||||
{
|
||||
UART_T* uart;
|
||||
uart = (UART_T *)serial->parent.user_data;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_CLR_INT: {
|
||||
/* Disable Interrupt */
|
||||
UART_DisableInt(uart, UART_IER_RDA_IEN_Msk);
|
||||
break;
|
||||
}
|
||||
case RT_DEVICE_CTRL_SET_INT: {
|
||||
UART_EnableInt(uart, UART_IER_RDA_IEN_Msk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static int m05x_putc(struct rt_serial_device *serial, char c)
|
||||
{
|
||||
UART_T* uart;
|
||||
uart = (UART_T *)serial->parent.user_data;
|
||||
if (UART_IS_TX_FULL(uart)) {
|
||||
UART_WAIT_TX_EMPTY(uart);
|
||||
|
||||
}
|
||||
UART_WRITE(uart, c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int m05x_getc(struct rt_serial_device *serial)
|
||||
{
|
||||
int ch = -1;
|
||||
UART_T* uart;
|
||||
uart = (UART_T *)serial->parent.user_data;
|
||||
|
||||
if (UART_IS_RX_READY(uart))
|
||||
ch = UART_READ(uart);
|
||||
return ch;
|
||||
}
|
||||
|
||||
static const struct rt_uart_ops m05x_uart_ops =
|
||||
{
|
||||
m05x_configure,
|
||||
m05x_control,
|
||||
m05x_putc,
|
||||
m05x_getc,
|
||||
};
|
||||
|
||||
#if defined(RT_USING_UART0)
|
||||
struct rt_serial_device serial0;
|
||||
|
||||
void UART0_IRQHandler(void)
|
||||
{
|
||||
/* enter interrupt */
|
||||
rt_interrupt_enter();
|
||||
|
||||
if (UART_IS_RX_READY(UART0)) {
|
||||
rt_hw_serial_isr(&serial0, RT_SERIAL_EVENT_RX_IND);
|
||||
}
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
#endif /* RT_USING_UART0 */
|
||||
|
||||
void rt_hw_usart_init(void)
|
||||
{
|
||||
#ifdef RT_USING_UART0
|
||||
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
|
||||
config.baud_rate = BAUD_RATE_115200;
|
||||
serial0.ops = &m05x_uart_ops;
|
||||
serial0.config = config;
|
||||
|
||||
/* register UART0 device */
|
||||
rt_hw_serial_register(&serial0, "uart0",
|
||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
||||
UART0);
|
||||
#endif /* RT_USING_UART0 */
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* File : usart.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006-2014, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2014-11-29 Bright the first version
|
||||
*/
|
||||
|
||||
#ifndef __USART_H__
|
||||
#define __USART_H__
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#define RT_USING_UART0
|
||||
//#define RT_USING_UART1
|
||||
|
||||
void rt_hw_usart_init(void);
|
||||
|
||||
#endif
|
|
@ -207,8 +207,8 @@
|
|||
<AdsLsun>1</AdsLsun>
|
||||
<AdsLven>1</AdsLven>
|
||||
<AdsLsxf>1</AdsLsxf>
|
||||
<RvctClst>1</RvctClst>
|
||||
<GenPPlst>1</GenPPlst>
|
||||
<RvctClst>0</RvctClst>
|
||||
<GenPPlst>0</GenPPlst>
|
||||
<AdsCpuType>"Cortex-M0"</AdsCpuType>
|
||||
<RvctDeviceName></RvctDeviceName>
|
||||
<mOS>0</mOS>
|
||||
|
@ -363,7 +363,7 @@
|
|||
<MiscControls></MiscControls>
|
||||
<Define>INIT_SYSCLK_AT_BOOTING</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>.;..\..\components\drivers\include;..\..\components\init;..\..\include;..\..\libcpu\arm\common;..\..\libcpu\arm\cortex-m0;Libraries\CMSIS\Include;Libraries\CMSIS\Nuvoton\M051Series\Include;Libraries\StdDriver\inc;applications;drivers</IncludePath>
|
||||
<IncludePath>.;..\..\components\drivers\include;..\..\components\finsh;..\..\components\init;..\..\include;..\..\libcpu\arm\common;..\..\libcpu\arm\cortex-m0;Libraries\CMSIS\Include;Libraries\CMSIS\Nuvoton\M051Series\Include;Libraries\StdDriver\inc;applications;drivers</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
|
@ -396,7 +396,7 @@
|
|||
<ScatterFile>.\nuvoton_m05x.sct</ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
<Misc> --keep __rt_init* </Misc>
|
||||
<Misc> --keep __fsym_* --keep __vsym_* --keep __rt_init* </Misc>
|
||||
<LinkerInputFile></LinkerInputFile>
|
||||
<DisabledWarnings></DisabledWarnings>
|
||||
</LDads>
|
||||
|
@ -431,6 +431,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>drivers\led.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>usart.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>drivers\usart.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -648,6 +653,76 @@
|
|||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>finsh</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>shell.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\shell.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>symbol.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\symbol.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>cmd.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\cmd.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_compiler.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_compiler.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_error.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_error.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_heap.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_heap.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_init.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_init.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_node.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_node.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_ops.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_ops.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_parser.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_parser.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_var.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_var.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_vm.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_vm.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>finsh_token.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\components\finsh\finsh_token.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Components</GroupName>
|
||||
<Files>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
/* PRIORITY_MAX */
|
||||
#define RT_THREAD_PRIORITY_MAX 32
|
||||
|
||||
#define IDLE_THREAD_STACK_SIZE 128
|
||||
/* Tick per Second */
|
||||
#define RT_TICK_PER_SECOND 100
|
||||
|
||||
|
@ -54,7 +54,6 @@
|
|||
|
||||
/* Using Small MM */
|
||||
#define RT_USING_SMALL_MEM
|
||||
#define RT_USING_TINY_SIZE
|
||||
|
||||
// <bool name="RT_USING_COMPONENTS_INIT" description="Using RT-Thread components initialization" default="true" />
|
||||
#define RT_USING_COMPONENTS_INIT
|
||||
|
@ -68,19 +67,20 @@
|
|||
#define RT_USING_SERIAL
|
||||
|
||||
/* SECTION: Console options */
|
||||
//#define RT_USING_CONSOLE
|
||||
#define RT_USING_CONSOLE
|
||||
/* the buffer size of console*/
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
#define RT_CONSOLEBUF_SIZE 64
|
||||
// <string name="RT_CONSOLE_DEVICE_NAME" description="The device name for console" default="uart1" />
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart1"
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart0"
|
||||
|
||||
|
||||
|
||||
/* SECTION: finsh, a C-Express shell */
|
||||
//#define RT_USING_FINSH
|
||||
#define RT_USING_FINSH
|
||||
/* configure finsh parameters */
|
||||
#define FINSH_THREAD_PRIORITY 25
|
||||
#define FINSH_THREAD_STACK_SIZE 1024
|
||||
#define FINSH_THREAD_STACK_SIZE 512
|
||||
#define FINSH_USING_HISTORY 0
|
||||
#define FINSH_HISTORY_LINES 1
|
||||
/* Using symbol table */
|
||||
#define FINSH_USING_SYMTAB
|
||||
|
|
Loading…
Reference in New Issue