CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

CCS SD/MMC driver MBR support

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

CCS SD/MMC driver MBR support
PostPosted: Fri Aug 27, 2010 7:15 am     Reply with quote

(See also CCS FAT driver bugfix!)

(Copied from original post in General forum)

I know there's quite a few people using this driver because it's bundled with the compiler. It may not be the best, but the price is hard to beat!

One of its shortcomings is that it doesn't handle cards with a Master Boot Record. Naturally, every single SD card I had on hand had an MBR! Rolling Eyes Support for the MBR is relatively trivial to implement, so I thought I'd post how. This involves the "mmcsd.c" CCS driver file with "Copyright 2007" in the header comments. Make a backup copy of it before starting to edit it, just in case.

Search for:
Code:
uint32_t g_mmcsdBufferAddress;
and add under it:
Code:
uint32_t g_mmcsdPartitionOffset;

Next, just before the "mmcsd_init" function add a new function:
Code:
void mmcsd_check_part(uint16_t off)
{
  if (g_mmcsd_buffer[off + 0] == 0x80)
  {
    // active partition
    uint8_t t;
    t = g_mmcsd_buffer[off + 4];
    if (t == 0x04 || t == 0x06 || t == 0x0B)
    {
      // FAT16 or FAT32 partition
      g_mmcsdPartitionOffset = make32(
        g_mmcsd_buffer[off + 11], g_mmcsd_buffer[off + 10],
        g_mmcsd_buffer[off + 9], g_mmcsd_buffer[off + 8]) * MMCSD_MAX_BLOCK_SIZE;
    }
  }
}

In the "mmcsd_init" function, right after the line:
Code:
r1 = mmcsd_load_buffer();
Add the lines:
Code:
g_mmcsdPartitionOffset = 0;
mmcsd_check_part(0x1EE);
mmcsd_check_part(0x1DE);
mmcsd_check_part(0x1CE);
mmcsd_check_part(0x1BE);

Finally, in the function "mmcsd_move_buffer", after the line:
Code:
new_block = new_addr - (new_addr % MMCSD_MAX_BLOCK_SIZE);
Add the line:
Code:
new_block += g_mmcsdPartitionOffset;

This doesn't do anything about FAT16 vs FAT32 or SD vs SDHC. If only dynamic runtime support for all those was as easy!
_________________
Andrew
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group