提交 3abf1fd5 编写于 作者: B Bright Pan

Add uart driver and finsh function

上级 d50ab16e
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
; * ; *
; ******************************************************************************/ ; ******************************************************************************/
Stack_Size EQU 0x00000200 Stack_Size EQU 0x00000100
AREA STACK, NOINIT, READWRITE, ALIGN=3 AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size Stack_Mem SPACE Stack_Size
......
...@@ -56,7 +56,7 @@ static void rt_init_thread_entry(void* parameter) ...@@ -56,7 +56,7 @@ static void rt_init_thread_entry(void* parameter)
/* Create led thread */ /* Create led thread */
led_thread = rt_thread_create("led", led_thread = rt_thread_create("led",
led_thread_entry, RT_NULL, led_thread_entry, RT_NULL,
256, 20, 20); 128, 20, 20);
if(led_thread != RT_NULL) if(led_thread != RT_NULL)
rt_thread_startup(led_thread); rt_thread_startup(led_thread);
} }
......
...@@ -14,9 +14,8 @@ ...@@ -14,9 +14,8 @@
#include <rthw.h> #include <rthw.h>
#include <rtthread.h> #include <rtthread.h>
#include "board.h" #include "board.h"
#include "usart.h"
/* RT_USING_COMPONENTS_INIT */ /* RT_USING_COMPONENTS_INIT */
#ifdef RT_USING_COMPONENTS_INIT #ifdef RT_USING_COMPONENTS_INIT
#include <components.h> #include <components.h>
...@@ -44,7 +43,7 @@ void NVIC_Configuration(void) ...@@ -44,7 +43,7 @@ void NVIC_Configuration(void)
* @param nCount: specifies the delay time length. * @param nCount: specifies the delay time length.
* @retval None * @retval None
*/ */
static void Delay(__IO uint32_t nCount) static void delay(__IO uint32_t nCount)
{ {
/* Decrement nCount value */ /* Decrement nCount value */
while (nCount != 0) while (nCount != 0)
...@@ -53,6 +52,30 @@ static void Delay(__IO uint32_t nCount) ...@@ -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. * This is the timer interrupt service routine.
* *
...@@ -75,10 +98,13 @@ void rt_hw_board_init() ...@@ -75,10 +98,13 @@ void rt_hw_board_init()
/* NVIC Configuration */ /* NVIC Configuration */
NVIC_Configuration(); NVIC_Configuration();
/* Configure the system clock */
rt_hw_system_init();
/* Configure the SysTick */ /* Configure the SysTick */
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
/* Initial usart deriver, and set console device */ /* Initial usart deriver, and set console device */
rt_hw_usart_init();
#ifdef RT_USING_CONSOLE #ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME); rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif #endif
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "M051Series.h" #include "M051Series.h"
#define BOARD_PLL_CLOCK 50000000
/* board configuration */ /* board configuration */
// <o> Internal SRAM memory size[Kbytes] // <o> Internal SRAM memory size[Kbytes]
// <i>Default: 64 // <i>Default: 64
......
/*
* 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 */
}
/*
* 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 @@ ...@@ -207,8 +207,8 @@
<AdsLsun>1</AdsLsun> <AdsLsun>1</AdsLsun>
<AdsLven>1</AdsLven> <AdsLven>1</AdsLven>
<AdsLsxf>1</AdsLsxf> <AdsLsxf>1</AdsLsxf>
<RvctClst>1</RvctClst> <RvctClst>0</RvctClst>
<GenPPlst>1</GenPPlst> <GenPPlst>0</GenPPlst>
<AdsCpuType>"Cortex-M0"</AdsCpuType> <AdsCpuType>"Cortex-M0"</AdsCpuType>
<RvctDeviceName></RvctDeviceName> <RvctDeviceName></RvctDeviceName>
<mOS>0</mOS> <mOS>0</mOS>
...@@ -363,7 +363,7 @@ ...@@ -363,7 +363,7 @@
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define>INIT_SYSCLK_AT_BOOTING</Define> <Define>INIT_SYSCLK_AT_BOOTING</Define>
<Undefine></Undefine> <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> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
...@@ -396,7 +396,7 @@ ...@@ -396,7 +396,7 @@
<ScatterFile>.\nuvoton_m05x.sct</ScatterFile> <ScatterFile>.\nuvoton_m05x.sct</ScatterFile>
<IncludeLibs></IncludeLibs> <IncludeLibs></IncludeLibs>
<IncludeLibsPath></IncludeLibsPath> <IncludeLibsPath></IncludeLibsPath>
<Misc> --keep __rt_init* </Misc> <Misc> --keep __fsym_* --keep __vsym_* --keep __rt_init* </Misc>
<LinkerInputFile></LinkerInputFile> <LinkerInputFile></LinkerInputFile>
<DisabledWarnings></DisabledWarnings> <DisabledWarnings></DisabledWarnings>
</LDads> </LDads>
...@@ -431,6 +431,11 @@ ...@@ -431,6 +431,11 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>drivers\led.c</FilePath> <FilePath>drivers\led.c</FilePath>
</File> </File>
<File>
<FileName>usart.c</FileName>
<FileType>1</FileType>
<FilePath>drivers\usart.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
...@@ -648,6 +653,76 @@ ...@@ -648,6 +653,76 @@
</File> </File>
</Files> </Files>
</Group> </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> <Group>
<GroupName>Components</GroupName> <GroupName>Components</GroupName>
<Files> <Files>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
/* PRIORITY_MAX */ /* PRIORITY_MAX */
#define RT_THREAD_PRIORITY_MAX 32 #define RT_THREAD_PRIORITY_MAX 32
#define IDLE_THREAD_STACK_SIZE 128
/* Tick per Second */ /* Tick per Second */
#define RT_TICK_PER_SECOND 100 #define RT_TICK_PER_SECOND 100
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
/* Using Small MM */ /* Using Small MM */
#define RT_USING_SMALL_MEM #define RT_USING_SMALL_MEM
#define RT_USING_TINY_SIZE
// <bool name="RT_USING_COMPONENTS_INIT" description="Using RT-Thread components initialization" default="true" /> // <bool name="RT_USING_COMPONENTS_INIT" description="Using RT-Thread components initialization" default="true" />
#define RT_USING_COMPONENTS_INIT #define RT_USING_COMPONENTS_INIT
...@@ -68,19 +67,20 @@ ...@@ -68,19 +67,20 @@
#define RT_USING_SERIAL #define RT_USING_SERIAL
/* SECTION: Console options */ /* SECTION: Console options */
//#define RT_USING_CONSOLE #define RT_USING_CONSOLE
/* the buffer size of 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" /> // <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 */ /* SECTION: finsh, a C-Express shell */
//#define RT_USING_FINSH #define RT_USING_FINSH
/* configure finsh parameters */ /* configure finsh parameters */
#define FINSH_THREAD_PRIORITY 25 #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 #define FINSH_HISTORY_LINES 1
/* Using symbol table */ /* Using symbol table */
#define FINSH_USING_SYMTAB #define FINSH_USING_SYMTAB
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册