News:

;) This forum is the property of Proton software developers

Main Menu

USB Mass Storage with PIC24/DsPic33

Started by Wimax, Jul 22, 2024, 06:04 PM

Previous topic - Next topic

Wimax

Hello everybody  ;)

Has anyone used Positron16 with PIC24 or DsPic33 equipped with USB OTG as USB Mass Storage devices?

Stephen Moss

You want to use a PIC as a flash drive (memory stick)?

Why would anyone bother going to that trouble when you can just buy a flash drive for a similar price as the PIC that...
  • You don't need to program
  • Would have more storage and
  • Would probably have faster data transfer

Wimax

Yes, there's no doubt, but actually the intent is slightly different, the MCU is part of a system and has access to an SD to store data. When needed, it should be able to interface with the PC, perhaps directly via USB, acting as a sort of mass storage device and allowing the manipulation of files residing on the SD.

Wimax


Stephen Moss

Now people havea clearer idea of what you want to do I think you may be on you won with this one, if someone had an answer you would probably have recieved it by now.
Have you tried using the forum search facility, it is possible something simlar, like recieving data and placing it into an EPROM rather than a SD has been discussed that could give you an idea of how to go about it.

I think you will find that for most USB related projects the PIC will be configured as a HID slave device because it is the simplest option when it comes to USB, however, as I recall HID devices tend to be low speed devices and for file transerfer you would need to configure it as a high or full speed device. So if were to try to transfere a lot of data to HID device could mean that...
  • It may take a long time to transfer large amouns of data as I don't think Bulk transfers are allowed for HID devices.
  • The host may not allow file transfers to HID devices.
From what little I can remember of USB, configuring the PIC as a mass storage device may be better in your case as it allows for faster bulk transfers (assuming the PIC can keep up) but examples may be harder to find than for HID devices.

Wimax

Sometimes it is good to relaunch hoping for better luck  ;) .
Actually in my case SD was an almost forced choice for portability reasons and I always solved using a classic serial communication when needed.
Curiosity arose migrating the project to a higher class 16 bit MCU with usb otg inside. Before asking for info I searched the site, but I found only information about HID mode. On the net I found something on the Microchip site about mass storage device mode, but it refers to libraries and topics proper of a parallel world for me ;D, I think it's a hard battle to win.

Stephen Moss

Unfortunately USB is not an easy subject, I did get a book of from a member here called USB Complete by Jan Axelson.
I did not get to far into it as I don't have time to work on my project and feel a USB project is a subject I need time to work on consistently otherwise I may have to re-learn USB/why I was doing something a certain way all over again if I can only work on it occasionally.

However, from the first couple of chapters that I did read I though it was well written and explained things in a way that was blowing away some of the USB fog so it was starting to make some sense, it also has some sample code from the PC side of how to communicate with USB devices. So anyone wanting to work on a USB project may find it worth taking a look at and should be able to pick up used copies cheaply.   

Wimax

I had a suspicion that it wasn't really simple because I couldn't find anything in the forum other than the valuable input on the HID mode.

Thank you very much for the infos Stephen ;)

John Lawton

Have you looked on the Microchip forum, there seems to be some stuff there that might be translatable to Positron?

https://www.microchip.com/en-us/search?searchQuery=%20USB%20Mass%20Storage%20device&category=ALL&fq=start%3D0%26rows%3D10

John

JonW

#9
I am starting to work on USB for the 16F series as it's a subject I have not had too much experience with, and I would like to give it a go. I have Jan's book, but unfortunately, it's not a 5-minute read, and I am under no impression that it's going to be a considerable investment in time and hardware to get it running proficiently (the reason I'm starting on the 16F). 

HERE is a good site with some basic information.

My way of approaching this will be to avoid using existing USB stacks or compiler functions and try to create my procedures from the ground up; this way, it forces me to understand the specifics of the protocol and hardware, I did this for the WIZ chips for UDP/TCPIP using procedures in Positron rather that the provided bloated C routines. I also want to use the USB CDC comms and the Powered Device protocols to get higher voltages and power, plus comms, in some future projects and set a goal to construct a USB-based bootloader and CDC stack where I can use standard Windows VCPs on the PC side, finally ending up creating custom USB drivers. 

My development board is currently being manufactured. I opted to add a secondary USB port for debugging and repeating USB - USB-VCP, I will write a dual VCP port Gui to stress my firmware and transfers. I did consider going Microchip and even ST's USB stack in C, but that was even more work for me.

On the hardware side, I spent some time looking at bespoke, hardware USB analysers and was tempted to buy the Beagle 12, I only want Low speed or High Speed as Full-Speed is a big jump up in hardware analysers and coding. I found that the Beagle 12's are tricky to obtain in the UK, at close to £500, I think there are better solutions for that amount of money.  After a bit of digging around, I ordered an open-source hardware analyser from Aliexpress based on Alex Tardov's work; these are cheap and are worth investigating.  In addition to Alex's hardware, I also settled on a Saleae Logic 8, which can decode low-speed and high-speed packets, signalling frames etc; it can also do ANY protocol analysis/decode, as you can write decoders for it, and this is something I need for some other projects so was a good fit.

One thing I have learned is that you have to be careful with hubs and newer PC ports, etc., as these can start or even repackage to full speed (depending on where you break out the USB D+/D-). I don't have the hardware to decode full-speed and I found this out trying to analyse a CP2102 through breakout boards with my logic 8, not seeing anything. To circumvent this issue, I found some 20-year-old USB 1.1 hubs on eBay for a few £, it seems this is the way to force the transfer to low or high speed if you have a device that is not forced to a specific speed from pull-ups.

Its early days for me as I have only been looking at it for a few days.  Once I have a basic stack running, I will share the progress.



EDIT:  If you don't want super speed, then a CP2102 or FTDI can run at pretty decent speeds and they have solid VCP drivers, not sure what the limitation of the DSPic UART is, but with DMA you may get a decent throughput and low code/time overhead.  Ah just re-read and you want USB OTG, what about the STOTG04ESQTR


Logic 8 Decode


logic8_usb decode.jpg


Wimax

Yes, I'm currently using an FTDI FT232 that works quite well even if I cannot expect exaggerated speeds. Considering the level of difficulty to be faced in case of switching to an USB-host mode I think I will switch in standby for quite a while and will follow very closely the evolution of your very interesting work.