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: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
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: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
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: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
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: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
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: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
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: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
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: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
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.

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by Kisen »

Hi Ben,

Are you able to share any progress on the MSD or how to add the C files in order to create an MSD?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by LeighM »

Hi,
I started working on a methodology of getting external C libraries into the ST ARM build but other priorities took over. I will try and get back to it over the next few days and see if I can come up with a workable solution.
Leigh

Kisen
Posts: 73
Joined: Fri Jan 24, 2020 10:38 am
Has thanked: 4 times
Been thanked: 2 times
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by Kisen »

Thanks very much Leigh, much appreciated.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by LeighM »

I’ve hopefully now got something that might help.
The attached updated batch file needs to be copied into directory:
C:\Program Files (x86)\Flowcode\Common\Compilers\starm\batch

Copy any additional code, such as STM32CubeMX generated code, into your Flowcode project directory.
When using STM32CubeMX, choose to create a Makefile project.
Example
project_directory.png
project_directory.png (6.44 KiB) Viewed 14778 times

Create a file “include.txt” that contains the list of header directories, these can be copied from the Makefile
Example

Code: Select all

-IInc 
-IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc 
-IMiddlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc 
Create a file “source.txt” that contains the list of source files, these can be copied from the Makefile
Example (The backslash \ can be copied across, or omitted)

Code: Select all

Src/usb_device.c \
Src/usbd_conf.c \
Src/usbd_desc.c \
Src/usbd_storage_if.c \
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \
Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c \
Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c \
Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c \
Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c
These will now be included into the Flowcode build process.
Any functions to be used from these external files can be called from within a C icon in Flowcode.
This might also require a forward declaration of the function by including the relevant header file into the Flowcode “Supplementary Code” dialog.
Attachments
stm32comp.bat
(5.17 KiB) Downloaded 333 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: CREATE A USB MASS STORAGE DEVICE USING AN STM32

Post by QMESAR »

Hi leigh,

This is nice and a big step in the right direction.
Could this be done also for code generated by MPLAX Code configurator (H and C files) not HARMONY for PIC32 ,the Code configurator generate code for P16/18 dsPIC's and some PIC32 this is the one which will be good if we can use it in FC

Have nice Time

Post Reply