led独立出来,uart自动初始化
This commit is contained in:
parent
091ec81a3c
commit
7a3d67d720
@ -77,9 +77,10 @@ CONFIG_RT_USING_COMPONENTS_INIT=y
|
|||||||
#
|
#
|
||||||
CONFIG_RT_USING_FINSH=y
|
CONFIG_RT_USING_FINSH=y
|
||||||
CONFIG_FINSH_THREAD_NAME="tshell"
|
CONFIG_FINSH_THREAD_NAME="tshell"
|
||||||
# CONFIG_FINSH_USING_HISTORY is not set
|
CONFIG_FINSH_USING_HISTORY=y
|
||||||
# CONFIG_FINSH_USING_SYMTAB is not set
|
CONFIG_FINSH_HISTORY_LINES=3
|
||||||
# CONFIG_FINSH_USING_DESCRIPTION is not set
|
CONFIG_FINSH_USING_SYMTAB=y
|
||||||
|
CONFIG_FINSH_USING_DESCRIPTION=y
|
||||||
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
|
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
|
||||||
CONFIG_FINSH_THREAD_PRIORITY=25
|
CONFIG_FINSH_THREAD_PRIORITY=25
|
||||||
CONFIG_FINSH_THREAD_STACK_SIZE=1024
|
CONFIG_FINSH_THREAD_STACK_SIZE=1024
|
||||||
@ -278,5 +279,5 @@ CONFIG_RT_USING_SERIAL=y
|
|||||||
CONFIG_STM32F030R8=y
|
CONFIG_STM32F030R8=y
|
||||||
# CONFIG_RT_USING_HSI is not set
|
# CONFIG_RT_USING_HSI is not set
|
||||||
CONFIG_RT_HSE_VALUE=8000000
|
CONFIG_RT_HSE_VALUE=8000000
|
||||||
# CONFIG_RT_USING_UART1 is not set
|
CONFIG_RT_USING_UART1=y
|
||||||
CONFIG_RT_USING_UART2=y
|
CONFIG_RT_USING_UART2=y
|
||||||
|
@ -23,21 +23,6 @@
|
|||||||
#include <board.h>
|
#include <board.h>
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
#include "led.h"
|
|
||||||
|
|
||||||
/* led thread entry */
|
|
||||||
static void led_thread_entry(void* parameter)
|
|
||||||
{
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
rt_hw_led_on();
|
|
||||||
rt_thread_delay(RT_TICK_PER_SECOND);
|
|
||||||
|
|
||||||
rt_hw_led_off();
|
|
||||||
rt_thread_delay(RT_TICK_PER_SECOND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rt_init_thread_entry(void* parameter)
|
static void rt_init_thread_entry(void* parameter)
|
||||||
{
|
{
|
||||||
rt_thread_t led_thread;
|
rt_thread_t led_thread;
|
||||||
@ -52,12 +37,12 @@ static void rt_init_thread_entry(void* parameter)
|
|||||||
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
|
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||||
#endif /* RT_USING_FINSH */
|
#endif /* RT_USING_FINSH */
|
||||||
|
|
||||||
/* 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);
|
// 256, 20, 20);
|
||||||
if(led_thread != RT_NULL)
|
// if(led_thread != RT_NULL)
|
||||||
rt_thread_startup(led_thread);
|
// rt_thread_startup(led_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_application_init()
|
int rt_application_init()
|
||||||
|
82
bsp/stm32f0x/applications/led.c
Normal file
82
bsp/stm32f0x/applications/led.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* File : led.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2006-2013, 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
|
||||||
|
* 2013-11-15 bright the first version
|
||||||
|
*/
|
||||||
|
|
||||||
|
// #include "led.h"
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <stm32f0xx.h>
|
||||||
|
|
||||||
|
#define rt_hw_led_on() GPIO_SetBits(GPIOA, GPIO_Pin_5)
|
||||||
|
#define rt_hw_led_off() GPIO_ResetBits(GPIOA, GPIO_Pin_5)
|
||||||
|
/*
|
||||||
|
LED_Green : PA5
|
||||||
|
*/
|
||||||
|
ALIGN(RT_ALIGN_SIZE)
|
||||||
|
static rt_uint8_t led_stack[512];
|
||||||
|
/* 线程的 TCB 控制块 */
|
||||||
|
static struct rt_thread led_thread;
|
||||||
|
|
||||||
|
/* Initial led gpio pin */
|
||||||
|
int rt_hw_led_init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
|
|
||||||
|
/* Enable the GPIO_LED Clock */
|
||||||
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
||||||
|
|
||||||
|
/* Configure the GPIO_LED pin */
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
|
||||||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* led thread entry */
|
||||||
|
static void led_thread_entry(void* parameter)
|
||||||
|
{
|
||||||
|
rt_hw_led_init();
|
||||||
|
while (1) {
|
||||||
|
rt_hw_led_on();
|
||||||
|
rt_thread_delay(RT_TICK_PER_SECOND);
|
||||||
|
|
||||||
|
rt_hw_led_off();
|
||||||
|
rt_thread_delay(RT_TICK_PER_SECOND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int led_app_init(void)
|
||||||
|
{
|
||||||
|
rt_err_t result;
|
||||||
|
|
||||||
|
/* init led thread */
|
||||||
|
result = rt_thread_init(&led_thread,
|
||||||
|
"led",
|
||||||
|
led_thread_entry,
|
||||||
|
RT_NULL,
|
||||||
|
(rt_uint8_t*)&led_stack[0],
|
||||||
|
sizeof(led_stack),
|
||||||
|
20,
|
||||||
|
5);
|
||||||
|
if (result == RT_EOK) {
|
||||||
|
rt_thread_startup(&led_thread);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* 加入到初始化线程中自动运行 */
|
||||||
|
#ifdef RT_USING_COMPONENTS_INIT
|
||||||
|
INIT_APP_EXPORT(led_app_init);
|
||||||
|
#endif
|
@ -26,16 +26,16 @@
|
|||||||
|
|
||||||
extern int rt_application_init(void);
|
extern int rt_application_init(void);
|
||||||
|
|
||||||
#ifdef __CC_ARM
|
// #ifdef __CC_ARM
|
||||||
extern int Image$$RW_IRAM1$$ZI$$Limit;
|
// extern int Image$$RW_IRAM1$$ZI$$Limit;
|
||||||
#define STM32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
|
// #define STM32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
|
||||||
#elif __ICCARM__
|
// #elif __ICCARM__
|
||||||
#pragma section="HEAP"
|
// #pragma section="HEAP"
|
||||||
#define STM32_SRAM_BEGIN (__segment_end("HEAP"))
|
// #define STM32_SRAM_BEGIN (__segment_end("HEAP"))
|
||||||
#else
|
// #else
|
||||||
extern int __bss_end;
|
// extern int __bss_end;
|
||||||
#define STM32_SRAM_BEGIN (&__bss_end)
|
// #define STM32_SRAM_BEGIN (&__bss_end)
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : assert_failed
|
* Function Name : assert_failed
|
||||||
@ -75,9 +75,9 @@ void rtthread_startup(void)
|
|||||||
/* init timer system */
|
/* init timer system */
|
||||||
rt_system_timer_init();
|
rt_system_timer_init();
|
||||||
|
|
||||||
#ifdef RT_USING_HEAP
|
// #ifdef RT_USING_HEAP
|
||||||
rt_system_heap_init((void*)STM32_SRAM_BEGIN, (void*)STM32_SRAM_END);
|
// rt_system_heap_init((void*)STM32_SRAM_BEGIN, (void*)STM32_SRAM_END);
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
/* init scheduler system */
|
/* init scheduler system */
|
||||||
rt_system_scheduler_init();
|
rt_system_scheduler_init();
|
||||||
|
@ -12,12 +12,10 @@
|
|||||||
* 2009-01-05 Bernard first implementation
|
* 2009-01-05 Bernard first implementation
|
||||||
* 2013-11-15 bright add RCC initial and print RCC freq function
|
* 2013-11-15 bright add RCC initial and print RCC freq function
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <rthw.h>
|
|
||||||
#include <rtthread.h>
|
|
||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
|
#include <rthw.h>
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup STM32
|
* @addtogroup STM32
|
||||||
@ -136,18 +134,20 @@ void rt_hw_board_init()
|
|||||||
RCC_Configuration();
|
RCC_Configuration();
|
||||||
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
|
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
|
||||||
|
|
||||||
/* Initial usart deriver, and set console device */
|
#ifdef RT_USING_HEAP
|
||||||
rt_hw_usart_init();
|
rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
|
||||||
#ifdef RT_USING_CONSOLE
|
|
||||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
|
||||||
#endif
|
#endif
|
||||||
/* Print RCC freq info */
|
/* Call components board initial (use INIT_BOARD_EXPORT()) */
|
||||||
#ifdef PRINT_RCC_FREQ_INFO
|
|
||||||
print_rcc_freq_info();
|
|
||||||
#endif
|
|
||||||
/* Call components board initial (use INIT_BOARD_EXPORT()) */
|
|
||||||
#ifdef RT_USING_COMPONENTS_INIT
|
#ifdef RT_USING_COMPONENTS_INIT
|
||||||
rt_components_board_init();
|
rt_components_board_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RT_USING_CONSOLE
|
||||||
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||||
|
#endif
|
||||||
|
/* Print RCC freq info */
|
||||||
|
#ifdef PRINT_RCC_FREQ_INFO
|
||||||
|
print_rcc_freq_info();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +41,21 @@
|
|||||||
#define STM32_SRAM_SIZE 8
|
#define STM32_SRAM_SIZE 8
|
||||||
#define STM32_SRAM_END (0x20000000 + STM32_SRAM_SIZE * 1024)
|
#define STM32_SRAM_END (0x20000000 + STM32_SRAM_SIZE * 1024)
|
||||||
|
|
||||||
void rt_hw_board_init(void);
|
#ifdef __CC_ARM
|
||||||
|
extern int Image$$RW_IRAM1$$ZI$$Limit;
|
||||||
|
#define HEAP_BEGIN ((void*)&Image$$RW_IRAM1$$ZI$$Limit)
|
||||||
|
#elif __ICCARM__
|
||||||
|
#pragma section = "HEAP"
|
||||||
|
#define HEAP_BEGIN (__segment_end("HEAP"))
|
||||||
|
#else
|
||||||
|
extern int __bss_end;
|
||||||
|
#define HEAP_BEGIN ((void*)&__bss_end)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* SD Card init function */
|
#define HEAP_END STM32_SRAM_END
|
||||||
void rt_hw_msd_init(void);
|
|
||||||
|
/***************************************************************/
|
||||||
|
void rt_hw_board_init(void);
|
||||||
|
|
||||||
#define PRINT_RCC_FREQ_INFO
|
#define PRINT_RCC_FREQ_INFO
|
||||||
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* File : led.c
|
|
||||||
* This file is part of RT-Thread RTOS
|
|
||||||
* COPYRIGHT (C) 2006-2013, 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
|
|
||||||
* 2013-11-15 bright the first version
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <rtthread.h>
|
|
||||||
#include "led.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
LED_RED : PA5
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Initial led gpio pin */
|
|
||||||
int rt_hw_led_init(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
|
||||||
|
|
||||||
/* Enable the GPIO_LED Clock */
|
|
||||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
|
||||||
|
|
||||||
/* Configure the GPIO_LED pin */
|
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|
||||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
||||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
||||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/* Initial components for device */
|
|
||||||
INIT_DEVICE_EXPORT(rt_hw_led_init);
|
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* File : led.h
|
|
||||||
* This file is part of RT-Thread RTOS
|
|
||||||
* COPYRIGHT (C) 2009, 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
|
|
||||||
* 2013-13-05 bright the first version
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __LED_H__
|
|
||||||
#define __LED_H__
|
|
||||||
|
|
||||||
#include <rtthread.h>
|
|
||||||
#include <stm32f0xx.h>
|
|
||||||
|
|
||||||
#define rt_hw_led_on() GPIO_SetBits(GPIOA, GPIO_Pin_5)
|
|
||||||
#define rt_hw_led_off() GPIO_ResetBits(GPIOA, GPIO_Pin_5)
|
|
||||||
|
|
||||||
int rt_hw_led_init(void);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -12,9 +12,11 @@
|
|||||||
* 2013-11-15 bright the first version
|
* 2013-11-15 bright the first version
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stm32f0xx.h>
|
|
||||||
#include <rtdevice.h>
|
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
|
#include "board.h"
|
||||||
|
#include <rtdevice.h>
|
||||||
|
#include <rthw.h>
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
/* USART1 */
|
/* USART1 */
|
||||||
#define UART1_GPIO_TX GPIO_Pin_9
|
#define UART1_GPIO_TX GPIO_Pin_9
|
||||||
@ -262,7 +264,7 @@ static void NVIC_Configuration(struct stm32_uart* uart)
|
|||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rt_hw_usart_init(void)
|
int rt_hw_usart_init(void)
|
||||||
{
|
{
|
||||||
struct stm32_uart* uart;
|
struct stm32_uart* uart;
|
||||||
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
|
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
|
||||||
@ -299,4 +301,6 @@ void rt_hw_usart_init(void)
|
|||||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
||||||
uart);
|
uart);
|
||||||
#endif /* RT_USING_UART2 */
|
#endif /* RT_USING_UART2 */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
INIT_BOARD_EXPORT(rt_hw_usart_init);
|
@ -19,12 +19,9 @@
|
|||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include "stm32f0xx.h"
|
#include "stm32f0xx.h"
|
||||||
|
|
||||||
#define RT_USING_UART1
|
|
||||||
#define RT_USING_UART2
|
|
||||||
|
|
||||||
#define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
|
#define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
|
||||||
#define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n))
|
#define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n))
|
||||||
|
|
||||||
void rt_hw_usart_init(void);
|
extern int rt_hw_usart_init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,6 +43,10 @@
|
|||||||
|
|
||||||
#define RT_USING_FINSH
|
#define RT_USING_FINSH
|
||||||
#define FINSH_THREAD_NAME "tshell"
|
#define FINSH_THREAD_NAME "tshell"
|
||||||
|
#define FINSH_USING_HISTORY
|
||||||
|
#define FINSH_HISTORY_LINES 3
|
||||||
|
#define FINSH_USING_SYMTAB
|
||||||
|
#define FINSH_USING_DESCRIPTION
|
||||||
#define FINSH_THREAD_PRIORITY 25
|
#define FINSH_THREAD_PRIORITY 25
|
||||||
#define FINSH_THREAD_STACK_SIZE 1024
|
#define FINSH_THREAD_STACK_SIZE 1024
|
||||||
#define FINSH_CMD_SIZE 80
|
#define FINSH_CMD_SIZE 80
|
||||||
@ -129,6 +133,7 @@
|
|||||||
|
|
||||||
#define STM32F030R8
|
#define STM32F030R8
|
||||||
#define RT_HSE_VALUE 8000000
|
#define RT_HSE_VALUE 8000000
|
||||||
|
#define RT_USING_UART1
|
||||||
#define RT_USING_UART2
|
#define RT_USING_UART2
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user