RetroBSD

2.11BSD operating system for microcontrollers
It is currently Sun Mar 29, 2020 1:01 pm

All times are UTC




Post new topic Reply to topic  [ 47 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Thu Nov 12, 2015 9:07 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Task swap mid write? Don't forget that RetroBSD has to dump it's whole memory to swap when task switching but LiteBSD does it in RAM and only needs to access the SD rarely for task switching.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Thu Nov 12, 2015 9:23 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
But that will influence the read as well..
Attachment:
sdcards rdwr.JPG
sdcards rdwr.JPG [ 28.68 KiB | Viewed 18958 times ]

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Thu Nov 12, 2015 9:55 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
I would expect something like this:
Attachment:
sdcards rdwr2.JPG
sdcards rdwr2.JPG [ 36.5 KiB | Viewed 18955 times ]

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Thu Nov 12, 2015 10:19 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Quote:
But that will influence the read as well..

Only if it actually happens during a read. A read is faster than a write, and thus takes less time - so less chance of swapping happening during the write.

You should try your tests in single user mode so there are no other processes running - such as cron, etc.

Cron could be the cause - it wakes every minute. With a 6 second read there's a 1-in-10 chance of it waking while reading. With a 20 second write a 1-in-3 chance.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Thu Nov 12, 2015 11:05 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
How can I invoke single user on retrobsd?

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Thu Nov 12, 2015 11:14 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
You normally hold a button down while you boot - if there is a button and it's configured. Either that or you can do it through the shutdown command.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Fri Nov 27, 2015 9:47 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
The SDcard SPI frequencies for pic32mx and RetroBSD:
Attachment:
SD_SPI_FREQ.JPG
SD_SPI_FREQ.JPG [ 65 KiB | Viewed 18730 times ]

I've done almost all interesting combinations (Fubarino SD baremetal), SPI at 30-40MHz works but not 100% stable.
It seems the 48/24 is the optimal balance, or with a little bit overclocking 96/24 is the most powerful combination.

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Fri Nov 27, 2015 11:42 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
v470 with built-in cmd6:
Code:
2.11 BSD Unix for PIC32, revision G470 build 5:
     Compiled 2015-11-28 by pito@UBU1404:
     /home/pito/Retronew/retrobsd/sys/pic32/baremetal
cpu: 795F512H 48 MHz, bus 48 MHz
oscillator: HS crystal, PLL div 1:3 mult x18
spi2: pins sdi=RG7/sdo=RG8/sck=RG6
uart2: pins rx=RF4/tx=RF5, interrupts 40/41/42, console
sd0: port SPI2, pin cs=RG9
gpio1: portB, pins iiiiiiiiiiiiiiii
gpio2: portC, pins iiii------------
gpio3: portD, pins ----iiiiiiii---i
gpio4: portE, pins --------iioiiiii
gpio5: portF, pins ------------i-ii
gpio6: portG, pins ------------ii--
adc: 15 channels
pwm: 5 channels
sd0: type SDHC, size 7838720 kbytes, speed 24 Mbit/sec, current 200 mA
sd0a: partition type b7, sector 2, size 204800 kbytes
sd0b: partition type b8, sector 409602, size 2048 kbytes
sd0c: partition type b7, sector 413698, size 102400 kbytes
phys mem  = 128 kbytes
user mem  = 96 kbytes
root dev  = (0,1)
swap dev  = (0,2)
root size = 204800 kbytes
swap size = 2048 kbytes
/dev/sd0a: 1515 files, 15163 used, 188836 free
/dev/sd0c: 3 files, 3 used, 101996 free
I2C dev found, addr(r/w): 00(01/00)  1E(3D/3C)  4C(99/98)  53(A7/A6)  57(AF/AE)  68(D1/D0)  69(D3/D2)  77(EF/EE)
Sat Nov 28 00:37:32 CET 2015
Starting daemons: update cron


2.11 BSD UNIX (pic32) (console)

login:

You have to use (in Config):
Code:
options         "SD_FAST_MHZ=24"   

With:
Code:
options        "SD_MHZ=24"
it did not find the filesystem and the sdcard size was 1kB.

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 12:01 am 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Hi Pito,
I finally managed to merge your changes into the SD driver. Seems like it works pretty stable on Fubarino board with default CPU speed. I've tested it with a dozen of different cards, and all work fine.

Now we have two kernel options to control the SD clock:
Code:
options "SD_MHZ=12"
options "SD_FAST_MHZ=25"

A capability of the SD card to support high-speed mode is automatically detected. For legacy cards which don't support high-speed mode, SD_MHZ clock is used, which is close to the max 12.5MHz value, as defined in the spec. For newer cards, max clock is defined as 25MHZ, so the driver uses SD_FAST_MHZ option.

There is no need to specify exact values, as the SPI driver will use the nearest possible clock. Default values should work fine in your case.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 12:12 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Great!!
Btw, the SD_MHZ=24 did a panic.
Also there is none such frequency like 12 or 12.5MHz with default 80MHz (see the table above).

I like the mA information :).

