精简Sys,编译通过,测试通过

This commit is contained in:
nnhy 2015-10-05 14:04:34 +00:00
parent 884a147676
commit d273ac7589
5 changed files with 16 additions and 21 deletions

View File

@ -142,7 +142,7 @@ bool assert_ptr_(const void* p)
} }
uint ramEnd = SRAM_BASE + (Sys.RAMSize << 10); uint ramEnd = SRAM_BASE + (Sys.RAMSize << 10);
if((uint)p >= ramEnd) if(Sys.RAMSize > 0 && (uint)p >= ramEnd)
{ {
debug_printf("ptr:0x%08x >= SRAM_END:0x%08x\r\n", p, ramEnd); debug_printf("ptr:0x%08x >= SRAM_END:0x%08x\r\n", p, ramEnd);
return false; return false;
@ -154,7 +154,7 @@ bool assert_ptr_(const void* p)
#endif #endif
uint flashEnd = FLASH_BASE + (Sys.FlashSize << 10); uint flashEnd = FLASH_BASE + (Sys.FlashSize << 10);
if((uint)p >= flashEnd && (uint)p < SRAM_BASE) if(Sys.FlashSize > 0 && (uint)p >= flashEnd && (uint)p < SRAM_BASE)
{ {
debug_printf("ptr:0x%08x >= FLASH_END:0x%08x\r\n", p, flashEnd); debug_printf("ptr:0x%08x >= FLASH_END:0x%08x\r\n", p, flashEnd);
return false; return false;
@ -185,7 +185,7 @@ void ShowFault(uint exception)
debug_printf("是总线fault存储器管理fault 或是用法fault 上访的结果\r\n"); debug_printf("是总线fault存储器管理fault 或是用法fault 上访的结果\r\n");
// GD不能映射中断向量表必须使用Flash开头的那个默认中断向量表而这需要在Keil的ARM属性页设置GD32=1 // GD不能映射中断向量表必须使用Flash开头的那个默认中断向量表而这需要在Keil的ARM属性页设置GD32=1
// __Vectors_Size只是一个标记需要先取地址才得到它的值 // __Vectors_Size只是一个标记需要先取地址才得到它的值
if(Sys.IsGD && (uint)&__Vectors_Size <= 7 * 4) //if(Sys.IsGD && (uint)&__Vectors_Size <= 7 * 4)
{ {
debug_printf("GD不能映射中断向量表必须使用Flash开头的那个默认中断向量表而这需要在Keil的ARM属性页设置GD32=1\r\n"); debug_printf("GD不能映射中断向量表必须使用Flash开头的那个默认中断向量表而这需要在Keil的ARM属性页设置GD32=1\r\n");
} }

View File

@ -82,7 +82,14 @@ extern "C"
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
//RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL6); //RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL6);
// 支持多种倍频 // 支持多种倍频
mull = clock / cystalClock; //mull = clock / cystalClock;
// 干掉除法
mull = 0;
while(clock > cystalClock)
{
clock -= cystalClock;
mull++;
}
pll = ((mull - 2) * 4) << 16; pll = ((mull - 2) * 4) << 16;
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | pll); RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | pll);
//SystemCoreClock = cystalClock * mull; //SystemCoreClock = cystalClock * mull;

View File

@ -428,7 +428,7 @@ extern "C"
/* 重载fputc可以让用户程序使用printf函数 */ /* 重载fputc可以让用户程序使用printf函数 */
int fputc(int ch, FILE *f) int fputc(int ch, FILE *f)
{ {
if(!Sys.Inited) return ch; if(Sys.Clock == 0) return ch;
int _index = Sys.MessagePort; int _index = Sys.MessagePort;
if(_index == COM_NONE) return ch; if(_index == COM_NONE) return ch;
@ -446,11 +446,7 @@ extern "C"
if(_printf_sp) if(_printf_sp)
{ {
//_printf_sp->SendData((byte)ch); _printf_sp->Write(ByteArray(ch, 1));
//byte bt = (byte)ch;
//_printf_sp->Write(&bt, 1);
ByteArray bs(ch, 1);
_printf_sp->Write(bs);
} }
isInFPutc = false; isInFPutc = false;

11
Sys.cpp
View File

@ -130,9 +130,6 @@ void SysStop()
TSys::TSys() TSys::TSys()
{ {
Inited = false;
Started = false;
#ifdef STM32F0 #ifdef STM32F0
Clock = 48000000; Clock = 48000000;
#elif defined(STM32F1) #elif defined(STM32F1)
@ -144,7 +141,7 @@ TSys::TSys()
CystalClock = HSE_VALUE; // 晶振时钟 CystalClock = HSE_VALUE; // 晶振时钟
MessagePort = COM1; // COM1; MessagePort = COM1; // COM1;
IsGD = Get_JTAG_ID() == 0x7A3; bool IsGD = Get_JTAG_ID() == 0x7A3;
#ifdef STM32F0 #ifdef STM32F0
void* p = (void*)0x1FFFF7AC; // 手册里搜索UID优先英文手册 void* p = (void*)0x1FFFF7AC; // 手册里搜索UID优先英文手册
@ -251,8 +248,6 @@ void TSys::InitClock()
Clock = RCC_GetSysClock(); Clock = RCC_GetSysClock();
SystemCoreClock = Clock; SystemCoreClock = Clock;
} }
Inited = true;
} }
void TSys::Init(void) void TSys::Init(void)
@ -284,6 +279,7 @@ void TSys::ShowInfo()
debug_printf("%s::%s Code:%04X ", Company, Name, Code); debug_printf("%s::%s Code:%04X ", Company, Name, Code);
debug_printf("Ver:%x.%x Build:%s\r\n", *ver++, *ver++, BuildTime); debug_printf("Ver:%x.%x Build:%s\r\n", *ver++, *ver++, BuildTime);
debug_printf("SmartOS::"); debug_printf("SmartOS::");
bool IsGD = Get_JTAG_ID() == 0x7A3;
if(IsGD) if(IsGD)
debug_printf("GD32"); debug_printf("GD32");
else else
@ -500,7 +496,6 @@ void TSys::Start()
#if DEBUG #if DEBUG
//AddTask(ShowTime, NULL, 2000000, 2000000); //AddTask(ShowTime, NULL, 2000000, 2000000);
#endif #endif
Started = true;
if(OnStart) if(OnStart)
{ {
// 设置重载值让其每1ms重载一次 // 设置重载值让其每1ms重载一次
@ -514,7 +509,7 @@ void TSys::Start()
void TimeSleep(uint us) void TimeSleep(uint us)
{ {
// 在这段时间里面,去处理一下别的任务 // 在这段时间里面,去处理一下别的任务
if(Sys.Started && us != 0 && us >= 50) if(Sys.Clock > 0 && us != 0 && us >= 50)
{ {
TaskScheduler* sc = Task::Scheduler(); TaskScheduler* sc = Task::Scheduler();
// 记录当前正在执行任务 // 记录当前正在执行任务

3
Sys.h
View File

@ -70,10 +70,7 @@ typedef enum
class TSys : Object class TSys : Object
{ {
public: public:
bool Inited; // 是否已完成初始化
bool Started; // 是否调试
COM_Def MessagePort;// 消息口默认0表示USART1 COM_Def MessagePort;// 消息口默认0表示USART1
bool IsGD; // 是否GD芯片
uint Clock; // 系统时钟 uint Clock; // 系统时钟
uint CystalClock;// 晶振时钟 uint CystalClock;// 晶振时钟