cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Writing to a Text File

Khaled Aljehani
Associate III
Posted on October 03, 2017 at 20:40

Hi,

I am trying to write data to a text. The code is shown below. I am using STM32L152D board with Keil V5.

When I exceute the code, nothing works at all.

#include <stdio.h>

main()

{

FILE *fp;

fp = fopen('/tmp/test.txt', 'w+');

fprintf(fp, 'This is testing for fprintf...\n');

fputs('This is testing for fputs...\n', fp);

fclose(fp);

}

So, how can I write to a text file? and also reading.

Best regards.

5 REPLIES 5
Posted on October 03, 2017 at 21:16

Have you implemented a file system, or have a block storage device you might expect this data to go into?

The EVAL board use FATFS and SPI/SDIO implementations for SD cards. There you'd use f_open() rather than fopen(), etc.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on October 03, 2017 at 21:19

The device is my PC not SD card.

Best regards.

Posted on October 03, 2017 at 21:58

I don't believe uVision provides the sort of Semi-Hosting you are expecting, you should discuss with Keil support.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on October 06, 2017 at 20:01

Hi

Turvey.Clive

Could you please give an example or functions list that I can use for file I/O on SD card?

Regarding Keil, is this the functions list?

https://www.keil.com/pack/doc/mw/FileSystem/html/fs_function_reference.html

Best regards.

Posted on October 06, 2017 at 21:51

I'm not using the Keil Middleware, you'll need to review the documentation they provide.

I used FATFS

http://elm-chan.org/fsw/ff/00index_e.html

 

http://www.st.com/content/ccc/resource/technical/document/user_manual/61/79/2b/96/c8/b4/48/19/DM00105259.pdf/files/DM00105259.pdf/jcr:content/translations/en.DM00105259.pdf

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