904 lines
28 KiB
C
Raw Normal View History

2019-10-24 17:37:35 +08:00
/*
*********************************************************************************************************
*
2019-11-01 11:16:09 +08:00
* :
* : prog_if.c
* : V1.0
* :
2019-10-24 17:37:35 +08:00
*
2019-11-01 11:16:09 +08:00
* :
*
* V1.0 2019-03-19 armfly
2019-10-24 17:37:35 +08:00
*
2019-11-01 11:16:09 +08:00
* Copyright (C), 2019-2030, www.armfly.com
2019-10-24 17:37:35 +08:00
*
*********************************************************************************************************
*/
2020-11-29 21:36:51 +08:00
#include "includes.h"
2020-02-06 23:01:29 +08:00
#include "swd_host.h"
#include "swd_flash.h"
#include "elf_file.h"
#include "stm8_flash.h"
#include "n76e003_flash.h"
2020-05-29 22:53:39 +08:00
#include "SW_DP_Multi.h"
#include "swd_host_multi.h"
2020-11-29 21:36:51 +08:00
#include "w25q_flash.h"
2019-10-24 17:37:35 +08:00
2020-02-06 23:01:29 +08:00
extern const program_target_t flash_algo;
2019-10-24 17:37:35 +08:00
2020-02-06 23:01:29 +08:00
OFFLINE_PROG_T g_tProg = {0};
2019-10-24 18:03:30 +08:00
2020-02-06 23:01:29 +08:00
PROG_INI_T g_tProgIni = {0};
2019-10-24 17:37:35 +08:00
2020-09-10 17:01:38 +08:00
FIX_DATA_T g_tFixData = {0};
uint8_t flash_buff[sizeof(FsReadBuf)];
2020-09-10 17:01:38 +08:00
uint8_t PG_CheckFlashFix(uint32_t _FlashAddr, uint32_t _BuffSize, uint32_t _FileIndex);
uint8_t PG_CheckFixSplit(uint32_t _FlashAddr, uint32_t _BuffSize, uint32_t _FileIndex);
uint8_t PG_FixFlashMem(uint32_t _FlashAddr, char *_Buff, uint32_t _BuffSize, uint32_t _FileIndex, uint8_t _chan);
2019-10-24 17:37:35 +08:00
/*
*********************************************************************************************************
2020-02-06 23:01:29 +08:00
* : CancelKey
* :
2019-11-01 11:16:09 +08:00
* :
2020-02-06 23:01:29 +08:00
* : 1
2019-10-24 17:37:35 +08:00
*********************************************************************************************************
*/
2020-02-06 23:01:29 +08:00
uint8_t ProgCancelKey(void)
{
if (bsp_GetKey() == KEY_LONG_DOWN_C)
2019-11-01 11:16:09 +08:00
{
2020-02-06 23:01:29 +08:00
return 1;
2019-11-01 11:16:09 +08:00
}
2020-02-06 23:01:29 +08:00
return 0;
2019-10-24 17:37:35 +08:00
}
/*
*********************************************************************************************************
* : GetChipTypeFromLua
* : lua中解析芯片类型. g_tProg.ChipType
* :
* : 1
*********************************************************************************************************
*/
uint32_t GetChipTypeFromLua(lua_State *L)
{
g_tProg.ChipType = CHIP_SWD_ARM;
if (L > 0)
{
/* 器件接口类型: "SWD", "SWIM", "SPI", "I2C" */
if (lua_getglobal(L, "CHIP_TYPE") != 0)
{
const char *name;
if (lua_isstring(g_Lua, -1))
{
name = lua_tostring(g_Lua, -1);
if (strcmp(name, "SWD") == 0)
{
g_tProg.ChipType = CHIP_SWD_ARM;
}
else if (strcmp(name, "SWIM") == 0)
{
g_tProg.ChipType = CHIP_SWIM_STM8;
}
else if (strcmp(name, "SPI") == 0)
{
g_tProg.ChipType = CHIP_SPI_FLASH;
}
else if (strcmp(name, "I2C") == 0)
{
g_tProg.ChipType = CHIP_I2C_EEPROM;
}
else if (strcmp(name, "NUVOTON_8051") == 0)
{
g_tProg.ChipType = CHIP_NUVOTON_8051;
}
}
}
lua_pop(L, 1);
}
return g_tProg.ChipType;
}
/*
*********************************************************************************************************
* : WaitChipRemove
* :
* :
* : 10
*********************************************************************************************************
*/
extern void sysTickInit(void);
uint8_t WaitChipRemove(void)
{
2020-05-29 22:53:39 +08:00
/* 由LUA程序提供函数 */
const char *ret_str;
lua_do("ret_str = CheckChipRemove()");
lua_getglobal(g_Lua, "ret_str");
if (lua_isstring(g_Lua, -1))
{
ret_str = lua_tostring(g_Lua, -1);
}
else
{
ret_str = "";
}
lua_pop(g_Lua, 1);
if (strcmp(ret_str, "removed") == 0)
{
return 1;
}
2020-05-29 22:53:39 +08:00
return 0;
}
/*
*********************************************************************************************************
* : WaitChipInsert
* :
* :
* : 10
*********************************************************************************************************
*/
uint8_t WaitChipInsert(void)
{
const char *ret_str;
lua_do("ret_str = CheckChipInsert()");
lua_getglobal(g_Lua, "ret_str");
if (lua_isstring(g_Lua, -1))
{
ret_str = lua_tostring(g_Lua, -1);
}
else
{
ret_str = "";
}
lua_pop(g_Lua, 1);
if (strcmp(ret_str, "inserted") == 0)
{
return 1;
}
2020-05-29 22:53:39 +08:00
return 0;
}
/*
*********************************************************************************************************
* : PG_ReloadLuaVar
* : lua文件全局变量.
* : _str :
* :
*********************************************************************************************************
*/
extern void h7swim_ReadLuaVar(void);
void PG_ReloadLuaVar(void)
{
GetChipTypeFromLua(g_Lua);
/* VERIFY_MODE; 校验模式 */
g_tProg.VerifyMode = lua_GetVarUint32("VERIFY_MODE", VERIFY_READ_BACK);
2020-05-29 22:53:39 +08:00
/* ERASE_CHIP_TIME; 全片擦除时间ms */
g_tProg.EraseChipTime = lua_GetVarUint32("ERASE_CHIP_TIME", 60 * 1000);
/* 0B VERIFY; option byte 验证取消 */
g_tProg.VerifyOptionByteDisalbe = lua_GetVarUint32("OB_VERIFY_DISABLE", 0);
/* SwdClockDelay; SWD接口时序延迟 */
g_tProg.SwdClockDelay = lua_GetVarUint32("SWD_CLOCK_DELAY", 0);
/* 复位延迟 */
g_tProg.SwdResetDelay = lua_GetVarUint32("RESET_DELAY", 20);
/* 读取复位类型: 软件还是硬件复位 */
g_tProg.ResetMode = lua_GetVarUint32("RESET_MODE", 0);
/* 多路模式下,出错后立刻同时终止 */
g_tProg.AbortOnError = lua_GetVarUint32("ABORT_ON_ERROR", 1);
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
/*
2021-01-24 MM32L073FP时
static uint8_t MUL_swd_read_data(uint32_t addr, uint32_t *val);
20us 30us成功, 50us
*/
g_tProg.MulDelayUsReadData = lua_GetVarUint32("MUL_DELAYUS_READ_DATA", 0);
/* 2021-03-16 多路模式烧录STM32F103C8T6(可能是国产的增加延迟1us */
g_tProg.MulDelayUsReadAck = lua_GetVarUint32("MUL_DELAYUS_READ_ACK", 0);
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
h7swim_ReadLuaVar(); /* 读取LUA中的全局变量 */
}
2020-11-29 21:36:51 +08:00
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
// uint32_t Capacity; /* 芯片容量 */
// uint32_t SectorSize; /* 扇区大小 */
// uint32_t EraseSectorCmd; /* 扇区擦除指令 */
// uint32_t EraseSectorTimeout; /* 擦除扇区超时 ms */
// uint32_t EraseChipTimeout; /* 擦除整片超时 ms */
// uint32_t ProgPageTimeout; /* 编程page超时 */
// uint8_t AutoAddrInc; /* AAI模式写 */
g_tW25Q.Capacity = lua_GetVarUint32("FLASH_SIZE", 0);
g_tW25Q.SectorSize = lua_GetVarUint32("SECTOR_SIZE", 4096);
g_tW25Q.EraseSectorCmd = lua_GetVarUint32("ERASE_SECTOR_CMD", 0x20);
g_tW25Q.EraseSectorTimeout = lua_GetVarUint32("ERASE_SECTOR_TIMEOUT", 2 * 1000);
g_tW25Q.EraseChipTimeout = lua_GetVarUint32("ERASE_CHIP_TIMEOUT", 400 * 1000);
g_tW25Q.ProgPageTimeout = 100; /* 100ms */
g_tW25Q.AutoAddrInc = lua_GetVarUint32("PROG_AAI", 0);
g_tW25Q.ReadMode = lua_GetVarUint32("READ_MODE", 0);
g_tW25Q.ReadIDCmd = lua_GetVarUint32("READ_ID_CMD", 0x9F);
g_tW25Q.EraseChipCmd = lua_GetVarUint32("ERASE_CHIP_CMD", 0xC7);
g_tW25Q.UnlockCmd = lua_GetVarUint32("UNLOCK_CMD", 0x00);
}
}
2020-09-10 17:01:38 +08:00
/*
*********************************************************************************************************
* : PG_LuaFixData
* : UID,SN,USR数据
* : _Path :
* _FlashAddr : flash起始地址
* : 0 = ok,
*********************************************************************************************************
*/
uint8_t PG_LuaFixData(void)
{
size_t len;
int i;
//lua FIX_TABLE结构
//1, 0, 0x08000000, 05 00 00 00
//1, 1, 0x08000000, 02
//1, 2, 0x08000000, FF
//1, 3, 0x08000000, 01
//1, 1, 0x08000000, FB 32 C9 38 BE C8 06 F1
//1, 1, 0x08000000, 92 06 02 0E 90 7C C4 02 90 00 4A 0E 96 58 C4 02
//lua->stack得到全局表位置-1
lua_getglobal(g_Lua, "FIX_TABLE");
g_tFixData.Count = 0;
for (i = 0; i < MAX_FIX_LINE; i++)
{
lua_pushinteger(g_Lua, i * 4 + 1); //c->statck设置key值位置-1(上面的-1变为-2)
lua_gettable(g_Lua, -2);//返回值为值的类型
if (lua_isinteger(g_Lua, -1))
{
g_tFixData.Lines[i].Enable = lua_tointeger(g_Lua, -1);
lua_pop(g_Lua, 1);
}
else
{
lua_pop(g_Lua, 1);
break;
}
lua_pushinteger(g_Lua, i * 4 + 2); //c->statck设置key值位置-1(上面的-1变为-2)
lua_gettable(g_Lua, -2);//返回值为值的类型
if (lua_isinteger(g_Lua, -1))
{
g_tFixData.Lines[i].Chan = lua_tointeger(g_Lua, -1);
lua_pop(g_Lua, 1);
}
else
{
lua_pop(g_Lua, 1);
break;
}
lua_pushinteger(g_Lua, i * 4 + 3); //c->statck设置key值位置-1(上面的-1变为-2)
lua_gettable(g_Lua, -2);//返回值为值的类型
if (lua_isinteger(g_Lua, -1))
{
g_tFixData.Lines[i].Addr = lua_tointeger(g_Lua, -1);
}
lua_pop(g_Lua, 1);
lua_pushinteger(g_Lua, i * 4 + 4); //c->statck设置key值位置-1(上面的-1变为-2)
lua_gettable(g_Lua, -2);//返回值为值的类型
if (lua_isstring(g_Lua, -1))
{
g_tFixData.Lines[i].pData = luaL_checklstring(g_Lua, -1, &len); /* 1是参数的位置 len是string的长度 */
g_tFixData.Lines[i].Len = len;
}
lua_pop(g_Lua, 1);
g_tFixData.Count++;
}
lua_pop(g_Lua, 1);
return 0;
}
2019-10-24 17:37:35 +08:00
/*
*********************************************************************************************************
2020-02-06 23:01:29 +08:00
* : PG_PrintText
* :
* : _str :
2019-11-01 11:16:09 +08:00
* :
2019-10-24 17:37:35 +08:00
*********************************************************************************************************
*/
2020-02-06 23:01:29 +08:00
void PG_PrintText(char *_str)
2019-10-24 17:37:35 +08:00
{
2020-02-06 23:01:29 +08:00
char str[128];
/* 输出文本 */
StrUTF8ToGBK(_str, str, sizeof(str));
2020-05-29 22:53:39 +08:00
if (g_gMulSwd.MultiMode > 0) /* 多路模式, 1拖1 */
2020-05-29 22:53:39 +08:00
{
if (g_gMulSwd.MultiMode == 1)
2020-05-29 22:53:39 +08:00
{
if (g_gMulSwd.Error[0] != 0)
{
if (g_gMulSwd.SwitchPin == 0) strcat(str, " #1");
else if (g_gMulSwd.SwitchPin == 1) strcat(str, " #2");
else if (g_gMulSwd.SwitchPin == 2) strcat(str, " #3");
else if (g_gMulSwd.SwitchPin == 3) strcat(str, " #4");
}
2020-05-29 22:53:39 +08:00
}
else /* 1拖2,3,4 */
2020-05-29 22:53:39 +08:00
{
if (g_gMulSwd.Error[0] != 0)
{
strcat(str, " #1");
}
if (g_gMulSwd.Error[1] != 0)
{
strcat(str, " #2");
}
if (g_gMulSwd.Error[2] != 0)
{
strcat(str, " #3");
}
if (g_gMulSwd.Error[3] != 0)
{
strcat(str, " #4");
}
2020-05-29 22:53:39 +08:00
}
}
2020-02-06 23:01:29 +08:00
if (g_MainStatus == MS_PROG_WORK)
2019-11-01 11:16:09 +08:00
{
DispProgProgress(str, -1, 0xFFFFFFFF); /* -1表示不刷新进度 */
2019-11-01 11:16:09 +08:00
}
2020-02-06 23:01:29 +08:00
printf("%s\r\n", str);
2020-05-29 22:53:39 +08:00
2020-02-06 23:01:29 +08:00
bsp_Idle();
2019-10-24 17:37:35 +08:00
}
/*
*********************************************************************************************************
2020-02-06 23:01:29 +08:00
* : PG_PrintPercent
* :
* :
2019-11-01 11:16:09 +08:00
* :
2019-10-24 17:37:35 +08:00
*********************************************************************************************************
*/
2020-02-06 23:01:29 +08:00
extern void DispProgVoltCurrent(void);
void PG_PrintPercent(float _Percent, uint32_t _Addr)
2019-10-24 17:37:35 +08:00
{
2020-05-29 22:53:39 +08:00
#if 1
if (_Percent == 0)
{
printf(" %dms, %0.2f%%\r\n", bsp_CheckRunTime(g_tProg.Time), _Percent);
2020-05-29 22:53:39 +08:00
}
else if (_Percent == 100)
{
2020-09-10 17:01:38 +08:00
//printf("\r\n %dms, %0.2f%%\r\n", bsp_CheckRunTime(g_tProg.Time), _Percent);
//printf("\r\n");
printf(" %dms, %0.2f%%\r\n", bsp_CheckRunTime(g_tProg.Time), _Percent);
2020-05-29 22:53:39 +08:00
}
else
{
printf(".");
}
#else
printf(" %dms, %0.2f%%\r\n", bsp_CheckRunTime(g_tProg.Time), _Percent);
#endif
2020-02-06 23:01:29 +08:00
if (g_MainStatus == MS_PROG_WORK)
{
g_tProg.Percent = _Percent;
DispProgProgress(0, _Percent, _Addr); /* 0表示不刷新文本 */
2020-02-06 23:01:29 +08:00
DispProgVoltCurrent(); /* 刷新TVCC电压和电流 */
2020-02-06 23:01:29 +08:00
}
bsp_Idle();
2019-10-24 17:37:35 +08:00
}
/*
*********************************************************************************************************
2020-02-06 23:01:29 +08:00
* : PG_FixFlashMem
2020-09-10 17:01:38 +08:00
* :
2020-02-06 23:01:29 +08:00
* : _Path :
* _FlashAddr : flash起始地址
2020-09-10 17:01:38 +08:00
* _BuffSize :
* _chan : 01-4
2020-02-06 23:01:29 +08:00
* : 0 1
2019-10-24 17:37:35 +08:00
*********************************************************************************************************
*/
2020-09-10 17:01:38 +08:00
uint8_t PG_FixFlashMem(uint32_t _FlashAddr, char *_Buff, uint32_t _BuffSize, uint32_t _FileIndex, uint8_t _chan)
2019-10-24 17:37:35 +08:00
{
2020-09-10 17:01:38 +08:00
uint16_t m;
2020-02-06 23:01:29 +08:00
uint16_t i;
uint8_t change = 0;
2020-09-10 17:01:38 +08:00
for (m = 0; m < g_tFixData.Count; m++)
2019-11-01 11:16:09 +08:00
{
2020-09-10 17:01:38 +08:00
if (g_tFixData.Lines[m].Enable == _FileIndex)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
if (g_tFixData.Lines[m].Chan == 0 || _chan == 0 || g_tFixData.Lines[m].Chan == _chan)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
for (i = 0; i < g_tFixData.Lines[m].Len; i++)
{
if (g_tFixData.Lines[m].Addr + i >= _FlashAddr && g_tFixData.Lines[m].Addr + i < _FlashAddr + _BuffSize)
{
_Buff[g_tFixData.Lines[m].Addr - _FlashAddr + i] = g_tFixData.Lines[m].pData[i];
change = 1;
}
}
2020-02-06 23:01:29 +08:00
}
}
}
return change;
}
2019-11-01 11:16:09 +08:00
2020-02-06 23:01:29 +08:00
/*
*********************************************************************************************************
2020-09-10 17:01:38 +08:00
* : PG_CheckFlashFix
* : flash区域是否存在fix区数据
2020-02-06 23:01:29 +08:00
* : _Path :
* _FlashAddr : flash起始地址
2020-09-10 17:01:38 +08:00
* _FileIndex : 1-10)
* : 0 1
2020-02-06 23:01:29 +08:00
*********************************************************************************************************
*/
2020-09-10 17:01:38 +08:00
uint8_t PG_CheckFlashFix(uint32_t _FlashAddr, uint32_t _BuffSize, uint32_t _FileIndex)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
uint16_t m;
2020-02-06 23:01:29 +08:00
uint8_t change = 0;
2020-09-10 17:01:38 +08:00
/*
add 0000000000 0000000000 0000000000 0000000000
fix 11111 11111 11111 111111111111
*/
if (_BuffSize == 0)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
return 0;
}
2020-02-06 23:01:29 +08:00
2020-09-10 17:01:38 +08:00
for (m = 0; m < g_tFixData.Count; m++)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
if (g_tFixData.Lines[m].Enable == _FileIndex
&& g_tFixData.Lines[m].Addr + g_tFixData.Lines[m].Len > _FlashAddr
&& g_tFixData.Lines[m].Addr < _FlashAddr + _BuffSize)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
change = 1;
break;
2019-11-01 11:16:09 +08:00
}
}
2020-02-06 23:01:29 +08:00
return change;
2019-10-24 17:37:35 +08:00
}
2020-02-06 23:01:29 +08:00
2019-10-24 17:37:35 +08:00
/*
*********************************************************************************************************
2020-09-10 17:01:38 +08:00
* : PG_CheckFixSplit
* : fix区数据是否需要顺序写入
2020-02-06 23:01:29 +08:00
* : _Path :
* _FlashAddr : flash起始地址
2020-09-10 17:01:38 +08:00
* _FileIndex : 1-10)
* : 0 1,
2019-10-24 17:37:35 +08:00
*********************************************************************************************************
*/
2020-09-10 17:01:38 +08:00
uint8_t PG_CheckFixSplit(uint32_t _FlashAddr, uint32_t _BuffSize, uint32_t _FileIndex)
{
uint16_t m;
uint8_t change = 0;
2020-09-10 17:01:38 +08:00
/*
add 0000000000 0000000000 0000000000 0000000000
fix 11111 11111 11111 111111111111
*/
2020-02-06 23:01:29 +08:00
2020-09-10 17:01:38 +08:00
for (m = 0; m < g_tFixData.Count; m++)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
if (g_tFixData.Lines[m].Enable == _FileIndex
&& g_tFixData.Lines[m].Addr + g_tFixData.Lines[m].Len > _FlashAddr
&& g_tFixData.Lines[m].Addr < _FlashAddr + _BuffSize)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
if (g_tFixData.Lines[m].Chan >= 2)
2020-02-06 23:01:29 +08:00
{
2020-09-10 17:01:38 +08:00
change = 1;
break;
2020-02-06 23:01:29 +08:00
}
}
}
2020-09-10 17:01:38 +08:00
return change;
2020-02-06 23:01:29 +08:00
}
2020-09-10 17:01:38 +08:00
2020-02-06 23:01:29 +08:00
/*
*********************************************************************************************************
2020-09-10 17:01:38 +08:00
* : PG_FixDataIsDiff
* : FIX数据是否每个通道都一样
* :
* : 01
2020-02-06 23:01:29 +08:00
*********************************************************************************************************
*/
2020-09-10 17:01:38 +08:00
uint8_t PG_FixDataIsDiff(void)
2019-10-24 17:37:35 +08:00
{
2020-09-10 17:01:38 +08:00
uint16_t m;
2020-02-06 23:01:29 +08:00
2020-09-10 17:01:38 +08:00
// --返回C程序用的table结构为 {
// -- 0, 0x08000000, "1234567", 0表示全部通道数据一样 1表示第1通4表示4通道
// -- 1, 0x08000200, "AAA",
// -- 2, 0x08000300, "BBBB",
// -- }
2019-11-01 11:16:09 +08:00
2020-09-10 17:01:38 +08:00
for (m = 0; m < g_tFixData.Count; m++)
{
if (g_tFixData.Lines[m].Chan >= 2)
2020-05-29 22:53:39 +08:00
{
2020-09-10 17:01:38 +08:00
return 1; /* 至少2个通道存在不同的数据 */
}
2020-05-29 22:53:39 +08:00
}
2020-09-10 17:01:38 +08:00
return 0;
2019-10-24 17:37:35 +08:00
}
2020-11-29 21:36:51 +08:00
/*
*********************************************************************************************************
* . pg_prog_file.c
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* : PG_GetSectorSize
* :
* : _Addr :
* :
*********************************************************************************************************
*/
uint32_t PG_GetSectorSize(const char *_Algo, uint32_t _Addr)
{
uint32_t sz;
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
sz = 1024;
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
sz = lua_GetVarUint32("FLASH_BLOCK_SIZE", 64);
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
sz = 128;
2020-11-29 21:36:51 +08:00
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
sz = lua_GetVarUint32("SECTOR_SIZE", 4*1024);
}
return sz;
}
/*
*********************************************************************************************************
* : PG_EraseSector
* : API
* : _Addr :
* : 0 1OK
*********************************************************************************************************
*/
uint8_t PG_EraseSector(const char *_Algo, uint32_t _Addr)
{
2020-11-29 21:36:51 +08:00
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
/* ARM不用这个文件 */;
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
/* STM8都是整片擦除 */;
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
/* 选择整片擦除 */
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
W25Q_EraseSector(_Addr);
}
return 1;
}
/*
*********************************************************************************************************
* : PG_GetPageSize
* : page大小
* :
* :
*********************************************************************************************************
*/
uint32_t PG_GetPageSize(const char *_Algo)
{
uint32_t sz;
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
sz = 1024;
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
sz = lua_GetVarUint32("FLASH_BLOCK_SIZE", 64);
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
sz = 32;
2020-11-29 21:36:51 +08:00
}
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
sz = lua_GetVarUint32("FLASH_PAGE_SIZE", 1024);;
}
return sz;
}
/*
*********************************************************************************************************
* : PG_GetDeviceAddr
* :
* :
* :
*********************************************************************************************************
*/
uint32_t PG_GetDeviceAddr(const char *_Algo)
{
uint32_t addr;
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
addr = 0x08000000;
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
if (strcmp(_Algo, "FLASH") == 0)
{
addr = lua_GetVarUint32("FLASH_ADDRESS", 0);
}
else if (strcmp(_Algo, "EEPROM") == 0)
{
addr = lua_GetVarUint32("EEPROM_ADDRESS", 0);
}
else
{
addr = 0x008000;
}
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
if (strcmp(_Algo, "APROM") == 0)
{
addr = lua_GetVarUint32("APROM_ADDRESS", 0);
}
else if (strcmp(_Algo, "LDROM") == 0)
{
addr = lua_GetVarUint32("LDROM_ADDRESS", 0);
}
else if (strcmp(_Algo, "SPROM") == 0)
{
addr = lua_GetVarUint32("SPROM_ADDRESS", 0);
}
else
{
addr = 0;
}
}
2020-11-29 21:36:51 +08:00
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
addr = lua_GetVarUint32("FLASH_ADDRESS", 0);
}
return addr;
}
/*
*********************************************************************************************************
* : PG_GetDeviceSize
* :
* :
* :
*********************************************************************************************************
*/
uint32_t PG_GetDeviceSize(const char *_Algo)
{
uint32_t sz;
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
sz = 0x08000000;
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
if (strcmp(_Algo, "FLASH") == 0)
{
sz = lua_GetVarUint32("FLASH_SIZE", 0);
}
else if (strcmp(_Algo, "EEPROM") == 0)
{
sz = lua_GetVarUint32("EEPROM_SIZE", 0);
}
else
{
sz = 1024;
}
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
if (strcmp(_Algo, "APROM") == 0)
{
sz = lua_GetVarUint32("APROM_SIZE", 0);
}
else if (strcmp(_Algo, "LDROM") == 0)
{
sz = lua_GetVarUint32("LDROM_SIZE", 0);
}
else if (strcmp(_Algo, "SPROM") == 0)
{
sz = lua_GetVarUint32("SPROM_SIZE", 0);
}
else
{
sz = 1024;
}
}
2020-11-29 21:36:51 +08:00
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
sz = lua_GetVarUint32("FLASH_SIZE", 0);
}
return sz;
}
/*
*********************************************************************************************************
* : PG_EraseChip
* : API
* :
* : 0 1OK
*********************************************************************************************************
*/
uint8_t PG_EraseChip(void)
{
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
;
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
N76E_EraseChip();
}
2020-11-29 21:36:51 +08:00
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
W25Q_EraseChip();
}
return 1;
}
/*
*********************************************************************************************************
* : PG_CheckBlank
* :
* :
* : 0 1
*********************************************************************************************************
*/
uint8_t PG_CheckBlank(const char *_Algo, uint32_t _Addr, uint32_t _Size)
{
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
;
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
;
}
2020-11-29 21:36:51 +08:00
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
;
}
return 0;
}
/*
*********************************************************************************************************
* : PG_ProgramBuf
* : Programs a memory block
* : _FlashAddr :
* _Buff : Pointer to buffer containing source data.
* _Size : 1block
* : 0 : ; 1 :
*********************************************************************************************************
*/
uint8_t PG_ProgramBuf(const char *_Algo, uint32_t _FlashAddr, uint8_t *_Buff, uint32_t _Size)
{
uint8_t re = 0;
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
re = STM8_FLASH_ProgramBuf(_FlashAddr, _Buff, _Size);
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
re = N76E_FLASH_ProgramBuf(_FlashAddr, _Buff, _Size);
}
2020-11-29 21:36:51 +08:00
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
re = W25Q_FLASH_ProgramBuf(_FlashAddr, _Buff, _Size);
}
return re;
}
/*
*********************************************************************************************************
* : PG_ReadBuf
* : flash
* : _FlashAddr :
* _Buff : Pointer to buffer containing source data.
* _Size : 1block
* : 0 : ; 1 :
*********************************************************************************************************
*/
uint8_t PG_ReadBuf(const char *_Algo, uint32_t _FlashAddr, uint8_t *_Buff, uint32_t _Size)
{
uint8_t re = 0;
if (g_tProg.ChipType == CHIP_SWD_ARM)
{
}
else if (g_tProg.ChipType == CHIP_SWIM_STM8)
{
re = STM8_FLASH_ReadBuf(_FlashAddr, _Buff, _Size);
}
else if (g_tProg.ChipType == CHIP_NUVOTON_8051)
{
re = N76E_ReadBuf(_FlashAddr, _Buff, _Size);
}
2020-11-29 21:36:51 +08:00
else if (g_tProg.ChipType == CHIP_SPI_FLASH)
{
re = W25Q_ReadBuf(_FlashAddr, _Buff, _Size);
}
return re;
}
2019-10-24 18:03:30 +08:00
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/