fixed really nasty write bug

This commit is contained in:
bsx 2011-06-17 14:29:32 +02:00
parent 84433bb1d6
commit c966b71e5b
3 changed files with 12 additions and 6 deletions

View File

@ -117,7 +117,8 @@ DRESULT dataflash_random_write(const BYTE *buff, DWORD offset, DWORD length) {
do {
wait_for_ready();
DWORD pageaddr = ((offset/256) << 9) | (offset%256);
DWORD pageaddr = (offset/256) << 9;
DWORD buffaddr = (offset%256);
DWORD remaining = 256 - offset%256;
if (remaining > length) {
remaining = length;
@ -137,9 +138,9 @@ DRESULT dataflash_random_write(const BYTE *buff, DWORD offset, DWORD length) {
// write bytes into the dataflash buffer
CS_LOW();
xmit_spi(OP_BUFFER1WRITE);
xmit_spi(0x00);
xmit_spi(0x00);
xmit_spi(0x00);
xmit_spi((BYTE)(buffaddr >> 16));
xmit_spi((BYTE)(buffaddr >> 8));
xmit_spi((BYTE)buffaddr);
do {
xmit_spi(*buff++);
} while (--remaining);

View File

@ -9,6 +9,8 @@
#include "filesystem/ff.h"
#include "filesystem/diskio.h"
#include "usb/usbmsc.h"
#include "core/ssp/ssp.h"
void incBacklight(void);
@ -44,6 +46,7 @@ const struct MENU_DEF menu_list = {"FS List", &fs_list};
const struct MENU_DEF menu_create = {"FS Create", &fs_create};
const struct MENU_DEF menu_format = {"FS format", &fs_format};
const struct MENU_DEF menu_read = {"FS read", &fs_read};
const struct MENU_DEF menu_usb = {"USB mount", &usbMSCInit};
const struct MENU_DEF menu_nop = {"---", NULL};
static menuentry menu[] = {
@ -55,6 +58,8 @@ static menuentry menu[] = {
&menu_nop,
&menu_format,
&menu_nop,
&menu_usb,
&menu_nop,
&menu_ISP,
&menu_incBL,
&menu_decBL,

View File

@ -14,11 +14,11 @@ MSC_DEVICE_INFO MscDevInfo;
ROM ** rom = (ROM **)0x1fff1ff8;
void usbMSCWrite(uint32_t offset, uint8_t src[], uint32_t length) {
dataflash_random_write(src, offset+1, length);
dataflash_random_write(src, offset, length);
}
void usbMSCRead(uint32_t offset, uint8_t dst[], uint32_t length) {
dataflash_random_read(dst, offset+1, length);
dataflash_random_read(dst, offset, length);
}
void usbMSCInit(void) {