STM32 USB MSC Device using RAM/SD CARD

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ย. 2024

ความคิดเห็น • 86

  • @Audionaut90
    @Audionaut90 3 ปีที่แล้ว +1

    I've worked on SD-Card support for days now and your video finally helped me out. Thank you so much! Sent you a few coins for that ;)

  • @salmonhust
    @salmonhust 4 วันที่ผ่านมา +1

    How to auto format USB MSC Device using RAM ? Please help me 🙏🙏🙏

  • @hosseinhamidi4776
    @hosseinhamidi4776 4 ปีที่แล้ว

    Excellent video and exact to the point. Worked for me on stm32f4 discovery. Thank you!

  • @electronscape
    @electronscape 3 ปีที่แล้ว

    ok these kinda videos... INVALUABLE!!! THANK YOU!!

  • @woldecosgrove
    @woldecosgrove 2 หลายเดือนก่อน

    Hello... i try your code (RAM) on H743 Nucleo (the only board with USB OTG FS) i cant see USB Drive at all, Device Manager error : Unknown USB device (Device descriptor Request fail ) please help ....

  • @cocoobi
    @cocoobi 7 หลายเดือนก่อน

    Hi,
    I'm facing the same problem as some of the others. I did exactly the same steps as in this tutorial, but at the point where I have to format the device, an error is shown, which say's "Unable to format device".
    Does anyone found a solution for this problem?

  • @noweare1
    @noweare1 4 ปีที่แล้ว +1

    Thanks for your work on making this video.

  • @tarcisiosouzademelo8857
    @tarcisiosouzademelo8857 3 ปีที่แล้ว +3

    I'm having a problem, the computer recognizes, requests formatting but can't complete the formatting

    • @BJH-fm1pf
      @BJH-fm1pf 2 ปีที่แล้ว

      Hi, I have the same issue. Did you figure out the solution? Thanks.

    • @cocoobi
      @cocoobi 7 หลายเดือนก่อน

      Having the same problem.. did you found a solution? @ControllersTech

  • @Nachodis
    @Nachodis 2 ปีที่แล้ว

    Why does the SDIO clock need to run at same speed as the USB speed (12 MHz)? I would expect that SDIO and USB can work independently, and the read() and write() functions just pass data from one to the other?

  • @paulopecegueiro1694
    @paulopecegueiro1694 3 ปีที่แล้ว +1

    Hi, is this method work if I use a spi flash memory instead of uSD card? I was thinking about W25Q128JV 🤔

  • @cocoobi
    @cocoobi 7 หลายเดือนก่อน

    Hi, Like others I'm also facing the problem that I can not format the device on the host. Tried al possible configuration and size option.. dindnt help. Do you have an Idea? I also ask in the ST Community for help but nothing so far..

  • @CaliBeta
    @CaliBeta 2 ปีที่แล้ว +1

    hello I am trying part 1 and using 8KB of SRAM of my stm32f103c8 as mass storage, the problem is that when I connect the USB drive to the computer it asks me to format it, but when I start it it gives me a message saying that the drive could not be formatted.
    I use windows 10 and the USB is connected externally with 3 resistors on a breadboard, a 22 ohm resistor in series from USB D- to PA11(USBDM), for PA12(USBDP) the connection is slightly different, I have two resistors, one of 4.7kohms as pull up from USB (5V) to PA12(USBDP) and the other 22ohms resistor from USB D+ of USB connector to PA11 (USBDP)

    • @paulnewf6164
      @paulnewf6164 ปีที่แล้ว

      Maybe your disk size was too small? Mine failed same on 32*512bytes, but worked with 80*512bytes.

    • @cocoobi
      @cocoobi 7 หลายเดือนก่อน

      Having the sam problem.. have you found a solution? The size increase did not help..

  • @woldecosgrove
    @woldecosgrove 3 หลายเดือนก่อน

    Hello... you mentioned in the first part using RAM , connect the USB. what USB is that? is it the external thumb drive? where to connect ? to the nucleo bd USB port? or PC USB port ?

    • @ControllersTech
      @ControllersTech  3 หลายเดือนก่อน

      It is usb cable. Connect it between the dev board and computer. If you are using nucleo or discovery board, keep in mind that the user USB is a separate port than the ST Link USB. Any USB operation can be performed on the user USB port, and not on the ST Link USB port.

    • @woldecosgrove
      @woldecosgrove 3 หลายเดือนก่อน

      @@ControllersTech ok i got you, thx ..

  • @a1nelson
    @a1nelson 4 ปีที่แล้ว +1

    Not sure, but it appears that the writes are not being made with the block size that is native to the flash device. This is commonly 32K, but could be a little smaller or larger. (By comparison, hard drives are typically 512 bytes and SSDs are 4K.) Ona flash device , a single byte, or even a single bit, change requires that the entire block be rewritten. Therefore, small writes - for instance 512 bytes at a time - will result in the same block being written 32K / 512 = 64 writes to each block. Thus, writes are 64 times slower and the flash device wears out 64 times faster. It’s something to check.

    • @Nachodis
      @Nachodis 2 ปีที่แล้ว +1

      I would assume that this info (block size and number of blocks) is passed through via the STORAGE_GetCapacity_FS() function which retrieves it from the SD card via HAL_SD_GetCardInfo().
      If that information is correctly used, it might all end up fine.
      On the other hand, reading/writing a 32k block would probably require a RAM memory buffer of the same size, not sure if this is the case (I would need to check where the "uint8_t *buf" memory is created and if it's RAM or e.g. peripheral memory).

    • @a1nelson
      @a1nelson 2 ปีที่แล้ว +1

      @@Nachodis Edit: wanted to clarify the the following comments refer to the possibility that the OS manages the buffering itself. If the user manages the buffers, then they are free to make good decisions about available memory and it’s usage. Your comment was a very good one.
      If the file system (in memory) permits writes less than the full block size (e.g., 32K), that implies at least a minimum amount of write caching. Thus, (a) the write from user land isn’t guaranteed to be physically written to the target media. At least one buffer must be maintained, and unless writes are perfectly aligned with those block boundaries, then the write time will become even less deterministic. Whether or not this is an issue is naturally application dependent.
      (b) Although this behavior isn’t as well known, read cycles also put wear on flash decides. So, it follows that there may be a similarly sized read cache as well. Taken together, 1K-128K (recall that this size can vary quite a bit from device to device, from 512 bytes to 64K) could be required, on top of other file system structures in RAM. It seems unlikely that these large buffers would be baked into the code by default. Perhaps there are caching modes that can be enabled/disabled using preprocessor switches, in the same manner as other OS features.
      (c) The caching mechanism absolutely requires that there be some mechanism to reliably flush the write cache. On an embedded device, which may be expected to be powered down at arbitrary points in time, this could become a serious issue. LittleFS, though obviously not as portable as FAT, does take into account this idiosyncrasy.

    • @Nachodis
      @Nachodis 2 ปีที่แล้ว +1

      @@a1nelson Yes, insightful comment.
      Actually, I just got everything to work after reducing the SDMMC speed. This video does not properly explain why that's necessary, but it is necessary since the MCU might be too slow to take in the fast data from the SDMMC peripheral, which causes errors on the interface.
      With respect to block sizes, I think we need to distinguish the FATFS allocation unit size and the flash block size. I have an 8GB SD card which is reported in the code to have block_size 512 and block_num 15523840 (in total 7.948.206.080 bytes). The flash memory works in blocks of 512 bytes. The fatFS filesystem on top of it however, works in sectors of 32 kB. This means that, if a FS data sector is allocated for a new file, 64 blocks of 512 bytes might actually need to be allocated (not verified though). The FatFS is defined in sectors of 32 kB but handles the SD card in blocks of 512 byte.

  • @Unique_Think
    @Unique_Think 2 ปีที่แล้ว

    STM32F4 USB (MSC) connect pendrive + SDIO SD_Card not working on same time ?

  • @EmbSysDev
    @EmbSysDev 4 ปีที่แล้ว

    Nice videos, keep them coming !! Can you do something about the robot voice though :-)

    • @gtcollection6933
      @gtcollection6933 4 ปีที่แล้ว +4

      The author's written English is clearly to perfection. His spoken language may not be to par with the voice-over or he could simply a have disability. Quality of the content is what matters.

  • @ucontrolchannel5967
    @ucontrolchannel5967 4 ปีที่แล้ว

    @Controllers Tech again great job. Thank you soooo much. Can you also make a video on USB mass storage class as a host

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว

      I want to but don't have the otg cable..

  • @bluewaveengineering8734
    @bluewaveengineering8734 2 ปีที่แล้ว +1

    If you could provide an example like this using a composite USB with CDC + MSC (using the SD Card) that would be amazing!

    • @ControllersTech
      @ControllersTech  2 ปีที่แล้ว

      I guess you can't use 2 modes at the same time. The peripheral needs to be initialised in a particular mode. If you want to change from MSC to CDC, you need to reinitialise it in CDC mode

    • @lukeh7638
      @lukeh7638 2 ปีที่แล้ว

      @@ControllersTech You have to use the new Composite Mode that Sasha with STM is developing... or use tinyUSB. I just haven't seen anyone get either working on a full project.

  • @conorstewart2214
    @conorstewart2214 2 ปีที่แล้ว

    Does the SD card speed really need to be the same as the USB speed. It seems like it takes a buffer and then writes it to the SD card, couldnt you get a faster write speed by having the SD card speed faster?

  • @m.nauman7801
    @m.nauman7801 4 ปีที่แล้ว

    Awesome videos regarding stm32 boards. Would you make series on TI TM4C boards also?

  • @taozhai3568
    @taozhai3568 4 ปีที่แล้ว +1

    Thanks!! Can you make another video to use DMA to speed up the transfer rate, please!

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว

      I will test it. I am not sure though. But i think the speed can be increased somehow

    • @taozhai3568
      @taozhai3568 4 ปีที่แล้ว

      @@ControllersTech find a problem that , i can format card by using 'SD Card Formatter 5.0.1' from TUXERA, but cannot do format directly from windows disk format.

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว

      no problem here. I can format it with windows too

  • @felixr.1821
    @felixr.1821 3 ปีที่แล้ว +1

    @Controllers Tech Thanks for your great videos! But could you please do the same tutorial with the SD Card connected via SPI ? I can read and write from my microSD Card using SPI, but I also need to implement the USB MSC Device like in this Video. I can´t get the STORAGE_Read_FS/STORAGE_Write_FS functions in the usbd_storage_if.c file to work. If I connect my custom Board to the PC, Windows always wants me to format the disk. I´m getting the correct capacity of the SD Card in the format device window tho, so my STORAGE_GetCapacity_FS function seems to work. I already searched and tried many hours but i just cant get this to work. Would be really happy if you could help me out with this.

    • @mousseEV
      @mousseEV 3 ปีที่แล้ว

      Hi ! I have exactly the same problem on an F373CC ... I will come back to you if I find a solution or a tutorial that will unlock us!
      For STORAGE_GetCapacity_FS, did you change the constants by hand or did you find a function that did the job?

    • @Nachodis
      @Nachodis 2 ปีที่แล้ว +1

      What kind of SD card are you using? I am using SDHC and I'm wondering if the initialization code is correct. E.g. it initializes block size to hardcoded 512, I'm wondering if that's always correct.

  • @DanRalley
    @DanRalley 2 ปีที่แล้ว

    Can the RAM version of mass storage persist after power cycling? If so, how is the RAM retained?

    • @paulnewf6164
      @paulnewf6164 ปีที่แล้ว +1

      a) Not without battery backup (Some STM32 appear to have RAM blocks that can have battery backup, similar to the internal RTC)
      b) If power cycle then RAMDisk will need to be reformatted (i.e. write a routine to init RAMDisk on bootup)
      c) I believe the RAMDisk is just to show the minimum code to make this work, as any FLASH disk requires much more code, and possibly some flow control.
      Paul

  • @beyondintech
    @beyondintech 9 หลายเดือนก่อน

    @controllerstech
    I am using Mass storage with STM32F401 it gets the drive but if i copy anything into it using MSC after power cycle it dissappears , Can you suggest something

    • @ControllersTech
      @ControllersTech  9 หลายเดือนก่อน

      There is nothing to suggest here. That's how the ram works. Ram was used here just to demonstrate that it can work with anything, you should better use some external flash or eeprom for it.

    • @beyondintech
      @beyondintech 9 หลายเดือนก่อน

      i am using SD card , I did resolve the issue by doing 1B wide bus in the code but it would be great if you can suggest to do it with 4 because with 4 it doesnt work @@ControllersTech

  • @roniolivi
    @roniolivi 3 ปีที่แล้ว

    I'm trying do the second part (whit SD Card) in an STM32F411 and MX_SDIO_SD_Init return HAL_ERROR

  • @MrBorsoft
    @MrBorsoft 4 ปีที่แล้ว

    Hi! Thanks for the tutorial! Is this mass storage mode can be also used with SD card connected over SPI? Or SDIO only?

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว +1

      It only works with SDIO for now.

    • @ozcansorgun8597
      @ozcansorgun8597 3 ปีที่แล้ว +1

      @@ControllersTech Can you do the same with the SD card connected via SPI?

  • @ElectroCreativity
    @ElectroCreativity 4 ปีที่แล้ว

    Thanks for such videos.
    Is there any tutorial made by you for reading a text file in Pendrive connected to STM32 using OTG. If not, can you please make tutorial for that.

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว

      You mean the MSC as a host. I will do that soon.

    • @ElectroCreativity
      @ElectroCreativity 4 ปีที่แล้ว

      @@ControllersTech thanks in advance

  • @kiranpradeep6464
    @kiranpradeep6464 3 ปีที่แล้ว

    Even after changint the inquiry array the name of the drive is not changing in file explorer

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      Try uninstalling the previous driver from windows first.
      Then connect it again

  • @muratt44
    @muratt44 11 หลายเดือนก่อน

    I want to save files to Flash and not to RAM, how can I do this?

    • @alaa-eddinerabie4581
      @alaa-eddinerabie4581 14 วันที่ผ่านมา

      u can't, it's a ROM type of memory, read only memory ,so u can't write to it

  • @vipulshinde621
    @vipulshinde621 ปีที่แล้ว

    Will It work same for SDMMC ?

  • @alexanderwolf9653
    @alexanderwolf9653 ปีที่แล้ว

    you made my day

  • @xDR1TeK
    @xDR1TeK 4 ปีที่แล้ว

    Great video as always. I hate to ask an irrelevant question. For the stm32F103c8 using USB as virtual Com port. However everytime I'm uploading the firmware I have to pull out the USB cable and plug back again so that windows re-enumerate the Com port device. I don't want to ruin the USB recepticle, any solution for this? Looked everywhere.

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว +2

      I don't think that it can be done without removing the USB.

    • @xDR1TeK
      @xDR1TeK 4 ปีที่แล้ว

      @@ControllersTech Thank you.

  • @eduardodelarosaferrer2205
    @eduardodelarosaferrer2205 4 ปีที่แล้ว +1

    Amazing !

  • @tuloca011
    @tuloca011 4 ปีที่แล้ว +1

    Love you

  • @nutukidapoet6849
    @nutukidapoet6849 3 ปีที่แล้ว

    undefined reference to `hsd'
    USB_DEVICE/App/usbd_storage_if.o: In function `STORAGE_Read_FS':
    i have this problem, im using stm32f746ng

    • @charlesdecellieres6294
      @charlesdecellieres6294 3 ปีที่แล้ว +1

      Add this between those two flags in "usbd_storage_if.c" :)
      /* USER CODE BEGIN PRIVATE_TYPES */
      extern SD_HandleTypeDef hsd;
      /* USER CODE END PRIVATE_TYPES */

  • @aaaaa-ct1vn
    @aaaaa-ct1vn ปีที่แล้ว

    这个模拟u盘的原理是什么

  • @kadimkisi2918
    @kadimkisi2918 4 ปีที่แล้ว

    Hi! Thanks for videos..Can you make SD CARD VIEWER (file maneger and media player) on TFT(st7789 or ili9341) for next tutorial.Because a lot of example are for Arduino there is nomore for stm32(KEİL,IAR,CUBEIDE).İf you make this Project ,you will help people like me

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว +1

      Okk. It's in my todo list for a while. First need to make that st7735 display to work somehow.
      Will definitely work on this

    • @kadimkisi2918
      @kadimkisi2918 4 ปีที่แล้ว

      Thank you..I m waiting impatiently..I wish you continued success.

  • @jarrettmosco9624
    @jarrettmosco9624 10 หลายเดือนก่อน

    Your views would be 100x if you used your real voice

  • @ayoubkouch56
    @ayoubkouch56 3 ปีที่แล้ว

    stm32 + external flash memory + usb msd +fatfs .no one on this planet can do it.

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      What is external flash here for ?

    • @ayoubkouch56
      @ayoubkouch56 3 ปีที่แล้ว

      @@ControllersTech w25qxx for datalogging

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      Okay. And what's usb for then ?

    • @ayoubkouch56
      @ayoubkouch56 3 ปีที่แล้ว

      @@ControllersTech to get the txt file from the flash as usb mass storage

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      You know w25qxx is a SPI based flas memory right. How do you plan to use it with usb protocol ?