Page 2 of 4

Re: FAT: faster way to write data

Posted: Tue Mar 18, 2014 3:54 pm
by Mathy
mikn wrote:
hardware SPI instead of software as I said in my previous post.
Sorry, I thought you are talking about external clock.
Should I use SPI instead of SDcard module in FC? Is there big difference?
No, the SDCARD component use the SPI function to read/write on your SDCARD but in your flowchart, I can see in the panel property that you use it in software mode.
In hardware mode, you will have much much faster transaction between your MCU and your SDCARD.

Re: FAT: faster way to write data

Posted: Tue Mar 18, 2014 4:02 pm
by Mathy
It is the setting im talking about

Re: FAT: faster way to write data

Posted: Tue Mar 18, 2014 5:00 pm
by mikn
Another thing to note (don't know if this has been covered) is that 8Kz reads into 512 bytes takes 64ms. If the FAT write is 100ms you will always get a loss unless you increase your buffer size to 3 sections, so 0x600 bytes in your buffer.
Currently I have buffer size of 4096 bytes and while it fills second part of buffer I do write first part to sdcard (4 write operations by 512 bytes). You say 100ms for FAT write operation. Is there big difference in writting 512 bytes and 2048 bytes? 100ms*4 or less?
It is the setting im talking about
I tried to change this but it changes pinout also. DI and DO pins are connected to another, not standart Channel1 or Ch2 pins.

Re: FAT: faster way to write data

Posted: Tue Mar 18, 2014 6:03 pm
by Mathy
The peripheral pin select feature is your friend !
You can remap the SPI hardware peripheral pins to others pins if you want.
You can do this by adding c code or with the tips given by Benj in one of my previous post : http://www.matrixmultimedia.com/mmforum ... 54&t=14502

Re: FAT: faster way to write data

Posted: Tue Mar 18, 2014 10:29 pm
by mikn
You can remap the SPI hardware peripheral pins to others pins if you want.
You can do this by adding c code or with the tips given by Benj in one of my previous post : viewtopic.php?f=54&t=14502
Thanks for advice. I've added CAL_SPI and remapped pins to my own (set CAL_SPI to Channel1), then set FAT component to Channel1.
That didn't work. Should I do it different way?
When I put FAT component's Channel to Ch1 it gives me only CS parameter to edit. Others are set by default and non-editable. What I mean is when I do FAT.Initialize, doesn't it take these pins for initialize operation by default even if I remapped them with CAL_SPI or C code injection?

C code inserted at the beginning (didn't work too)

Code: Select all

// Unlocks PPS, make change, and locks again.
__builtin_write_OSCCONL(OSCCONL & ~(1 << 6));

_SS1R = 15; //B15 chip select
_SDI1R = 6; //B6 data in
_RP14R = 7; //B14 data out
_RP7R = 8; //B7 sck1out

__builtin_write_OSCCONL(OSCCONL | (1 << 6));

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 9:37 am
by Mathy
I think in the V6 Flowcode release, the best way to remap pin on existing component is the tips given by Benj which is a great improvement compared to the V5.

Benj said :

"Open the window via the view menu and tick the "expose full component tree" setting.

Next click the drop down menu at the top of the properties window and you can now see all the things that make up the TCP IP component. Select the CAL_SPI component and there are options there to allow you to set the prescaler."

Your problem is not the prescaler but the PPS feature but you have to do that to access to the remap feature.

I will post some screenshots.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 9:50 am
by Mathy
I don't understand very well your post, my english is not good enought so I don't know if you made the thing i've done in the screenshot.
You have in the attached file your flowchart with the modifications.

Tell me if it works.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 10:54 am
by mikn
yes, i did it with CAL_SPI module. It didn't work, program is stuck on FAT.Initialize and doesn't go further (led must blink twice during init circle, but it stays switched on. it means that the "while" loop doesn't continue to next step).

below are screenshots of components settings
CAL_SPI:
Image
FAT:
Image

I wonder if settings which I've marked with circle must change after I remapped pins in CAL_SPI?

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 11:21 am
by Mathy
There is maybe a little problem with Flowcode because I re open your program and I loose the changes I made.

I think you have to set the correct pin assignment in the cal_spi property,
You have to return to the fat component property and choose again software channel and then choose hardware.
That will import the settings you just entered in the cal_spi property.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 11:30 am
by mikn
I think you have to set the correct pin assignment in the cal_spi property,
You have to return to the fat component property and choose again software channel and then choose hardware.
Yes, I did it, but FAT settings for Ch1 left the same as default.
I also created new FAT component (FAT2) and it took default settings, not those which I have remapped with CAL_SPI.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 11:35 am
by Mathy
You made exactly the same things that I explained ?
As you can see in my attached file, Im able to have correct settings.
Set again in software channel and then, re-set hardware channel import the new settings from the cal_spi properties.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 11:46 am
by mikn
I do it exactly right way.
1. Set FAT to Software.
2. Created CAL_SPI component
3. remapped CAL_SPI pins to my own. Channel1, MOSI=14, MISO=6, CLK=7
4. Set FAT component from Software to Channel1
5. FAT settings got disabled with following values: MISO=13, MOSI=8, SCK=4.

Where am I wrong? Looks like a bug.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 11:53 am
by Mathy
Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh !
I understand what you are doing wrong.
You don't have to create CAL_SPI component. You have to read carefully my post.
As Benj said, you have to :

"Open the window via the view menu and tick the "expose full component tree" setting.

Next click the drop down menu at the top of the properties window and you can now see all the things that make up the FAT component. Select the CAL_SPI component and there are options there to allow you to set the prescaler."

Your problem is not the prescaler but the PPS feature but you have to do that to access to the remap feature.

As you can see in the attached file, I don't created CAL_SPI component, the CAL_SPI appears only after tick the "expose full component tree" setting.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 12:19 pm
by mikn
Found it now.
"Open the window via the view menu and tick the "expose full component tree" setting."
I didn't understand which window to open, now I found this checkbox in Component debugger.

Channel1 pins in FAT changed to new ones, which I need. But it still freezes on FAT.Initialize step. When I switch to Software - it works. When switch back to Channel1 - it stucks.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 12:33 pm
by Benj
Hello,

I was sure I had already brought through the remap pins to all components but must have missed the FAT component. Here is an updated component which brings the remap pins right the way through to the FAT properties so you don't have to hack your way in and do it to the CAL layer.
FAT.fcpx
(62.73 KiB) Downloaded 175 times
Copy the file to your "Flowcode 6/Components" directory and re-start Flowcode or reload the project to see the changes.

I have come across a hardware SPI lockup on a ECIO device but then been unable to replicate it. I will re-invstigate this with dsPIC just in case I missed anything.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 1:12 pm
by mikn
Updated FAT component but it became as a dot without properties. :-\
Below is the screenshot:
Image

UPD: tried to add new FAT, it says: Failed to add the component: FAT (SD,SDHC)

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 5:26 pm
by Mathy
Benj wrote:Hello,

I was sure I had already brought through the remap pins to all components but must have missed the FAT component. Here is an updated component which brings the remap pins right the way through to the FAT properties so you don't have to hack your way in and do it to the CAL layer.
FAT.fcpx
Copy the file to your "Flowcode 6/Components" directory and re-start Flowcode or reload the project to see the changes.

I have come across a hardware SPI lockup on a ECIO device but then been unable to replicate it. I will re-invstigate this with dsPIC just in case I missed anything.
Hi Benj,

What is the problem with dsPIC hardware SPI ?
I have a board with dsPIC33FJ128MC804 at home, maybe I can make a test for you.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 5:29 pm
by Mathy
mikn wrote:Found it now.
"Open the window via the view menu and tick the "expose full component tree" setting."
I didn't understand which window to open, now I found this checkbox in Component debugger.

Channel1 pins in FAT changed to new ones, which I need. But it still freezes on FAT.Initialize step. When I switch to Software - it works. When switch back to Channel1 - it stucks.
Do you have a scope to see what is happening on the SPI lines ?
Maybe try to set prescaler to 16 or 64 instead of 4 to reduce the SPI clock speed.

Re: FAT: faster way to write data

Posted: Wed Mar 19, 2014 5:37 pm
by mikn
Mathy wrote: Do you have a scope to see what is happening on the SPI lines ?
Maybe try to set prescaler to 16 or 64 instead of 4 to reduce the SPI clock speed.
No, I don't have it.
Tried to play with clock (changing form 4mhz upto 32mhz), with oscillator (FRC, FRC with PLL, with Prescaler), also played with FAT prescaler, made it /4, /16, /64. I even changed 3 different sd cards. Nothing helped. When I switch to Software - it works. When I switch to Channel1 or Channel2 (pins are correct now) - it stucks on the step FAT.Initialize. Most interesting that it totally freezes on this step and not rotating in "while" loop. :?

Re: FAT: faster way to write data

Posted: Fri Mar 21, 2014 12:31 am
by mikn
any updates?

Re: FAT: faster way to write data

Posted: Wed Apr 02, 2014 9:06 pm
by mikn
Returned back to this project. Again problem with FAT component and I found some other issue with pins.

Did some tests:
1st test - Software mode, MOSI=B14, MISO=B6 - initialized ok, created file.
2nd test - Channel 1, MOSI=B14, MISO=B6 - not initialized, retval>0
3rd test - back to Software mode, all same as test#1 - not initialized, retval>0.....
4th test - same Software mode, but exchanged pins MOSI=B6, MISO=B14 - initialized ok, created file.

I am confused. Seems like MOSI and MISO parameters get mixed during compilation or somewhere else...

Re: FAT: faster way to write data

Posted: Thu Apr 03, 2014 2:07 pm
by Benj
Hello,

To help sanity check this I would advise opening the "Component Debugger" window and ticking the "Expose full component tree" tickbox.

Then on the properties window you can use the drop down list right at the top to go into the FAT component to the cal_spi component to check that the settings you have assigned via the FAT component have been transferred to the SPI layer correctly.

If you see a repeatable problem then let me know and I will get right on it.

Re: FAT: faster way to write data

Posted: Thu Apr 03, 2014 8:08 pm
by mikn
Checked as you said, everything looks similar to main FAT properties.
The problem still continues: once I set Software channel - it works (writting of 4096 bytes (4x512 bytes) takes around 2.5 seconds according to my test led blinks). Once I change to Channel1 or Channel2 with same pins, it freezes on FAT::Initialize step

Re: FAT: faster way to write data

Posted: Tue Apr 08, 2014 9:51 pm
by mikn
Benj, any news on this issue?

Reviewed the generated C code. Isn't it a mistake with remappable pins? According to datasheet of my pic, RPs must be different.

Re: FAT: faster way to write data

Posted: Wed Apr 09, 2014 12:21 pm
by LeighM
Hi
Thanks for the screen shots.
MOSI_SDO “7” and CLK_SCK “8” are the Output Function Numbers for SPI1 Data and Clock outputs, and not related to port pin numbers.
The outputs are directed to RP14 and RP7.
Which looks correct. Hope that helps.
Leigh