解决方法:
写操作前须进行页擦除。
问题描述:
我尝试用“hr8p506_iap_table”及“lib_flashiap.c”的api,都无法实现iap的正常写入功能。以下为iap功能测试的主要代码:
具体效果表现为,通过keil烧录,选择"erase full chip"则第一次运行程序iap能够写入成功,第二次及往后运行则无法正常写入。须重新整片擦除后才能第一次iap写入成功,往后都失败。
函数名: main
描 述: 主函数
输入值: 无
输出值: 无
返回值: 无
uint8_t databuf[1024] = {0};
#define flashaddr_start0x8C00
#define PAGEADDRflashaddr_start/1024
#define startaddr_systemdataflashaddr_start
typedef struct{
uint8_t flag_firstpoweron;
uint64_t powerontime_ms;
uint32_t productwatertime_ro_s;
uint32_t productwatertime_filter_s;
uint32_t powerontime_s;
uint32_t productwatertime_s;
uint8_t mode_timeset_flushfilter;
uint8_t mode_gallon;
uint8_t flag_initialtds_pure;
uint8_t flag_initialtds_clean;
uint16_t initialtds_pure;
uint16_t initialtds_clean;
}_t_system_data;
_t_system_data t_system_data;
void uartx_init(UART_TypeDef* uartx, uint32_t BaudRate, NVIC_IRQPriority priority)
{
GPIO_InitSettingType x;
UART_InitStruType y;
GPIO_Pin tx_pin, rx_pin;
NVIC_IRQChannel NVIC_UARTx_IRQn;
if(uartx == UART0)//UART0
{
tx_pin = GPIO_Pin_A23;
rx_pin = GPIO_Pin_A22;
NVIC_UARTx_IRQn = NVIC_UART0_IRQn;
}
else//UART1
{
tx_pin = GPIO_Pin_B0;
rx_pin = GPIO_Pin_B1;
NVIC_UARTx_IRQn = NVIC_UART1_IRQn;
}
x.Signal = GPIO_Pin_Signal_Digital;
x.Dir = GPIO_Direction_Output;
x.Func = GPIO_Reuse_Func1;
x.ODE = GPIO_ODE_Output_Disable;
x.DS = GPIO_DS_Output_Strong;
x.PUE = GPIO_PUE_Input_Disable;
x.PDE = GPIO_PDE_Input_Disable;
GPIO_Init(tx_pin, &x); //TXD
x.Signal = GPIO_Pin_Signal_Digital;
x.Dir = GPIO_Direction_Input;
x.Func = GPIO_Reuse_Func1;
x.ODE = GPIO_ODE_Output_Disable;
x.DS = GPIO_DS_Output_Strong;
x.PUE = GPIO_PUE_Input_Disable;
x.PDE = GPIO_PDE_Input_Disable;
GPIO_Init(rx_pin, &x); //RXD
y.UART_StopBits = UART_StopBits_1; //停止位:1
y.UART_TxMode = UART_DataMode_8; //发送数据格式:8位数据
y.UART_TxPolar = UART_Polar_Normal; //发送端口极性:正常
y.UART_RxMode = UART_DataMode_8; //接收数据格式:8位数据
y.UART_RxPolar = UART_Polar_Normal; //接收端口极性:正常
y.UART_BaudRate = BaudRate; //波特率
y.UART_ClockSet = UART_Clock_1; //时钟选择:Pclk
UART_Init(uartx, &y);
UART_TBIMConfig(uartx, UART_TBIM_Byte);
UART_RBIMConfig(uartx, UART_TBIM_Byte);
UART_ITConfig(uartx, UART_IT_RB, Enable);
NVIC_Init(NVIC_UARTx_IRQn, priority, Enable);
uartx->CON0.TXEN = 1;
uartx->CON0.RXEN = 1;
}
void uartx_send(UART_TypeDef* uartx, uint8_t* databuf, uint32_t len)
{
uint32_t i;
for(i = 0;i