CREATE A USB MASS STORAGE DEVICE USING AN STM32

For anyone wishing to receive additional help with a project or simply looking to hire an embedded contractor we have a few contacts who would be more then willing to help.

Moderators: Benj, Mods

Post Reply
Kisen
Posts: 66
Joined: Fri Jan 24, 2020 10:38 am
Contact:

CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by Kisen »

Hi,

I am in need of a USB mass storage device using STM32F042K6 and SPI Flash memory, the storage.

The function of the device is as follows.

Device is plugged into USB on a computer.
Device identifies as a MASS STORAGE DEVICE.
Files can be created by the device that the computer can read.
Files can be placed onto the drive that the device can read. A config file for example.

Is anyone capable of doing this?

Kisen
Posts: 66
Joined: Fri Jan 24, 2020 10:38 am
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by Kisen »

It would appear in flowcode, what i am looking for is a USB MSC component creating.

mnf
Valued Contributor
Valued Contributor
Posts: 853
Joined: Wed May 31, 2017 11:57 am
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by mnf »

https://www.keil.com/download/docs/362.asp
Not FC - but might be worth some study?

Kisen
Posts: 66
Joined: Fri Jan 24, 2020 10:38 am
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by Kisen »

Hi Martin

I downloaded this weeks ago. I still cannot understand it.
I dont even understand how I should use it. There doesn't appear to be any instructions.

FC I understand because it's got a logical flow and i can follow it. This is just something else.

Better to just pay someone else to provide me what I need at this point.

mnf
Valued Contributor
Valued Contributor
Posts: 853
Joined: Wed May 31, 2017 11:57 am
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by mnf »

Looking at the Kiel code - it would be possible to convert to FC, but it would be a lot of work....

My advice would be - do the USB code in C... (Or pay someone to do it in C?). It should be possible to handle the USB seperately - downloading updates etc (which can still be in FC...)
Plan B - use hardware that can treat usb as a virtual UART and transfer data for updates over that (using an 'updater' on PC)

Another area to look at is the microPython (http://micropython.org/) - which uses an ARM processor and can behave as a USB storage.. (Note that this is not quite analagous - python programs are interpreted so maybe don't get written to eeprom...)

As an aside - it would be a major plus if FC could incorporate C/C++ code more easily. It 'should' be possible (as FC is C under the hood) - it is certainly possible to include / call C libraries at present (for example avr/sleep.h) but mileage varies depending on the complexity of the library (number of dependencies etc) . Did you try 'adding' the C to your code using supplementary code?

Martin

Kisen
Posts: 66
Joined: Fri Jan 24, 2020 10:38 am
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by Kisen »

I would like to keep this in FC. I understand FC and the rest of the program i am working on is also written in FC.

There is no opportunity to change the hardware since the hardware is already developed.

I have never worked with the C block beyond adding 1 or 2 lines of C. A while back i recall creating a graphic font set in supplementary. Noting to this magnitude with multiple pages.

I havnt tried to add the code in supplementary yet, Im not sure what to add to be honest. Surely you dont just copy every page and just paste it there?
Thats a hell of a lot of code, with no real way to manage it.

Not just that but i seem to be really struggling to understand the USB at all.
With the likes of I2C and SPI i understand the protocol and how data gets from A to B. With this USB i cant seem to grasp the how the library functions.

I have an example where in the main all you do is init the USB. Then it just goes into a loop and the USB is all interrupt based. So what is getting called and what isnt is a mystery to me. From this particular example you can view files on the MSD and also put new ones on there. But it doesnt tell me where this magical data is being passed back and forth, so i cant use it. I expect its in a buffer somewhere in the C code.

What i want to be able to do is have my code look at a file that has been put onto the MSD. Say CONFIG.txt, read its contents and then use the data to update its own configuration.
Similarly, the data on the device needs to be given to the outside world. So the data stored in the memory in some raw format need to be compiled at some point into a file that is then visible on the MSD.

User avatar
Benj
Matrix Staff
Posts: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by Benj »

Hello,

We are investigating the problem for you. However what about this for an alternative.

Use something like a USB to Serial IC such as a FTDI or similar, then connect this to a UART on the STM32 device and then stream in your configuration using either a serial emulator which can be used to send files or maybe use Flowcode SCADA as a standalone app to take a file and transfer it to the micro? It's maybe not ideal but gets you out of a hole with currently working features.

Kisen
Posts: 66
Joined: Fri Jan 24, 2020 10:38 am
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by Kisen »

Hi Ben

There are a couple of issues with your suggestion.

The first one which is most important is that the specification for the device is that there be no drivers. It needs to communicate on any machine.

The second which is more inconvenient than anything, is that the hardware is designed. The only way to do what you suggest would be to develop a comms cable, which then brings us back to the first point.

Post Reply