MICRO SD CARD is not working on the PSoC 059 kit ( emFile)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

Hello everybody,

Please i really need your help, I’m struggling with the micro sd card part for more than a month. It worked perfectly on one of my projects two years ago, but this time, with the same kit ( PSoC5 lp 059 kit/ 3.3 volt) , in a new project, no data is saved on the card. At first, I thought the problem was the choice of the ports for the whole program, so I made some researches on the forum and i used, as recommended in a post, the port 12 as follows: MISO 12[2] MOSI 12[3] clk 12[4] CS 12[5] ( I'd already used 12[0] and 12 [1] to I2C communication with the OLED display). This combination worked perfectly on the PSoC5 lp /050kit for emFILE exemple 01 with LCD, but not for my project with the PSoC 059 kit.

After that, I just copied the part of the program related to sd card  in a new project and I tested a simple addition operation  on two different PSoC5, but it didn’t work either, so the problem is really the micro sd card part.

I tested this short program as follow:

 First, on my PSoC 059 kit/ 3.3 volt ( kit prog removed, programmed via miniprog3  / micro sd 2Gb )

Second test on another PSoC 059 kit/5 volt / micro sd 2Gb

The same results for both kits (and that was the case also with the whole program):

When the sd card is not inserted, the program works, I can read at first ‘’Failed to open RESULTS ‘’( which is the fname file) , then the results of the addition/time/ SD good =0, so the ‘’sd prepare’’ is executed.

When I insert the sd card, the program doesn't work, I get a blue screen on the OLED display. 

I tried the debug on the PSoC 059 kit/ 5 volt, the program stopped at the first line of main…

I have used three different supports for the micro sd card(3.3 volt and 5 volt) which worked perfectly on the PSoC5 050 kit, so the problem of the support is eliminated.  The sd card I tested with ( 2GB from SanDisc) has been tested succefully on the PSoC5 050 kit . Also, i have used the formatter of sd card ( from tuxera) as recommended in that post on the forum.

thanks for your help in advance!   

regards,  

 

0 Likes
1 Solution
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

LEN,
I can't thank you enough, the problem of the sd card is fixed!
my short test program didn't work yesterday, because I  shortened the name of the file on the sd card and i forgot to do the same on the program( cause i 'm haunted by this clock issue )
So, the real problem of the sd card was the low bus clk( i have lowered it to 6MHz in my case), which must be at least 24 MHz for the emfile.
To be correct and useful, I will post my clock problem on a new post, with another appropriate title.
Thanks again LEN !!!!

Update!!!!!


LEN , has found a solution, we can lowered the master/ bus clock and get the sd card worsk, we just have to respect the condition Max SPI frequency (KHz):" can be no higher than 1/2 MASTER_CLK
More details on his post of Dec 27, 2022 05:40 AM below, also a solution for long name file.
thanks LEN

View solution in original post

0 Likes
26 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

IREEN,

Please supply the brand and part number of the MICRO SD card board you are using with the -059 kit.

In general, the MICRO SD cards I'm familiar with ALL run off of 3.3V.  Interfacing to a 5V system requires logic level-translation.  Some MICRO SD card boards already have it on-board, some do not.

If the  MICRO SD card board you are using does not, it is possible using the SIO port (port 12) pins to do level-translation without extra HW.

While you're at it, can you supply the brand and part number of the MICRO SD card board you are using with the -050 kit?  We can do a comparison between the two boards.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

Thanks a lot for your reply,

You can find on the attached photo the three sd card boards and the micro sd card I used on the PSoC 050 for the emfile exemple, which works perfectly, while doesn’t work on the PSoC 059   

I use the smallest one just for 3.3 volt system, the two others sd card boards have already a voltage regulator ( AMS 1117  3.3 volt)  ….

My program must be suppled to 3.3 volt, I used the PSoC 059 with the kit prog at 5 volt just to test the debug

regards, 

 

 

 

0 Likes

IREEN,

The middle board automatically provides 5V to 3V3 level translation on-board.

Len_CONSULTRON_0-1671806425708.png

Where VCC is supplied 5V.

The white board at the top is virtually the same (earlier revision?) with the pinouts slightly different.

The board at the bottom is almost certainly 3.3V (The VCC pin is labeled "3V3").  It has no logic level translations.  This is evident by the direct routing of the interface connector pins to the SD card slot.  Recommendation:  Do not use this board without appropriate level translation and a 3.3V supply.  Wiring this board to a 5V system without level translation might damage the MICRO SD card.

