CH32V307的U盘中bin文件的IAP程序下载后无法启动问题

是这样的,我是想使用U盘通过IAP更新APP程序,我是使用例程:EXAM\IAP\USB+UARTT\CHV30x_IAP修改的程序,在程序中屏蔽了usbhs device,添加U盘的usbhs host;在全部修改后,我发现一旦我程序里有CH103子程序库的读取函数,就会复位后芯片完全没有反应(有点像死机,具体还不太清楚);


现在就是添加了U盘的IAP下载代码,原有的串口IAP下载都无法使用了

具体就是代码中出现了ret = CHRV3ByteRead( );函数,没有调用都会导致IAP下载后复位没有反应

不知道是不是CH103子程序库和IAP程序不兼容吗?希望解答一下谢谢!



部分程序

while(1)
    {
        //串口,只是为了验证程序可以通过串口升级
        if( USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET){
            UART_Rx_Deal();
        }


        //U盘,在整个过程我没有链接U盘,所以就代码来说下面代码是不会执行的,
        //但我使用上面的串口进行在IAP下载成功后,通过复位按键或断电复位芯片完全没有反应
        //通过排查,在程序中出现了CHRV3ByteRead函数后,就出现复位后没有反应的问题,
        //一旦屏蔽CHRV3ByteRead函数,就可以通过上面的串口进行IAP下载,并复位后可以跳转到APP正常运行
        if( USBHSH->INT_FG & USBHS_DETECT_FLAG )
        {
            USBHSH->INT_FG = USBHS_DETECT_FLAG;
            if( USBHSH->MIS_ST & USBHS_ATTCH )
            {
                ret = USBHS_HostEnum( );
                if( ret == ERR_SUCCESS )
                {

                    printf( "Enum Succeed\r\n" );
                    Delay_Ms(100);
                    // U盘操作流程:USB总线复位、U盘连接、获取设备描述符和设置USB地址、可选的获取配置描述符,之后到达此处,由CH103子程序库继续完成后续工作
                    CHRV3DiskStatus = DISK_USB_ADDR;

                          printf( "Wait DiskReady\r\n" );
                          ret = CHRV3DiskReady( );                                 //等待U盘准备好
                          if ( ret == ERR_SUCCESS )
                          {

                              printf("CHRV3DiskStatus:%02x\r\n",CHRV3DiskStatus);
                              /* 读文件 */
                              strcpy( (PCHAR)mCmdParam.Open.mPathName, "/708/EXAM_ALL.BIN" );  //设置将要操作的文件路径和文件名
                              ret = CHRV3FileOpen( );                                       //打开文件
                              if ( ret == ERR_MISS_DIR || ret == ERR_MISS_FILE )            //没有找到文件
                              {
                                  printf("没有找到文件\r\n");
                              }
                              else
                              {

                                  adr=0;
                                  mCmdParam.ByteLocate.mByteOffset = 0x00;  //移到文件的开头
                                  CHRV3ByteLocate( );
                                  i = CHRV3FileQuery( );                  //查询当前文件的信息
                                  mStopIfError( i );
                                  printf( "file size:%u\r\n",CHRV3vFileSize );
                                  memset(buf,0,sizeof(buf));
                                  USB_Deal(buf,2,CMD_IAP_ERASE,adr);    //IAP开始命令
                                  ///////////二、读取文件字节/////////////////////////////////////////
                                  TotalCount = CHRV3vFileSize;                                      //设置准备读取总长度100字节

                                  while ( TotalCount )
                                  { 
                                      //如果文件比较大,一次读不完,可以再调用CH103ByteRead继续读取,文件指针自动向后移动
                                      //模拟串口的数据包大小
                                      if ( TotalCount > 60 ) t = 60;/* 剩余数据较多,限制单次读写的长度不能超过 sizeof( mCmdParam.Other.mBuffer ) */
                                      else t = TotalCount;                                 /* 最后剩余的字节数 */
                                      mCmdParam.ByteRead.mByteCount = t;                   /* 请求读出几十字节数据 */
                                      mCmdParam.ByteRead.mByteBuffer= &buf[0];
//在程序中出现了CHRV3ByteRead函数,就算没有调用,在IAP下载成功后,复位芯片就完全没有反应!!!
//                                      ret = CHRV3ByteRead( );                                /* 以字节为单位读取数据块,单次读写的长度不能超过MAX_BYTE_IO,第二次调用时接着刚才的向后读 */
                                      TotalCount -= mCmdParam.ByteRead.mByteCount;           /* 计数,减去当前实际已经读出的字符数 */

                                      USB_Deal(buf,mCmdParam.ByteRead.mByteCount,CMD_IAP_PROM,adr); //发送数据并写入FLASH
                                      adr += mCmdParam.ByteRead.mByteCount; //IAP数据地址偏移

                                      //数据查看
//                                      for ( i=0; i!=mCmdParam.ByteRead.mByteCount; i++ )
//                                      {
//                                          printf( "%c", buf[i] );  /* 显示读出的字符 */
//                                      }
//                                      if ( mCmdParam.ByteRead.mByteCount < t )
//                                      {
//                                          /* 实际读出的字符数少于要求读出的字符数,说明已经到文件的结尾 */
//                                          printf( "\r\n" );
//                                          printf( "文件已经结束\r\n" );
//                                          break;
//                                      }

                                  }

                                  printf("IAP END,To verify\r\n");
                                  //验证数据
                                  adr = 0;
                                  mCmdParam.ByteLocate.mByteOffset = 0x00;  //移到文件的开头
                                  CHRV3ByteLocate( );
                                  i = CHRV3FileQuery( );                  //查询当前文件的信息
                                  mStopIfError( i );
//                                  printf( "file size:%u\r\n",CHRV3vFileSize );
                                  TotalCount = CHRV3vFileSize;                                      //设置准备读取总长度100字节
                                  while ( TotalCount )
                                  {                                                      //如果文件比较大,一次读不完,可以再调用CH103ByteRead继续读取,文件指针自动向后移动
                                      if ( TotalCount > 60 ) t = 60;/* 剩余数据较多,限制单次读写的长度不能超过 sizeof( mCmdParam.Other.mBuffer ) */
                                      else t = TotalCount;                                 /* 最后剩余的字节数 */
                                      mCmdParam.ByteRead.mByteCount = t;                   /* 请求读出几十字节数据 */
                                      mCmdParam.ByteRead.mByteBuffer= &buf[0];
//                                      ret = CHRV3ByteRead( );                                /* 以字节为单位读取数据块,单次读写的长度不能超过MAX_BYTE_IO,第二次调用时接着刚才的向后读 */
                                      TotalCount -= mCmdParam.ByteRead.mByteCount;           /* 计数,减去当前实际已经读出的字符数 */

                                      USB_Deal(buf,mCmdParam.ByteRead.mByteCount,CMD_IAP_VERIFY,adr); //发送数据,这里会进行对比
                                      adr += mCmdParam.ByteRead.mByteCount; //IAP数据地址偏移

//                                      for ( i=0; i!=mCmdParam.ByteRead.mByteCount; i++ )
//                                      {
//                                          printf( "%c", buf[i] );  /* 显示读出的字符 */
//                                      }
//                                      if ( mCmdParam.ByteRead.mByteCount < t )
//                                      {
//                                          /* 实际读出的字符数少于要求读出的字符数,说明已经到文件的结尾 */
//                                          printf( "\r\n" );
//                                          printf( "文件已经结束\r\n" );
//                                          break;
//                                      }
                                  }

                                  adr= 0;
                                  USB_Deal(buf,2,CMD_IAP_END,adr);    //IAP结束命令
                                  printf( "Close\r\n" );
                                  i = CHRV3FileClose( );                                    /* 关闭文件 */
                                  mStopIfError( i );
                              }
                              break;
                          }
                          else
                          {
                              printf("s = %02x\r\n",ret);
                              printf("CHRV3DiskStatus:%02x\n",CHRV3DiskStatus);
                          }
      //                    Delay_Ms( 50 );
                }
                else
                {

                }
            }
            else
            {
                USBHS_HostInit(DISABLE);
                USBHS_HostInit(ENABLE);
                CHRV3DiskStatus = DISK_DISCONNECT;
                printf("disconnect\n");
            }
        }
        IWDG_ReloadCounter();
    }


