移植到stm32f1,实现手动线赋码控制器功能
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
#include "dev_backup.h"
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f10x.h"
|
||||
#include "board.h"
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
#include "rtthread.h"
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f10x.h"
|
||||
#include "board.h"
|
||||
#include "dev_flash.h"
|
||||
#include "debug.h"
|
||||
@@ -19,6 +19,39 @@
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
bootloader 0~7
|
||||
app 8~57
|
||||
buff 58~107
|
||||
params 108
|
||||
scheme 109~110
|
||||
|
||||
*/
|
||||
#define FLASH_SECTOR_SIZE 2048
|
||||
#define FLASH_APP_SECTOR (8)
|
||||
#define FLASH_APP_SECTOR_NUM (50)
|
||||
#define FLASH_BUFF_SECTOR (58)
|
||||
#define FLASH_BUFF_SECTOR_NUM (50)
|
||||
#define FLASH_BUFF_SECTOR (58)
|
||||
#define FLASH_BUFF_SECTOR_NUM (50)
|
||||
#define FLASH_PARAM_SECTOR (108)
|
||||
#define FLASH_PARAM_SECTOR_NUM (1)
|
||||
#define FLASH_SCHEME_SECTOR (109)
|
||||
#define FLASH_SCHEME_SECTOR_NUM (3)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct{
|
||||
void *mutex;
|
||||
}self_def;
|
||||
@@ -32,20 +65,6 @@ typedef struct{
|
||||
uint32_t sector;
|
||||
}flash_item;
|
||||
|
||||
const static flash_item g_flash_addr_table[]={
|
||||
{(uint32_t *)0x08000000,FLASH_Sector_0},
|
||||
{(uint32_t *)0x08004000,FLASH_Sector_1},
|
||||
{(uint32_t *)0x08008000,FLASH_Sector_2},
|
||||
{(uint32_t *)0x0800c000,FLASH_Sector_3},
|
||||
{(uint32_t *)0x08010000,FLASH_Sector_4},
|
||||
{(uint32_t *)0x08020000,FLASH_Sector_5},
|
||||
{(uint32_t *)0x08040000,FLASH_Sector_6},
|
||||
{(uint32_t *)0x08060000,FLASH_Sector_7},
|
||||
{(uint32_t *)0x08080000,FLASH_Sector_8},
|
||||
{(uint32_t *)0x080a0000,FLASH_Sector_9},
|
||||
{(uint32_t *)0x080c0000,FLASH_Sector_10},
|
||||
{(uint32_t *)0x080e0000,FLASH_Sector_11},
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -53,8 +72,7 @@ const static flash_item g_flash_addr_table[]={
|
||||
|
||||
|
||||
#define FLASH_CLEAR_FLAG() \
|
||||
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR|\
|
||||
FLASH_FLAG_PGAERR|FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR|FLASH_FLAG_RDERR);
|
||||
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
|
||||
|
||||
|
||||
|
||||
@@ -72,8 +90,8 @@ static int flash_erase(uint32_t FLASH_Sector)
|
||||
rt_mutex_take(s->mutex,RT_WAITING_FOREVER);
|
||||
FLASH_Unlock();
|
||||
FLASH_CLEAR_FLAG();
|
||||
FLASH_DataCacheCmd(DISABLE);
|
||||
ret=FLASH_EraseSector(FLASH_Sector,VoltageRange_3);
|
||||
// 对于f103 2048byte为一个扇区,这里把扇区地址转化为flash地址
|
||||
ret=FLASH_ErasePage(FLASH_Sector*2048);
|
||||
rt_mutex_release(s->mutex);
|
||||
if(ret!=FLASH_COMPLETE)
|
||||
{
|
||||
@@ -96,7 +114,6 @@ int flash_operate_end(void)
|
||||
param_check(s->mutex);
|
||||
#endif
|
||||
rt_mutex_take(s->mutex,RT_WAITING_FOREVER);
|
||||
FLASH_DataCacheCmd(ENABLE);
|
||||
FLASH_Lock();
|
||||
rt_mutex_release(s->mutex);
|
||||
return 0;
|
||||
@@ -104,63 +121,67 @@ int flash_operate_end(void)
|
||||
|
||||
|
||||
|
||||
// 参数区16K
|
||||
// 参数区2K
|
||||
int flash_erase_param(void)
|
||||
{
|
||||
int ret;
|
||||
ret=flash_erase(FLASH_Sector_1);
|
||||
if(ret!=0) return -1;
|
||||
for(int i=0;i<FLASH_PARAM_SECTOR_NUM;i++){
|
||||
ret=flash_erase(FLASH_PARAM_SECTOR+i);
|
||||
if(ret!=0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//程序区1 256K
|
||||
//程序区1 100K
|
||||
int flash_erase_app1(void)
|
||||
{
|
||||
int ret;
|
||||
ret=flash_erase(FLASH_Sector_5);
|
||||
if(ret!=0) return -1;
|
||||
ret=flash_erase(FLASH_Sector_6);
|
||||
if(ret!=0) return -1;
|
||||
for(int i=0;i<FLASH_APP_SECTOR_NUM;i++){
|
||||
ret=flash_erase(FLASH_APP_SECTOR+i);
|
||||
if(ret!=0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//程序区2 256K
|
||||
//程序区2 100K 对于f103 程序区2与小板程序区相同
|
||||
int flash_erase_app2(void)
|
||||
{
|
||||
int ret;
|
||||
ret=flash_erase(FLASH_Sector_7);
|
||||
if(ret!=0) return -1;
|
||||
ret=flash_erase(FLASH_Sector_8);
|
||||
if(ret!=0) return -1;
|
||||
for(int i=0;i<FLASH_BUFF_SECTOR_NUM;i++){
|
||||
ret=flash_erase(FLASH_BUFF_SECTOR+i);
|
||||
if(ret!=0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//小板程序区 128K
|
||||
//小板程序区 100K
|
||||
int flash_erase_slave(void)
|
||||
{
|
||||
int ret;
|
||||
ret=flash_erase(FLASH_Sector_9);
|
||||
if(ret!=0) return -1;
|
||||
for(int i=0;i<FLASH_BUFF_SECTOR_NUM;i++){
|
||||
ret=flash_erase(FLASH_BUFF_SECTOR+i);
|
||||
if(ret!=0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//方案区 16K
|
||||
//方案区 4K
|
||||
int flash_erase_scheme(void)
|
||||
{
|
||||
int ret;
|
||||
ret=flash_erase(FLASH_Sector_2);
|
||||
if(ret!=0) return -1;
|
||||
for(int i=0;i<FLASH_SCHEME_SECTOR_NUM;i++){
|
||||
ret=flash_erase(FLASH_SCHEME_SECTOR+i);
|
||||
if(ret!=0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//脚本区 128K
|
||||
//脚本区
|
||||
int flash_erase_lua(void)
|
||||
{
|
||||
int ret;
|
||||
ret=flash_erase(FLASH_Sector_11);
|
||||
if(ret!=0) return -1;
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
uint32_t *flash_get_param(void)
|
||||
{
|
||||
return (void *)0x08004000;
|
||||
return (void *)(FLASH_BASE+FLASH_SECTOR_SIZE*FLASH_PARAM_SECTOR);
|
||||
}
|
||||
|
||||
//uint32_t *flash_get_app1(void)
|
||||
@@ -170,22 +191,22 @@ uint32_t *flash_get_param(void)
|
||||
|
||||
uint32_t *flash_get_app2(void)
|
||||
{
|
||||
return (void *)0x08060000;
|
||||
return (void *)(FLASH_BASE+FLASH_SECTOR_SIZE*FLASH_BUFF_SECTOR);
|
||||
}
|
||||
|
||||
uint32_t *flash_get_slave(void)
|
||||
{
|
||||
return (void *)0x080a0000;
|
||||
return (void *)(FLASH_BASE+FLASH_SECTOR_SIZE*FLASH_BUFF_SECTOR);
|
||||
}
|
||||
|
||||
uint32_t *flash_get_scheme(void)
|
||||
{
|
||||
return (void *)0x08008000;
|
||||
return (void *)(FLASH_BASE+FLASH_SECTOR_SIZE*FLASH_SCHEME_SECTOR);
|
||||
}
|
||||
|
||||
uint32_t *flash_get_lua(void)
|
||||
{
|
||||
return (void *)0x080e0000;
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +271,7 @@ uint8_t *flash_get_rom(rom_head **head)
|
||||
|
||||
int flash_updata_app(uint8_t *rom,uint32_t size)
|
||||
{
|
||||
uint8_t *dst=(uint8_t *)0x08020000;
|
||||
uint8_t *dst=(uint8_t *)0x08004000;
|
||||
flash_erase_app1();
|
||||
return flash_write(dst,rom,size);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f10x.h"
|
||||
#include "board.h"
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user