Some initial bringup of the dfu bootloader on the mk20dx256vlh7
This commit is contained in:
parent
46fc3e596b
commit
e41444304b
17 changed files with 249 additions and 65 deletions
|
@ -1,5 +1,5 @@
|
|||
/* Copyright (c) 2011,2012 Simon Schubert <2@0x2c.org>.
|
||||
* Modifications by Jacob Alexander 2014 <haata@kiibohd.com>
|
||||
* Modifications by Jacob Alexander 2014-2015 <haata@kiibohd.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -35,14 +35,18 @@ int ftfl_submit_cmd(void)
|
|||
{
|
||||
FTFL.fstat.raw = ((struct FTFL_FSTAT_t){
|
||||
.ccif = 1,
|
||||
.rdcolerr = 1,
|
||||
.accerr = 1,
|
||||
.fpviol = 1
|
||||
}).raw;
|
||||
//.rdcolerr = 1,
|
||||
.accerr = 1,
|
||||
.fpviol = 1
|
||||
}).raw;
|
||||
|
||||
// Wait for the operation to complete
|
||||
struct FTFL_FSTAT_t stat;
|
||||
while (!(stat = FTFL.fstat).ccif)
|
||||
/* NOTHING */; /* XXX maybe WFI? */
|
||||
return (!!stat.mgstat0);
|
||||
while (!(stat = FTFL.fstat).ccif); // XXX maybe WFI?
|
||||
|
||||
// Mask error bits
|
||||
return stat.raw & (FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL | FTFL_FSTAT_MGSTAT0);
|
||||
//return (!!stat.mgstat0);
|
||||
}
|
||||
|
||||
int flash_prepare_flashing(void)
|
||||
|
@ -66,20 +70,65 @@ int flash_erase_sector(uintptr_t addr)
|
|||
return (ftfl_submit_cmd());
|
||||
}
|
||||
|
||||
int flash_program_section(uintptr_t addr, size_t num_words)
|
||||
int flash_program_section_longwords(uintptr_t addr, size_t num_words)
|
||||
{
|
||||
FTFL.fccob.program_section.fcmd = FTFL_FCMD_PROGRAM_SECTION;
|
||||
FTFL.fccob.program_section.addr = addr;
|
||||
FTFL.fccob.program_section.num_words = num_words;
|
||||
return (ftfl_submit_cmd());
|
||||
|
||||
return ftfl_submit_cmd();
|
||||
}
|
||||
|
||||
int flash_program_section_phrases(uintptr_t addr, size_t num_phrases)
|
||||
{
|
||||
FTFL.fccob.program_section.fcmd = FTFL_FCMD_PROGRAM_SECTION;
|
||||
FTFL.fccob.program_section.addr = addr;
|
||||
FTFL.fccob.program_section.num_words = num_phrases;
|
||||
|
||||
return ftfl_submit_cmd();
|
||||
}
|
||||
|
||||
int flash_program_longword(uintptr_t addr, uint8_t *data)
|
||||
{
|
||||
FTFL.fccob.program_longword.fcmd = FTFL_FCMD_PROGRAM_LONGWORD;
|
||||
FTFL.fccob.program_longword.addr = addr;
|
||||
FTFL.fccob.program_longword.data_be[0] = data[0];
|
||||
FTFL.fccob.program_longword.data_be[1] = data[1];
|
||||
FTFL.fccob.program_longword.data_be[2] = data[2];
|
||||
FTFL.fccob.program_longword.data_be[3] = data[3];
|
||||
|
||||
return ftfl_submit_cmd();
|
||||
}
|
||||
|
||||
int flash_program_sector(uintptr_t addr, size_t len)
|
||||
{
|
||||
#if defined(_mk20dx128vlf5_)
|
||||
return (len != FLASH_SECTOR_SIZE ||
|
||||
(addr & (FLASH_SECTOR_SIZE - 1)) != 0 ||
|
||||
flash_erase_sector(addr) ||
|
||||
flash_program_section(addr, FLASH_SECTOR_SIZE/4));
|
||||
flash_program_section_longwords(addr, FLASH_SECTOR_SIZE / 4));
|
||||
#elif defined(_mk20dx256vlh7_)
|
||||
/*
|
||||
return (len != FLASH_SECTOR_SIZE ||
|
||||
(addr & (FLASH_SECTOR_SIZE - 1)) != 0 ||
|
||||
flash_erase_sector(addr) ||
|
||||
flash_program_section_phrases(addr, FLASH_SECTOR_SIZE / 8));
|
||||
*/
|
||||
return (len != FLASH_SECTOR_SIZE ||
|
||||
(addr & (FLASH_SECTOR_SIZE - 1)) != 0 ||
|
||||
flash_erase_sector(addr) ||
|
||||
flash_program_section_phrases(addr, FLASH_SECTOR_SIZE / 8));
|
||||
#endif
|
||||
}
|
||||
|
||||
int flash_prepare_reading(void)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
int flash_read_sector(uintptr_t addr, size_t len)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
void *flash_get_staging_area(uintptr_t addr, size_t len)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue