@@ -0,0 +1,205 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
#define BSP_MODULE
|
||||
|
||||
#include <bsp.h>
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL TABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL GLOBAL VARIABLES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
/** This function will initial STM32 board**/
|
||||
void rt_hw_board_init()
|
||||
{
|
||||
BSP_Init();
|
||||
//add for finsh
|
||||
stm32_hw_usart_init();
|
||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* RCC configuration
|
||||
*/
|
||||
static void RCC_Configuration(void)
|
||||
{
|
||||
//下面是给各模块开启时钟
|
||||
//启动GPIO
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | \
|
||||
RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | \
|
||||
RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOG,
|
||||
ENABLE);
|
||||
|
||||
//启动USART1时钟
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
//启动USART2时钟
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
//启动DMA时钟
|
||||
RCC_APB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
|
||||
/* Enable ADC1 and GPIOC clock */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
||||
/* Enable WWDG clock */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* NVIC Configuration
|
||||
*/
|
||||
static void NVIC_Configuration(void)
|
||||
{
|
||||
#if defined(VECT_TAB_RAM)
|
||||
// Set the Vector Table base location at 0x20000000
|
||||
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x00);
|
||||
#elif defined(VECT_TAB_FLASH)
|
||||
// Set the Vector Table base location at 0x08000000
|
||||
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00);
|
||||
#elif defined(VECT_TAB_USER)
|
||||
// Set the Vector Table base location by user
|
||||
NVIC_SetVectorTable(NVIC_VectTab_FLASH, USER_VECTOR_TABLE);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* GPIO Configuration
|
||||
*/
|
||||
static void GPIO_Configuration(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/* PA13:SWDIO PA14:SWCLK for debug, can't set to output mode */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All & (~(GPIO_Pin_13 | GPIO_Pin_14));
|
||||
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);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||
GPIO_Init(GPIOF, &GPIO_InitStructure);
|
||||
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||
|
||||
/******************系统运行LED指示灯配置*******************/
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
||||
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(GPIOB, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* IWDG_Configuration
|
||||
*/
|
||||
static void IWDG_Configuration(void)
|
||||
{
|
||||
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
|
||||
IWDG_SetPrescaler(IWDG_Prescaler_64);
|
||||
IWDG_SetReload(1875);
|
||||
IWDG_ReloadCounter();
|
||||
IWDG_Enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* feed IWDG dog
|
||||
*/
|
||||
void IWDG_Feed(void)
|
||||
{
|
||||
IWDG_ReloadCounter();//reload
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SysTick Configuration
|
||||
*/
|
||||
void SysTick_Configuration(void)
|
||||
{
|
||||
RCC_ClocksTypeDef rcc_clocks;
|
||||
rt_uint32_t cnts;
|
||||
|
||||
RCC_GetClocksFreq(&rcc_clocks);
|
||||
|
||||
cnts = (rt_uint32_t)rcc_clocks.HCLK_Frequency / RT_TICK_PER_SECOND;
|
||||
cnts = cnts / 8;
|
||||
|
||||
SysTick_Config(cnts);
|
||||
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
|
||||
}
|
||||
/**
|
||||
* This is the timer interrupt service routine.
|
||||
*
|
||||
*/
|
||||
void rt_hw_timer_handler(void)
|
||||
{
|
||||
/* enter interrupt */
|
||||
rt_interrupt_enter();
|
||||
|
||||
rt_tick_increase();
|
||||
|
||||
/* leave interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
void assert_failed(u8* file, u32 line)
|
||||
{
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* Infinite loop */
|
||||
rt_kprintf("assert failed at %s:%d \n", file, line);
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* LOCAL CONFIGURATION ERRORS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* BSP_Init()
|
||||
*
|
||||
* Description : Initialize the Board Support Package (BSP).
|
||||
*
|
||||
* Argument(s) : none.
|
||||
*
|
||||
* Return(s) : none.
|
||||
*
|
||||
* Caller(s) : Application.
|
||||
*
|
||||
* Note(s) : (1) This function SHOULD be called before any other BSP function is called.
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void BSP_Init (void)
|
||||
{
|
||||
RCC_Configuration();
|
||||
NVIC_Configuration();
|
||||
SysTick_Configuration();
|
||||
GPIO_Configuration();
|
||||
//TODO Now temporary comment this code, the official version will open his
|
||||
// IWDG_Configuration();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
#ifndef BSP_PRESENT
|
||||
#define BSP_PRESENT
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* EXTERNS
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INCLUDE FILES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <stm32f4xx_conf.h>
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
#include "usart.h"
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* DEFINES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
/* board configuration */
|
||||
// <o> SDCard Driver <1=>SDIO sdcard <0=>SPI MMC card
|
||||
// <i>Default: 1
|
||||
#define STM32_USE_SDIO 0
|
||||
|
||||
/* whether use board external SRAM memory */
|
||||
// <e>Use external SRAM memory on the board
|
||||
// <i>Enable External SRAM memory
|
||||
#define STM32_EXT_SRAM 0
|
||||
// <o>Begin Address of External SRAM
|
||||
// <i>Default: 0x68000000
|
||||
#define STM32_EXT_SRAM_BEGIN 0x68000000 /* the begining address of external SRAM */
|
||||
// <o>End Address of External SRAM
|
||||
// <i>Default: 0x68080000
|
||||
#define STM32_EXT_SRAM_END 0x68080000 /* the end address of external SRAM */
|
||||
// </e>
|
||||
|
||||
#define STM32_SRAM_BEGIN SRAM_BASE
|
||||
// <o> Internal SRAM memory size[Kbytes]
|
||||
// <i>Default: 128
|
||||
#define STM32_SRAM_SIZE 128
|
||||
#define STM32_SRAM_END (SRAM_BASE + STM32_SRAM_SIZE * 1024)
|
||||
|
||||
#define VECT_TAB_FLASH /* use Flash to store vector table */
|
||||
|
||||
/* RT_USING_UART */
|
||||
#define RT_USING_UART1
|
||||
#define RT_UART_RX_BUFFER_SIZE 64
|
||||
|
||||
#define LED_RUN_ON GPIO_SetBits (GPIOB,GPIO_Pin_12) //RUN
|
||||
#define LED_RUN_OFF GPIO_ResetBits(GPIOB,GPIO_Pin_12) //RUN
|
||||
|
||||
/*********************************************************************************************************/
|
||||
/** MACRO'S */
|
||||
/***********************************************************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************************************************/
|
||||
/* DATA TYPES */
|
||||
/***********************************************************************************************************/
|
||||
|
||||
|
||||
/**********************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
**********************************************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* FUNCTION PROTOTYPES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
void BSP_Init(void);
|
||||
|
||||
void rt_hw_board_init(void);
|
||||
void IWDG_Feed(void);
|
||||
void rt_hw_timer_handler(void);
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* INTERRUPT SERVICES
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#endif /* End of module include. */
|
||||
@@ -0,0 +1,51 @@
|
||||
/*###ICF### Section handled by ICF editor, don't touch! ****/
|
||||
/*-Editor annotation file-*/
|
||||
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
|
||||
/*-Specials-*/
|
||||
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
|
||||
/* 软件及硬件版本号存放地址 */
|
||||
define symbol __ICFEDIT_version_start__ = __ICFEDIT_intvec_start__ + 512;
|
||||
/*-Memory Regions-*/
|
||||
define symbol __ICFEDIT_region_ROM_start__ = __ICFEDIT_intvec_start__;
|
||||
define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF;
|
||||
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
|
||||
define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF;
|
||||
/*-Sizes-*/
|
||||
define symbol __ICFEDIT_size_cstack__ = 0x2000;
|
||||
define symbol __ICFEDIT_size_heap__ = 0x2000;
|
||||
/**** End of ICF editor section. ###ICF###*/
|
||||
|
||||
define symbol __region_RAM1_start__ = 0x10000000;
|
||||
define symbol __region_RAM1_end__ = 0x1000FFFF;
|
||||
|
||||
define memory mem with size = 4G;
|
||||
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
|
||||
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
|
||||
define region RAM1_region = mem:[from __region_RAM1_start__ to __region_RAM1_end__];
|
||||
|
||||
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
|
||||
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
|
||||
|
||||
initialize by copy { readwrite };
|
||||
do not initialize { section .noinit };
|
||||
|
||||
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
|
||||
|
||||
place in ROM_region { readonly };
|
||||
place in RAM_region { section .sram};
|
||||
place in RAM1_region { readwrite ,
|
||||
block CSTACK, block HEAP};
|
||||
|
||||
/* armink add for e-boot serial command */
|
||||
keep { section IbootSerialCmdTab };
|
||||
|
||||
/* armink add for wifi command dispather */
|
||||
keep { section RCSymTab };
|
||||
|
||||
/* armink add for version storage */
|
||||
keep { section .version };
|
||||
place at address mem:__ICFEDIT_version_start__ { readonly section .version };
|
||||
|
||||
/* armink add for finsh */
|
||||
keep { section FSymTab };
|
||||
keep { section VSymTab };
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
#ifndef TYPES_H_
|
||||
#define TYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
typedef int bool_t; /**< boolean type */
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#define success 0
|
||||
#define fail 1
|
||||
|
||||
|
||||
#ifndef disable
|
||||
#define disable 0
|
||||
#endif
|
||||
|
||||
#ifndef enable
|
||||
#define enable 1
|
||||
#endif
|
||||
|
||||
#endif /* TYPES_H_ */
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "utils.h"
|
||||
|
||||
/* current system status */
|
||||
static SystemStatus cur_system_status = SYSTEM_STATUS_INIT;
|
||||
|
||||
|
||||
/**
|
||||
* System go to fault status.
|
||||
*/
|
||||
void system_go_to_fault_status(void){
|
||||
cur_system_status = SYSTEM_STATUS_FAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current system status.
|
||||
*
|
||||
* @param status system status
|
||||
*/
|
||||
void set_system_status(SystemStatus status){
|
||||
cur_system_status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current system status.
|
||||
*
|
||||
* @return current system status
|
||||
*/
|
||||
SystemStatus get_system_status(void){
|
||||
return cur_system_status;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef UTILS_H_
|
||||
#define UTILS_H_
|
||||
|
||||
#include <stm32f4xx_conf.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
/* system status */
|
||||
typedef enum{
|
||||
SYSTEM_STATUS_INIT,
|
||||
SYSTEM_STATUS_RUN,
|
||||
SYSTEM_STATUS_FAULT,
|
||||
SYSTEM_STATUS_SLEEP,
|
||||
}SystemStatus;
|
||||
|
||||
void Delay(vu32 nCount);
|
||||
void system_go_to_fault_status(void);
|
||||
void set_system_status(SystemStatus status);
|
||||
SystemStatus get_system_status(void);
|
||||
|
||||
#endif /* UTILS_H_ */
|
||||
Reference in New Issue
Block a user