cancel
Showing results for 
Search instead for 
Did you mean: 

Without using SD card how to access the .txt or csv file?

MDeva.1
Associate II

Hello,

I am working on Nucleo-H745ziq board. I have to read the .txt and .csv file, but on this board there is no SD card implementation, so how I read the .txt file. I tried to read the file using below programmed but unable to read please help me.

num;

FILE *fptr;

if ((fptr = fopen("C:\\program.txt","r")) == NULL){

printf("Error! opening file");

// Program exits if the file pointer returns NULL.

exit(1);

}

fscanf(fptr,"%d", &num);

printf("Value of n=%d", num);

fclose(fptr);

6 REPLIES 6
TDK
Guru

Your mcu isn't going to be able to read files from your computer. You will need to place those within the mcu's memory, or establish some other form of communication between the PC and the chip, perhaps through a USB to UART adapter with the appropriate PC-side software.

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

Can you elaborate this how i can done it, there is some example for that how to do this. Because I tried to search information but I didn't find much help-full information.

Paul1
Lead

I suspect you need to plug in a USB Stick (Flash drive/Thumb drive),

you might need an adapter cable to plug the Stick into the small USB jack.

Look for tutorials/examples for other Nucleo boards that show using USB Stick.

Products with SD-Card need licence from the governing association, while USB doesn't.

If you are putting a USB tick on a product for long term use consider a "locking" socket so it won't vibrate out.

Paul

There is some example for that can you share it. I am new in embedded field so I doesn't have much experience in it.

Dump files content to an uint8_t byte array to a .H or .C file you can include/add to your project.

Any prior C or general CS​ experience/training you can leverage?

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

Tesla's idea to put all the data in text arrays will give simplest hardware and software, likely your most cost effective solution.

If you truly need to read files that aren't available at compile time, then a USB or SD filesystem may be your solution.

Refer to resources listed below to learn those.

For USB look at "USB Host" and "USB OTG" = "On The Go".

Resources: Personally I like MOOC best, but have used all of these to get started with STM32 ARM:

USB Host (Files): https://www.st.com/content/st_com/en/support/learning/stm32-education/stm32-moocs/STM32-USB-training.html

Older examples in here often don't use STM32CubeMX/STM32CubeIDE.

If you truly need USB filesystem, then I might have a experimental USB Host FileIO project I can dig out, from back when we started using STM32H743 which is same family as your STM32H745, and I believe pin & code compatible if you only use resources that exist in both ICs.

Paul