您好,附件为CH32V307 U盘IAP升级例程,可以参考一下

icon_rar.gifCH32V307 U盘IAP.zip



好的,谢谢!



你好,使用提供的U盘IAP范例,插入U盘,侦测不到,请问是什么原因?板子为购买的开发板


您好,该U盘IAP例程对应的USB引脚为PB6、PB7引脚,注意一下插入USB口是否正确。目前,在我们CH32V307 EVT中有对应的USBFS以及USBHS IAP升级例程,你可以用最新EVT例程测试一下。EVT下载链接如下,后续若有问题,可通过邮箱(lzs@wch.cn)和我沟通。此外,需要注意一下你U盘文件系统的格式,目前不支持NTFS

/downloads/CH32V307EVT_ZIP.html 


image.png



试过三种U盘,FAT32,用转接头接在TYPEC接口上(PB6,PB7),均无法检测到U盘插入。范例:CH32V307EVT\EVT\EXAM\USB\USBHS\HOST_IAP

YD-CH32V307VCT6-board-720x616.png


您好,我用我们的评估版测试是没问题的,我们U盘例程中第一个示例需要在U盘中手动创建C51文件夹,否则会提示找不到文件目录的错误,具体操作流程已发您的邮箱,后续有问题可以邮箱联系我:kx@wch.cn


只有登录才能回复,可以选择微信账号登录