AnsweredAssumed Answered

Using USB MSC with internal flash in MK64

Question asked by Changeseon Jee on Sep 6, 2017
Latest reply on Sep 6, 2017 by Changeseon Jee

Hello,

 

I want my Hexiwear (MK64) act as USB mass storage when connected with PC.

But in this USB msc driver, the data partition was hardcoded as below. And I can't use internal flash with this driver.

How can I link msc with internal flash?

 

In addition, how can I set my flash memory map?

 

Header 1

static const mbr_t mbr = {
    .boot_sector = {
        0xEB,0x3C, // x86 Jump
        0x90,      // NOP
        'M','S','W','I','N','4','.','1' // OEM Name in text
    },

    .bytes_per_sector         = MBR_BYTES_PER_SECTOR,
    .sectors_per_cluster      = WANTED_SECTORS_PER_CLUSTER,
    .reserved_logical_sectors = 1,
    .num_fats                 = 2,
    .max_root_dir_entries     = 32,
    .total_logical_sectors    = ((MBR_NUM_NEEDED_SECTORS > 32768) ? 0 : MBR_NUM_NEEDED_SECTORS),
    .media_descriptor         = MEDIA_DESCRIPTOR,
    .logical_sectors_per_fat  = MBR_SECTORS_PER_FAT, /* Need 3 sectors/FAT for every 1024 clusters */

    .physical_sectors_per_track = 1,
    .heads = 1,
    .hidden_sectors = 0,
    .big_sectors_on_drive = ((MBR_NUM_NEEDED_SECTORS > 32768) ? MBR_NUM_NEEDED_SECTORS : 0),

    .physical_drive_number = 0,
    .not_used = 0,
    .boot_record_signature = 0x29,
    .volume_id = 0x27021974,
    .volume_label = {'M','b','e','d',' ','U','S','B',' ',' ',' '},
    .file_system_type = {'F','A','T','1','2',' ',' ',' '},

    /* Executable boot code that starts the operating system */
    .bootstrap = {
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    },
    .signature = 0xAA55,
};

.....................................................

  

SECTOR sectors[] = {
    /* Reserved Sectors: Master Boot Record */
    {(const uint8_t *)&mbr , 512},

    /* FAT Region: FAT1 */
    {fat1, sizeof(fat1)},   // fat1, sect1
    EMPTY_FAT_SECTORS

    /* FAT Region: FAT2 */
    {fat2, 0},              // fat2, sect1
    EMPTY_FAT_SECTORS

    /* Root Directory Region */
    {root_dir1, sizeof(root_dir1)}, // first 16 of the max 32 (mbr.max_root_dir_entries) root dir entries
    {root_dir2, sizeof(root_dir2)}, // last 16 of the max 32 (mbr.max_root_dir_entries) root dir entries

    /* Data Region */

    // Section for mac compatibility
    {sect5, sizeof(sect5)},

    // contains mbed.htm
    {(const uint8_t *)BlockBuf, 512},
};

Outcomes