static int flash_program_section(uintptr_t addr, size_t len) { *(volatile uint32_t *)&FTFL_FCCOB3 = addr; /* this overwrites B0 */ FTFL_FCCOB0 = FTFL_FCMD_PROGRAM_SECTION; *(volatile uint16_t *)&FTFL_FCCOB5 = len / FLASH_ELEM_SIZE; return (ftfl_submit_cmd()); }
static int flash_erase_sector(uintptr_t addr) { if (addr < (uintptr_t)&_app_rom && flash_ALLOW_BRICKABLE_ADDRESSES != 0x00023420) return (-1); *(volatile uint32_t *)&FTFL_FCCOB3 = addr; /* this overwrites B0 */ FTFL_FCCOB0 = FTFL_FCMD_ERASE_SECTOR; return (ftfl_submit_cmd()); }
int flash_prepare_flashing(void) { /* switch to FlexRAM_BASE_PTR */ if (!bf_get_reg(FTFL_FCNFG, FTFL_FCNFG_RAMRDY)) { FTFL_FCCOB0 = FTFL_FCMD_SET_FLEXRAM; FTFL_FCCOB1 = FTFL_FLEXRAM_RAM; return (ftfl_submit_cmd()); } return (0); }
static int flash_program_section(uintptr_t addr, size_t len) { FTFE_FCCOB0 = FTFE_FCMD_PROGRAM_SECTION; FTFE_FCCOB1 = addr >> 16; FTFE_FCCOB2 = addr >> 8; FTFE_FCCOB3 = addr; FTFE_FCCOB4 = (len / FLASH_ELEM_SIZE) >> 8; FTFE_FCCOB5 = (len / FLASH_ELEM_SIZE); return (ftfl_submit_cmd()); }
static int flash_erase_sector(uintptr_t addr) { if (addr < (uintptr_t)&_app_rom && flash_ALLOW_BRICKABLE_ADDRESSES != 0x00023420) return (-1); FTFE_FCCOB0 = FTFE_FCMD_ERASE_SECTOR; FTFE_FCCOB1 = addr >> 16; FTFE_FCCOB2 = addr >> 8; FTFE_FCCOB3 = addr; return (ftfl_submit_cmd()); }
int sector_print( void* buf, size_t sector, size_t chunks ) { uint8_t* start = (uint8_t*)buf + sector * USB_DFU_TRANSFER_SIZE; uint8_t* end = (uint8_t*)buf + (sector + 1) * USB_DFU_TRANSFER_SIZE; uint8_t* pos = start; // Verify if sector erased FTFL.fccob.read_1s_section.fcmd = FTFL_FCMD_READ_1s_SECTION; FTFL.fccob.read_1s_section.addr = (uintptr_t)start; FTFL.fccob.read_1s_section.margin = FTFL_MARGIN_NORMAL; FTFL.fccob.read_1s_section.num_words = 250; // 2000 kB / 64 bits int retval = ftfl_submit_cmd(); #ifdef FLASH_DEBUG print( NL ); print("Block "); printHex( sector ); print(" "); printHex( (size_t)start ); print(" -> "); printHex( (size_t)end ); print(" Erased: "); printHex( retval ); print( NL ); #endif // Display sector for ( size_t line = 0; pos < end - 24; line++ ) { // Each Line printHex_op( (size_t)pos, 4 ); print(": "); // Each 2 byte chunk for ( size_t chunk = 0; chunk < chunks; chunk++ ) { // Print out the two bytes (second one first) printHex_op( *(pos + 1), 2 ); printHex_op( *pos, 2 ); print(" "); pos += 2; } print( NL ); } return retval; }