led独立出来,uart自动初始化

This commit is contained in:
chinky 2018-08-27 18:52:14 +08:00
parent 091ec81a3c
commit 7a3d67d720
11 changed files with 147 additions and 130 deletions

View File

@ -77,9 +77,10 @@ CONFIG_RT_USING_COMPONENTS_INIT=y
#
CONFIG_RT_USING_FINSH=y
CONFIG_FINSH_THREAD_NAME="tshell"
# CONFIG_FINSH_USING_HISTORY is not set
# CONFIG_FINSH_USING_SYMTAB is not set
# CONFIG_FINSH_USING_DESCRIPTION is not set
CONFIG_FINSH_USING_HISTORY=y
CONFIG_FINSH_HISTORY_LINES=3
CONFIG_FINSH_USING_SYMTAB=y
CONFIG_FINSH_USING_DESCRIPTION=y
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
CONFIG_FINSH_THREAD_PRIORITY=25
CONFIG_FINSH_THREAD_STACK_SIZE=1024
@ -278,5 +279,5 @@ CONFIG_RT_USING_SERIAL=y
CONFIG_STM32F030R8=y
# CONFIG_RT_USING_HSI is not set
CONFIG_RT_HSE_VALUE=8000000
# CONFIG_RT_USING_UART1 is not set
CONFIG_RT_USING_UART1=y
CONFIG_RT_USING_UART2=y

View File

@ -23,21 +23,6 @@
#include <board.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)
{
rt_thread_t led_thread;
@ -52,12 +37,12 @@ static void rt_init_thread_entry(void* parameter)
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
#endif /* RT_USING_FINSH */
/* Create led thread */
led_thread = rt_thread_create("led",
led_thread_entry, RT_NULL,
256, 20, 20);
if(led_thread != RT_NULL)
rt_thread_startup(led_thread);
// /* Create led thread */
// led_thread = rt_thread_create("led",
// led_thread_entry, RT_NULL,
// 256, 20, 20);
// if(led_thread != RT_NULL)
// rt_thread_startup(led_thread);
}
int rt_application_init()

View 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

View File

@ -26,16 +26,16 @@
extern int rt_application_init(void);
#ifdef __CC_ARM
extern int Image$$RW_IRAM1$$ZI$$Limit;
#define STM32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
#elif __ICCARM__
#pragma section="HEAP"
#define STM32_SRAM_BEGIN (__segment_end("HEAP"))
#else
extern int __bss_end;
#define STM32_SRAM_BEGIN (&__bss_end)
#endif
// #ifdef __CC_ARM
// extern int Image$$RW_IRAM1$$ZI$$Limit;
// #define STM32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
// #elif __ICCARM__
// #pragma section="HEAP"
// #define STM32_SRAM_BEGIN (__segment_end("HEAP"))
// #else
// extern int __bss_end;
// #define STM32_SRAM_BEGIN (&__bss_end)
// #endif
/*******************************************************************************
* Function Name : assert_failed
@ -75,9 +75,9 @@ void rtthread_startup(void)
/* init timer system */
rt_system_timer_init();
#ifdef RT_USING_HEAP
rt_system_heap_init((void*)STM32_SRAM_BEGIN, (void*)STM32_SRAM_END);
#endif
// #ifdef RT_USING_HEAP
// rt_system_heap_init((void*)STM32_SRAM_BEGIN, (void*)STM32_SRAM_END);
// #endif
/* init scheduler system */
rt_system_scheduler_init();

View File

@ -12,12 +12,10 @@
* 2009-01-05 Bernard first implementation
* 2013-11-15 bright add RCC initial and print RCC freq function
*/
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
#include "usart.h"
#include <rthw.h>
#include <rtthread.h>
/**
* @addtogroup STM32
@ -136,18 +134,20 @@ void rt_hw_board_init()
RCC_Configuration();
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);
#ifdef RT_USING_HEAP
rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
#endif
/* Print RCC freq info */
#ifdef PRINT_RCC_FREQ_INFO
print_rcc_freq_info();
#endif
/* Call components board initial (use INIT_BOARD_EXPORT()) */
/* Call components board initial (use INIT_BOARD_EXPORT()) */
#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
}

View File

@ -41,10 +41,21 @@
#define STM32_SRAM_SIZE 8
#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 */
void rt_hw_msd_init(void);
#define HEAP_END STM32_SRAM_END
/***************************************************************/
void rt_hw_board_init(void);
#define PRINT_RCC_FREQ_INFO

View File

@ -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);

View File

@ -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

View File

@ -12,9 +12,11 @@
* 2013-11-15 bright the first version
*/
#include <stm32f0xx.h>
#include <rtdevice.h>
#include "usart.h"
#include "board.h"
#include <rtdevice.h>
#include <rthw.h>
#include <rtthread.h>
/* USART1 */
#define UART1_GPIO_TX GPIO_Pin_9
@ -262,7 +264,7 @@ static void NVIC_Configuration(struct stm32_uart* uart)
NVIC_Init(&NVIC_InitStructure);
}
void rt_hw_usart_init(void)
int rt_hw_usart_init(void)
{
struct stm32_uart* uart;
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,
uart);
#endif /* RT_USING_UART2 */
return 0;
}
INIT_BOARD_EXPORT(rt_hw_usart_init);

View File

@ -19,12 +19,9 @@
#include <rtthread.h>
#include "stm32f0xx.h"
#define RT_USING_UART1
#define RT_USING_UART2
#define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
#define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n))
void rt_hw_usart_init(void);
extern int rt_hw_usart_init(void);
#endif

View File

@ -43,6 +43,10 @@
#define RT_USING_FINSH
#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_STACK_SIZE 1024
#define FINSH_CMD_SIZE 80
@ -129,6 +133,7 @@
#define STM32F030R8
#define RT_HSE_VALUE 8000000
#define RT_USING_UART1
#define RT_USING_UART2
#endif