Weird bug in SD card code

Frank van den Hoef, who is adapting the Steckschwein SPI & FAT32 code for his tiny65 machine made me aware of a classic mistake for a 6502 assembly coder to make. Namely in our sdcard driver, when waiting for the “proper” response from the card (which should have bit 7 cleared). The routine handling this looked like this:

1  sd_cmd_response_wait:
2 	ldy #sd_cmd_response_retries
3 @l:	dey
4         beq sd_block_cmd_timeout ; y already 0? then invalid response or timeout
5         jsr spi_r_byte
6         bit #80	; bit 7 clear
7         bne @l  ; no, next byte
8         cmp #$00 ; got cmd response, check if $00 to set z flag accordingly
9         rts
10 sd_block_cmd_timeout:
11        debug "sd_block_cmd_timeout"
12        lda #$1f ; make up error code distinct from possible sd card responses to mark timeout
13        rts

Classic. Obviously, line 6 should read:

          bit #$80 ; bit 7 clear

With that fixed, the sd card init routine now fails, which is odd since we fixed something that was obviously broken.

sd_fail.jpg

Ok, now what? Enabling Marko’s mighty debugging macros, it becomes apparent that the sd card init fails right after sending CMD0 to the card. This command is the first command of the init sequence and is supposed to put the card into “idle mode”. Which the card confirms with an answer of $01. Which is what the init code is expecting, and not getting. Instead, we get $3F, which does not make a lot of sense.

But why did it work before the fix?
Assuming that the card did not change it’s behaviour at the same time I fixed the code, let’s check what actually happened. Before the fix, we were ANDing $3F with 80:

00111111 $3f
01010000 80 (no $, decimal)

In this case, the BNE after the BIT #80 would take the branch to @l, causing the next byte being read, until finally the card responds with $01:

00000001 $01
01010000 80 (no $, decimal)

Now the BNE does not take the branch, and the routine exits.

Now, with the fixed code,  ANDing $3F with $80, to check if bit 7 is clear, which it is:

00111111 $3F
10000000 $80

Alright, exit the loop and return $3f as response of the card. Which isn’t $01, so init failed.

At this point, I have no explanation for the card responding $3F. I assume that the card might be not ready to process commands at this point, so I added code to repeat sending CMD0 until we get $01 or we run out of retries.

 

 

Posted in assembly, code, debugging, murphy, SD-Karte, SPI

Forth Benchmarks

The main motivation to get Forth up and running on the Steckschwein was to participate at The Ultimate Benchmark, in order to crush all 8bit competition to dust.

So the plan was to benchmark the Steckschwein live at the VCFe. Unfortunately, Carsten could not be there, so no Forth benchmark competition this year.
Recently, Carsten presented his benchmark results using TaliForth2, which led us to run the same benchmarks he did and send the results to Carsten, who was kind enough to include them on his site:

https://theultimatebenchmark.org/#sec-7

 

Posted in Allgemein

NVRAM improvements

As real computer is not a real computer without a real time clock, the Steckschwein is no exception here. As we know, we use the Maxim DS1306 RTC, which is a very common RTC which comes as DIP IC and has an SPI interface. And of course it supports battery backup in various configurations. And this is where things get interesting.

Continue reading

Posted in bios, RTC, UART

VCFe 20.0 – over and out

VCFe 20.0 is over, all of a sudden, and we had lots of fun as always.

Many thanks to everyone stopping by at our table, especially to those who voted for us at the poll. We got the fo(u)rth place.

Special thanks to Michael Steil, Andre Fachat und Marco Baye for hanging and hacking with us.

Very special thanks to Andre Fachat for his inpromptu 6502 talk right before our turn. I think we did prepare a real feast for every 6502 afficionado.

Posted in Allgemein

Vintage Computer Festival Europe

Das VCFe steht wieder vor der Tür. Am kommenden Wochenende, also vom 27.4. bis 28.4., findet das Vintage Computer Festival Europe in München statt.

Das diesjährige Motto ist “Pixelritter – Programmieren am Limit”.
Und auch auf dem Steckschwein werden wir Pixel zeigen, teilweise am Limit programmiert.

Veranstaltungsort ist das Kulturzentrum Trudering

Wasserburger Landstrasse 32
81825 München

Posted in Allgemein

Make Munich 2019 – It’s been our pleasure

Make Munich 2019 was awesome. Thanks to everyone who helped making this great event possible.

Again, we are stunned by how much positive feedback we got from so many people. Thank you all!!

Also, like in 2016, our booth was partly turned by a lot of kids into the official Make Munich arcade. So we definitely need to write more games. And build more Steckschweins. Let the children play.

Posted in Allgemein

Meet us at Make Munich, 2.3. – 3.3.2019

Check out our homebrew 65c02 8bit goodness including our brand new video/sound-hardware at the Make Munich fair. We’ll also have BASIC, Forth, a couple of games and candy.
Our booth is in Hall 1, Booth Nr. 49, in the “Electronic Innovators”-Area. The did get that right, didn’t they?

 

 

 

Posted in Allgemein