KSDK 1.1 and Processor Expert adding SD card with MFS

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

KSDK 1.1 and Processor Expert adding SD card with MFS

3,290 Views
adyr
Contributor V

Hi,

 

I have created a KSDK 1.1 + MQX project with Processor Expert for my custom board that has a MK64FN1MoVLQ12 processor.

I now want to use MFS on an microSD card through the SDHC interface.

 

Do I need to add the memoryCard component or an sdcard component or just the Init_SDHC?

If so, how can I connect the MFS to one of them?

 

I have run the sdcard_twrk64f120m sample project in the MFS folder on my board and if I by-pass the card detect code it seems to work but that doesn't appear to use any of the above. So if I copy the technology from that project how would I change it to use the CD3 pin as the card detect?

 

I am not sure if I am missing something obvious or if I am just wanting things that have not been implemented yet so I would appreciate any hints.

 

P.S. If I add the memoryCard component with the auto-initialise option set then I get a hard afult when the Init thread ends. If I switch off auto-initialise and call the SDCARD_DRV_Init function from my thread then it appears to be OK.

 

Best regards,

Adrian

Labels (1)
0 Kudos
21 Replies

1,859 Views
loicguillain
Contributor II

Finally does someone succeed in making a MSD Device  + (MFS) SD Card? If "yes" could we have the example code? I'm trying for too long and my brain is going to explode :smileysad:

0 Kudos

1,859 Views
adyr
Contributor V

Hi Loic,

I'm not sure you are doing the same as me. I have setup the SD card so I can read / write files from my code using FatFS. I assume you are trying to create a USB MSD device that access the SD card so a PC can read / write directly to the card via USB? If so then the demo that Iva mentioned appears to be what you need.

Best regards,

Adrian.

0 Kudos

1,859 Views
loicguillain
Contributor II

Yep it's what I want except I want to use PEx ^^

0 Kudos

1,859 Views
ivadorazinova
NXP Employee
NXP Employee

Dear ,

please, what do you exactly find? Do you have the same issue as Adrian?

We have created example for MSD Device and SD Card, located at <ksdk1.2_path>\examples\frdmk64f\demo_apps\usb\device\msd

You can also look at the example,How to implement a USB Device MSD demo based on KSDK PEx components and KDS 3.0

Best Regards,

Iva

0 Kudos

1,859 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Adrian,

So far, KDS doesn't have PE component for MFS with eSDHC support, just FatFs component, so maybe you can use FatFS instead? Please kindly refer to the following for details.

sf1.png


Have a great day,
Kan

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

0 Kudos

1,859 Views
adyr
Contributor V

Hi Kan,

Thank you for the information. I searched the internet and found the FatFsMemSDHC you mentioned but when I add it to my processor expert project I get an error.

ERROR: This component is not supported in Kinetis SDK project mode. SDHC1.

Is there a version that is compatible?

Any idea when Processor Expert  might support MFS or FatFs using KSDK? If it is not too long then I will wait rather than spend time trying to make something

Best regards,

Adrian.

0 Kudos

1,859 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Adrian,

I am sorry this component just support non-KSDK mode, so you have to uncheck the KSDK option in the wizard as below:

sf.png

Otherwise PEx would report issue, but I am not sure if PEx would add KSDK support for this component in the future, I will check with the software team and let you know when I have any more information.

Thanks for your patience!


Have a great day,
Kan

0 Kudos

1,859 Views
adyr
Contributor V

Thanks Kan for your suggestion and looking into possible future support for the file system in PEx.

I have created another project without the KSDK as you recommended. I added the FAT_FileSystem and FatFsMemSDHC but when I Generate the processor expert code it fails with:

  Unknown macro: "PullCodeEnabled" (file: Drivers\sw\FatFsMemSDHC.drv). Any suggestions on how to fix that?

There were no errors prior to generating code so I think all the options are configured.

It also appears the Reentrant tab of the FAT_FileSystem only supports FreeRTOS and not MQX, is that correct or have I missed something else?

