To create a project using FatFs in STM32 with CubeMX, follow these steps:
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.
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.
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.
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.
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).
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.
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.
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.
@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.
@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..