SD card logging for S32K144 using Simulink

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SD card logging for S32K144 using Simulink

Jump to solution
2,179 Views
soheil_fard
Contributor I

Hi,

I'd like to use Adafruit MicroSD Card Breakout Board on S32K144 to log some data. I use Simulink to program my NXP board. Is there any document or example showing how I can log data on SD card?

There is a tutorial for data logging using NXP Design Stuido here: FatFS with Adafruit MicroSD Breakout Board and NXP FRDM-KL25Z | MCU on Eclipse , but I'd like to do the same process using Simulink. 

Thanks

1 Solution
2,062 Views
mariuslucianand
NXP Employee
NXP Employee

Hello soheil.fard@litens.com‌,

Can you please explain a bit your scenario?

Do you want to get a shell exactly like in Eric's tutorial? Or do you want to slog different parameters at runtime on the SD Card?

Well, both ways in NXP's MBDT fro S32K we do not offer native support for the SD card. But, you can achieve this functionality by using custom code.

In order to write and read data on an SD card, you need to have a file system. For that, the tutorial presented is using the FATFS library. So to this in Simulink you have to do the following:

1. Use NXP SPI blocks to configure the SPI peripheral that will act as the physical layer for the SD Card.

2. Add all the files from the FATFS to your project and integrate them same way like in this tutorial here https://community.nxp.com/docs/DOC-345880 

3. for each read and write blocks basically you will use a Matlab function that will call the c code for the functionality you want to achieve.

Hope this helps,

Marius

View solution in original post

4 Replies
2,063 Views
mariuslucianand
NXP Employee
NXP Employee

Hello soheil.fard@litens.com‌,

Can you please explain a bit your scenario?

Do you want to get a shell exactly like in Eric's tutorial? Or do you want to slog different parameters at runtime on the SD Card?

Well, both ways in NXP's MBDT fro S32K we do not offer native support for the SD card. But, you can achieve this functionality by using custom code.

In order to write and read data on an SD card, you need to have a file system. For that, the tutorial presented is using the FATFS library. So to this in Simulink you have to do the following:

1. Use NXP SPI blocks to configure the SPI peripheral that will act as the physical layer for the SD Card.

2. Add all the files from the FATFS to your project and integrate them same way like in this tutorial here https://community.nxp.com/docs/DOC-345880 

3. for each read and write blocks basically you will use a Matlab function that will call the c code for the functionality you want to achieve.

Hope this helps,

Marius

2,062 Views
soheil_fard
Contributor I

mariuslucianandrei‌,

Thanks for your response.

All I want to do is to record some data on an SD card using S32k144EVB. 

I took the first two steps but when I generate the code from my model I get an error regarding the definition of a variable in the C-code. It looks like that the c-codes are not initialized in the model. I can't find the function in c-code to initialize it. Also, I am not sure if I have downloaded correct FATFS files.

The other question that I have is about step 3. How can I find the function that is used to log data on the SD card. After I call that function, is it used as a trigger for the SPI block? 

I have attached my model and associated c-codes and headers. I really appreciate if you could take a look and help with these issues. 

0 Kudos
1,065 Views
saurabhkulkarni123
Contributor II

Hello,

I saw your post and I am facing the same problem with sd card data logging using MBD. Can you please suggest to me steps for sd card data logging with mbd? how can I send data over SPI to sd card.

0 Kudos
2,062 Views
mariuslucianand
NXP Employee
NXP Employee

Hello Soheil Fard‌,

You are definitely on the right path regarding SDcard implementation over SPI!

However, there is a lot to be written by your side in order to achieve the required functionality. I've never used this FatFS but I had a look over the documentation and basically you have to implement the following c code functions:

pastedImage_1.png

Basically the FatFS is a layer that represents the file system, but the physical layer, in our case SPI has to be implemented by yourself. In other words, you need to tell to the FATFS how to send data over SPI. You started well using our config block for setting up the SPI peripheral but you need to implement all the above functions in the diskio.c 

If you have a look at the lpspi_master_driver.h file in our generated code you can see that you can send data using the LPSPI_DRV_MasterTransferBlocking blocking. You see there the implementation.

Luckily there are some samples projects there so you might find something interesting. http://www.elm-chan.org/fsw/ff/ffsample.zip  

There is also a lighter version called petitFS. Even is for the 8bit processors, if you only want to store data, I think it might work.

Hope this helps,

Marius

0 Kudos