This lower board might work with the 050-kit but the eval board has a 3.3V regulated supply for VCC.

Second Note:

I downloaded your project.  It builds successfully in the HW connection phase but fails in the compile phase.  I believe this is because the utils.h and rtcIntHandler.c files are missing.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

IREEN,

There are many things to unravel here.

Normally translating a 050-kit board project to a 059-kit project is fairly trivial from a SW perspective.

There are some very minor HW differences but usually not a problem either.

You wrote:


When I insert the sd card, the program doesn't work, I get a blue screen on the OLED display. 

 


I don't know the prerequisites for not getting a "blue screen".   Are you doing a read or write to the SD before the "blue screen" event?

Recommendation:  You need to copy your 059-kit project and get rid of the OLED and RTC parts of the project. (Walk before running.)  The idea is to perform "unit testing" on a smaller portion of your project.

I recommend that you load a pre-formatted SD card with 1 or 2 known files.  This can be done on your PC.

With this SD card unit test project, once initialization is complete, try perform a directory API call.  The return of a good read of the SD card through the 059--kit HW connection should return the first entry.  (Ie no SD writes just reads)

If this is successful, try reading the first 10 bytes of the first file.  

If successful, try creating a new directory on the SD card.  This should test the write HW.

Debugging issue


I tried the debug on the PSoC 059 kit/ 5 volt, the program stopped at the first line of main…

 

 When you enter the debugger, it normally halts on the first line of main().  This is to allow you to step through the code.  Once halted, you can issue a "Run" command to run the code.   A "Pause" will halt the running code or setting a Breakpoint will halt the code if the code reaches that location.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

Thanks for your answers,

For the blue screen, as soon as I plug in (the usb cable to the pc), I have this blue screen and the first operation was sd prepare with the FS command pf= FS_FOpen

Debugging issue :

I know that there is RUN/ PAUSE / HALT command for the debug 🙄  I used it many time, here what happened,  I inserted a breakpoint at the operation of adition and the debug run all the time without a break  ( i waited 10 minuts for this simple program)  and never reaches the first breakpoint. That's what I meant

 

i have tried what you recommended, a short program without rtc and the oled. you can check it, it is attached. I have created two file on the sd card from my pc with some data , testread1, testread2

So, no directory on the sd card were created

and when i run de debug, it reaches the first breakpoint at pf= FS_FOpen("testread1.txt", "r"); then run all the time without break, without reaching any other breakpoint the (FS_Read ).☹️☹️☹️

Thanks for your help, I really don’t know what to do, I have a big project to finish, I need to save data...   

0 Likes

IREEN,

Thanks for the feedback.


 

and when i run de debug, it reaches the first breakpoint at pf= FS_FOpen("testread1.txt", "r"); then run all the time without break, without reaching any other breakpoint the (FS_Read ).☹️☹️☹️

Suggestion:  After the breakpoint on FS_Open() single-step through the function.  It should be a blocking function.  If the debug session returns normally the FS_Open() command had attempted to execute.  Check the return code. 

If not, the code is getting stuck into the emFile library code.  You should be able to execute a HALT and the call stack may give you a clue where the code is stalled.

Thanks for the minimized project.   I will take a look at it in the next few days.  My wife would not be appreciative if I work too diligently on the holidays.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

LEN,
i really appreciate your valuable help, i was really desperate i'm gonna test and give you a feedback, enjoy your holidays with your family, nothing more important !
PS: i'm still novice but i'm realy a big fan of PSOC  circuit, and this forum is realy great, thanks for all members for their contributions and help !
Thanks again sir,

0 Likes
lock attach
Attachments are accessible only for community members.

IREEN,

You're welcome.  I and others try to help where we can.  Sometimes we do encounter stumpers.

In your case. there is probably something trivial we're missing.

I resurrected my SD card board I've used in the past.  I got it working with a very simple program that only reads a file called "new.txt" on the root directory.  It parses the '0's and '1's in the file and turns on ('1') or off ('0') the 059-kit board Blue LED.  In addition, it dumps the '0's and '1's to the standard UART @ 115.2Kbaud 8N1 along with the "End of File" indicator.

To restart the program, press the reset.

I've attached this very simple program as a base test of the SD card interface.  If it works, your HW interface for reading the SD should not be the problem.  