Best regards,

Adrian.

0 Kudos

1,859 Views
BlackNight
NXP Employee
NXP Employee

Hi Adrian,

I'm affraid that because the Kinetis SDK introduces a different API, all these non-SDK components are not compatible with the SDK.So if you want to use the SD_Card/FatFS/SHDC components, you have to create a project without the SDK enabled.

And yes, the FatFS component comes with FreeRTOS support in it, and not MQX.

Erich

0 Kudos

1,859 Views
adyr
Contributor V

Hi Erich,

Thank you for getting back so quick. The "PullCodeEnabled" errors I'm getting are in a new project created without the SDK support as shown in Kan's image he posted above. I'm using Process Expert Software version 10.4.2, build b141031 to generate a non-SDK project for the MK64FN1MoVLQ12 processor using the IAR compiler. I added the MQX, FB:Init_FB and the ADC1:ADC_LDD components then the Fat_FileSystem, FatFsMemSDHC and Shell components and tried to generate the code.

Best regards,

Adrian.

0 Kudos

1,859 Views
BlackNight
NXP Employee
NXP Employee

Hi Adrian,

sorry, I thought your project is still on KDSK. It looks like you bumped into this issue:

https://github.com/ErichStyger/McuOnEclipse_PEx/commit/388b6af305847bb044b1522181f93a133fa42e5b

You can either apply this fix on your side, or use the attached component, as I have not released a new package yet.

I hope this solves your problem.

Erich

1,858 Views
adyr
Contributor V

I'm not sure the FatFsMemSDHC and other collection of beans is compatible with the current Processor Expert. A lot of the component options have no effect on the code generation so I have had to search the internet and browse the code very carefully to work out how to connect things together. E.g. the FreeRTOS task component doesn't actually create any tasks?

The help seems to be sparse and lagging well behind the generated code so is not very helpful.

After 3 days I have managed to get the shell and a task in FreeRTOS to work but still any attempts to do a 'dir' on the SD card just returns a low level driver error.

I know the hardware is good as I have managed to get a modified sdcard_twrk64f120m example project to work.

So for now I will put the job on hold and hope that Freescale come up with an official file system that will work with KSDK or until I find some time to integrate the working example code into a Processor Expert / KSDK project.

Adrian.

0 Kudos

1,858 Views
BlackNight
NXP Employee
NXP Employee

Hi Adrian,

the FatFsMemSDHC component is compatible with the current Processor Expert. But it is not compatible with the Kinetis SDK. Making it work with the Kinetis SDK would be a big task, as the API and driver structure is completely different.

On the other side, there is FatFS included with the Kinetis SDK itself, have you tried that one?

Erich

0 Kudos

1,859 Views
adyr
Contributor V

I have now hacked the filesystem\fatfs KSDK code into my KSDK project and it can read and write files, etc on the SD card. And it seems to be very efficient. Now I need to re-work it to use the PEx generated fsl_card / fsl_sdhc components instead of it's own instances of them that are configured via #define and tidy it up.

I know nothing about making PEx components but it seems creating a component for fsl_sd_disk would be similar complexity to the fsl_card so if there are any PEx experts out there willing to take the challenge I'm sure the community would be very grateful.
Maybe even extend to create a FatFs component based on the new fsl_sd_disk :-)

Adrian

0 Kudos

1,859 Views
leonardobueno
Contributor I

Adrian,

Can you provide part of your code. I am running into a hardfault when trying to initialize the SDCard using the FRDM K64F KSDK 1.0.0 code. Apparently the processor is not detecting the present/absence of a card. The tries to send a command, a hardfault is raised.

Any idea of what could be happening?

0 Kudos

1,859 Views
adyr
Contributor V

Hi,

I'm on holiday until 20th July and can't get to my PC.

I am using KSDK 1.2 so maybe that fixes the issue you are having. From what I can remember the type of card detect is configured through #defines so check you have the correct type set for the board. My project is on custom hardware (micro-SD) so it maybe a different type to FRDM board.

