bugfixes for SD card compatibility in DMA mode
This commit is contained in:
7
src/ff.c
7
src/ff.c
@@ -1504,8 +1504,6 @@ FRESULT f_open (
|
||||
}
|
||||
|
||||
fp->dir_sect = FSBUF.sect; /* Pointer to the directory entry */
|
||||
/* Moved sync from mode & FA_CREATE_ALWAYS because it can reset FSBUF.sect */
|
||||
sync(fs); /* not sure if this is needed in all cases, but kept */
|
||||
fp->dir_ptr = dir;
|
||||
#endif
|
||||
fp->flag = mode; /* File access mode */
|
||||
@@ -1516,6 +1514,11 @@ FRESULT f_open (
|
||||
fp->csect = 1; /* Sector counter */
|
||||
fp->fs = fs; //fp->id = fs->id; /* Owner file system object of the file */
|
||||
|
||||
#if !_FS_READONLY
|
||||
if (mode & (FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW))
|
||||
sync(fs); /* sync buffer in case the file was just created */
|
||||
/* can't sync earlier, modifies FSBUF.sect */
|
||||
#endif
|
||||
return FR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,8 @@ restart:
|
||||
|
||||
while(0) {
|
||||
SD_SPI_OFFLOAD=1;
|
||||
sd_read(0, file_buf, 32L, 1);
|
||||
set_avr_addr(0L);
|
||||
sd_read(0, file_buf, 8L, 1);
|
||||
// sram_writeblock((void*)file_buf, 0, 0x200);
|
||||
sram_hexdump(0,0x10);
|
||||
uart_putc('+');
|
||||
@@ -264,7 +265,8 @@ restart:
|
||||
set_rom_mask(0x3fffff); // force mirroring off
|
||||
uart_putc(')');
|
||||
uart_putcrlf();
|
||||
// sram_hexdump(0, 0x200);
|
||||
// sram_hexdump(0x7ffff0, 0x10);
|
||||
// sram_hexdump(0, 0x400);
|
||||
// save_sram((uint8_t*)"/sd2snes/dump", 65536, 0);
|
||||
|
||||
sram_writebyte(0, SRAM_CMD_ADDR);
|
||||
|
||||
13
src/memory.c
13
src/memory.c
@@ -207,18 +207,19 @@ uint32_t load_sram(uint8_t* filename, uint32_t base_addr) {
|
||||
filesize = file_handle.fsize;
|
||||
if(file_res) return 0;
|
||||
for(;;) {
|
||||
FPGA_SS_HIGH();
|
||||
SPI_SS_LOW();
|
||||
// FPGA_SS_HIGH();
|
||||
// SPI_SS_LOW();
|
||||
SPI_OFFLOAD=1;
|
||||
bytes_read = file_read();
|
||||
SPI_SS_HIGH();
|
||||
// SPI_SS_HIGH();
|
||||
if (file_res || !bytes_read) break;
|
||||
FPGA_SS_LOW();
|
||||
spiTransferByte(0x91);
|
||||
// FPGA_SS_LOW();
|
||||
/* spiTransferByte(0x91);
|
||||
for(int j=0; j<bytes_read; j++) {
|
||||
spiTransferByte(file_buf[j]);
|
||||
}
|
||||
spiTransferByte(0x00); // dummy tx
|
||||
FPGA_SS_HIGH();
|
||||
FPGA_SS_HIGH(); // */
|
||||
}
|
||||
file_close();
|
||||
return (uint32_t)filesize;
|
||||
|
||||
18
src/sdcard.c
18
src/sdcard.c
@@ -68,7 +68,7 @@
|
||||
#include "spi.h"
|
||||
#include "uart.h"
|
||||
#include "sdcard.h"
|
||||
|
||||
#include "fpga_spi.h"
|
||||
#ifndef TRUE
|
||||
#define TRUE -1
|
||||
#endif
|
||||
@@ -540,6 +540,7 @@ DRESULT sd_read(BYTE drv, BYTE *buffer, DWORD sector, BYTE count) {
|
||||
|
||||
if (res != 0) {
|
||||
uart_putc('?');
|
||||
dprintf("SD error: %02x\n", res);
|
||||
SPI_SS_HIGH(drv);
|
||||
disk_state = DISK_ERROR;
|
||||
return RES_ERROR;
|
||||
@@ -565,19 +566,18 @@ DRESULT sd_read(BYTE drv, BYTE *buffer, DWORD sector, BYTE count) {
|
||||
// uart_putc('O');
|
||||
PORTB |= _BV(PB2);
|
||||
DDRB |= _BV(PB2);
|
||||
_delay_us(1);
|
||||
PORTB &= ~_BV(PB2);
|
||||
PORTB |= _BV(PB2);
|
||||
PORTB &= ~_BV(PB7);
|
||||
DDRB &= ~_BV(PB7); // tristate SCK
|
||||
// SPCR=0;
|
||||
PORTB |= _BV(PB2);
|
||||
DDRB &= ~_BV(PB2);
|
||||
_delay_us(1);
|
||||
loop_until_bit_is_set(PINB, PB2);
|
||||
DDRB |= _BV(PB2);
|
||||
// SPCR=0b01010000;
|
||||
SD_SPI_OFFLOAD = 0;
|
||||
deselectCard(drv);
|
||||
while(!(PINB & _BV(PB2)));
|
||||
DDRB |= _BV(PB7);
|
||||
DDRB |= _BV(PB2);
|
||||
// _delay_us(1);
|
||||
deselectCard(drv);
|
||||
SD_SPI_OFFLOAD = 0;
|
||||
return RES_OK;
|
||||
SPDR = 0xff;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user