FAT: faster way to write data

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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.

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post by Mathy »

It is the setting im talking about
Attachments
softvshard.jpg
(290.59 KiB) Downloaded 1098 times

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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.
FC 6.1.3.2 (18.02.2016)

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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));
FC 6.1.3.2 (18.02.2016)

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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.

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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.
Attachments
Flowcode1sma.fcfx
(16.13 KiB) Downloaded 217 times
PPS.jpg
(384.49 KiB) Downloaded 1083 times

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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?
FC 6.1.3.2 (18.02.2016)

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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.
Attachments
FAT.jpg
FAT.jpg (69.32 KiB) Viewed 11721 times

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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.
FC 6.1.3.2 (18.02.2016)

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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.
FC 6.1.3.2 (18.02.2016)

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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.
Attachments
FAT_CAL_SPI.jpg
FAT_CAL_SPI.jpg (29.42 KiB) Viewed 11714 times

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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.
FC 6.1.3.2 (18.02.2016)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT: faster way to write data

Post 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 158 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.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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)
FC 6.1.3.2 (18.02.2016)

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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.

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FAT: faster way to write data

Post 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.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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. :?
FC 6.1.3.2 (18.02.2016)

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post by mikn »

any updates?
FC 6.1.3.2 (18.02.2016)

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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...
FC 6.1.3.2 (18.02.2016)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT: faster way to write data

Post 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.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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
Attachments
sc-fat11.GIF
sc-fat11.GIF (29.64 KiB) Viewed 11611 times
FC 6.1.3.2 (18.02.2016)

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: FAT: faster way to write data

Post 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.
Attachments
sc-rpins.GIF
sc-rpins.GIF (56.77 KiB) Viewed 11590 times
FC 6.1.3.2 (18.02.2016)

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: FAT: faster way to write data

Post 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

Post Reply