Skip to main content
KSing.8
Associate
January 4, 2023
Question

How to store a file in pendrive as pdf in STM32 using Mass Storage Class and FATFS?

  • January 4, 2023
  • 18 replies
  • 5710 views

..

This topic has been closed for replies.

18 replies

KnarfB
Super User
January 4, 2023

Just copy the .pdf to your STM32 using Mass Storage Class and FATFS.

hth

KnarfB

KSing.8
KSing.8Author
Associate
January 4, 2023

The thing is with .pdf i am able to create a file but i am not able to open that file.

Tesla DeLorean
Guru
January 4, 2023

Check content in file manager or viewer. Check integrity and that it contains what your expect / wrote.

If you update on-the-fly generate a Media Changed Sense Code, so the PC Side OS will reread.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
GagandeepSingh.6
Associate II
January 4, 2023

Please fix the problem ​

GagandeepSingh.6
Associate II
January 4, 2023

Pdf file open in note++​

GagandeepSingh.6
Associate II
January 4, 2023

Without note++ , I m not able to open pdf file ​

Tesla DeLorean
Guru
January 4, 2023

Could it be that the PDF is not correctly constructed/written?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Ghofrane GSOURI
ST Technical Moderator
January 5, 2023

Hello @KSing.8​ 

To create a project using FatFs in STM32 with CubeMX, follow these steps:

  1. Start by launching CubeMX and creating a new project. Select the STM32 microcontroller that you want to use and configure the project settings as desired.
  2. In the Configuration tab, expand the Connectivity category and select the USB_OTG_FS node. Enable the USB Device mode and select the Mass Storage Class (MSC) option. This will allow the STM32 to act as a mass storage device, such as a USB drive.
  3. Expand the FatFs node and enable the FatFs option. This will add the FatFs library to your project and configure it for use with the STM32.
  4. In the Configuration tab, click the Generate Code button to generate the initial project code. This will create a basic project structure with the necessary files and libraries to use FatFs with the STM32.
  5. Next, you will need to configure the hardware connections for the USB and storage device. Connect the STM32 to the storage device (such as a USB drive) using the appropriate interface (such as USB or SDIO).
  6. In your project code, use the FatFs API functions to initialize the file system, mount the storage device, and perform file operations such as reading and writing files. For example, you can use the f_open function to open a file, the f_write function to write data to the file, and the f_close function to close the file when you are finished.
  7. You can then build and run the project to test the FatFs functionality. You should be able to access the storage device from your computer and read and write files as desired

Thx

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
KSing.8
KSing.8Author
Associate
January 6, 2023

Hi @Ghofrane GSOURI​ 

I have already followed the above mentioned steps but i am not able to create a PDF file using f_open command.

Thanks

Karanvir Singh

Ghofrane GSOURI
ST Technical Moderator
January 6, 2023

Hello @KSing.8 (Community Member)​ 

It's possible that the issue is with the file name or access mode that you are using with the f_open function. Make sure that you are specifying the correct file name, including the ".pdf" extension, and that you are using the correct access mode.

For example, to create a new PDF file with read-write access, you can use the following code:

FIL file;
FRESULT result;
 
result = f_open(&file, "myfile.pdf", FA_CREATE_ALWAYS | FA_WRITE);
 
if (result != FR_OK) {
 // an error occurred, check the error code (f_err)
}

Keep in mind that the FatFs library uses 8.3 file naming conventions, so the maximum length of the file name (excluding the extension) is 8 characters.

Thx

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Peter BENSCH
ST Technical Moderator
January 6, 2023

@KSing.8​ Before we continue to talk past each other, please explain what data you actually write in the file TEST.pdf?

As mentioned above, a PDF file does not contain text, but a binary structure that has been standardised as ISO32000. You had also written earlier:

Using FATS (file handling commands) of STM32 MCU

[...] f_open(&myFile, "TEST.pdf", [...]

.pdf get created in my connected pen drive

so that the file is obviously also created. You can also call this file TEST.exe or TEST.odf, but this does not make it an executable Windows program or an OpenDocument for e.g. LibreOffice.

If you want to create a real PDF, you must also write the appropriate data into the file.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
KSing.8
KSing.8Author
Associate
January 7, 2023

@Peter BENSCH​ "If you want to create a real PDF, you must also write the appropriate data into the file."

So i am looking for way to to convert my data lets say any string into data that further gets stored in pdf file and shows my string.Is there any possible way for this..

Thanks

Karanvir Singh

Piranha
Principal III
January 9, 2023

https://www.microchip.com/forums/m956973.aspx

Anyway, that is not a task for an absolute beginners...