完善SmartOS系统的初始化
This commit is contained in:
parent
496fb25acd
commit
ce90a37869
70
Sys.cpp
70
Sys.cpp
|
@ -91,11 +91,13 @@ __asm void TSys::EnableInterrupts()
|
||||||
|
|
||||||
//利用SysTick定时器产生1ms时基
|
//利用SysTick定时器产生1ms时基
|
||||||
|
|
||||||
// SysTick_Handler 滴答定时器中断
|
extern "C"
|
||||||
void SysTick_Handler(void) //需要最高优先级 必须有抢断任何其他中断的能力才能 //供其他中断内延时使用
|
|
||||||
{
|
{
|
||||||
if(TickStat)
|
// SysTick_Handler 滴答定时器中断
|
||||||
TickStat--;
|
void SysTick_Handler(void) //需要最高优先级 必须有抢断任何其他中断的能力才能 //供其他中断内延时使用
|
||||||
|
{
|
||||||
|
if(TickStat) TickStat--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************
|
/****************************************************
|
||||||
|
@ -145,7 +147,6 @@ void TSys::Delay(uint us)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GD32F1
|
|
||||||
// 获取JTAG编号,ST是0x041,GD是0x7A3
|
// 获取JTAG编号,ST是0x041,GD是0x7A3
|
||||||
uint16_t Get_JTAG_ID()
|
uint16_t Get_JTAG_ID()
|
||||||
{
|
{
|
||||||
|
@ -158,7 +159,7 @@ uint16_t Get_JTAG_ID()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void STM32_BootstrapCode()
|
void Bootstrap()
|
||||||
{
|
{
|
||||||
uint n = 0;
|
uint n = 0;
|
||||||
uint RCC_CFGR_ADC_BITS = RCC_CFGR_ADCPRE_DIV8;
|
uint RCC_CFGR_ADC_BITS = RCC_CFGR_ADCPRE_DIV8;
|
||||||
|
@ -288,27 +289,54 @@ void STM32_BootstrapCode()
|
||||||
Sys.Clock = Sys.CystalClock * mull;
|
Sys.Clock = Sys.CystalClock * mull;
|
||||||
if( (RCC->CFGR & RCC_CFGR_PLLXTPRE_HSE_Div2) && !isGD ) Sys.Clock /= 2;
|
if( (RCC->CFGR & RCC_CFGR_PLLXTPRE_HSE_Div2) && !isGD ) Sys.Clock /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TSys::TSys()
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Debug = false;
|
||||||
|
#else
|
||||||
|
Debug = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void TSys::Init(void)
|
Clock = 72000000;
|
||||||
{
|
CystalClock = 8000000; // 晶振时钟
|
||||||
#ifndef GD32F1
|
MessagePort = 0; // COM1;
|
||||||
RCC_ClocksTypeDef clock;
|
|
||||||
|
|
||||||
RCC_GetClocksFreq(&clock);
|
|
||||||
Clock = clock.SYSCLK_Frequency;
|
|
||||||
#endif
|
|
||||||
#ifdef STM32F10X
|
|
||||||
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4); //中断优先级分配方案4 四位都是抢占优先级
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ID[0] = *(__IO uint *)(0X1FFFF7F0); // 高字节
|
ID[0] = *(__IO uint *)(0X1FFFF7F0); // 高字节
|
||||||
ID[1] = *(__IO uint *)(0X1FFFF7EC); //
|
ID[1] = *(__IO uint *)(0X1FFFF7EC); //
|
||||||
ID[2] = *(__IO uint *)(0X1FFFF7E8); // 低字节
|
ID[2] = *(__IO uint *)(0X1FFFF7E8); // 低字节
|
||||||
FlashSize = *(__IO ushort *)(0X1FFFF7E0); // 容量
|
MCUID = *(__IO uint *)(0xE0042000); // MCU编码。低字设备版本,高字子版本
|
||||||
|
FlashSize = *(__IO ushort *)(0x1FFFF7E0); // 容量
|
||||||
|
//JTAGID = *(__IO ushort *)(0xE00FFFE8);
|
||||||
|
IsGD = Get_JTAG_ID() == 0x7A3;
|
||||||
|
|
||||||
#if GD32F1
|
if(IsGD) Clock = 120000000;
|
||||||
STM32_BootstrapCode();
|
}
|
||||||
|
|
||||||
|
void TSys::Init(void)
|
||||||
|
{
|
||||||
|
// 获取当前频率
|
||||||
|
RCC_ClocksTypeDef clock;
|
||||||
|
|
||||||
|
RCC_GetClocksFreq(&clock);
|
||||||
|
//Clock = clock.SYSCLK_Frequency;
|
||||||
|
// 如果当前频率不等于配置,则重新配置时钟
|
||||||
|
if(Clock != clock.SYSCLK_Frequency) Bootstrap();
|
||||||
|
|
||||||
|
#ifdef STM32F10X
|
||||||
|
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4); //中断优先级分配方案4 四位都是抢占优先级
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delay_init(Clock/1000000);
|
delay_init(Clock/1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*extern "C"
|
||||||
|
{
|
||||||
|
void Reset_Handler()
|
||||||
|
{
|
||||||
|
Bootstrap();
|
||||||
|
//SystemInit();
|
||||||
|
//__main();
|
||||||
|
//main();
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
41
Sys.h
41
Sys.h
|
@ -4,7 +4,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "stm32.h"
|
#include "stm32.h"
|
||||||
|
|
||||||
/* 类型定义 */
|
/* 类型定义 */
|
||||||
typedef char sbyte;
|
typedef char sbyte;
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
typedef unsigned short ushort;
|
typedef unsigned short ushort;
|
||||||
|
@ -14,34 +14,29 @@ typedef char* string;
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
|
|
||||||
/*Spi定义*/
|
/* 引脚定义 */
|
||||||
//SPI1..这种格式与st库冲突
|
|
||||||
#define SPI_1 0
|
|
||||||
#define SPI_2 1
|
|
||||||
#define SPI_3 2
|
|
||||||
#define SPI_NONE 0XFF
|
|
||||||
|
|
||||||
/* 引脚定义 */
|
|
||||||
typedef ushort Pin;
|
typedef ushort Pin;
|
||||||
#include "Pin.h"
|
#include "Pin.h"
|
||||||
|
|
||||||
// 系统类
|
// 系统类
|
||||||
class TSys
|
class TSys
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool Debug; // 是否调试
|
bool Debug; // 是否调试
|
||||||
uint Clock; // 系统时钟
|
uint Clock; // 系统时钟
|
||||||
#if GD32F1
|
uint CystalClock; // 晶振时钟
|
||||||
uint CystalClock; // 晶振时钟
|
byte MessagePort; // 消息口,默认0表示USART1
|
||||||
#endif
|
uint ID[3]; // 芯片ID
|
||||||
byte MessagePort; // 消息口,默认0表示USART1
|
uint FlashSize; // 芯片Flash容量
|
||||||
uint ID[3]; // 芯片ID
|
uint MCUID; // MCU编码。低字设备版本,高字子版本
|
||||||
uint FlashSize; // 芯片Flash容量
|
//ushort JTAGID; // Joint Test Action Group编号
|
||||||
void Init(); // 初始化系统
|
bool IsGD; // 是否GD芯片
|
||||||
void Sleep(uint ms); // 毫秒级延迟
|
TSys();
|
||||||
void Delay(uint us); // 微秒级延迟
|
void Init(); // 初始化系统
|
||||||
void DisableInterrupts(); // 关闭中断
|
void Sleep(uint ms); // 毫秒级延迟
|
||||||
void EnableInterrupts(); // 打开中断
|
void Delay(uint us); // 微秒级延迟
|
||||||
|
void DisableInterrupts(); // 关闭中断
|
||||||
|
void EnableInterrupts(); // 打开中断
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TSys Sys;
|
extern TSys Sys;
|
||||||
|
|
Loading…
Reference in New Issue