cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L412KB <-> USB <-> A log as Filesystem in PC

Anonymous
Associate II

I want to connect a USB to STM32L412KB externally. Next, I would connect that USB to my computer. I want it to show up as a filesystem which displays a log data from MCU. How should I proceed? Any tips? Also, I have never worked on filesystems. Can anyone share a good source where I could start looking for filesystems? Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions

The data would be stored in the medium enabled by the DISKIO layer.

If that is using a MicroSD card, the MESSAGE.TXT would need to already exist on the root directory of the card.

For the USB MSC to access that same data the Read/Write routines for that would need to be the equivalent to those used by FatFs's DISKIO

For it to use the internal flash, you'd need to create a file system image that gets written into the flash. As a binary image you could use STM32 Cube Programmer to write it to a specific address within the L412's address space. The MSC READ IO routines would then need to fetch that data as blocks from the flash.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

6 REPLIES 6
TDK
Guru

Start looking at examples. Plenty of them out there.

https://github.com/STMicroelectronics/STM32CubeL4/tree/fd2610d0f313d46c8e9ef33e10dcbd2b1dd7fdff/Projects/32L4P5GDISCOVERY/Applications/USB_Device/MSC_Standalone

Will probably need a storage device onboard unless you plan to store the files in RAM.

If you feel a post has answered your question, please click "Accept as Solution".
Anonymous
Associate II

Yes I've started looking into the examples but, there are no examples for using the USB. They're all related to storing it in the SD card. Actually today I tried connecting USB to my Eval board and it did show up as a USB device when I connected it to a computer. My target is to make a .text file (more like a log) which shows up in that USB connection which I made.

Also, I do plan to store it in the RAM for now at least. I took an example code from http://elm-chan.org/fsw/ff/doc/open.html. It is as follows:

/* Read a text file and display it */

FATFS FatFs; /* Work area (filesystem object) for logical drive */

int main (void)

{

FIL fil; /* File object */

char line[100]; /* Line buffer */

FRESULT fr; /* FatFs return code */

/* Gives a work area to the default drive */

f_mount(&FatFs, "", 0);

/* Open a text file */

fr = f_open(&fil, "message.txt", FA_READ);

if (fr) return (int)fr;

/* Read every line and display it */

while (f_gets(line, sizeof line, &fil)) {

printf(line);

}

/* Close the file */

f_close(&fil);

return 0;

}

The problem is, I'm not able to locate the message.txt file. Where is it? Looking at the disassembly, it shows that it is in the Flash but, how can I access it? I want to make a flash file that first shows up in let's say the folder where my project source code is for example. Next step would be to try and get it to store in the USB. How should I proceed? Any ideas?

The data would be stored in the medium enabled by the DISKIO layer.

If that is using a MicroSD card, the MESSAGE.TXT would need to already exist on the root directory of the card.

For the USB MSC to access that same data the Read/Write routines for that would need to be the equivalent to those used by FatFs's DISKIO

For it to use the internal flash, you'd need to create a file system image that gets written into the flash. As a binary image you could use STM32 Cube Programmer to write it to a specific address within the L412's address space. The MSC READ IO routines would then need to fetch that data as blocks from the flash.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

The OP is using an L4, he wants to be an MSC, not attach one via a USB Flash Drive.

ie Instantiate a faux MSC drive from which to host locally captured data, if I read the tea leaves correctly..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Anonymous
Associate II

Thanks to everyone who replied! I was able to set a File System just using STM32CubeMX. It was fairly easy as compared to what I thought and I was able to make something like a Flash drive. I am now trying to write to flash using the Standard programming technique in the reference manual. I did everything what was mentioned but, I was not able to write to Flash. There's plenty of examples using built-in function from HAL but, I don't want to use them. I'd like to directly write using something like memset/memcpy. I'll start a new post for the same. Thank you once again especially, @Community member​ 

Link: https://community.st.com/s/question/0D53W0000081CcFSAU/talk-to-flash-in-stm32l412kb-without-using-hal-library