cancel
Showing results for 
Search instead for 
Did you mean: 

USB FataFS and RTOS

Johanan1
Associate II
Posted on November 03, 2014 at 08:07

I need to sent a message to my main task, that tells it USB is connected. (so I can display a message on screen, and display file names etc.)

What events are generated? any documentation or sample code on this?

It does not seems right to poll the FatFS with f_mount()..

Thanks

9 REPLIES 9
Posted on November 03, 2014 at 09:34

Hi Johanan,

I don't really have enough insight into what specifically you are doing, and how. Can you tell us what STM32 are you using, and with any FW package ?

Regards,

Heisenberg.

Johanan1
Associate II
Posted on November 03, 2014 at 11:09

My system is STM32F429, the hardware has 8 MB SDRAM, 8 MB Nor flash, 800x480LCD., plus some ohter interface, SPI flash, USB host and microSD card.

Software is using FreeRTOS and emWin. the touch screen is driven by software with ADC and GPIO conversion .

I used CubeMX to generate the infrastructure code, and spent a lot of time getting it to work, it took a lot of effort to get things to work, at this point I have the LCD, touch screen, SDRAM, NOR flash working. The USB is also working and the USB memory is detected. (it is clear the CubMX needs a lot of work, I found at least 2 bugs, and I had no luck of any generated code working ''out of the box'', on the other hand, I have a lot of staff working, there is no way I could do it alone without the basic generated code)

Now I need to use the FatFS in a separate thread, but could not find any documentation on this. I can see that the USB driver send some osMessages, but have no idea how to use and interpret theses events.

To start , I need to have the FS thread to wait for an event, which will dispaly a short message like '' USB detected'' or similar, then I can start the FS with f_mount etc.

I hope tat this gives some more details.

Thanks for your help.

 

chen
Associate II
Posted on November 03, 2014 at 11:38

Hi

''Now I need to use the FatFS in a separate thread, but could not find any documentation on this.''

Having the disk in a separate thread May or May NOT be a good idea !

Usually, 'disk' is treated like any sharable resource and should be guarded (Mutex or semaphore) against multiple access.

It is possible to have it guarded by using it in a thread (in fact the system I am working on treats shared resources like this. However, it has caused many more problems than it has solved. Not my idea and I did advise against it!) What you must do now is treat all access to disk as a inter-task message. Your design now becomes a tasking/event driven system.

This is a system design decision.

''To start , I need to have the FS thread to wait for an event, which will dispaly a short message like '' USB detected'' or similar, then I can start the FS with f_mount etc.''

I think is is becoming apparent that there is not a clear understanding between the USB and FatFS.''

Firstly, it sounds like you are dealing with a USB host MSC implementation. This will generate a number of IRQs. These  should be handled by the code generated by STM32Cube.

FatFS sits on top of the USB host MSC implementation. It should be tied in to some of the USB IRQs eg device connect should be linked to FatFS mount device.

A successful (or un-successful) mount can then send an inter-task message to what ever task deals with displaying the message.

''I think is is becoming apparent that there is not a clear understanding between the USB and FatFS.''

It is apparent that there is a lack of understanding of 'Tasking' in a mult-tasking operating system.

It is apparent that there is a lack of understanding of separation of driver layer (USB) and services (disk format provided by FatFS) and tasking.

Johanan1
Associate II
Posted on November 03, 2014 at 12:08

Sung,

You are correct that I don't fully understand the FatFS <-> MSC relationships.

That is why I am looking for some proper documentation or help.

Seems to me that CubeMX code is working as I can set breakpoints at the USB and MSC and verify.

Johanan1
Associate II
Posted on November 03, 2014 at 12:17

BTW, the discovery board for STM32429 has a file browser demo to display jpg images, and I could not get this to show any file.

Anybody seen this demo (the image browser part, other parts like calender and game are OK) working?

chen
Associate II
Posted on November 03, 2014 at 12:39

Hi

''You are correct that I don't fully understand the FatFS <-> MSC relationships.

That is why I am looking for some proper documentation or help.''

This is a steep learning curve!

So the ST Cube (as far as I understand) took the original code from the USB OTG library and put it into a Java program that would generate the same code but with some name changes.

Have a look at he document UM1021 which is an overview of the USB UTG library.

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257882

You are only interrested in the USB Host part and in particular the 'Host' 'Mass Storage Class' implementation in the library.

Now, the ST examples have already integrated FatFS with the USB MSC (after all who want to work with the raw sectors in a USB stick or memory card).

If you look at the code in the library and the documentation, it should tell you which functions need to be integrated for 'disk access' and this should already be integrated with FatFS in the example.

When you have got your head around this, this is only has the STM32 can access USB memory stick.

Next, you will have to get your head around Multi-tasking and inter-task messages.

Johanan1
Associate II
Posted on November 03, 2014 at 12:51

Hi,

would you be so kind and send me your email to:

tmp0@technocon-eng.com

(this is a temporary mail and will be removed later)

Thanks.

chen
Associate II
Posted on November 03, 2014 at 15:07

''would you be so kind and send me your email to:''

No thank you.

chen
Associate II
Posted on November 03, 2014 at 17:15

BTW have you read this

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/DM00105259.pdf

?

It looks like it comes at it from the other side - FatFS

ie. what functions FatFS needs integrating with