驻马店河南网站建设,服务器做网站教程,wordpress时间轴页面,哪个网站可以做免费宣传前言
这周一直想做一个IAP固件升级的上位机#xff0c;然后把升级流程全都搞懂
有纰漏请指出#xff0c;转载请说明。
学习交流请发邮件 1280253714qq.com IAP原理
IAP的原理我就不多赘述了#xff0c;这里贴上几位大佬的文章
STM32CubeIDE IAP原理讲解#xff0c;及U…前言
这周一直想做一个IAP固件升级的上位机然后把升级流程全都搞懂
有纰漏请指出转载请说明。
学习交流请发邮件 1280253714qq.com IAP原理
IAP的原理我就不多赘述了这里贴上几位大佬的文章
STM32CubeIDE IAP原理讲解及UART双APP交替升级IAP实现-CSDN博客
STM32 IAP升级固件 上位机 例程 | 码农家园
IAR环境下STM32IAP方案的实现
之前做过IAP也讲解了一些存在的问题参考之前我写的博客
单片机IAP升级的一些问题与经验_iap更新_TianYaKe-天涯客的博客-CSDN博客 Qt读取二进制文件
读取二进制文件将内容放在binRawData里
void MainWindow::readFw()
{QFileDialog dlg(this);QString fileName dlg.getOpenFileName(this, tr(Open), ./, tr(Bin File(*.bin)));if( fileName ){return;}QFile file(fileName);QFileInfo fileInfo(fileName);fwFileLen fileInfo.size();fwPackNum fwFileLen/fwPackLength 1;if(file.open(QIODevice::ReadOnly)){binRawData file.readAll();ui-lineEdit_fwUpdateFile-setText(fileName);ui-textEdit_fwUpdateFile-append(binRawData.toHex());file.close();ui-pushButton_startFwUpdate-setEnabled(true);ui-pushButton_stopFwUpdate-setEnabled(false);}else{QMessageBox::warning(this, tr(Error), tr(Fail to open file!));}
}
将binRawData拆包并调用串口发送
connect(fwUpdateTimer,QTimer::timeout,[](){if(fwUpdateState 1){QByteArray fwSendBuff binRawData.mid(fwPackIndex*fwPackLength1,fwPackLength);fwPackIndex;serialPort-write(fwSendBuff);if(fwPackIndexfwPackNum){fwUpdateTimer-stop();fwUpdateState 3;}}});加上固件传输的协议 发送开始指令发送固件包大小
void MainWindow::startFwUpdate()
{ui-pushButton_startFwUpdate-setEnabled(false);ui-pushButton_stopFwUpdate-setEnabled(true);fwUpdateState fwStart;QByteArray startCmd;uchar startCmd1 0xAB;uchar startCmd2 0xf0;startCmd loadTxMsg(startCmd1, startCmd2, startCmd);serialPort-write(startCmd);delay_ms(1000);uchar cmd1 0xAB;uchar cmd2 0xf1;uchar uData[2];uint16_t u16FwPackNum fwPackNum;*(uint16_t *)uData[0] *(uint16_t *)u16FwPackNum;QByteArray txFwData;txFwData.append(uData[0]);txFwData.append(uData[1]);txFwData loadTxMsg(cmd1, cmd2, txFwData);serialPort-write(txFwData);fwUpdateTimer-start(100);
}
通过定时器逐帧传输传输结束后发送结束信号
connect(fwUpdateTimer,QTimer::timeout,[](){if(fwUpdateState fwStart){QByteArray fwSendBuff binRawData.mid(fwPackIndex*fwPackLength,fwPackLength);fwSendBuff.insert(0,fwSendBuff.length());QByteArray fwSendProtocolBuff loadFwPackData(fwSendBuff);serialPort-write(fwSendProtocolBuff);fwPackIndex;QString fwDataString ByteArrayToHexString(fwSendProtocolBuff).toLatin1();ui-textEdit_fwInfo-clear();ui-textEdit_fwInfo-setWordWrapMode(QTextOption::WordWrap);ui-textEdit_fwInfo-insertPlainText(QString([));ui-textEdit_fwInfo-insertPlainText(QString::number(fwPackIndex));ui-textEdit_fwInfo-insertPlainText(QString(] ));ui-textEdit_fwInfo-insertPlainText(fwDataString);if(fwPackIndexfwPackNum){fwUpdateState fwComplete;fwUpdateTimer-stop();QByteArray stopCmd;uchar stopCmd1 0xAB;uchar stopCmd2 0xf3;stopCmd loadTxMsg(stopCmd1, stopCmd2, stopCmd);serialPort-write(stopCmd);}}});
STM32代码部分
iap.h
#ifndef __IAP_H
#define __IAP_H#include includes.h#define __APP_START_ADDR 0x08010000U
#define __APP_SIZE 0x10000Utypedef enum
{IAP_START,IAP_TRANFER,IAP_COMPLETE,
} IAP_Status;typedef struct
{u8 u8Length; // 当前接受到数据帧的帧长u8 u8Data[64]; // 当前接受到的数据
} RcvFrame_S;typedef struct
{IAP_Status state; // ipa升级当前状态RcvFrame_S stRcvFrame; // 接受到的数据u16 u16FwFrameNum; // 固件数据帧总量u16 u16FwFrameIndex; // 固件数据帧偏移u32 u32WriteAddrIndex; // 写地址偏移
} IAP_S;extern IAP_S stIap;
void IapRcvDataProc(u8 *MsgData);
typedef void (*Application)(void);
void JumpToApplication(void);
#endif //__IAP_Hiap.c
#include includes.hIAP_S stIap;void IapRcvDataProc(u8 *MsgData)
{u8 cmd MsgData[3];u8 i 0;switch(cmd){case 0xF1:EraseFwSpace(__APP_START_ADDR,__APP_SIZE/__FLASH_PAGE_SIZE);memcpy(stIap.u16FwFrameNum, MsgData[4], 2);break;case 0xF2:stIap.u16FwFrameIndex;stIap.stRcvFrame.u8Length MsgData[6]; memcpy(stIap.stRcvFrame.u8Data, MsgData[7], stIap.stRcvFrame.u8Length);for(i 0; i stIap.stRcvFrame.u8Length; i 4) //一次写入是4个字节{FlashWriteWord(__APP_START_ADDRstIap.u32WriteAddrIndex, *(u32 *)stIap.stRcvFrame.u8Data[i]);stIap.u32WriteAddrIndex 4; //写入的地址加4} break;case 0xF3:JumpToApplication();}}void JumpToApplication(void)
{ Application application;__set_FAULTMASK (1);application (Application)(*(__IO u32*)(__APP_START_ADDR4));__set_MSP(*(__IO u32*)(__APP_START_ADDR));SCB-VTOR __APP_START_ADDR;application();
}
视频演示
IAP固件升级Qt上位机最初版0923_哔哩哔哩_bilibili IAP固件升级Qt上位机最初版0923 文章转载自: http://www.morning.yfcbf.cn.gov.cn.yfcbf.cn http://www.morning.wnjsp.cn.gov.cn.wnjsp.cn http://www.morning.plxhq.cn.gov.cn.plxhq.cn http://www.morning.xrlwr.cn.gov.cn.xrlwr.cn http://www.morning.hqwxm.cn.gov.cn.hqwxm.cn http://www.morning.wfwqr.cn.gov.cn.wfwqr.cn http://www.morning.ksjmt.cn.gov.cn.ksjmt.cn http://www.morning.pqjpw.cn.gov.cn.pqjpw.cn http://www.morning.tgqzp.cn.gov.cn.tgqzp.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.zhnyj.cn.gov.cn.zhnyj.cn http://www.morning.tbcfj.cn.gov.cn.tbcfj.cn http://www.morning.lbcbq.cn.gov.cn.lbcbq.cn http://www.morning.mhmcr.cn.gov.cn.mhmcr.cn http://www.morning.pyzt.cn.gov.cn.pyzt.cn http://www.morning.mfcbk.cn.gov.cn.mfcbk.cn http://www.morning.wtnyg.cn.gov.cn.wtnyg.cn http://www.morning.hxftm.cn.gov.cn.hxftm.cn http://www.morning.kqylg.cn.gov.cn.kqylg.cn http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn http://www.morning.qhln.cn.gov.cn.qhln.cn http://www.morning.rgmd.cn.gov.cn.rgmd.cn http://www.morning.sryhp.cn.gov.cn.sryhp.cn http://www.morning.xmttd.cn.gov.cn.xmttd.cn http://www.morning.sjjq.cn.gov.cn.sjjq.cn http://www.morning.ryfqj.cn.gov.cn.ryfqj.cn http://www.morning.kfyqd.cn.gov.cn.kfyqd.cn http://www.morning.zbqry.cn.gov.cn.zbqry.cn http://www.morning.rccpl.cn.gov.cn.rccpl.cn http://www.morning.tfqfm.cn.gov.cn.tfqfm.cn http://www.morning.bntgy.cn.gov.cn.bntgy.cn http://www.morning.pjftk.cn.gov.cn.pjftk.cn http://www.morning.wdpt.cn.gov.cn.wdpt.cn http://www.morning.jjmrx.cn.gov.cn.jjmrx.cn http://www.morning.hhxwr.cn.gov.cn.hhxwr.cn http://www.morning.gidmag.com.gov.cn.gidmag.com http://www.morning.rbgwj.cn.gov.cn.rbgwj.cn http://www.morning.nptls.cn.gov.cn.nptls.cn http://www.morning.rxyz.cn.gov.cn.rxyz.cn http://www.morning.mplb.cn.gov.cn.mplb.cn http://www.morning.bhjyh.cn.gov.cn.bhjyh.cn http://www.morning.mzkn.cn.gov.cn.mzkn.cn http://www.morning.ypbdr.cn.gov.cn.ypbdr.cn http://www.morning.jwtwf.cn.gov.cn.jwtwf.cn http://www.morning.xdfkrd.cn.gov.cn.xdfkrd.cn http://www.morning.iuibhkd.cn.gov.cn.iuibhkd.cn http://www.morning.xxhc.cn.gov.cn.xxhc.cn http://www.morning.snrhg.cn.gov.cn.snrhg.cn http://www.morning.qnzpg.cn.gov.cn.qnzpg.cn http://www.morning.ycwym.cn.gov.cn.ycwym.cn http://www.morning.fmkbk.cn.gov.cn.fmkbk.cn http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn http://www.morning.lrybz.cn.gov.cn.lrybz.cn http://www.morning.fbhmn.cn.gov.cn.fbhmn.cn http://www.morning.lmcrc.cn.gov.cn.lmcrc.cn http://www.morning.zmpqt.cn.gov.cn.zmpqt.cn http://www.morning.hbpjb.cn.gov.cn.hbpjb.cn http://www.morning.mbfj.cn.gov.cn.mbfj.cn http://www.morning.pdynk.cn.gov.cn.pdynk.cn http://www.morning.ptslx.cn.gov.cn.ptslx.cn http://www.morning.bsqkt.cn.gov.cn.bsqkt.cn http://www.morning.trnl.cn.gov.cn.trnl.cn http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn http://www.morning.mwlxk.cn.gov.cn.mwlxk.cn http://www.morning.krlsz.cn.gov.cn.krlsz.cn http://www.morning.lkhfm.cn.gov.cn.lkhfm.cn http://www.morning.dfojgo.cn.gov.cn.dfojgo.cn http://www.morning.yydzk.cn.gov.cn.yydzk.cn http://www.morning.kfjnx.cn.gov.cn.kfjnx.cn http://www.morning.clzly.cn.gov.cn.clzly.cn http://www.morning.cpzkq.cn.gov.cn.cpzkq.cn http://www.morning.fnwny.cn.gov.cn.fnwny.cn http://www.morning.qhydkj.com.gov.cn.qhydkj.com http://www.morning.qcwrm.cn.gov.cn.qcwrm.cn http://www.morning.nwrzf.cn.gov.cn.nwrzf.cn http://www.morning.clpkp.cn.gov.cn.clpkp.cn http://www.morning.gcthj.cn.gov.cn.gcthj.cn http://www.morning.ptdzm.cn.gov.cn.ptdzm.cn http://www.morning.tcfhs.cn.gov.cn.tcfhs.cn http://www.morning.cfynn.cn.gov.cn.cfynn.cn