6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Oct 23, 2024 2:26 pm

All times are UTC




Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: SD Card interfacing
PostPosted: Tue Oct 15, 2013 5:53 am 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
enso wrote:
Arlet, your 6502 core is perhaps the smallest usable general purpose core for FPGAs (I like Picoblaze, but it is only good for very small applications), and at 45MHz it can go head to head with many modern microcontrollers. There are a lot of 6502 tools out there as well. I know I am preaching to the choir, but it is hardly that odd to chose a 6502 core for a small FPGA.

If you already need an FPGA for something else, and also need a simple control processor, the 6502 is a decent choice. I've actually used it for a commercial project for the reasons you've stated. But if your project doesn't otherwise need an FPGA, I can't think of a good reason to use a 6502, except for fun.


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Wed Oct 16, 2013 9:17 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Arlet wrote:
I've actually used it for a commercial project for the reasons you've stated. But if your project doesn't otherwise need an FPGA, I can't think of a good reason to use a 6502, except for fun.

I'm curious, what commercial project?
If you're a novice to FPGA design and you have programmed the 6502 before, this is a perfect reason to use a softcore 6502 IMO. The bridge is already there for programming.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Wed Oct 16, 2013 9:34 am 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
ElEctric_EyE wrote:
I'm curious, what commercial project?

Custom camera interface over serial port. Board had a VGA camera module, some SDRAM and an FPGA for grabbing video. Over the serial link you could talk to the 6502, and request (part of) the image. I needed a simple CPU, and I had recently finished my 6502 core, so I decided to use that. The core was capable enough, and I was already familiar with it.


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Mon Nov 04, 2013 6:25 pm 
Offline

Joined: Fri Sep 20, 2013 4:35 pm
Posts: 32
Hey guys,

Does anyone have any empirical data on SD card performance with 6502s? I have a 1Mhz system and am bit banging SPI using a 6522. I am getting about 170ms read time per 512-byte sector. I'm curious what timings others are getting who are bit-banging or using Daryl's 65SPI chip. I'm also curious how long a sector read takes on an 16mhz (or so) AVR.

The perf isn't terrible as compared to 6502 systems from decades ago, but it is definitely noticeable. My brain keeps filling in the head seeking noise as it follows chains in the FAT :-)


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Nov 28, 2013 1:59 am 
Offline

