mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
13 files changed
+2364
-704
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,36 @@
|
||||
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 $ENV_DIR
|
||||
string
|
||||
option env="ENV_ROOT"
|
||||
default "/"
|
||||
|
||||
source "$RTT_DIR/Kconfig"
|
||||
source "$PKGS_DIR/Kconfig"
|
||||
|
||||
|
||||
config SOC_STM32F1
|
||||
bool
|
||||
select ARCH_ARM_CORTEX_M3
|
||||
default y
|
||||
|
||||
source "$BSP_DIR/drivers/Kconfig"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-01-05 Bernard the first version
|
||||
* 2018-08-17 whj remove finsh_set_device add components
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -38,6 +39,11 @@ extern int lwip_system_init(void);
|
||||
|
||||
void rt_init_thread_entry(void* parameter)
|
||||
{
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
/* initialization RT-Thread Components */
|
||||
rt_components_init();
|
||||
#endif
|
||||
|
||||
{
|
||||
extern void rt_platform_init(void);
|
||||
rt_platform_init();
|
||||
@@ -72,11 +78,6 @@ void rt_init_thread_entry(void* parameter)
|
||||
rt_kprintf("TCP/IP initialized!\n");
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
/* initialize finsh */
|
||||
finsh_system_init();
|
||||
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
#endif
|
||||
}
|
||||
|
||||
int rt_application_init(void)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
config RT_USING_UART1
|
||||
bool "Enable UART1 (PA9/10)"
|
||||
default n
|
||||
|
||||
config RT_USING_UART2
|
||||
bool "Enable UART2 (PD5/6)"
|
||||
default y
|
||||
|
||||
config RT_USING_UART3
|
||||
bool "Enable UART3 (PC10/11)"
|
||||
default n
|
||||
@@ -16,6 +16,13 @@ platform.c
|
||||
if GetDepend('RT_USING_LWIP'):
|
||||
src += ['stm32_eth.c']
|
||||
|
||||
if GetDepend(['RT_USING_PIN']):
|
||||
src += ['gpio.c']
|
||||
|
||||
# add Ethernet drivers.
|
||||
if GetDepend('RT_USING_RTC'):
|
||||
src += ['stm32f1_rtc.c']
|
||||
|
||||
if GetDepend('RT_USING_SPI'):
|
||||
src += ['rt_stm32f10x_spi.c']
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-01-05 Bernard first implementation
|
||||
* 2018-08-17 whj add to new rt_console_set_device
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -67,8 +68,14 @@ void rt_hw_board_init(void)
|
||||
/* Configure the SysTick */
|
||||
SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND );
|
||||
|
||||
rt_components_board_init();
|
||||
|
||||
rt_hw_usart_init();
|
||||
|
||||
#ifdef RT_USING_CONSOLE
|
||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* File : gpio.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2015, 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
|
||||
* 2015-01-05 Bernard the first version
|
||||
*/
|
||||
#ifndef GPIO_H__
|
||||
#define GPIO_H__
|
||||
|
||||
|
||||
struct stm32_hw_pin_userdata
|
||||
{
|
||||
int pin;
|
||||
uint32_t mode;
|
||||
};
|
||||
|
||||
#define PIN_USERDATA_END {-1,0}
|
||||
|
||||
extern struct stm32_hw_pin_userdata stm32_pins[];
|
||||
|
||||
int stm32_hw_pin_init(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* File : stm32f1_rtc.c
|
||||
* 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
|
||||
* 2009-01-05 Bernard the first version.
|
||||
* 2011-11-26 aozima implementation time.
|
||||
* 2015-07-16 FlyM rename rtc to stm32f1_rtc. remove finsh export function
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <stm32f10x.h>
|
||||
#include "stm32f1_rtc.h"
|
||||
|
||||
static struct rt_device rtc;
|
||||
static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
{
|
||||
if (dev->rx_indicate != RT_NULL)
|
||||
{
|
||||
/* Open Interrupt */
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_size_t rt_rtc_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static rt_err_t rt_rtc_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
rt_time_t *time;
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_RTC_GET_TIME:
|
||||
time = (rt_time_t *)args;
|
||||
/* read device */
|
||||
*time = RTC_GetCounter();
|
||||
break;
|
||||
|
||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||
{
|
||||
time = (rt_time_t *)args;
|
||||
|
||||
/* Enable PWR and BKP clocks */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
|
||||
|
||||
/* Allow access to BKP Domain */
|
||||
PWR_BackupAccessCmd(ENABLE);
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
|
||||
/* Change the current time */
|
||||
RTC_SetCounter(*time);
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
|
||||
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_Configuration
|
||||
* Description : Configures the RTC.
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : 0 reday,-1 error.
|
||||
*******************************************************************************/
|
||||
int RTC_Configuration(void)
|
||||
{
|
||||
u32 count=0x200000;
|
||||
|
||||
/* Enable PWR and BKP clocks */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
|
||||
|
||||
/* Allow access to BKP Domain */
|
||||
PWR_BackupAccessCmd(ENABLE);
|
||||
|
||||
/* Reset Backup Domain */
|
||||
BKP_DeInit();
|
||||
|
||||
/* Enable LSE */
|
||||
RCC_LSEConfig(RCC_LSE_ON);
|
||||
/* Wait till LSE is ready */
|
||||
while ( (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (--count) );
|
||||
if ( count == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Select LSE as RTC Clock Source */
|
||||
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
||||
|
||||
/* Enable RTC Clock */
|
||||
RCC_RTCCLKCmd(ENABLE);
|
||||
|
||||
/* Wait for RTC registers synchronization */
|
||||
RTC_WaitForSynchro();
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
|
||||
/* Set RTC prescaler: set RTC period to 1sec */
|
||||
RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rt_hw_rtc_init(void)
|
||||
{
|
||||
rtc.type = RT_Device_Class_RTC;
|
||||
|
||||
if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
|
||||
{
|
||||
rt_kprintf("rtc is not configured\n");
|
||||
rt_kprintf("please configure with set_date and set_time\n");
|
||||
if ( RTC_Configuration() != 0)
|
||||
{
|
||||
rt_kprintf("rtc configure fail...\r\n");
|
||||
return ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Wait for RTC registers synchronization */
|
||||
RTC_WaitForSynchro();
|
||||
}
|
||||
|
||||
/* register rtc device */
|
||||
rtc.init = RT_NULL;
|
||||
rtc.open = rt_rtc_open;
|
||||
rtc.close = RT_NULL;
|
||||
rtc.read = rt_rtc_read;
|
||||
rtc.write = RT_NULL;
|
||||
rtc.control = rt_rtc_control;
|
||||
|
||||
/* no private */
|
||||
rtc.user_data = RT_NULL;
|
||||
|
||||
rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* File : stm32f1_rtc.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
|
||||
* 2009-01-05 Bernard the first version
|
||||
*/
|
||||
|
||||
#ifndef __STM32F1_RTC_H__
|
||||
#define __STM32F1_RTC_H__
|
||||
|
||||
void rt_hw_rtc_init(void);
|
||||
|
||||
#endif
|
||||
@@ -8,11 +8,12 @@
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-01-05 Bernard the first version
|
||||
* 2010-03-29 Bernard remove interrupt Tx and DMA Rx mode
|
||||
* 2013-05-13 aozima update for kehong-lingtai.
|
||||
* 2015-01-31 armink make sure the serial transmit complete in putc()
|
||||
* Date Author Notes
|
||||
* 2009-01-05 Bernard the first version
|
||||
* 2010-03-29 Bernard remove interrupt Tx and DMA Rx mode
|
||||
* 2013-05-13 aozima update for kehong-lingtai.
|
||||
* 2015-01-31 armink make sure the serial transmit complete in putc()
|
||||
* 2018-08-17 whj add to usart3
|
||||
*/
|
||||
|
||||
#include "stm32f10x.h"
|
||||
@@ -38,6 +39,11 @@
|
||||
#define UART2_GPIO GPIOA
|
||||
#endif
|
||||
|
||||
/* USART3_REMAP = 1 */
|
||||
#define UART3_GPIO_TX GPIO_Pin_10
|
||||
#define UART3_GPIO_RX GPIO_Pin_11
|
||||
#define UART3_GPIO GPIOC
|
||||
|
||||
/* STM32 uart driver */
|
||||
struct stm32_uart
|
||||
{
|
||||
@@ -184,7 +190,7 @@ void USART1_IRQHandler(void)
|
||||
}
|
||||
if (USART_GetFlagStatus(uart->uart_device, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ReceiveData(uart->uart_device);
|
||||
stm32_getc(&serial1);
|
||||
}
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
@@ -221,7 +227,7 @@ void USART2_IRQHandler(void)
|
||||
}
|
||||
if (USART_GetFlagStatus(uart->uart_device, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
USART_ReceiveData(uart->uart_device);
|
||||
stm32_getc(&serial2);
|
||||
}
|
||||
|
||||
/* leave interrupt */
|
||||
@@ -229,6 +235,44 @@ void USART2_IRQHandler(void)
|
||||
}
|
||||
#endif /* RT_USING_UART2 */
|
||||
|
||||
#if defined(RT_USING_UART3)
|
||||
/* UART1 device driver structure */
|
||||
struct stm32_uart uart3 =
|
||||
{
|
||||
USART3,
|
||||
USART3_IRQn,
|
||||
};
|
||||
struct rt_serial_device serial3;
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
struct stm32_uart* uart;
|
||||
|
||||
uart = &uart3;
|
||||
|
||||
/* enter interrupt */
|
||||
rt_interrupt_enter();
|
||||
if(USART_GetITStatus(uart->uart_device, USART_IT_RXNE) != RESET)
|
||||
{
|
||||
rt_hw_serial_isr(&serial3, RT_SERIAL_EVENT_RX_IND);
|
||||
/* clear interrupt */
|
||||
USART_ClearITPendingBit(uart->uart_device, USART_IT_RXNE);
|
||||
}
|
||||
if (USART_GetITStatus(uart->uart_device, USART_IT_TC) != RESET)
|
||||
{
|
||||
/* clear interrupt */
|
||||
USART_ClearITPendingBit(uart->uart_device, USART_IT_TC);
|
||||
}
|
||||
if (USART_GetFlagStatus(uart->uart_device, USART_FLAG_ORE) == SET)
|
||||
{
|
||||
stm32_getc(&serial3);
|
||||
}
|
||||
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
#endif /* RT_USING_UART3 */
|
||||
|
||||
static void RCC_Configuration(void)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
||||
@@ -252,6 +296,11 @@ static void RCC_Configuration(void)
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
#endif /* RT_USING_UART2 */
|
||||
|
||||
#if defined(RT_USING_UART3)
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOC, ENABLE);
|
||||
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
|
||||
#endif /* RT_USING_UART3 */
|
||||
}
|
||||
|
||||
static void GPIO_Configuration(void)
|
||||
@@ -281,6 +330,18 @@ static void GPIO_Configuration(void)
|
||||
GPIO_InitStructure.GPIO_Pin = UART2_GPIO_TX;
|
||||
GPIO_Init(UART2_GPIO, &GPIO_InitStructure);
|
||||
#endif /* RT_USING_UART2 */
|
||||
|
||||
#if defined(RT_USING_UART3)
|
||||
/* Configure USART3 Rx (PC.11) as input floating */
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_InitStructure.GPIO_Pin = UART3_GPIO_RX;
|
||||
GPIO_Init(UART3_GPIO, &GPIO_InitStructure);
|
||||
|
||||
/* Configure USART3 Tx (PC.10) as alternate function push-pull */
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_InitStructure.GPIO_Pin = UART3_GPIO_TX;
|
||||
GPIO_Init(UART3_GPIO, &GPIO_InitStructure);
|
||||
#endif /* RT_USING_UART3 */
|
||||
}
|
||||
|
||||
static void NVIC_Configuration(struct stm32_uart* uart)
|
||||
@@ -327,9 +388,24 @@ void rt_hw_usart_init(void)
|
||||
|
||||
NVIC_Configuration(&uart2);
|
||||
|
||||
/* register UART1 device */
|
||||
/* register UART2 device */
|
||||
rt_hw_serial_register(&serial2, "uart2",
|
||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
||||
uart);
|
||||
#endif /* RT_USING_UART2 */
|
||||
|
||||
#if defined(RT_USING_UART3)
|
||||
uart = &uart3;
|
||||
|
||||
config.baud_rate = BAUD_RATE_115200;
|
||||
serial2.ops = &stm32_uart_ops;
|
||||
serial2.config = config;
|
||||
|
||||
NVIC_Configuration(&uart3);
|
||||
|
||||
/* register UART3 device */
|
||||
rt_hw_serial_register(&serial3, "uart3",
|
||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
||||
uart);
|
||||
#endif /* RT_USING_UART3 */
|
||||
}
|
||||
+593
-570
File diff suppressed because it is too large.
Load diff
+170
-121
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user