Note:  My SPI interface pin assignment is nearly the same as yours.  You'll have to change my assignment of CS from P12.0 to P12.5.

I've also attached a "new.txt" file (in the new.zip) as an example.  This needs to be added to the SD on the PC.

 

I've downloaded your latest version and will now have a chance to look at it.

Happy holidays to you and your family!

UPDATE!

If you build my example project, you will probably have to change the directories to find the emFile Code otherwise my build locations will not be found and it will not build successfully.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

IREEN,

I've begun testing your minimized test2 project.

I have found a few POTENTIAL issues/conflicts.  To determine if they are actual issues, need you to answer a few questions.

  • Your project DWR/Clock definitions define that you are using both a 24MHz crystal (ECO) AND a watch crystal (WCO).  The 059-kit board does not normally have these crystals on-board.   Does your add-on board have these crystals? The reason for the question is that running your code as-is does not get to main().  It is stuck in the Reset() vector waiting for the crystal(s) to lock in.
  • What is the emFile configuration you plan to use?   There is an inconsistency in your project's build defs.  Here are the options available:
    • 16noslfn
    • 16nosnlfn
    • 16oslfn
    • 16osnlfn
    • 32noslfn
    • 32nosnlfn
    • 32oslfn
    • 32osnlfn
      Here is the definition from the datasheet.
      Len_CONSULTRON_0-1671894867402.png

I believe the same result you are.  It never returns from the FS_Open() command. 

Still debugging ...

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

IREEN,

I figured you're busy and not seeing my last responses.   I suggest answering my questions as best yo can.

However, with more testing, I have found the following issues:

Issue #1:  BUS_CLK too slow.

When I run the debugger, it appears to halt at the FS_FOpen() code line.

The operative word is "appears".   It actually returns from FS_FOpen() if you wait long enough.  (usually about 15 minutes.)

The return code copied to *pf is still '0' but that's another issue under investigation.

I notice that your DWR/Clocks configuration looks like this:

Len_CONSULTRON_0-1671903802614.png

Note the '8' MASTER_CLK   divider in the RED box.

This causes the BUS_CLK to be 6MHz.

Apparently the FS_FOpen() command is fairly computation intensive.  Therefore a slower BUS_CLK take MUCH longer.  Hence the big delay to return for many emFile API calls.

When I change the MASTER_CLK  divider to 1, the BUS_CLK is 48MHz, and virtually all the emFile API calls return nearly immediately.

One problem solved.

Issue #2:  File name too long.

In your project "Build Settings/Linker/General/Additional Libraries" settings you have em16nosnlfn. See the pic below.

Len_CONSULTRON_1-1671904758593.png

with "nlfn" = No Long File Names.   This means the name must conform to 8.3.

However, the file you reference in FS_FOpen("testread1.txt", "r")  is 9.3.   Therefore it cannot find the file and the return placed into *pf is '0'.

If I change the name of the file on the SD card to "testread.txt" and in the FSFOpen(), it works.

This is a partial solve.  

Theoretically if you want to support Long File names, you should be able to change "Build Settings/Linker/General/Additional Libraries" settings to em16noslfn.

Now here's where I'm stuck.   When I made the above change, it appears to still not find "testread1.txt" on the SD card.

Still working on the issue.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

LEN,
i'm really sorry, as you told me that you will be some busy with your family this holiday, i took one day off to visit relatives too, i was far from home. i promess, i'm not gonna goes that far any more 😊
ok, i'm gonne respond first to your questions:
yes I have two external clocks connected to my PSoC 059, ,in my project, I’m using a 3 clocks of 100Hz and I needed an accurate clock, with 30PPM, this is why I added the extern clock MXTAL of 24MHz, and the divider (6 ) has been chosen for that reason, cause, I suffered long time from a delay of 1 sec which appear regularly after processing my data, and for a long while I thought that it was a bad synchronization between the different parts of my project , the data acquisition, the hardware / softer parts, I have figured out that problem was the accuracy of that 100 Hz clock which causes a delay and need to be with extreme precision.
and of course, the 32khz for RTC component.


yes i have chosen that option of "nlfn" = No Long File Names (16nosnlfn) and I didn't pay attention to this detail when I named the file I created on the sd card 🙄( thanks a lot for that details )I'm going to do the opposite of what you have done, i will reduce the file name and test again.


I am gonna test your program and answering you after a moment
thanks a lot for your help!

0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