Joined: Sun Sep 11, 2011 6:38 am
Posts: 13
Location: Singapore
Hi,
I was using a SD card with FatFs on a Apple 2 with a VIA 6522 card.
The VIA shift register is used for sending a byte to the SD card, whereas a bit-bang routine (from some C64 group on the Net) was used for receive.
A low ohm resistor is placed between CB1 (SR clock for Send) and Port B0 (Bit-Bang Clk for Receive) just to isolate the outputs. (I've no better way to connect the pins (B0 and CB1) to the SCK the SD card).
Diodes are used to isolate the 5V outputs from the 3.3V inputs of the SD card (with pullups to 3.3V)
A drawing is desperately needed here! Anyway it works with NMOS and CMOS 6522.

Below is a snippet of the bit-banged code for receiving a byte from the SD card (rcvr_mmc).
Just follow the pin connections on Port B. ~12 clocks per bit when unrolled.
Code:
=======================================================
; Faster loading when used SR as output compared to when SR used as input
;  SCK Bit 0  // Serial Clock (output)                SD Pin 5
; MOSI CB2 // Master Out / Slave In (output)       SD Pin 2
; MISO Bit 7 // Master In / Slave Out (input)        SD Pin 7
;   CS Bit 2  // Slave Select                         SD Pin 1
; CB1 - clock jumpered to SCK (through 40 ohm resistor )
; CB2 - MOSI

via_ora equ $c0f1
via_orb equ $c0f0
via_dra equ $c0f3
via_drb equ $c0f2
via_sr  equ $c0fa
via_acr equ $c0fb
       
; Preserve X-Reg if used ..phx ...plx
; ACC and Y-Reg always destroyed

via_init:
        lda     #$7f
        sta     via_drb
        lda     #$18    ; shift reg clocked by Phase 2
        sta     via_acr
        rts
 
 
xmit_mmc:
        sta via_sr
        rts
 
 
;xmit_mmc:
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya        ;(2)
;        asl a      ;(2)
;        and #$80   ;(2)
;        sta via_orb ;(4)
;        inc via_orb ;(6)   
       
;        rts

;rcvr_mmc:  ; shift register in using phase 2 - ACR=0x08
;        lda     via_sr
;        nop             ; min 14 cycles between for 1 byte
;        nop
;        nop
;        nop
;        nop
;        nop
;        nop
;        lda     via_sr       
;        rts


rcvr_mmc: 
 
        ldy        #$01     ; set clk hi
        lda        #$00                         
        sta        via_orb  ; clk lo, cs lo

        sty        via_orb     ; clk hi, data will be in bit 7 shortly   (4)
        asl        via_orb     ; data in bit 7, clk lo after shift left  (6)
        rol        a           ; carry into A                            (2)

       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
       
               
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, last bit comes in
        cpy        via_orb     ; (4) no need to clear clk
        rol        a
        eor        #$01        ; fix first last bit0
       
        rts

       end


Last edited by lak on Thu Nov 28, 2013 4:15 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Nov 28, 2013 2:57 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8524
Location: Southern California
lak, put [code] and [/code] around your code to keep the spaces and make it monospaced so things line up the way you intended. Make sure the "Disable BBCode" box is not checked. If you're signed in, you can go back and edit your post above.

Thanks for the code.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Nov 28, 2013 3:24 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8448
Location: Midwestern USA
I reformatted his source code.

Code:
=======================================================
; Faster loading when used SR as output compared to when SR used as input
;  SCK Bit 0  // Serial Clock (output)                SD Pin 5
; MOSI CB2 // Master Out / Slave In (output)       SD Pin 2
; MISO Bit 7 // Master In / Slave Out (input)        SD Pin 7
;   CS Bit 2  // Slave Select                         SD Pin 1
; CB1 - clock jumpered to SCK (through 40 ohm resistor )
; CB2 - MOSI

via_ora equ $c0f1
via_orb equ $c0f0
via_dra equ $c0f3
via_drb equ $c0f2
via_sr  equ $c0fa
via_acr equ $c0fb
       
; Preserve X-Reg if used ..phx ...plx
; ACC and Y-Reg always destroyed

via_init:
        lda     #$7f
        sta     via_drb
        lda     #$18    ; shift reg clocked by Phase 2
        sta     via_acr
        rts
 
 
xmit_mmc:
        sta via_sr
        rts
 
 
;xmit_mmc:
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya
;        asl a
;        tay
;        and #$80
;        sta via_orb
;        inc via_orb
       
;        tya        ;(2)
;        asl a      ;(2)
;        and #$80   ;(2)
;        sta via_orb ;(4)
;        inc via_orb ;(6)   
       
;        rts

;rcvr_mmc:  ; shift register in using phase 2 - ACR=0x08
;        lda     via_sr
;        nop             ; min 14 cycles between for 1 byte
;        nop
;        nop
;        nop
;        nop
;        nop
;        nop
;        lda     via_sr       
;        rts


rcvr_mmc: 
 
        ldy        #$01     ; set clk hi
        lda        #$00                         
        sta        via_orb  ; clk lo, cs lo

        sty        via_orb     ; clk hi, data will be in bit 7 shortly   (4)
        asl        via_orb     ; data in bit 7, clk lo after shift left  (6)
        rol        a           ; carry into A                            (2)

       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
       
               
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, data will be in bit 7 shortly
        asl        via_orb     ; data in bit 7, clk lo after shift left
        rol        a           ; carry into A
       
        sty        via_orb     ; clk hi, last bit comes in
        cpy        via_orb     ; (4) no need to clear clk
        rol        a
        eor        #$01        ; fix first last bit0
       
        rts

       end

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Nov 28, 2013 5:50 am 
Offline

Joined: Sun Sep 11, 2011 6:38 am
Posts: 13
Location: Singapore
BDD, thanks for formatting the code.
I was in a hurry. Hope it's useful.


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Nov 28, 2013 6:50 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8524
Location: Southern California
lak, you put [code] and [/code] around your code, but you did not uncheck the "Disable BBCode" box. Do that and you'll get the appearance you wanted.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Nov 28, 2013 10:38 am 
Offline
User avatar

Joined: Fri Oct 31, 2003 10:00 pm
Posts: 200
Lak,

Thanks for sharing the code! Good read!


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Feb 25, 2016 11:49 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
As a FYI addition to this thread, I have found that Adafruit has a breakout board for MicroSD cards that can handle 3.3V and 5V (which means it should work with the 5V-only 65SPI, if I understand things correctly): https://www.adafruit.com/product/254 There is also a tutorial, though obviously for the Arduino: https://learn.adafruit.com/adafruit-mic ... l?view=all


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Fri Feb 26, 2016 11:19 am 
Offline

Joined: Wed Nov 18, 2015 8:36 am
Posts: 102
Location: UK
Hi, interesting thread. I have a bit-banged SPIO interface wired to a similar board from hobbytronics. My 6502 is running @ 2.7Mhz and the raw transfer speed is about 8.5KB/s. But as mentioned by others, that raw speed is not achievable in real world situations - the FAT16 driver software requires multiple reads and updates to FAT and Directory tables to do practical things like creating files. I hope the log below helps:

https://hackaday.io/project/5789-6502-h ... -interface


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Oct 06, 2016 8:09 pm 
Offline

Joined: Thu Oct 06, 2016 8:04 pm
Posts: 3
Hi gentlement, I have an issue at hand that is even more intriguing than how to use an SD card via bit banging, and that is,

How do you *emulate an SD card using bit banging*?

I.e. you have an ARM chip plugged in as SD card to a host machine, and that host machine (e.g. Windows whatever) will see a block device/disk however that disk's contents is delivered by the ARM chip software, and it would source the content from anywhere, e.g. from its own memory or even an SD card that it itself has.


Finally what about using Teensy 3.5, Raspberry Pi, LM3S811 (used in this related project http://webpages.uncc.edu/~jmconrad/ECGR ... ROLLER.pdf / ftp://ftp.circuitcellar.com/pub/Circuit ... ne-209.zip) - or what would be the tiniest footprint and cheapest hardware to do this? (Preferably with a microSD slot on it still.)

Please let me know, thanks!!


(Related threads: https://forum.pjrc.com/threads/37739-Ca ... ock-device) , http://raspberrypi.stackexchange.com/qu ... -raspberry , http://forum.espruino.com/conversations/293982/ )


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Thu Oct 06, 2016 8:13 pm 
Offline

Joined: Thu Oct 06, 2016 8:04 pm
Posts: 3
Made a separate thread of how to emulate an SD card here: viewtopic.php?f=4&t=4269


Top
 Profile  
Reply with quote  
 Post subject: Re: SD Card interfacing
PostPosted: Tue Oct 11, 2016 9:04 pm 
Offline

Joined: Sat Dec 12, 2015 7:48 pm
Posts: 145
Location: Lake Tahoe
I took a slightly different approach. I first implemented a bit-banged SPI interface to slave an Arduino Uno to an Apple II using the game port. I used my own command set to allow the Apple II access to the Arduino's I/O. Then I figured out a good reason to talk to an SD card, but being sorta lazy, I decided to take advantage of the SdFat library for the Arduino so I didn't have to implement the FAT filesystem on the Apple II. Extending my custom command set to export the high level SdFat calls to the Apple so a simple library could access the files on an SD card was pretty easy. The intention was to use the SD card more as a sneaker-net way to transfer files back and forth to my Apples from my PC. I got a lot of functionality without a great deal of work. My write up is here:

http://schmenk.is-a-geek.com/wordpress/?p=239

Dave...


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


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:
Jump to: