first commit
This commit is contained in:
127
App/Inc/Board.h
Normal file
127
App/Inc/Board.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#ifndef __BOARD_H__
|
||||
#define __BOARD_H__
|
||||
|
||||
#include <stm32f10x.h>
|
||||
|
||||
#define VERSION "v1.0.0"
|
||||
|
||||
/* **********NVIC中断向量控制器组别********** */
|
||||
#define NVIC_GROUP_LEVEL NVIC_PriorityGroup_2
|
||||
/* **********END********** */
|
||||
|
||||
/* **********SystemClock相关********** */
|
||||
// GPIO
|
||||
#define GPIO_ENABLE
|
||||
#define USE_GPIOA
|
||||
#define USE_GPIOB
|
||||
#define USE_GPIOC
|
||||
#define USE_GPIOD
|
||||
#define USE_GPIOE
|
||||
#define USE_GPIOF
|
||||
#define USE_GPIOG
|
||||
// USART
|
||||
#define USART_ENABLE
|
||||
#define USE_USART1
|
||||
#undef USE_USART2
|
||||
#undef USE_USART3
|
||||
#undef USE_USART4
|
||||
#undef USE_USART5
|
||||
#undef USE_USART6
|
||||
/* **********END********** */
|
||||
|
||||
/* **********GPIO DO DI相关********** */
|
||||
// 数字输出
|
||||
#undef USE_DIGITAL_OUTPUT
|
||||
#ifdef USE_DIGITAL_OUTPUT
|
||||
#define DO_NUM 2
|
||||
#define DO1 0
|
||||
#define DO2 1
|
||||
#endif
|
||||
|
||||
// 数字输入
|
||||
#undef USE_DIGITAL_INPUT
|
||||
#ifdef USE_DIGITAL_INPUT
|
||||
#define DI_NUM 2
|
||||
#define DI1 0
|
||||
#define DI2 1
|
||||
#endif
|
||||
|
||||
// LED灯
|
||||
#define USE_LED
|
||||
#ifdef USE_LED
|
||||
#define LED_NUM 2
|
||||
#define LED0 0
|
||||
#define LED1 1
|
||||
#endif
|
||||
/* **********END********** */
|
||||
|
||||
/* **********串口相关********** */
|
||||
#ifdef USE_USART1
|
||||
#define COM0 USART1_BASE
|
||||
#define COM0_IRQN USART1_IRQn
|
||||
#define COM0_TX_PORT GPIOA
|
||||
#define COM0_RX_PORT GPIOA
|
||||
#define COM0_TX_PIN GPIO_Pin_9
|
||||
#define COM0_RX_PIN GPIO_Pin_10
|
||||
#endif
|
||||
#ifdef USE_USART2
|
||||
#define COM1 USART2_BASE
|
||||
#define COM1_IRQN USART2_IRQn
|
||||
#define COM1_TX_PORT GPIOA
|
||||
#define COM1_RX_PORT GPIOA
|
||||
#define COM1_TX_PIN GPIO_Pin_2
|
||||
#define COM1_RX_PIN GPIO_Pin_3
|
||||
#endif
|
||||
#ifdef USE_USART3
|
||||
#define COM2 USART3_BASE
|
||||
#define COM2_IRQN USART3_IRQn
|
||||
#define COM2_TX_PORT GPIOB
|
||||
#define COM2_RX_PORT GPIOB
|
||||
#define COM2_TX_PIN GPIO_Pin_10
|
||||
#define COM2_RX_PIN GPIO_Pin_11
|
||||
#endif
|
||||
#ifdef USE_USART4
|
||||
#define COM3 UART4_BASE
|
||||
#define COM3_IRQN UART4_IRQn
|
||||
#define COM3_TX_PORT GPIOC
|
||||
#define COM3_RX_PORT GPIOC
|
||||
#define COM3_TX_PIN GPIO_Pin_10
|
||||
#define COM3_RX_PIN GPIO_Pin_11
|
||||
#endif
|
||||
#ifdef USE_USART5
|
||||
#define COM4 UART5_BASE
|
||||
#define COM4_IRQN UART5_IRQn
|
||||
#define COM4_TX_PORT GPIOB
|
||||
#define COM4_RX_PORT GPIOD
|
||||
#define COM4_TX_PIN GPIO_Pin_12
|
||||
#define COM4_RX_PIN GPIO_Pin_2
|
||||
#endif
|
||||
/* LetterShell */
|
||||
#define USE_SHELL
|
||||
#ifdef USE_SHELL
|
||||
#define TTY_COM COM0
|
||||
#define TTY_COM_IRQN COM0_IRQN
|
||||
#endif
|
||||
/* **********END********** */
|
||||
|
||||
#define USE_ANALOG_INPUT
|
||||
#define USE_ANALOG_OUTPUT
|
||||
|
||||
|
||||
/* 自定义Flash布局相关 */
|
||||
#define BOOT_SIZE_16 /* 16Kb的Bootloader大小 不带网络*/
|
||||
//#define BOOT_SIZE_32 /* 32Kb的Bootloader大小 带网络*/
|
||||
|
||||
#define FLASH_BASE_ADDR 0x08000000 //Flash基地址
|
||||
#define BOOT_ADDR 0x08000000 //引导程序地址
|
||||
//BOOT程序大小
|
||||
#ifdef BOOT_SIZE_16
|
||||
#define BOOT_ROM 0x4000
|
||||
#endif
|
||||
#ifdef BOOT_SIZE_32
|
||||
#define BOOT_ROM 0x8000
|
||||
#endif
|
||||
#define USER_PARAM_ADDR (FLASH_BASE_ADDR + BOOT_ROM) //用户参数分区
|
||||
#define APPLICATION_ADDR 0x08010000 //从128K的位置开始是应用程序
|
||||
/* **********END********** */
|
||||
#endif
|
||||
8
App/Inc/LetterShell.h
Normal file
8
App/Inc/LetterShell.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __LETTER_SHELL_H__
|
||||
#define __LETTER_SHELL_H__
|
||||
|
||||
#include "Bsp.h"
|
||||
|
||||
void LetterShellInit(uint32_t ComId, uint32_t baud);
|
||||
|
||||
#endif
|
||||
103
App/Src/LetterShell.c
Normal file
103
App/Src/LetterShell.c
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "LetterShell.h"
|
||||
#include "shell.h"
|
||||
|
||||
#define WR_BUFFER_SIZE 512
|
||||
|
||||
/* 1. 创建shell对象,开辟shell缓冲区 */
|
||||
Shell Host; //Shell实例化
|
||||
char HostBuffer[WR_BUFFER_SIZE]; //读写缓冲区
|
||||
uint32_t HostId; //串口号
|
||||
|
||||
/**
|
||||
* @brief Shell写函数
|
||||
* @param ComId 串口号,ch 数据
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
signed short ShellWrite(char* ch, unsigned short Len)
|
||||
{
|
||||
UsartSendStr(HostId, (uint8_t* )ch,Len);
|
||||
return Len;
|
||||
}
|
||||
/**
|
||||
* @brief Shell读函数 - 中断回调实现
|
||||
* @param Vector 中断向量号
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void LetterShellIrqFunc(uint32_t Vector)
|
||||
{
|
||||
uint8_t ch = 0x00;
|
||||
ch = UsartReceiveChar(Vector);
|
||||
|
||||
shellHandler(&Host, ch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化Shell
|
||||
* @param ComId 串口号,baud 波特率
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void LetterShellInit(uint32_t ComId, uint32_t baud)
|
||||
{
|
||||
HostId = ComId;
|
||||
|
||||
//初始化串口
|
||||
UsartStdConfig(ComId, baud);
|
||||
//设置串口回调函数
|
||||
IntCbReg(TTY_COM_IRQN, LetterShellIrqFunc);
|
||||
//设置中断等级
|
||||
IntSetLevel(TTY_COM_IRQN,1,1);
|
||||
//注册写函数
|
||||
Host.write = ShellWrite;
|
||||
|
||||
shellInit(&Host, HostBuffer, WR_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 打印版本号
|
||||
* @param void
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
int version(void)
|
||||
{
|
||||
printf("%s\r\n",VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DO控制
|
||||
* @param chnl 通道号 val状态值
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void doSet(uint8_t chnl, uint8_t val)
|
||||
{
|
||||
IoCtl(IO_TYPE_DO, chnl, val);
|
||||
}
|
||||
/**
|
||||
* @brief DO控制反转
|
||||
* @param chnl 通道号
|
||||
* @retval void
|
||||
* @note void
|
||||
* @example void
|
||||
*/
|
||||
void doToggle(uint8_t chnl)
|
||||
{
|
||||
IoCtlToggleDo(chnl);
|
||||
}
|
||||
|
||||
//打印版本号
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), version, version, version);
|
||||
//控制DO
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), doSet, doSet, doSet);
|
||||
//反转DO
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), doToggle, doToggle, doToggle);
|
||||
20
App/Src/main.c
Normal file
20
App/Src/main.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* MCU INCLUDE */
|
||||
#include "stm32f10x.h"
|
||||
/* BSP INCLUDE */
|
||||
#include "Bsp.h"
|
||||
/* OPEN_SOURCE_LIB INCLUDE */
|
||||
#include "LetterShell.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//bsp初始化
|
||||
BspConfigInit();
|
||||
|
||||
//LetterShell初始化
|
||||
LetterShellInit(TTY_COM,115200);
|
||||
|
||||
while (1){
|
||||
IoCtlLedToggle(LED0);
|
||||
DelayMs(100);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user