Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Bootloader
ota在线升级
U盘升级固件,STM32F407同时挂载U盘和Flash,写U盘出问题
发布于 2023-04-13 18:50:17 浏览:1180
订阅该版
目的是通过U盘和OTA实现固件升级,卡在u盘读写上了: 1.参考https://blog.csdn.net/weixin_41738023/article/details/113390312 进行U盘和Flash挂载。 2.用函数测试`void readwrite(const char* filename)`出现`CBW size error usb mass_storage read failed`问题。 `length = write(fd, test_data, sizeof(test_data));`这一步挂的。 ```c #define TEST_FN "/udisk/test_usbh.c" void readwrite(const char* filename) { int fd; int index, length; rt_kprintf("write data come 1\n"); fd = open(TEST_FN, O_WRONLY | O_CREAT | O_TRUNC, 0); if (fd < 0) { rt_kprintf("open file for write failed\n"); return; } rt_kprintf("write data come 2\n"); for (index = 0; index < sizeof(test_data); index ++) { test_data[index] = index + 27; } rt_kprintf("write data come 3\n"); length = write(fd, test_data, sizeof(test_data)); rt_kprintf("write data come 3.5\n"); if (length != sizeof(test_data)) { rt_kprintf("write data failed\n"); close(fd); return; } close(fd); rt_kprintf("write data come 4\n"); fd = open(TEST_FN, O_RDONLY, 0); if (fd < 0) { rt_kprintf("check: open file for read failed\n"); return; } rt_kprintf("write data come 5\n"); length = read(fd, buffer, sizeof(buffer)); if (length != sizeof(buffer)) { rt_kprintf("check: read file failed\n"); close(fd); return; } rt_kprintf("write data come 6\n"); for (index = 0; index < sizeof(test_data); index ++) { if (test_data[index] != buffer[index]) { rt_kprintf("check: check data failed at %d\n", index); close(fd); return; } } rt_kprintf("usb host read/write udisk successful\r\n"); close(fd); } ``` 3.ls能看到U盘文件里的内容,如下是启动,打印的测试结果: ``` [SFUD]Find a Winbond flash chip. Size is 16777216 bytes. [SFUD]spi flash device is initialize success. ////////////////////////////////////////////////////// /////////////Hello!HS Tech-Wxm Welcome!/////////////// ////////////////////////////////////////////////////// Powered by RT-Thread. V0.9.2 build Apr 8 2023 [D/FAL] (fal_flash_init:63) Flash device | onchip_flash_16k_part | addr: 0x08000000 | len: 0x00020000 | blk_size: 0x00004000 |initialized finish. [D/FAL] (fal_flash_init:63) Flash device | onchip_flash | addr: 0x08020000 | len: 0x000e0000 | blk_size: 0x00020000 |initialized finish. [D/FAL] (fal_flash_init:63) Flash device | nor_flash | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish. [32;22m[I/FAL] ==================== FAL partition table ====================[0m [32;22m[I/FAL] | name | flash_dev | offset | length |[0m [32;22m[I/FAL] -------------------------------------------------------------[0m [32;22m[I/FAL] | app | onchip_flash | 0x00000000 | 0x00080000 |[0m [32;22m[I/FAL] | download | nor_flash | 0x00000000 | 0x00080000 |[0m [32;22m[I/FAL] | factory | nor_flash | 0x00080000 | 0x00080000 |[0m [32;22m[I/FAL] =============================================================[0m [32;22m[I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.[0m [32;22m[I/FAL] System initialization successful.[0m [I]RT-Thread OTA package(V0.2.1) initialize success. [E]Verify firmware CRC32(calc.crc: df6bed7c != hdr.crc: 36f70c7e) failed on partition 'download'. [E]Verify firmware hash(calc.hash: 4176c76f != hdr.hash: 741edaf7) failed on partition 'app'. [I]Begin to execute the program on app partition. [32;22m[I/FAL] Find user firmware at app partition 0x08020000 successfully.[0m [32;22m[I/FAL] Bootloader jumps to user firmware now.[0m [32m[I/I2C] I2C bus [i2c2] registered[0m \ | / - RT - Thread Operating System / | \ 5.0.0 build Apr 12 2023 17:05:59 2006 - 2022 Copyright by RT-Thread team lwIP-2.0.3 initialized! [32m[I/SFUD] Find a Winbond flash chip. Size is 16777216 bytes.[0m [32m[I/SFUD] norflash0 flash device is initialize success.[0m [32m[I/SFUD] Probe SPI flash norflash0 by SPI device spi10 success.[0m [32m[I/sal.skt] Socket Abstraction Layer initialize success.[0m [D/FAL] (fal_flash_init:61) Flash device | onchip_flash_16k | addr: 0x08000000 | len: 0x00010000 | blk_size: 0x00004000 |initialized finish. [D/FAL] (fal_flash_init:61) Flash device | onchip_flash_128k | addr: 0x08020000 | len: 0x000e0000 | blk_size: 0x00020000 |initialized finish. [D/FAL] (fal_flash_init:61) Flash device | norflash0 | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish. [32;22m[I/FAL] ==================== FAL partition table ====================[0m [32;22m[I/FAL] | name | flash_dev | offset | length |[0m [32;22m[I/FAL] -------------------------------------------------------------[0m [32;22m[I/FAL] | bootload | onchip_flash_16k | 0x00000000 | 0x00020000 |[0m [32;22m[I/FAL] | app | onchip_flash_128k | 0x00020000 | 0x00080000 |[0m [32;22m[I/FAL] | download | norflash0 | 0x00000000 | 0x00080000 |[0m [32;22m[I/FAL] | factory | norflash0 | 0x00080000 | 0x00080000 |[0m [32;22m[I/FAL] | filesystem | norflash0 | 0x00100000 | 0x00f00000 |[0m [32;22m[I/FAL] =============================================================[0m [32;22m[I/FAL] RT-Thread Flash Abstraction Layer (V0.4.0) initialize success.[0m [32;22m[I/FAL] The FAL block device (filesystem) created successfully[0m filesystem mount successful! [32m[I/at.clnt] AT client(V1.3.1) on device uart2 initialize success.[0m [0m[D/at.dev.ec20] start init e0 device.[0m The current version of APP firmware is 2.0.0 found part[0], begin: 65536, size: 7.511GB [31m[E/at.clnt] wait AT client(uart2) connect timeout(5000 tick).[0m [32m[I/at.dev.ec20] e0 device initialize retry...[0m [31m[E/at.clnt] wait AT client(uart2) connect timeout(5000 tick).[0m [32m[I/at.dev.ec20] e0 device initialize retry...[0m [31m[E/at.dev.ec20] e0 device network initialize failed(-2).[0m [0m[D/at.dev.ec20] network interface device(e0) set up status.[0m The current version of APP firmware is 2.0.0 msh />ls Directory /: udisk
test
msh /> msh />cd udisk msh /udisk>ls Directory /udisk: rt-thread.rbl 254528 msh /udisk> msh /udisk>readwrite write data come 1 write data come 2 write data come 3 request size 512, transfer size 0 csw signature error usb mass_storage write 1 sector failed write data come 3.5 write data failed CBW size error usb mass_storage write 1 sector failed msh /udisk> msh /udisk>list device device type ref count -------- -------------------- ---------- ud0-0 Block Device 1 filesyst Block Device 1 spi20 SPI Device 0 norflash Block Device 0 spi10 SPI Device 0 usbh USB Host Bus 0 rtc RTC 0 pwm14 PWM Device 0 pwm2 PWM Device 0 e0 Network Interface 1 timer14 Timer Device 0 timer2 Timer Device 0 spi2 SPI Bus 0 spi1 SPI Bus 0 sspi1 SPI Bus 0 i2c2 I2C Bus 0 adc1 ADC Device 0 uart6 Character Device 0 uart5 Character Device 0 uart4 Character Device 0 uart3 Character Device 0 uart2 Character Device 1 uart1 Character Device 2 pin Pin Device 0 msh /udisk> ``` 4.看许多问答,提示`static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts)`函数有问题,请求如何解决? 根据 https://blog.csdn.net/weixin_41738023/article/details/113390312 做过修改。 不修改一测试就崩溃。 ```c static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts) { int timeout = timeouts; int res = 0; while (1) { if (!connect_status) { return -1; } rt_completion_init(&urb_completion); HAL_HCD_HC_SubmitRequest(&stm32_hhcd_fs, pipe->pipe_index, (pipe->ep.bEndpointAddress & 0x80) >> 7, pipe->ep.bmAttributes, token, buffer, nbytes, 0); rt_thread_mdelay(1);//wxm 1 //rt_completion_wait(&urb_completion, timeout); if((res = rt_completion_wait(&urb_completion, timeout)) != RT_EOK)//wxm { RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_completion_wait failed = %d\r\n", res)); connect_status = RT_FALSE; return -RT_ETIMEOUT; } rt_thread_mdelay(50);//wxm 1 if (HAL_HCD_HC_GetState(&stm32_hhcd_fs, pipe->pipe_index) == HC_NAK) { RT_DEBUG_LOG(RT_DEBUG_USB, ("nak\n")); if (pipe->ep.bmAttributes == USB_EP_ATTR_INT) { rt_thread_delay((pipe->ep.bInterval * RT_TICK_PER_SECOND / 1000) > 0 ? (pipe->ep.bInterval * RT_TICK_PER_SECOND / 1000) : 1); } HAL_HCD_HC_Halt(&stm32_hhcd_fs, pipe->pipe_index); HAL_HCD_HC_Init(&stm32_hhcd_fs, pipe->pipe_index, pipe->ep.bEndpointAddress, pipe->inst->address, USB_OTG_SPEED_FULL, pipe->ep.bmAttributes, pipe->ep.wMaxPacketSize); continue; } else if (HAL_HCD_HC_GetState(&stm32_hhcd_fs, pipe->pipe_index) == HC_STALL) { RT_DEBUG_LOG(RT_DEBUG_USB, ("stall\n")); pipe->status = UPIPE_STATUS_STALL; if (pipe->callback != RT_NULL) { pipe->callback(pipe); } connect_status = RT_FALSE;//wxm return -1; } else if (HAL_HCD_HC_GetState(&stm32_hhcd_fs, pipe->pipe_index) == URB_ERROR) { RT_DEBUG_LOG(RT_DEBUG_USB, ("error\n")); pipe->status = UPIPE_STATUS_ERROR; if (pipe->callback != RT_NULL) { pipe->callback(pipe); } connect_status = RT_FALSE;//wxm return -1; } else if(URB_DONE == HAL_HCD_HC_GetURBState(&stm32_hhcd_fs, pipe->pipe_index)) { RT_DEBUG_LOG(RT_DEBUG_USB, ("ok\n")); pipe->status = UPIPE_STATUS_OK; if (pipe->callback != RT_NULL) { pipe->callback(pipe); } size_t size = HAL_HCD_HC_GetXferCount(&stm32_hhcd_fs, pipe->pipe_index); if (pipe->ep.bEndpointAddress & 0x80) { return size; } else if (pipe->ep.bEndpointAddress & 0x00) { return size; } return nbytes; } continue; } } ``` 5.可否出个例程,同时挂载U盘和Flash,通过U盘和OTA实现固件升级啊? 根据文章: https://blog.csdn.net/ShenZhen_zixian/article/details/121101799 出现如下问题 ```c static int ota_usb_download_entry(void* parameter) { DIR *dirp; static size_t update_file_total_size, update_file_cur_size; static const struct fal_partition * dl_part = RT_NULL; static int fd; //static rt_uint8_t buf[1024]; .... ``` 打印如下: ``` msh /udisk>ota_usb_start msh /udisk> msh /udisk> msh /udisk> msh /udisk>Default save firmware on download partition. Warning: usb has started! This operator will not recovery. [0m[D/ota_usb] /udisk/rt-thread.rbl file size is : 254528 [0m [32m[I/ota_usb] --wxm-- Firmware ok! File size (254528), 'download' partition size (524288)[0m [32m[I/ota_usb] ---wxm--- Firmware download! Partition (download) erase![0m CBW size error usb mass_storage read failed [31;22m[E/FAL] (fal_partition_write:423) Partition write error! Partition address out of bound.[0m [31m[E/ota_usb] Firmware download failed! Partition (download) write data error![0m [31m[E/ota_usb] download rtthread.rbl file failed[0m ``` 6.再补充个测试的问题,如上u盘格式是FAT32,接下来用电脑右键将U盘格式化为NTFS,同样用Readwrite进行测试,可以成功,ls能看到文件test_usbh.c,但是插电脑上看不见。 ``` msh />readwrite write data come 1 write data come 2 write data come 3 write data come 3.5 write data come 4 write data come 5 write data come 6 usb host read/write udisk successful msh />ls Directory /: udisk
test
msh /> msh />cd udisk msh /udisk>ls Directory /udisk: test_usbh.c 120 ``` 7.往回测试,发现问题应该还是出在读写U盘上,目前无论用4.0.X还是最新版本,用readwrite测试都会挂住,用的F407的开发板。
查看更多
0
个回答
默认排序
按发布时间排序
暂无答案,快来添加答案吧
撰写答案
登录
注册新账号
关注者
0
被浏览
1.2k
关于作者
xmwang025
这家伙很懒,什么也没写!
提问
5
回答
5
被采纳
0
关注TA
发私信
相关问题
1
Linux下通过USBTinyISP为Arduino开发板烧?写Bootloader
2
请教修改NVIC后RTT调度函数失效的问题[已解决 bootloader中打开了不必要的中断]
3
进入bootloader的方式探讨
4
求助:IAP里的APP使用的RTT,跳转后出错。[已解决]
5
有没有人在STM32F103上用UART IAP跑过RT-Thread?
6
想做网口的IAP远程升级,不知可不可行
7
IAP问题
8
[已解决]请教基于RTT的IAP程序切换到应用程序不成功的问题(基于STM32F4)?
9
stm32f4xx-----IAP移植APP程序需要注意的地方
10
在调试IAP网络升级遇到跳转之后bootloader程序网络不通
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【RT-Thread】【ci】【scons】将ci.attachconfig.yml和scons结合使用
2
Rt-thread中OTA下载后,bootloader不搬程序
3
ulog 日志 LOG_HEX 输出时间改为本地日期时间
4
在RT-Thread Studio中构建前执行python命令
5
研究一了一段时间RTT,直接标准版上手太难,想用nano,但又舍不得组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
cubemx
PWM
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
xusiwei1236
8
个答案
2
次被采纳
踩姑娘的小蘑菇
1
个答案
2
次被采纳
用户名由3_15位
9
个答案
1
次被采纳
bernard
4
个答案
1
次被采纳
RTT_逍遥
3
个答案
1
次被采纳
本月文章贡献
聚散无由
2
篇文章
15
次点赞
catcatbing
2
篇文章
5
次点赞
Wade
2
篇文章
4
次点赞
Ghost_Girls
1
篇文章
7
次点赞
xiaorui
1
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部