LEN,
I have shorten the name of the file on the sd card, changed the master clock to be 48MHz just for the test, still the debug running after 30 min, not reaching any other breakpoint .
The good news is that your program worked !!! I can’t describe my joy seeing that blue led blinking😊

so no hardware problem !!

where is the difference, why that short test don't work 😥

0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

clock system configuration issue :  BUS_CLK too slow

  some of you may  ask why I lowered the master clock to 6 MHz instead of using freq divider components to get my 100 Hz clocks, because when i tried this solution, i exceed my UDB RESOURCES (Resource limit: Maximum number of Macrocells exceeded (max=192, needed=232)) I'm already at 96.9 % on my project...........

So the FS commend will never work with that 6 Mhz bus clock??

0 Likes

IREEN,

I don't know why a 24MHz or higher BUS_CLK to the SPI devices but a BUS_CLK at 6MHz is impractical.  I think it has something to do about internal component timers used is causing the additional and unreasonable delays.

It might have something to do with the emFile is set for a 4MHz maximum frequency but the BUS_CLK is at 6MHz.(?)

In theory, if the emFile component was constructed with the ability to source the input clock to the SPI, you could source the MASTER_CLK (@48MHz) directly.  Sadly, they didn't provide this option.

The original project you placed on this forum ONLY has < 13% of the UDB resources being used.  I'm assuming you are not sharing the actual project on this forum.

Many times with effective knowledge of how the PSoC Creator application builder allocates resources, you can combine common resources such as clock dividers.

For example, it is common to source the lower frequency clocks using the Watch crystal WCO that you call out.  This requires less clock divider resources.  For example: 32.768 KHz/326 = 99.9 Hz.

There are other ways to share resources to minimize over-saturation of the PSoC resources.

Suggestion: Without sharing the entire project, attach your TopDesign file on this forum.

With it we can go through the "Application Build" phase to check the PSoC resources.  We can then advice if resource reduction techniques can be used.

By sharing only this code, we don't have the underlying application source code that controls the components on the TopDesign.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

Hi  Len,

For example, it is common to source the lower frequency clocks using the Watch crystal WCO that you call out.  This requires less clock divider resources.  For example: 32.768 KHz/326 = 99.9 Hz.

This is exactly the clock I was using at the beginning, but after combining two parts of the project, I get this delay which appears regularly after a number of acquisitions, so that missing 0.1Hz really matter, getting finally that accurate 100Hz clock, fixed that problem.

 

 Yes,  96.9 % of UDB resources is relatif to the big project.

 and this is exactly what I was doing today, optimizing my schematic ( 74% UDB) , but using  freqdivider from 24 MHz to 100 Hz is very greedy, it devours resources !

 this morning I was at (Resource limit: Maximum number of Macrocells exceeded (max=192, needed=232)

Now, I’m at : Resource limit: Maximum number of Macrocells exceeded (max=192, needed=194).

Still working on it……….

 

in the meantime, I have not yet solved my sd card problem, because this little test even with a 48MHz clock bus does not work !!!!!!

my little test still not working with you as well ??

 

Many thanks LEN for your help!!!

0 Likes

IREEN

I now understand.  You need a more accurate 100Hz clock source.

I got the SD card to work properly with my last suggested changes AND keeping the filename to to no more than 8.3.  (Still debugging why emf16noslfn is not working.)

The goal with trying my upload listed "SD_Card_Tests.cyprj.zip" was to test the SD card HW interface.  If you don't get that to work, the rest of the project emFile issues will still remain.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

Hi everybody,
Just want to tell you that using freq_divider instead of a source clock will never works if you have as my case a Counter and Timer with fixed function, that component will never accept freqdivider as clock source.


Timer "\Counter_1:CounterHW\" can only use one of the digital clock dividers or bus clock as the clock source.

0 Likes

IREEN,

You are correct. 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

IREEN,

I see you are trying to source a slow clock (100Hz or in the above case 50Hz) into a counter.

What is the intent of the counter output?

In theory the 100Hz input clock or counter output can be done entirely in SW. 

You can use the SysTick resource (@1ms) and a SysTick ISR to compute relatively slow events without consuming additional UDB HW.  It consumes FLASH and CPU time but sometimes there is enough to spare.

The advantage of a UDB (or fixed function) implementation is that the HW events are executed with virtually no latency.  A SW implementation may have some jitter introduced from cycle to cycle.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

LEN,
I can't thank you enough, the problem of the sd card is fixed!
my short test program didn't work yesterday, because I  shortened the name of the file on the sd card and i forgot to do the same on the program( cause i 'm haunted by this clock issue )
So, the real problem of the sd card was the low bus clk( i have lowered it to 6MHz in my case), which must be at least 24 MHz for the emfile.
To be correct and useful, I will post my clock problem on a new post, with another appropriate title.
Thanks again LEN !!!!