Best regards,

Adrian.

Sent from Samsung Mobile

0 Kudos

1,859 Views
adyr
Contributor V

Hi Erich,

The project with FatFsMemSDHC is not using the KSDK but I couldn't get it to work. One problem I worked around was caused by using a microSD on my board so it needs to use DAT3 as the CD pin which doesn't seem to be supported. I turned off the card detect option in the component but then the code always returns FALSE for the card detect and stops trying to access the card before anything is initialised. I changed the FATM1_CardPresent function to always return TRUE and that got me further (but my change gets overwritten every time I generated the code in PEx). So with that I now see "File System mounted" in the shell output.

The point at which I gave up is when using 'FAT1 dir' in the shell I get the following returned:

ERROR: getcwd failed: (1) A hard error occurred in the low level disk I/O layer

*** Failed or unknown command: FAT1 dir

It appears the card function SDHC1_GetCardInfo times out. At one point I didn't have the TMOUT1_AddTick call in the FRTOS1_vApplicationTickHook (eventually I found this requirement after searching the internet) and it locked up permanently so it's not just a case of too short a timeout.

Another issue that took me a while to work out was with the shell. The help shows passing the address of the ParseCommand function but I eventually discovered it is now an array of ParseCommand functions. Again I had to search the code to find the fat and shell callbacks to insert in the table which was not specified in any help.

I also tried to use the FreeRTOS_Tasks to add my tasks but no code is generated so I'm not sure of the purpose of this?

My shell task is currently as follows:

unsigned char cmd_buf[48];
memset( cmd_buf, 0, sizeof(cmd_buf) );
FAT1_FATFS fs;
memset( &fs, 0, sizeof(FAT1_FATFS) );
bool cardMounted = 0;
FAT1_Init();

FAT1_MountFileSystem( &fs, "0:", CLS1_GetStdio() );

(void)CLS1_ParseWithCommandTable((unsigned char*)CLS1_CMD_HELP, CLS1_GetStdio(), CmdParserTable); /* print help and prints as well the prompt */
for(;;)
{
  FAT1_CheckCardPresence( &cardMounted, "0:", &fs, CLS1_GetStdio() );
  (void)CLS1_ReadAndParseWithCommandTable(cmd_buf, sizeof(cmd_buf), CLS1_GetStdio(), CmdParserTable);
  FRTOS1_vTaskDelay(50/portTICK_RATE_MS);
}

If you have any suggestions on something I have missed out I would appreciate it.

Re: FatFs in KSDK. I have now found that but with no documentation or example code that I can find it will take a while for me to work out how to add it to my KDSK project.

Best regards,
Adrian.

0 Kudos

1,859 Views
BlackNight
NXP Employee
NXP Employee

Hi Adrian,

to solve your problem with FATM1_CardPresent(), find attached an update component. It has two new settings which are used if you have CD or WP pins disabled:

pastedImage_0.png

You can specify either TRUE, FALSE or a function name. In case of the function name, it will call a prototype like

bool myFunctionName(void);

That way you can provide your own function which tells the driver if the card is present or if it is write protected. That way I hope you have maximum flexibility.

Details of the change on GitHub: support for custom card detection and write protection handling. · 90edd2f · ErichStyger/McuOnEclips...

Erich

0 Kudos

1,858 Views
adyr
Contributor V

Hi Erich,

I appreciate your help. The new component helps but I still can’t get the project to work.

I have attached the project so maybe you could take a quick look to see if I have missed something or doing something wrong.

The problem is I can’t get passed the call to get the card information while initialising the driver. The call times out and the structure remains all zeros.

I am confident the hardware is OK as the MSF example works fine.

Best regards,

Adrian.

0 Kudos

1,858 Views
BlackNight
NXP Employee
NXP Employee

As an additional reference point, I have a bare metal project here for the TWR-K60 board:

mcuoneclipse/Examples/TRW-K60N512/TWR-K60N512_FatFS_BM at master · GitHub

0 Kudos