Skip to contentSkip to conversation

: Fix size checking in SD Memory Card Physical layer

PATCH New GreenTime 1 participant 1 message Mar 25, 2009

lore
Share & tools
lore

GreenTime

author
#0 lore raw

PATCH 1/1 : Fix size checking in SD Memory Card Physical layer

Hi all,

I found a problem when I use CMD25 to write data into the SD card and write to the end of the storage.
There will be a wrong state which can't accept command problem. I found there may be some codes written wrong in sd.c

sd->data_start += sd->blk_len; //data_start
has added blk_len
if (sd->data_start + sd->blk_len > sd->size) { //so it should
not be added again when checking sd->size

--- a/trunk/hw/sd.c
+++ b/trunk/hw/sd.c

@@ -1414,7 +1414,7 @@ void sd_write_data(SDState *sd, uint8_t value)

             sd->blk_written ++;
             sd->data_start += sd->blk_len;
             sd->data_offset = 0;
-            if (sd->data_start + sd->blk_len > sd->size) {
+            if (sd->data_start > sd->size) {
                 sd->card_status |= ADDRESS_ERROR;
                 break;
             }
@@ -1537,7 +1537,7 @@ uint8_t sd_read_data(SDState *sd)
         if (sd->data_offset >= sd->blk_len) {
             sd->data_start += sd->blk_len;
             sd->data_offset = 0;
-            if (sd->data_start + sd->blk_len > sd->size) {
+            if (sd->data_start > sd->size) {
                 sd->card_status |= ADDRESS_ERROR;
                 break;
             }
@@ -1568,7 +1568,7 @@ uint8_t sd_read_data(SDState *sd)
         if (sd->data_offset >= sd->blk_len) {
             sd->data_start += sd->blk_len;
             sd->data_offset = 0;
-            if (sd->data_start + sd->blk_len > sd->size) {
+            if (sd->data_start > sd->size) {
                 sd->card_status |= ADDRESS_ERROR;
                 break;
             }
Signature · 2 lines
GreenTime
: )