2020-05-11 07:43 AM
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!
Solved! Go to Solution.
2020-05-14 09:33 AM
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.
2020-05-11 05:12 PM
Start looking at examples. Plenty of them out there.
Will probably need a storage device onboard unless you plan to store the files in RAM.
2020-05-14 07:38 AM
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?
2020-05-14 09:33 AM
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.
2020-05-14 10:57 AM
Here is an example of fatfs with USB:
2020-05-14 12:24 PM
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..
2020-05-26 07:11 PM
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