You are using 0x80000001, people recommend 0x80FFFFF1, as the active cmd6 settings are with 6 lower nibbles, and "F" means "no change" (with 0 there you will overwrite default to 0).

What about "power" and "driver strength" settings ?? :)

My card shows 200mA * 3.6V = 0.72W (max).. That is for the lowest standard SDR12 speed.

SD specification says the High Speed mode (SDR25 and SDR50) may require higher max_power settings. It may require higher drivers too. See http://retrobsd.org/viewtopic.php?f=5&t=37313#p42261

I use 0x80FF11F1 here, it works fine.. (0x80FF22F2 could be even better, not tested yet).

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 12:33 am 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
There is not much sense to increase SD_MHZ much above allowed 12.5MHz, as the card usually becomes instable. From my experience, with 13.3MHz (which is used in case of 80Mhz cpu clock) all the cards work OK, but 16.6MHZ is already too much.

Well, I'm not sure F (no change) is a proper choice, as the default mode for all the groups is 0 anyway.

As for power and driver strength - I tried to print out the capability masks returned in a 64-byte reply from CMD6 command. All the cards I tried don't support anything other than modes F and 0 for groups 2..6, and modes F, 1 and 0 for group 1. So there is nothing to experiment with.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 12:40 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Maybe for the next release - could you add the 4(6) group's figures into the sdcard information - like
Code:
sd0: type SDHC, size 7838720 kbytes, speed 24 Mbit/sec, current 200 mA, 0/0/0/1
plz (the figures _after_ the setting by the cmd6) ?

Btw, my naïve understanding is following - firstly the sdcard shows the defaults, when you change the defaults to an another figure, the card answers again, and when the card's answer is equal to the new figure, the figure has been set (= the new figure is supported by the sdcard)..
Not sure you can change ie. all 3 values at once, but it needs to be done per partes (and you have to use the F for no change then).

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 1:36 am 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
OK; try rev471.
It will print the bitmasks of function groups capabilities, like:
Code:
sd0: function groups 3/1/1/1/1/1, max current 100 mA
sd0: type SDHC, size 7822336 kbytes, speed 20 Mbit/sec

Value 3/1/1/1/1/1 means that group 1 supports functions 0 and 1, and groups 2...6 support only function 0.

CMD6 always replies with a status message that contains a current mode for all six groups, as well as bitmasks of supported modes (which we print). It makes little sense to print current mode, as it will always be 1/0/0/0/0/0.

It's possible to switch all the function groups at once. Only group 1 is implemented in hardware, though.


Top
 Profile  
 
PostPosted: Sat Nov 28, 2015 11:03 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
1.
Quote:
Value 3/1/1/1/1/1 means that group 1 supports functions 0 and 1, and groups 2...6 support only function 0.
I am so confused now..
So it means 3/1/1/1/1/1 = G1/G2/G3/G4/G5/G6 ?
If that is a mask then the G1 (speed) supports 0-3, and the others 0-1, hmmm..
My Sammy CL10 UHS-I returns:
Code:
sd0: function groups 3/1/1/1/1/1, max current 200 mA
sd0: type SDHC, size 7838720 kbytes, speed 24 Mbit/sec


