fix: add missing MCU2 firmware project
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :debug_output.c
|
||||
* 描 述 :调试输出打印信息
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/26
|
||||
*********************************************************************************/
|
||||
#include "debug_conf.h"
|
||||
|
||||
//加入以下代码,支持printf函数,而不需要选择use MicroLIB
|
||||
#if 1
|
||||
#pragma import(__use_no_semihosting)
|
||||
//标准库需要的支持函数
|
||||
struct __FILE
|
||||
{
|
||||
int handle;
|
||||
};
|
||||
|
||||
FILE __stdout;
|
||||
//定义_sys_exit()以避免使用半主机模式
|
||||
_sys_exit(int x)
|
||||
{
|
||||
x = x;
|
||||
}
|
||||
|
||||
//重定义fputc函数
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)==RESET){};
|
||||
USART_SendData(UART5, (uint8_t)ch);
|
||||
return ch;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
@@ -0,0 +1,16 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :debug_output.h
|
||||
* 描 述 :调试输出打印信息头文件
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/04/26
|
||||
*********************************************************************************/
|
||||
#ifndef __DEBUG_OUTPUT_H
|
||||
#define __DEBUG_OUTPUT_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "delay.h"
|
||||
|
||||
static u8 fac_us=0;//us延时倍乘数
|
||||
static u16 fac_ms=0;//ms延时倍乘数
|
||||
|
||||
//初始化延迟函数
|
||||
//当使用ucos的时候,此函数会初始化ucos的时钟节拍
|
||||
//SYSTICK的时钟固定为HCLK时钟的1/8
|
||||
//SYSCLK:系统时钟
|
||||
void delay_init()
|
||||
{
|
||||
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //选择外部时钟 HCLK/8
|
||||
fac_us=SystemCoreClock/8000000; //为系统时钟的1/8
|
||||
|
||||
fac_ms=(u16)fac_us*1000;//非ucos下,代表每个ms需要的systick时钟数
|
||||
}
|
||||
|
||||
//延时nus
|
||||
//nus为要延时的us数.
|
||||
void delay_us(u32 nus)
|
||||
{
|
||||
u32 temp;
|
||||
SysTick->LOAD=nus*fac_us; //时间加载
|
||||
SysTick->VAL=0x00; //清空计数器
|
||||
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数
|
||||
do
|
||||
{
|
||||
temp=SysTick->CTRL;
|
||||
}
|
||||
while(temp&0x01&&!(temp&(1<<16)));//等待时间到达
|
||||
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器
|
||||
SysTick->VAL =0X00; //清空计数器
|
||||
}
|
||||
//延时nms
|
||||
//注意nms的范围
|
||||
//SysTick->LOAD为24位寄存器,所以,最大延时为:
|
||||
//nms<=0xffffff*8*1000/SYSCLK
|
||||
//SYSCLK单位为Hz,nms单位为ms
|
||||
//对72M条件下,nms<=1864
|
||||
void delay_ms(u16 nms)
|
||||
{
|
||||
u32 temp;
|
||||
SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit)
|
||||
SysTick->VAL =0x00; //清空计数器
|
||||
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数
|
||||
do
|
||||
{
|
||||
temp=SysTick->CTRL;
|
||||
}
|
||||
while(temp&0x01&&!(temp&(1<<16)));//等待时间到达
|
||||
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器
|
||||
SysTick->VAL =0X00; //清空计数器
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef __DELAY_H
|
||||
#define __DELAY_H
|
||||
#include "stm32f10x.h"
|
||||
|
||||
void delay_init(void);
|
||||
void delay_ms(u16 nms);
|
||||
void delay_us(u32 nus);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user