void flerase(uint32_t addrx) { if(addrx < STM32_FLASH_BASE || addrx % 4) return; FLASH_Unlock(); FLASH_DataCacheCmd(DISABLE); if(addrx<0X1FFF0000) { FLASH_EraseSector(flash_get_sector(addrx),VoltageRange_3); } FLASH_DataCacheCmd(ENABLE); FLASH_Lock(); }
/*! ******************************************************************************* ** ** \brief Get the number of flash sectors occupied by the boot image ** ** This function calculates the number of flash sectors occupied by the ** boot image and the leading boot block which contains some size and copy ** information as well as a variable number of register/value settings. ** ** \param device The type of boot device ** \param sectors The address of a buffer where to write the result into ** ** \return ** - GD_OK if successfull, the sectors argument contains the number of ** occupied sectors ** - non-GD_OK in case of error, see the GD_FLASH documentation for possible ** return values ** ******************************************************************************* */ GERR GD_SYS_BootImageGetSectors( GD_SYS_BOOT_DEVICE_E device, U16* sectors ) { GERR status; GD_HANDLE handle; GD_SYS_BOOT_S bootblock; U32 index; U16 u16words; U32 u32words; U32 address; U16 sector; GERR (*flash_open)(GD_HANDLE*); GERR (*flash_close)(GD_HANDLE*); GERR (*flash_get_sector)(GD_HANDLE,U32,U16*); #if !defined (SMARTMPEG_D) if( device == GD_SYS_BOOT_DEVICE_FLASH ) { flash_open = GD_FL_Open; flash_close = GD_FL_Close; flash_get_sector = GD_FL_GetSector; } else // device == GD_SYS_BOOT_DEVICE_SFLASH #endif { #if defined(SMARTMPEG_C) || defined(SMARTMPEG_M) || defined(SMARTMPEG_D) || defined(GK6105S) || defined(GK6106) flash_open = GD_SFLASH_Open; flash_close = GD_SFLASH_Close; flash_get_sector = GD_SFLASH_GetSector; #else return( GD_ERR_BAD_PARAMETER ); #endif } status = flash_open( &handle ); if( status == GD_OK ) { u16words = sizeof(bootblock) / sizeof(U16); u32words = sizeof(bootblock) / sizeof(U32); #if !defined(SMARTMPEG_D) if( device == GD_SYS_BOOT_DEVICE_FLASH ) { status = GD_FL_Read( handle, 0, (U16*)(void*)&bootblock, u16words ); } else #endif { #if defined(SMARTMPEG_C) || defined(SMARTMPEG_M) || defined(SMARTMPEG_D) || defined(GK6105S) || defined(GK6106) status = GD_SFLASH_Read( handle, 0, (U32*)(void*)&bootblock, u32words ); #else status = GD_ERR_BAD_PARAMETER; #endif } //GM_Printf( "bootblock.magic_id = 0x%08x\n", bootblock.magic_id ); //GM_Printf( "bootblock.image_words = 0x%08x\n", bootblock.image_words ); //GM_Printf( "bootblock.target_address = 0x%08x\n", bootblock.target_address ); //GM_Printf( "bootblock.start_address = 0x%08x\n", bootblock.start_address ); //for( index=0; bootblock.register_defs[index].address != 0x00000000; index++ ) //{ // GM_Printf( "bootblock.register_defs[%d] = 0x%08x:0x%08x\n", index, bootblock.register_defs[index].address, bootblock.register_defs[index].data ); //} if( status == GD_OK ) { if( ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_E1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_E2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_L1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_L2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_C1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_C2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_C4 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_M1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_M2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_M4 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_G1 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_G2 ) || ( bootblock.magic_id == GD_SYS_MAGIC_ID_SMARTMPEG_G4 ) ) { // search for the termination of register/value pairs for( index=0; bootblock.register_defs[index].address != 0x00000000; index++ ) ; u32words = 4 + ( index * ( sizeof(GD_SYS_BOOT_REG_S)/sizeof(U32) ) ) + 1; // calculate the required size in bytes for the // boot image plus the leading boot block information // containing the register/value pair settings u32words += bootblock.image_words; #if defined(SMARTMPEG_C) || defined(SMARTMPEG_M) || defined(SMARTMPEG_D) || defined(GK6105S) || defined(GK6106) if( device == GD_SYS_BOOT_DEVICE_SFLASH ) { address = u32words * sizeof(U32); } else { address = ( u32words * sizeof(U32) ) / sizeof(U16); } #else // SMARTMPEG, SMARTMPEG-L, SMARTMPEG-E address = ( u32words * sizeof(U32) ) / sizeof(U16); #endif status = flash_get_sector( handle, address, §or ); *sectors = sector + 1; } else { u32words = 0; *sectors = 0; } } } flash_close( &handle ); if( status != GD_OK ) { u32words = 0; *sectors = 0; } //GM_Printf( "first free (s)flash address = %d\n", address ); //GM_Printf( "used boot image sectors = %d\n", *sectors ); return( status ); }