Update!!!!!


LEN , has found a solution, we can lowered the master/ bus clock and get the sd card worsk, we just have to respect the condition Max SPI frequency (KHz):" can be no higher than 1/2 MASTER_CLK
More details on his post of Dec 27, 2022 05:40 AM below, also a solution for long name file.
thanks LEN

0 Likes

IREEN,

You're very welcome.

I'm still trying to solve why the emFile type emf16noslfn still isn't recognizing long file names.

In your fixed system, is "testread1.txt" working for you?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

Hi LEN,

I tested this morning, I have changed the build settings to longue file name , also changed the name of the file( to readtest1.txt) on the program and the sd card............ it doesn’t work, still debugging!!!  

0 Likes

IREEN,

I'm also still working on why LFN support is not working.

However, I do have some additional news.

I was doing some more testing about trying to get the MASTER_CLK to be 6 MHz and the emFile system to be OK with it.

I got it to work very reasonably.

Here's my specs:

MASTER_CLK_SRC divider = 8

MASTER_CLK = 6MHz  (This is used by emFile for the SPI comm as a '/1' internal clock)

BUS_CLK = 6 MHz

This is basically what you had configured.

This is VERY important!!! => The emFile component "Max SPI frequency (KHz):" can be no higher than 1/2 MASTER_CLK.   = 3000 KHz = 3MHz.

Once I made these changes, the FS_FOpen() returns within a reasonable amount of time.  Note:  The lower BUS_CLK means the processor will be slower overall.

For some reason, the emFile has problems if the Max SPI freq exceeds MASTER_CLK/2.  I've tried to look at the code but Seggar, who supplied the emFile system component to Cypress, did not include the library source code.  (If you're willing to personally license emFile, you can get the source.)

Sadly, the Max_SPI_freq <= MASTER_CLK/2 relationship is NOT mentioned in any notes or forum threads I can find OR the datasheet.  It should be.

There must be something going on when the SPI comm is too fast compared to the CPU speed to process it.

UPDATE!!!

I found this in the emFile datasheet.  You'll note in RED, the 'hint' is that the BUS_CLK must be at least 2x the SPI frequency.

Len_CONSULTRON_0-1672152916723.png

No reason is given 'why' however.

 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

IREEN,

I believe I have solved the LFN support issue!!!

There is a small note in the emFile datasheet "Application Programming Interface".

Note To use long file names (LFN) support on PSoC 5LP devices, you must call FS_FAT_SupportLFN(). For PSoC 3 devices, this feature is enabled by default.

Therefore by adding the code line FS_FAT_SupportLFN(); after the FS_Init(); line it now finds > 8.3 LFNs.  Example:

FS_Init();
FS_FAT_SupportLFN();

Without it, the PSoC5 default to FS_FAT_SupportLFN = disabled and only 8.3 names are recognized.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

you are great LEN !!! you were able to fix this long file name problem and may be my clock problem !!!!

 i was testing, that why i have took some time to respond

So, i have tested my first  program i have posted on the forum,

with master clock/ bus clock equal both to 6MHz and SPI max frequency to 3000MHz and it works !!! sd good=1, i get the file with the result off the addition operation on the SD card as expected

I don't want to scream my joy yet because the RTC, which was working very well, is playing tricks on me,  even when the sd card board is empty ….(that moment when you fix something and the other part which worked breaks down )

I will try to see what is happening with the RTC and I will test on the 3.3 volt  059 kit,  reconstitute my big project to see if it works.

I will keep you informed,

 LEN, i can't thank you enough!!!

 

 

0 Likes
IREEN
Level 2
Level 2
10 replies posted First solution authored 5 replies posted

Hi LEN,

I've just finish, it took me two days to reconstitute my project and test it. yes, tired and ill 🤒  I did a lot of stupid things !! i will not boring you with it...........and certainly it's time for me to put on glasses , I missed several pin on the breadboard🙄.

LEN,  thanks for your valuable help on this forum😊 , you saved me ! many thanks!!!

PS : i'm gonna fixe the chosen solution on the forum

 

0 Likes