使用外部存储模块w25q等情况时,当进行bootloader升级时,可是考虑使用双buff,一个buff接收满后,开始往外部flash中存数据,与此同时,另一个buff开始接收数据。
main.c不分代码:
test_count++;
Sequence_Num = (data[0] << 8) | data[1];
if(Sequence_Num == (Multiple_of_6 + 1))
{
if(num < 170){
Rx_data.Remainder_Count = num;
Rx_data.Lastdata_Of_Arr = num * 6 + Remainder_of_6 -1;
memcpy(&Rx_data.buf[num*6],&data[2],6);
memset(&Rx_data.buf[(num+1)*6],0xff,1020-(num+1)*6);
Rx_data.Recv_Finish = true;
}
else{
Rx_M_data.r_count = num;
Rx_M_data.Lastdata_Of_Arr = (num-170) * 6 + Remainder_of_6;
memcpy(&Rx_M_data.buf[(num-170)*6],&data[2],6);
memset(&Rx_data.buf[(num-170+1)*6],0xff,1020-(num-170+1)*6);
Rx_M_data.Recv_Finish = true;
}
num = 0;
}
else
{
if(num < 170) // for 1020 bytes data
{
memcpy(&Rx_data.buf[num*6],&data[2],6);
if(num == 169)
{
Rx_data.r_count++;
Rx_data.Recv_Finish = true;
}
else
send_confirm_msg(0xff);
}
else if(num < 340)
{
memcpy(&Rx_M_data.buf[(num-170)*6],&data[2],6);
if(num == 339)
{
Rx_M_data.r_count ++;
Rx_M_data.Recv_Finish = true;
num = 0;
}
else
send_confirm_msg(0xff);
}
num++;
}
功能代码:
void btld_FlashGo(My_struct *st)
{
uint16_t jack = 0;
uint32_t index;
static uint16_t Count = 0;
if(st->Recv_Finish == true)
{
if(st->t_count < 128)
{
jack =st->t_count * 8;
if(st->t_count == 127)
{
st->G_uint32_to_write = (uint32_t) st->buf[jack]
| (((uint32_t) st->buf[jack+1]) << 8)
| (((uint32_t) st->buf[jack+2]) << 16)
| (((uint32_t) st->buf[jack+3]) << 24);
HAL_CAN_DeactivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
// HAL_TIM_Base_Stop_IT(&htim4);
if(btld_FlashNext_32(st->G_uint32_to_write,&index) == BL_OK){
if(HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING) == HAL_OK){
send_confirm_msg(0xff);
}
else
send_confirm_msg(0x01);
}
else{
send_confirm_msg(0x00);
}
st->t_count = 0;
st->Recv_Finish = false;
st->D_1020_count ++;
Count ++;
if(Count == 70)
{
Count = 0;
}
}
else
{
st->G_uint64_to_write = (uint64_t) st->buf[jack]
| (((uint64_t) st->buf[jack+1]) << 8) | (((uint64_t) st->buf[jack+2]) << 16)
| (((uint64_t) st->buf[jack+3]) << 24)| (((uint64_t) st->buf[jack+4]) << 32)
| (((uint64_t) st->buf[jack+5]) << 40)| (((uint64_t) st->buf[jack+6]) << 48)
| (((uint64_t) st->buf[jack+7]) << 56);
// HAL_CAN_DeactivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);使用外部flash存储,就不涉及到进行flash写时需要禁掉总线的问题
btld_FlashNext(st->G_uint64_to_write);
// HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
}
st->t_count ++;
}
}
}