提交 44a8c3e2 作者: wysheng

支持升级与boot启动

上级 d97e947b
......@@ -794,7 +794,7 @@
</option>
<option>
<name>DoFill</name>
<state>0</state>
<state>1</state>
</option>
<option>
<name>FillerByte</name>
......@@ -802,11 +802,11 @@
</option>
<option>
<name>FillerStart</name>
<state>0x0</state>
<state>0x08008000</state>
</option>
<option>
<name>FillerEnd</name>
<state>0x0</state>
<state>0x0807FFFF</state>
</option>
<option>
<name>CrcSize</name>
......@@ -833,7 +833,7 @@
</option>
<option>
<name>CrcInitialValue</name>
<state>0x0</state>
<state>0xFFFF</state>
</option>
<option>
<name>DoCrc</name>
......
......@@ -31,6 +31,75 @@ u32 GetSystemTick(void)
}
/* Base address of the Flash sectors */
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
uint32_t GetSector(uint32_t Address)
{
uint32_t sector = 0;
if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
{
sector = FLASH_Sector_0;
}
else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1))
{
sector = FLASH_Sector_1;
}
else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2))
{
sector = FLASH_Sector_2;
}
else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3))
{
sector = FLASH_Sector_3;
}
else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4))
{
sector = FLASH_Sector_4;
}
else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5))
{
sector = FLASH_Sector_5;
}
else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6))
{
sector = FLASH_Sector_6;
}
else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7))
{
sector = FLASH_Sector_7;
}
else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8))
{
sector = FLASH_Sector_8;
}
else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9))
{
sector = FLASH_Sector_9;
}
else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10))
{
sector = FLASH_Sector_10;
}
else/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_11))*/
{
sector = FLASH_Sector_11;
}
return sector;
}
int CopyCode(u32 Des, u32 Scr, u32 Len)
{
u32 DesAddr;
......@@ -44,7 +113,13 @@ int CopyCode(u32 Des, u32 Scr, u32 Len)
for(i=0; i<Len; )
{
if(0 == (DesAddr%McnRomSectionSize))
FLASH_EraseSector(DesAddr, VoltageRange_1);
FLASH_EraseSector(GetSector(DesAddr), VoltageRange_3);
else if(ADDR_FLASH_SECTOR_2 == DesAddr)
FLASH_EraseSector(FLASH_Sector_2, VoltageRange_3);
else if(ADDR_FLASH_SECTOR_3 == DesAddr)
FLASH_EraseSector(FLASH_Sector_3, VoltageRange_3);
else if(ADDR_FLASH_SECTOR_4 == DesAddr)
FLASH_EraseSector(FLASH_Sector_4, VoltageRange_3);
FLASH_ProgramHalfWord(DesAddr, *(u16*)ScrAddr);
DesAddr += 2;
ScrAddr += 2;
......@@ -55,10 +130,11 @@ int CopyCode(u32 Des, u32 Scr, u32 Len)
return memcmp((void*)Des, (void*)Scr, Len);
}
int UpdateFlagSet(u32 Status)
{
FLASH_Unlock();/* Flash unlock */
FLASH_EraseSector(UpdateFlagAddr, VoltageRange_1);
FLASH_EraseSector(GetSector(UpdateFlagAddr), VoltageRange_3);
FLASH_ProgramWord(UpdateFlagAddr, 0x414E4D4D);
FLASH_ProgramWord(UpdateFlagAddr+4, Status);
FLASH_ProgramWord(UpdateFlagAddr+8, 0x414E4C50);
......@@ -66,6 +142,7 @@ int UpdateFlagSet(u32 Status)
return 0;
}
//*名称:BcDToHex
//*功能: BCD码转16进制
//*参数: bcd_data 要转换的BCD码数据(0-100)
......
......@@ -2,9 +2,9 @@
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
define symbol __ICFEDIT_intvec_start__ = 0x08008200;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_start__ = 0x08008000;
define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF;
......@@ -32,4 +32,7 @@ place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite,
block CSTACK, block HEAP };
place in RAM1_region { section .sram };
\ No newline at end of file
place in RAM1_region { section .sram };
place at start of ROM_region { readonly section ProgramStart };
place at end of ROM_region { ro section .checksum };
\ No newline at end of file
......@@ -371,7 +371,8 @@ void SystemInit(void)
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
//SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
SCB->VTOR = 0x08008000 | 0x200;
#endif
}
......
......@@ -28,10 +28,10 @@ void vApplicationIdleHook( void )
//FeedDog();
}
//#pragma section = ".checksum"
#pragma section = ".checksum"
//extern u16 __checksum;
//__root const u32 __aa__ = (u32)&__checksum;
extern u16 __checksum;
__root const u32 __aa__ = (u32)&__checksum;
/*
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论