2. The other issue is the CMD6 has got two modes - Check and Set.
We currently handle the Set function only.

Check is Mode0 with 0x0....... (bit31=0)
Set is Mode1 with 0x8....... (bit31=1).

Code:
4.3.10.2 Mode 0 Operation - Check Function
CMD6 mode 0 is used to query which functions the card supports, and to identify the maximum current/power consumption of the card under the selected functions.
Refer to Table 4-31: Switch function commands (class 10) for the argument definition of CMD6.
A query is done by setting the argument field of the command, as follows:
• Set the Mode bit to 0
• Select only one function in each function group. Selection of default function is done by setting the function to 0x0. Select a specific function by using appropriate values from Table 4-11. Selecting 0xF will keep the current function that has been selected for the function group.
• When the function in query is ready, the card returns the inquired function number, if busy, the card returns the current function number (See Table 4-15).
In response to a query, the switch function will return the following 3 statuses (see Table 4-13):
• The functions that are supported by each of the function groups
• The function that the card will switch to in each of the function groups. This value is identical to the provided argument if the host made a valid selection or 0xF if the selected function was invalid.
• Maximum current/power consumption under the selected functions. If one of the selected functions was wrong, the return value will be 0.

4.3.10.3 Mode 1 Operation - Set Function
CMD6 mode 1 is used to switch the functionality of the card.
Switching to a new functionality is done by:
• Setting the Mode bit to 1
• Selecting only one function in each function group. Selection of default function is done by set-ting the function to 0x0. It is recommended to specify 0xF (no influence) for all selected functions, except for functions that need to be changed. Selecting 0xF will keep the current function for the function group.
• When a function cannot be switched because it is busy, the card returns the current function number (not returns 0xF), the other functions in the other groups may still be switched.
In response to a set function, the switch function will return the following 3 statuses:
• The functions that are supported by each of the function groups
• The function that is the result of the switch command. In case of invalid selection of one function or more, all set values are ignored and no change will be done (identical to the case where the host selects 0xF for all functions groups). The response to an invalid selection of function will be 0xF.
• Maximum current/power consumption under the selected functions. If one of the selected functions was wrong, the return value will be 0.
:?

3. The spec says the actual switch occurs ~8 clocks after the receipt of status data
Attachment:
cmd6 timing.JPG
cmd6 timing.JPG [ 113.26 KiB | Viewed 18461 times ]

We do not wait 8 (slow) clocks but switch the SPI to higher speed.

4. I've seen somewhere it is recommended to wait 10msec after each cmd6, before we start to read the statuses.

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Sun Nov 29, 2015 9:17 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Well, I've tried harder and I've printed out the cmd6 stuff:
Code:
Check 0x00001001:

0 0 80 1 80 1 80 1 80 1 80 1 80 3 0 f0         <<< group4 error - does not support 1.44W
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0                      <<< supports HS
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sd0: Check function groups 3/1/1/1/1/1

Set 0x80FF1FF1:

0 0 80 1 80 1 80 1 80 1 80 1 80 3 0 f0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sd0: Set function groups 3/1/1/1/1/1


Check 0x00000001:

0 c8 80 1 80 1 80 1 80 1 80 1 80 3 0 0                      <<< c8 is 200mA (0.72W)
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0                                  <<< supports HS
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sd0: Check function groups 3/1/1/1/1/1, max current 200 mA

Set 0x80000001:

0 c8 80 1 80 1 80 1 80 1 80 1 80 3 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sd0: Set function groups 3/1/1/1/1/1, max current 200 mA


And "80 03" in the First Group means (1/0 per function in 16bits):
function 15-supported
function 1-supported
function 0-supported
(functions 15 and 0 are always supported).
"F" in statuses means "error - not supported". Interestingly it does not show power when F in G4 status.

Code:
      ------Capabilities flags----------- grp.stat
