Porting FatFs to LPC5411 with SPI throws a FR_NO_FILESYSTEM error?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Porting FatFs to LPC5411 with SPI throws a FR_NO_FILESYSTEM error?

跳至解决方案
13,820 次查看
puddletowntom
Contributor III

I have been following the tutorial attached below for setting up the LPC5411 with an SD card. I was able to write and read to the SD card as a basic data logger, but I haven't got the FAT file system working. 

I m now stuck on an issue which involves executing the f_open() function. Its fails after returning the FR_NO_FILESYSTEM (no valid FAT volume) error. I tried formating the SD card in a number of variations of the FATFS but to no luck. Looking deeper into this problem, it seems as though the issue is caused when checking the boot record signature in the ff.c file. eg    if(ld_word(fs->win + BS_55AA) != 0xAA55) return 3;

 

When the boot record signature does not result with the value 0xAA55 it returns a 3 which in turn results in the no valid FAT volume error (FR_NO_FILESYSTEM ). 

 

Does anybody know if the architecture of the LPC5411 is little endian or big endian? I couldnt find this on the datasheet. Reading the elm chan blog there is information about the FATFS being little endian and the need for conversion if using big endian architecture.

Porting FatFs file system to KL26 SPI SD card code 

标签 (1)
0 项奖励
回复
1 解答
12,039 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

  Good news, after I lot of modification, it works now, check the result:

pastedImage_1.png

You can find after running the spi sd card code with fatfs file system, we can create two files in the SD card, and write some Test data in the according files.

Now, please check my attached project on your side, whether you can make it works or not?

If it also works on your side, please help to tell Mark Hughes from AVENT EBV, who you have contacted, and let him know the problem is solved, and close the NXP case for this post, after that case is closed, please let DFAE also mark the case as solved.

This project really consume you and me a lot of time, actually, I also port my kinetis SD card driver in this code, because of some community rules, I delete the source code in the KL26 post in the last year. Otherwise, if you use my kinetis driver, the SD card driver should not have problems. That driver has been tested on my side. Anyway, this sd fatfs project for lpc54114 can work on my LPCXpresso LPC54114 board now. Please do the test on your side, any updated information, please kindly let me know!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
31 回复数
11,469 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

      The code in the last project will printf the log in the IDE debug console window, if you want to printf to the serial tool with UART, please use the project in this attachment.

      This code will printf the data to the lpcxpress LPC54114 on board virtual COM port, you can check the log in the serial tool.

      Now, do some summary for this post, with it helps to other customers.

1. Hardware:

     LPCXpress LPC54114 board, revA.

     SD card slot board.

    SD card pin to the LPC54114:

  • CS --> port0 pin10, J2_11
  • MISO --> port0 pin18, J1_11
  • Clock --> port0 pin19,J1_9
  • MOSI --> port0 pin20,J1_13

84.jpg

2. Format the SD card to FATfs32 in the PC at first.

85.jpg

3. Download the code to the LPCxpress54114 board, insert the the SD card, then press the reset button, you will find some printf log in the UART console

pastedImage_3.png

Some customer want the printf the data in the debug console window, then they just need to do the following configuration in the quick settins:

pastedImage_4.png

After you get "sd card fatfs testing is ready" information, it means the fatfs already complete the sd card file create and write operation.

pastedImage_5.png

This code function will create two file: TEST.csv and TEST.TXT file in the SD card, and write the Test1, Test2, Test3, Test4 in each file, you can see it in the above picture.

Wish it helps you and some other customer.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,469 次查看
puddletowntom
Contributor III

Hi Kerry,

This is great. If you manage to get it working tomorrow I would be very grateful. Thanks again.

Kind Regards,

Ronan

0 项奖励
回复
12,040 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

  Good news, after I lot of modification, it works now, check the result:

pastedImage_1.png

You can find after running the spi sd card code with fatfs file system, we can create two files in the SD card, and write some Test data in the according files.

Now, please check my attached project on your side, whether you can make it works or not?

If it also works on your side, please help to tell Mark Hughes from AVENT EBV, who you have contacted, and let him know the problem is solved, and close the NXP case for this post, after that case is closed, please let DFAE also mark the case as solved.

This project really consume you and me a lot of time, actually, I also port my kinetis SD card driver in this code, because of some community rules, I delete the source code in the KL26 post in the last year. Otherwise, if you use my kinetis driver, the SD card driver should not have problems. That driver has been tested on my side. Anyway, this sd fatfs project for lpc54114 can work on my LPCXpresso LPC54114 board now. Please do the test on your side, any updated information, please kindly let me know!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,469 次查看
puddletowntom
Contributor III

Hi Kerry,

Fantastic. I tried it on my side and its now working. :smileyhappy:. I checked the 2 Test files on my PC and they are appearing also. I am super grateful for this. Thank you so much. I know this was quite time consuming for you and I so I really appreciate it. I will let Mark Hughes know also. Thanks again,

Kind Regards,

Ronan

0 项奖励
回复
11,469 次查看
puddletowntom
Contributor III

In addition, for closing this question do I just click the button, "Mark Correct"? Is the post closed now?

0 项奖励
回复
11,469 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

   Yes, in the community side, if you mark correct answer, the post will closed, but don't worry, if you have any other question, you can create the new post, then just @kerry zhou, I will continue to help you.

   Beside, please tell Mark Hughes, after he close the case, he will get a survey, please let him mark as solved, thank you very much!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,469 次查看
puddletowntom
Contributor III

Hi Kerry,

That sounds good. Thank you for keeping in contact with me. I look forward to your update.

Kind Regards,

Ronan

0 项奖励
回复
11,469 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

   I get some progress today, I check the low level sd card driver step by step, and find a lot of bugs: SPI high and low speed, Get_Byte, SD initialization code, MMCReadSingleBlock ect. And I modify it.

   Now, I have finished the detail checking and modification for MMCInit(). MMCReadSingleBlock(), MMCWriteSingleBlock(). All these function can works OK now.

  I have tested it associated with the logical analyzer, check the SPI bus data, and then read and write the SD card sector, compare the SD data got by the code and the PC winhex software.

  Now, post some example:

    MMCInit();
     for (i=0; i<512; i++)
     {
          myBuff1[i] = 0x30;
     }
     readSuccess = MMCReadSingleBlock(0X00, getBuff2);
     for (i=0; i<512; i++)
     {
          if((i%16) ==0) printf("\n");
          printf("%x ", getBuff2[i]);

     }
     printf("\n");
     writeSuccess = MMCWriteSingleBlock(0x10, myBuff1);

     readSuccess = MMCReadSingleBlock(0x10, getBuff2);
     for (i=0; i<512; i++)
     {
          if((i%16) ==0) printf("\n");
          printf("%x ", getBuff2[i]);

     }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

1. sector 0x00, 512Byte data

WinHex data from PC after reading the SD card

pastedImage_1.png

Code debug data:

pastedImage_2.png

2. sector 0x10, 512Byte data

WinHex data from PC after reading the SD card

pastedImage_3.png

Code debug data:

pastedImage_4.png

So, now, the key function MMCInit(). MMCReadSingleBlock(), MMCWriteSingleBlock(). can work correct now.

Because time is limited, I still need to test MMCReadMultipleBolck, MMCWriteMultipleBlock.

Actually, if all these function, and some other sd card low level code works, the fatfs will have no problem.

Tomorrow, I will check the other code step by step.

I think we are close to success now, I will try my best tomorrow, if doing well, you may get the working fatfs sd card project tomorrow.

Please keep patient again, thank you!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,475 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

    You said, your own project already can read and write the SD card correctly.

    But in your attached code, diskio.c, disk_write and disk_read, why you comment MMCReadMultipleBolck instead of MMCReadSingleBlock? Otherwise, the code won't be work.MMCWriteMultipleBlock is the same.

   Do you test :

MMCWriteMultipleBlock

MMCReadMultipleBolck

  on your side directly without the fatfs file? Actually, if both the SD card, and the write and read API can work on your side, the fatfs porting should be very easy.

  So, I think, the Sd card leave code still important to check the function.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,473 次查看
puddletowntom
Contributor III

Hi Kerry,

The code below shows basic reading and writing to the SD card excluding the file system.

int main(void)
{
    uint16_t i,j;
    FATFS fs;
    FRESULT fr;
    FIL fil;
    UINT bw;
    char file_name1[12]="Test.csv";
    char file_name2[12]="Test.txt";
    CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
    CLOCK_AttachClk(kFRO12M_to_FLEXCOMM5);
    RESET_PeripheralReset(kFC5_RST_SHIFT_RSTn);
    BOARD_InitPins();
    BOARD_BootClockFROHF48M();
    BOARD_InitDebugConsole();
    GPIO_Configuration();

     MMCInit();

     for (i=0; i<512; i++)
     {
          myBuff1[i] = 17;
     }

     writeSuccess = MMCWriteSingleBlock(0x59, myBuff1);
     readSuccess = MMCReadSingleBlock(0x59, myBuff1);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 This will produce the values in the buffer destBuff as seen below in the image

I remove the SD card and put it back in again and change the code to the following,

int main(void)
{
    uint16_t i,j;
    FATFS fs;
    FRESULT fr;
    FIL fil;
    UINT bw;
    char file_name1[12]="Test.csv";
    char file_name2[12]="Test.txt";
    CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
    CLOCK_AttachClk(kFRO12M_to_FLEXCOMM5);
    RESET_PeripheralReset(kFC5_RST_SHIFT_RSTn);
    BOARD_InitPins();
    BOARD_BootClockFROHF48M();
    BOARD_InitDebugConsole();
    GPIO_Configuration();

     MMCInit();

//     for (i=0; i<512; i++)
//     {
//          myBuff1[i] = 17;
//     }

//     writeSuccess = MMCWriteSingleBlock(0x59, myBuff1);
     readSuccess = MMCReadSingleBlock(0x59, myBuff1);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This will also produce the same values in destBuff. 

I have noticed that the value at destBuff[0] is 255, but it should be 17. I m not sure why this is. Is it ok to use my Send_Byte() and Get_Byte() as the following,

#include "spi.h"

#define BUFFER_SIZE (10)

static uint8_t tempBuff1[1]; //1
static uint8_t destBuff[BUFFER_SIZE]; //2
static uint8_t dummyBuff[10] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
status_t spixferStatus = kStatus_Success;
static uint8_t srcBuff[BUFFER_SIZE]; //1
spi_master_config_t spimasterConfig = {0};
spi_transfer_t spi_xfer = {0};
#define regVal1 0x00

uint8_t Send_Byte(uint8_t byte_val){
    uint8_t ucTemp;
    tempBuff1[0] = byte_val;
    spi_xfer.txData = tempBuff1;
    spi_xfer.rxData = destBuff;
    spi_xfer.dataSize = 1;
    spixferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &spi_xfer);
     ucTemp = destBuff[0];
     return ucTemp;
}

uint8_t Get_Byte(void)
{
    uint8_t ucTemp;

     srcBuff[0] = regVal1;
     spi_xfer.txData = srcBuff;
     spi_xfer.rxData = destBuff;
     spi_xfer.dataSize = sizeof(destBuff);

     spixferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &spi_xfer);

     ucTemp = destBuff[0];
     return ucTemp;
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Maybe there is a better way than using SPI_MasterTransferBlocking() because I have to send an array each time I read and write over SPI. Could this be improved by sending individual bytes at a time instead? 

Thank you,

Ronan

0 项奖励
回复
11,470 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

     Thanks a lot for your detail information.

    You can use the Send_Byte and Get_Byte, but as you know, the LPC spi cs pin normally will be de-asserted after each SPI byte, so normally, we control the SPI Cs pin as the GPIO instead of the hardware_cs pin, do you modify the CS pin to GPIO, and control it in sd card functions?

  This question is a little complicated now, I will help you create a working SD card Fatfs project on my side, after testing it works, I will send you the working project directly. But, as you know, this is really need time.

  So, please give me more time, I will write the according code on my side, and send you the working project.

  Thanks a lot for your understanding.

PS: From tomorrow, I will leave for our Dragon Boat Festival, I will be back on 20th June, after I back, I will try my best to give you a direct working LPC54114 SD fatfs code ASAP. Please give me more time!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,470 次查看
puddletowntom
Contributor III

Hi Kerry,

I am using a GPIO pin for the chip select. This was confirmed from looking at the oscilloscope. In addition each of the sd commands in the MMCInit() function returned successfully which means that SPI communication is working in some way. I am inexperienced with using the NXP coding base which is why I am having difficulty getting this working. If you can get my code working that would be greatly appreciated. The sd_fs.rar file that I previously sent you contains code that compiles and the pins that I m using are also contained in that code. eg the pins are as follows,

  • CS --> port0 pin10,
  • MISO --> port0 pin18,
  • Clock --> port0 pin19
  • MOSI --> port0 pin20,

You can probably ignore most of the other pins that I have selected.

Thank you,

Ronan

0 项奖励
回复
11,470 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

    I am back now.

    Today, I create a platform which based on your code, actually, it is also from the KL series.

    I use the same SD card pin as you:

  • CS --> port0 pin10,
  • MISO --> port0 pin18,
  • Clock --> port0 pin19
  • MOSI --> port0 pin20,

   I am testing it now, with the SPI sd card wave checking, just want to check where you may have problems.

pastedImage_1.png

pastedImage_2.png

I will test it step by step carefully, so I need more time, tomorrow, I will continue to test your code, and modify it.

Any updated information on my side, I will let you know.

Besides, our AE team already help us to check another SD card driver which based on the sdk fsl driver.

On my side, I will mainly help you testing your project, use the same pin as you, then if it works on my side, it will also work on your side.

Please give me more time, thanks! It seems your MMCReadSingleBlock function still have problems.

Best Regards,

Kerry

0 项奖励
回复
11,476 次查看
puddletowntom
Contributor III

Hi Kerry,

The reason I had that commented out was because when i was in debug mode for f_open(), count = 1 so MMCReadMultipleBlock wasnt being used. In addition, it seemed like there was a mistake on the blog (Porting FatFs file system to KL26 SPI SD card code ). The MMCWriteMultipleBlock() was missing from the blog.

I m not sure if the way i implemented MMCWriteMultipleBlock() is correct. I was using code from a website, but i m not sure if it is right.

LPC1114 FAT下读写SD卡(原创) - 我心永恒的日志 - 网易博客 

I have not tested out the MMCReadMultipleBlock() and MMCWriteMultipleBlock() but they dont seem needed for testing the f_open function.

Just now I tried to put back in the commented out lines and it still has an error. 

I am also looking at the audio sample code you gave me but it is difficult to test.

Thank you,

Ronan

 

0 项奖励
回复
11,475 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

   Please check this code for LPC54114, it is the audio, but it contains the SD card, and the dfs_fs file system, you can refer to it.

GitHub - Magicoe/LPC54110_Audio 

  dfs_fs is based on FATFs file system, you can check it on your side, you can comment all other audio code.

 Please check it on your side.

   


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,476 次查看
puddletowntom
Contributor III

Hi Kerry,

I was trying to run a basic test with the SD card. As I m not using the full version of Keil, I cant run the entire project because I m limited to 32kb. I was wondering could you tell me which files I can ignore. In addition, is there a test file that you were using to create/read and write a file? I m having problems running this code. If you tested this on a LPC5411 device could you send me the code you used to test it?

Thank you,

Ronan

0 项奖励
回复
11,475 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

     MDK 32Kb limit is really too small to use.

     This is the project's code size:

pastedImage_1.png

  About the relate file, SD card, please check drv_msd_spi.c, and the filesystem.

  Now, I just find this MDK project which is related to the LPC54114 sd card and the fatfs, we don't have any other project which can work directly, otherwise, I will send to you directly.

  Anyway, I will help you to keep on eye on it, If I find any project which can work directly, I will send to you.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,475 次查看
puddletowntom
Contributor III

Hi Kerry,

Thank you for your response. I m currently away today so will be sure to check this out tomorrow and I ll let you know if it works.

Thanks,

Ronan

0 项奖励
回复
11,474 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Ronan,

   Can you upload your SD project which can write and read the basic SD card data?

   Then, I will try to help you to add the Fatfs file for you.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
11,474 次查看
puddletowntom
Contributor III

Hi Kerry,

Is there a way to attach files on the forum?

Thank you,

Ronan

0 项奖励
回复