diff --git a/pcb/cart/sd2snes18.brd b/pcb/cart/sd2snes18.brd index fc39185..c0c8839 100644 Binary files a/pcb/cart/sd2snes18.brd and b/pcb/cart/sd2snes18.brd differ diff --git a/pcb/cart/sd2snes18.sch b/pcb/cart/sd2snes18.sch index 8fbcfc7..1648ed0 100644 Binary files a/pcb/cart/sd2snes18.sch and b/pcb/cart/sd2snes18.sch differ diff --git a/src/config b/src/config index e402dff..a306bd8 100644 --- a/src/config +++ b/src/config @@ -27,7 +27,7 @@ CONFIG_MCU=atmega644 CONFIG_LINKER_RELAX=n -CONFIG_MCU_FREQ=13500000 +CONFIG_MCU_FREQ=12288000 CONFIG_BOOTLOADER=y CONFIG_BOOT_DEVID=0x4e534453 CONFIG_UART_DEBUG=y @@ -35,7 +35,7 @@ CONFIG_UART_BAUDRATE=38400 CONFIG_UART_BUF_SHIFT=7 CONFIG_HARDWARE_NAME=sd2snes CONFIG_SD_AUTO_RETRIES=10 -#CONFIG_SD_DATACRC=y +CONFIG_SD_DATACRC=y CONFIG_EEPROM_SIZE=512 CONFIG_EEPROM_OFFSET=512 CONFIG_MAX_PARTITIONS=1 diff --git a/src/config.h b/src/config.h index 6c33409..a5e6255 100644 --- a/src/config.h +++ b/src/config.h @@ -62,8 +62,8 @@ # error Unknown chip! # endif # define SD_CHANGE_VECT INT0_vect -# define SDCARD_WP (PINB & _BV(PB3)) -# define SDCARD_WP_SETUP() do { DDRB &= ~ _BV(PB3); PORTB |= _BV(PB3); } while(0) +# define SDCARD_WP (PINB & _BV(PB1)) +# define SDCARD_WP_SETUP() do { DDRB &= ~ _BV(PB1); PORTB |= _BV(PB1); } while(0) # define SD_CHANGE_ICR MCUCR # define SD_SUPPLY_VOLTAGE (1L<<21) # define DEVICE_SELECT (8+!(PINA & _BV(PA2))+2*!(PINA & _BV(PA3))) diff --git a/src/fpga.c b/src/fpga.c index 846f84d..516fc59 100644 --- a/src/fpga.c +++ b/src/fpga.c @@ -31,9 +31,11 @@ CCLK PD4 OUT INIT_B PD7 IN DIN PC7 OUT + DONE PA3 IN */ #include +#include #include "fpga.h" #include "config.h" #include "uart.h" @@ -89,11 +91,13 @@ void fpga_init() { DDRC = _BV(PC7); // for FPGA config, PC7 is output DDRD |= _BV(PD3) | _BV(PD4); // PD3, PD4 are outputs + + DDRA = ~_BV(PA3); // PA3 is input <- DONE set_cclk(0); // initial clk=0 } int fpga_get_done(void) { - return 0; + return PINA & _BV(PA3); } void fpga_postinit() { @@ -103,43 +107,45 @@ void fpga_postinit() { } void fpga_pgm(char* filename) { - set_prog_b(0); - uart_putc('P'); - set_prog_b(1); - loop_until_bit_is_set(PIND, PD7); - uart_putc('p'); - -// FIL in; -// FRESULT res; - UINT bytes_read; + int MAXRETRIES = 10; +// int retries = MAXRETRIES; + do { + set_prog_b(0); + uart_putc('P'); + set_prog_b(1); + loop_until_bit_is_set(PIND, PD7); + uart_putc('p'); + + UINT bytes_read; - // open configware file -// res=f_open(&in, filename, FA_READ); - file_open(filename, FA_READ); - if(file_res) { - uart_putc('?'); - uart_putc(0x30+file_res); - return; - } - // file open successful - set_cs_b(0); - set_rdwr_b(0); - - for (;;) { -// res = f_read(&in, file_buf, sizeof(file_buf), &bytes_read); - bytes_read = file_read(); - if (file_res || bytes_read == 0) break; // error or eof - for(int i=0; i +