stm32f103c usb spi flash mass storage

Post here first, or if you can't find a relevant section!
Post Reply
eldiamond
Posts: 1
Joined: Fri Nov 13, 2020 12:33 pm

stm32f103c usb spi flash mass storage

Post by eldiamond »

Hello, everyone!
I'm newbie in STM32, but it much prefer than anyone in Atmel family!
I want to make custom device which will collect sensor data and save it to 25QH32 chip via SPI. This part is implemented ;)
Next part is much interesting) I need to give all collected data to user. STM32F103C have USB interface on-boar, so the best solution i see, is mass storage device)
Internet says that there is the way to make it all thru HAL, but i'm not sure how exactly do this
So there is the question, how i can make it? Is there any libraries? How make all routines by interrupts?
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: stm32f103c usb spi flash mass storage

Post by mrburnette »

New users are asked to read:
viewtopic.php?f=2&t=301
eldiamond wrote: Mon Nov 16, 2020 9:12 am ...
I need to give all collected data to user. STM32F103C have USB interface on-boar, so the best solution i see, is mass storage device)
...
A good read:
http://www.emcu.it/STM32/STM32_USB_Devi ... t_OTG.html

Moving to a uC with USB Host as discussed in the article is recommended. OR, give your customer SD cards since you can use one of several SD-Card libraries to write using an SD-FAT file system.
[url]https://stm32duinoforum.com/forum/ ... _4443.html[/url]
alexweefs
Posts: 1
Joined: Tue Jul 13, 2021 4:06 pm

Re: stm32f103c usb spi flash mass storage

Post by alexweefs »

Recently, I was tinkering with connecting my device to the STM32F103 microcontroller as a USB Mass Storage Device , or in Russian as a USB flash drive. Everything seems to be relatively simple: in the graphical configurator STM32CubeMX, a couple of clicks generated the code, added the SD card driver, and voila - everything works. Only very slowly - 200 kB / s despite the fact that the bandwidth of the USB bus in Full Speed ​​mode is much higher - 12 mB / s (roughly 1.2 MB / s). Moreover, the start time of my flash drive in the operating system is about 50 seconds, which is simply uncomfortable in work. Since I dived into this area, why not fix the transmission speed.

Actually, I already wrote my driver for the SD card(more precisely, the SPI driver), which worked through DMA and provided speeds of up to 500 kb / s. Unfortunately, in the context of USB, this driver did not work. The reason for this is the USB communication model itself - everything is done on interrupts, while my driver was tuned to work in a normal stream. Yes, and powdered primitives synchronization FreeRTOS.
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: stm32f103c usb spi flash mass storage

Post by ag123 »

i did some experiments with usb serial, even for that matter Serial.write(buffer, length); it is about 1-2 Mbps, this compares to what is seen for usb mass storage i'd think.
the main thing about usb is that it is *polled*, so the host decides how to multiplex the devices and how much time slice to give to each device, and that each device is probably given a 1ms time slice each to 'speak'. getting about 1-2 Mbps reflects that there are about between several to a dozen devices on the bus. you could count your keyboard, mouse, hubs (including internal hubs) as devices. it isn't very efficient as many of that 1ms that is 'unused' would be 'wasted', say the keyboard / mouse send a couple of interrupts in its 1ms time slice. it is pretty much 'time sharing'.
i think it is possible to monitor statistics even from stm32 end by keeping counts, e.g. say in its own 1ms timeslice how much data is sent.
if it is about 1 KB for that 1ms timeslice, the usb bandwidth allocated is probably already fully utilized. 12 Mbps / 1000 ms ~ 1.2KB per 1ms slice. and you have not added the framing overheads

on some skus supporting usb high speed, it is possible to go usb high speed (480 mbps?), but that requires a separate high speed transceiver, and some additional circuits. one of the trouble is that ulpi high speeds if often run at say 60 mhz delivering a (8 * 60) 480 mbps signalling speed. a trouble is i think with ordinary 'dupont' cables, that 60 mhz signals may be badly compromised, unless one take precautions with capacitance etc.
there are some of such boards floating around if one is keen to experiment.
https://www.aliexpress.com/wholesale?ca ... xt=usb3300
usb high speeds is quite attractive as some stm32 adc has sample speeds that could make use of it, streaming out in real time
Post Reply

Return to “General discussion”