
FUNC  void flash_init (void) {
    unsigned int reg_val;

    // flash data to CPU CRC disable
	_WDWORD(0x0080301c, (_RDWORD(0x0080301c))&(~(1<<26)));

    // flash status register data to be written
    _WDWORD(0x0080301c, (_RDWORD(0x0080301c))&(~(0xffff<<10)));
    
    // cpu data writting enable
	  _WDWORD(0x0080301c, (_RDWORD(0x0080301c))|(1<<9));

    // flash operation command : WRSR2
    reg_val = _RDWORD(0x00803000);
    reg_val &= (~(0x1f<<24));                  // clr op_type_sw
    reg_val |= (0x07<<24) | (1<<29) | (1<<30); // op_sw, wp_value
	_WDWORD(0x00803000, reg_val);
    _sleep_(1000);
    while(_RDWORD(0x00803000) & (0x01<<31)){;}

    // flash operation command : CE
    reg_val = _RDWORD(0x00803000);
    reg_val &= (~(0x1f<<24));                  // clr op_type_sw
    reg_val |= (0x10<<24) | (1<<29) | (1<<30); // op_sw, wp_value
	_WDWORD(0x00803000, reg_val);
    _sleep_(10000);
    while(_RDWORD(0x00803000) & (0x01<<31)){;}
}

flash_init();

LOAD .\build\macsw_fmac_arm\bk-mx-wifi001.hex INCREMENTAL   
//LOAD .\build\macsw_fmac_arm\rwnx_fmac.axf INCREMENTAL       // Download