power grou6 grou5 grou4 grou3 grou2 grou1 65 43 21
00 c8 80 01 80 01 80 01 80 01 80 01 80 03 00 00 01

      ------Capabilities flags----------- grp.stat
power grou6 grou5 grou4 grou3 grou2 grou1 65 43 21
00 00 80 01 80 01 80 01 80 01 80 01 80 03 00 F0 01


Crazy stuff, indeed.. :shock:

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Mon Nov 30, 2015 9:30 am 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Pito and all,

Writing specs is crazy stuff indeed :).

If you write the specs, you can REALLY harass your 'competition'.

This was the basis of my much earlier comment about leaving USB alone. Too many BIG players harassing each other. USB is not universal and it is NOT a bus at least as I understand the term!

For us, I very much like the idea of open clear documentation so we can still keep our stuff running even when the basic operation of things like SD cards and USB protocol make huge changes as the BIG players harass each other.

Isn't it amazing that the RS-232 serial interface still 'just works' for most folks! Even OEMs have standardized on pin 9 for +5 power.

I am amazed that the parallel port has essentially died. I guess it REALLY needed a defined power pin (pin 25?). We ALL recreate parallel types of operations on our various computers without an real standardization. What a pain!

Another BIG nail in the parallel port coffin with the various 'enhanced' modes and IBM not making it 2 way from the beginning.

From what I see the big contribution of RaspPi is their B+ port. From what I see it is a total kludge, but at least some sort of 'standard'.

Maybe we should try to define one for us?

Lots of fun :).

Wiz


Top
 Profile  
 
PostPosted: Mon Nov 30, 2015 11:09 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Our "standard" is the Arduino Uno footprint. Ghastly, but at least there's lots of stuff you can just plug in...

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Mon Nov 30, 2015 9:33 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Pito wrote:
So it means 3/1/1/1/1/1 = G1/G2/G3/G4/G5/G6 ?

Exactly. These are the same bitmasks you see in your next comment as "80 01". I just removed the high bit for simplicity, as mode F is obviously always supported.

In G1 group, bits 0 and 1 are set, which means mode 0 (default) and mode 1 (high-speed) modes are supported.
In G2-G6, only bit 0 is set, as only mode 0 (default) is supported.

Pito wrote:
2. The other issue is the CMD6 has got two modes - Check and Set.
We currently handle the Set function only.

Well, it's possible to check the bitmasks first and then set the mode when supported. It would cost two commands instead of one with the same result. I don't think it makes sense to complicate the code.

Pito wrote:
3. The spec says the actual switch occurs ~8 clocks after the receipt of status data. We do not wait 8 (slow) clocks but switch the SPI to higher speed.

It works pretty stable without any additional clocks. I don't know how to explain the effect, but I would prefer to keep the code simple until any issues arise.

Pito wrote:
4. I've seen somewhere it is recommended to wait 10msec after each cmd6, before we start to read the statuses.

There is nothing about a delay in the spec. It's enough just to wait for the DATA_START_BLOCK byte, like any other commands.


Top
 Profile  
 
PostPosted: Tue Dec 01, 2015 7:31 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
The 8 clocks switch - I would guess today it switches when SPI is already in fast mode. Because our retrobsd's "fast" mode is basically a "slow" one, it does not matter..

It could be a problem with Litebsd though - 50MHz is much faster..

It is a matter of 2 lines after the statuses loop:

Code:
    /* Read 64-byte status. */
    for (i=0; i<64; i++)
        status[i] = spi_transfer(io, 0xFF);

    /* Make at least 8clocks to switch over to HS */
    for (i=0; i<2; i++)
        spi_transfer(io, 0xFF);
    sd_deselect(io);

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Tue Dec 01, 2015 7:49 am 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Pito and Serge,

It may sound a little bit opposed to progress, but I generally slow things down below their specified rates. so that when users plug whatever stuff into my boxes, my boxes still work without a glitch.

So I would vote for using more relaxed speed specs [75% or so] unless the user directs our software to go as fast as you can.

In other words, I try to stay away from the 'bleeding edge' as I have heard it called.

Lots of fun :).

Wiz


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 47 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission