コード例 #1
0
BOOL SF_BS_Driver::IsBlockErased(void *context, ByteAddress phyAddress, UINT32 BlockLength)
{

    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    UINT32 RegionIndex;
    UINT32 RangeIndex;
    UINT32 SectorsCount;
    UINT32 BytesPerSector;
    UINT32 BytesCount;

    BLOCK_CONFIG* pConfig = (BLOCK_CONFIG*)context;

    // this is static buffer, as the driver is current tailor for SD, a page size is 2048 bytes.
    BYTE *pSectorBuff = s_sectorBuff;


    BYTE state_After_Erase = 0xff;//g_SerialFlash_BL_Configuration.State_After_Erase ? 0xFF : 0x00;

    if(!pConfig->BlockDeviceInformation->FindRegionFromAddress(phyAddress, RegionIndex, RangeIndex))
        return FALSE;

    const BlockRegionInfo* pRegion = &pConfig->BlockDeviceInformation->Regions[RegionIndex];

    // as the input arg Sector may not be the startSector address of a block,
    // we need to recalculate it.
    BytesPerSector  = pConfig->BlockDeviceInformation->BytesPerSector;

    SectorsCount = BlockLength / BytesPerSector;
    
    if ((BlockLength % BytesPerSector) > 0) SectorsCount++;

    ByteAddress StartSector = phyAddress / BytesPerSector;
    
    UINT32 offset = phyAddress - (StartSector * BytesPerSector);
    
    UINT32 bytes  = (BlockLength + offset > BytesPerSector ? BytesPerSector - offset : BlockLength);
    
    BytesCount = 0;
    for(UINT32 i = 0; i < SectorsCount; i++)
    {
        Read(context, phyAddress, bytes, pSectorBuff);
        for(UINT32 j = 0; j < bytes; j++)
        {
            BytesCount++;
            if (BytesCount > BlockLength)
            {
                return TRUE;
            }
            if(pSectorBuff[j] != state_After_Erase)
            {
                return FALSE;
            }
        }
        bytes = BytesPerSector;
        offset = 0;
        phyAddress += BytesPerSector;
    }
    return TRUE;
}
コード例 #2
0
BOOL  SH7216_INTERNAL_FLASH_Driver::EraseBlock( void* context, ByteAddress address )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    BOOL result;
    CHIP_WORD  ChipAddress;
    
    UINT32 iRegion, iRange;

    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;
    const BlockDeviceInfo *    deviceInfo = config->BlockConfig.BlockDeviceInformation;

    if (deviceInfo->Attribute.WriteProtected) return FALSE;
    
    if (!deviceInfo->FindRegionFromAddress(address, iRegion, iRange)) return FALSE;

    address -= (address % deviceInfo->Regions[iRegion].BytesPerBlock);

    ChipAddress = (CHIP_WORD ) address;
   
    ChipReadOnly(context, FALSE, FLASH_PROTECTION_KEY);

    FLASH_BEGIN_PROGRAMMING_FAST();
    
    result =  Action_EraseSector( context, ChipAddress );

    FLASH_END_PROGRAMMING_FAST( "SH7216 INTERNAL FLASH EraseSector", ChipAddress);       


    ChipReadOnly(context, TRUE, FLASH_PROTECTION_KEY);

    return result;
}
コード例 #3
0
BOOL __section(SectionForFlashOperations) AM29DL_32_BS_Driver::Read(void* context, ByteAddress address, UINT32 numBytes, BYTE * pSectorBuff)
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    CHIP_WORD* ChipAddress, *EndAddress;

#if _DEBUG    
    UINT32 iRegion, iRange;

    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;
    const BlockDeviceInfo *    deviceInfo = config->BlockConfig.BlockDeviceInformation;
    if(!deviceInfo->FindRegionFromAddress(address, iRegion, iRange)) return FALSE;
#endif

    address = CPU_GetUncachableAddress(address);

    ChipAddress = (CHIP_WORD *) address;
    EndAddress  = (CHIP_WORD *)(address + numBytes);

    CHIP_WORD *pBuf = (CHIP_WORD *)pSectorBuff;

    while(ChipAddress < EndAddress)
    {
        *pBuf++ = *ChipAddress++;
    }

    return TRUE;
}
コード例 #4
0
BOOL SF_BS_Driver::EraseBlock(void *context, ByteAddress phyAddr)
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    UINT32 iRegion, iRange, BytesPerSector, i, j, k;
    
    unsigned char * Buff;
    
    Buff = (unsigned char *)private_malloc(0x10000);

    MEMORY_MAPPED_SERIAL_BLOCK_CONFIG* config = (MEMORY_MAPPED_SERIAL_BLOCK_CONFIG*)context;
    const BlockDeviceInfo *    deviceInfo = config->BlockConfig.BlockDeviceInformation;

    if (deviceInfo->Attribute.WriteProtected) return FALSE;

    if (!deviceInfo->FindRegionFromAddress(phyAddr, iRegion, iRange)) return FALSE;

    const BlockRegionInfo* pRegion = &deviceInfo->Regions[iRegion];

    BytesPerSector = deviceInfo->BytesPerSector;

    SF_Sector_Erase(/*i * SF_SECTOR_SIZE*/phyAddr);

    return TRUE;
}
コード例 #5
0
void __section(SectionForFlashOperations) AM29DL_32_BS_Driver::Action_ReadID( void* context, FLASH_WORD& ManufacturerCode, FLASH_WORD& DeviceCode )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    
    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;
    
    volatile CHIP_WORD* BaseAddress = (CHIP_WORD*)config->BlockConfig.BlockDeviceInformation->Regions[0].Start;

    ///////////////////////////////////
    //
    //
    FLASH_BEGIN_PROGRAMMING_FAST();
    
    // Exit "Autoselect" mode by writing reset '0xF0' to bus
    BaseAddress[0x0] = 0x00F000F0;
    // Enter "Autoselect" mode to read back chip details
    BaseAddress[0x0555] = 0x00AA00AA;
    BaseAddress[0x02AA] = 0x00550055;
    BaseAddress[0x0555] = 0x00900090;
    ManufacturerCode = BaseAddress[0x0000];
    DeviceCode       = BaseAddress[0x0001];    // read device ID, must read the A[0x01]. A[0x0E]. A[0x0F]
    // Exit "Autoselect" mode by writing reset '0xF0' to bus
    BaseAddress[0x0] = 0x00F000F0;
    
    FLASH_END_PROGRAMMING_FAST( "AM29DL_BS_32 ReadProductID", BaseAddress );
    //
    //
    ///////////////////////////////////
}
コード例 #6
0
    /////////////////////////////////////////////////////////
    // Description:
    //    Erases a block
    // 
    // Input:
    //    Address - Logical Sector Address
    //
    // Returns:
    //   true if succesful; false if not
    //
    // Remarks:
    //    Erases the block containing the sector address specified.
    //    
BOOL __section(SectionForFlashOperations)STM32_Flash_Driver::EraseBlock( void* context, ByteAddress Sector )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    // turn on HSI clock
    RCC->CR |= RCC_CR_HSION;
    while(!(RCC->CR & RCC_CR_HSIRDY));
    
    if (FLASH->CR & FLASH_CR_LOCK) { // unlock
        FLASH->KEYR = STM32_FLASH_KEY1;
        FLASH->KEYR = STM32_FLASH_KEY2;
    }
        
    // enable erasing
    FLASH->CR = FLASH_CR_PER;
    // set sector address
    FLASH->AR = Sector;
    // start erase
    FLASH->CR = FLASH_CR_PER | FLASH_CR_STRT;
    // asure busy flag is set up (see STM32 errata)
    FLASH->CR = FLASH_CR_PER | FLASH_CR_STRT;
    // wait for completion
    while (FLASH->SR & FLASH_SR_BSY);
    
    // reset & lock the controller
    FLASH->CR = FLASH_CR_LOCK;

    // stop HSI clock
    RCC->CR &= ~RCC_CR_HSION;

    return TRUE;
}
コード例 #7
0
BOOL __section("SectionForFlashOperations")I28F_16_BS_Driver::EraseBlock( void* context, ByteAddress Sector )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    CHIP_WORD * ChipAddress;
    
    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;

    const BlockDeviceInfo * deviceInfo = config->BlockConfig.BlockDeviceInformation;
    
    if (deviceInfo->Attribute.WriteProtected) return FALSE;

    ChipAddress = (CHIP_WORD *)Sector;
    
    ChipReadOnly(config, FALSE, FLASH_PROTECTION_KEY);

    
    ByteAddress StatusRegister = Action_EraseSector( config, ChipAddress, config );

    if(0 != (StatusRegister & ~SR_WSM_READY))
    {
        debug_printf( "Flash_EraseSector(0x%08x): Status Register non-zero after erase: 0x%08x\r\n", (size_t)Sector, StatusRegister );
    }

    ChipReadOnly(config, TRUE, FLASH_PROTECTION_KEY);

    return TRUE;
}
コード例 #8
0
BOOL USB_BS_Driver::CPU_USB_EraseBlock(void *context, ByteAddress phyAddr)
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    UINT32 RangeIndex;
    UINT32 RegionIndex;

    BLOCK_CONFIG* pConfig = (BLOCK_CONFIG*)context;

    if(!pConfig->BlockDeviceInformation->FindRegionFromAddress(phyAddr, RegionIndex, RangeIndex))
        return FALSE;

    const BlockRegionInfo* pRegion = &pConfig->BlockDeviceInformation->Regions[RegionIndex];

    ByteAddress StartSector = pConfig->BlockDeviceInformation->PhysicalToSectorAddress( pRegion, phyAddr );

    UINT32 SectorsPerBlock = pRegion->BytesPerBlock / pConfig->BlockDeviceInformation->BytesPerSector;

    SectorAddress SectorAddress = (StartSector / SectorsPerBlock) * SectorsPerBlock;

    CPU_USB_EraseSectors(SectorAddress, SectorsPerBlock);

    return TRUE;

}
コード例 #9
0
BOOL __section(SectionForFlashOperations) AM29DL_32_BS_Driver::EraseBlock( void* context, ByteAddress address )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    BOOL result;
    CHIP_WORD * ChipAddress;
    
    UINT32 iRegion, iRange;

    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;
    const BlockDeviceInfo *    deviceInfo = config->BlockConfig.BlockDeviceInformation;

    if (deviceInfo->Attribute.WriteProtected) return FALSE;
    
    if (!deviceInfo->FindRegionFromAddress(address, iRegion, iRange)) return FALSE;

    address -= (address % deviceInfo->Regions[iRegion].BytesPerBlock);

    ChipAddress = (CHIP_WORD *) address;
    
    ChipReadOnly(context, FALSE, FLASH_PROTECTION_KEY);
    
    result =  Action_EraseSector( context, ChipAddress );

    ChipReadOnly(context, TRUE, FLASH_PROTECTION_KEY);

    return result;
}
コード例 #10
0
/////////////////////////////////////////////////////////
// Description:
//    Erases a block
//
// Input:
//    Address - Logical Sector Address
//
// Returns:
//   true if successful; false if not
//
// Remarks:
//    Erases the block containing the sector address specified.
//
BOOL __section("SectionForFlashOperations")STM32F4_Flash_Driver::EraseBlock( void* context, ByteAddress Sector )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    BOOL SectorInBank2 = FALSE;

    if ((Sector - FLASH_BASE) >= 0x100000)
        SectorInBank2 = TRUE;

    UINT32  num = SectorInBank2?((Sector - 0x100000 - FLASH_BASE) >> 14):((Sector - FLASH_BASE) >> 14);
    if (num >= 4) num = (num >> 3) + 4;

    if (FLASH->CR & FLASH_CR_LOCK) { // unlock
        FLASH->KEYR = STM32F4_FLASH_KEY1;
        FLASH->KEYR = STM32F4_FLASH_KEY2;
    }

    // enable erasing
    UINT32 cr = num * FLASH_CR_SNB_0 | FLASH_CR_SER;
    if (SectorInBank2) cr |= 0x80;
    FLASH->CR = cr;
    // start erase
    cr |= FLASH_CR_STRT;
    FLASH->CR = cr;
    // asure busy flag is set up (see STM32F4 errata)
    FLASH->CR = cr;
    // wait for completion
    while (FLASH->SR & FLASH_SR_BSY);

    // reset & lock the controller
    FLASH->CR = FLASH_CR_LOCK;

    return TRUE;
}
コード例 #11
0
BOOL M29W640FB_WaitReady()
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    
    while(Driver_Flash0.GetStatus().busy == 1);
    
    return TRUE;
}
コード例 #12
0
/////////////////////////////////////////////////////////
// Description:
//    Erases a block
// 
// Input:
//    Address - Logical Sector Address
//
// Returns:
//   true if succesful; false if not
//
// Remarks:
//    Erases the block containing the sector address specified.
//    
BOOL M29W640FB_Flash_Driver::EraseBlock( void* context, ByteAddress Sector )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    M29W640FB_WaitReady();
    Driver_Flash0.EraseSector(Sector);
    M29W640FB_WaitReady();

    return TRUE;
}
コード例 #13
0
BOOL M29W640FB_Flash_Driver::ChipInitialize( void* context )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
        
    if(Driver_Flash0.Initialize(NULL) != ARM_DRIVER_OK)
    {
        return FALSE;
    }

    return TRUE;
}
コード例 #14
0
BOOL __section(SectionForFlashOperations) AM29DL_32_BS_Driver::ReadProductID(void* context, FLASH_WORD& ManufacturerCode, FLASH_WORD& DeviceCode )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    
    ChipReadOnly( context, FALSE, FLASH_PROTECTION_KEY );

    Action_ReadID( context, ManufacturerCode, DeviceCode );

    ChipReadOnly( context, TRUE, FLASH_PROTECTION_KEY );

    return TRUE;
}
コード例 #15
0
BOOL  SH7216_INTERNAL_FLASH_Driver::ReadProductID(void* context, FLASH_WORD& ManufacturerCode, FLASH_WORD& DeviceCode )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    
    ChipReadOnly( context, FALSE, FLASH_PROTECTION_KEY );

    Action_ReadID( context, ManufacturerCode, DeviceCode );

    ChipReadOnly( context, TRUE, FLASH_PROTECTION_KEY );

    return TRUE;
}
コード例 #16
0
void __section(SectionForFlashOperations) AM29DL_32_BS_Driver::Action_WriteWord( void* context, volatile CHIP_WORD* Address, CHIP_WORD Data )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;
    
    volatile CHIP_WORD* BaseAddress = (CHIP_WORD *)config->BlockConfig.BlockDeviceInformation->Regions[0].Start;
     
    ///////////////////////////////////
    //
    //    
    FLASH_BEGIN_PROGRAMMING_FAST();
    // reset "Autoselect" mode by writing reset '0xF0' to bus
    BaseAddress[0x0]    = 0x00F000F0;  
    BaseAddress[0x0555] = 0x00AA00AA;
    BaseAddress[0x02AA] = 0x00550055;
    BaseAddress[0x0555] = 0x00A000A0;

    *Address = Data ;

    // wait for device to signal completion
    // break when the device signals completion by looking for Data (0xff erasure value) on I/O 7 (a 0 on I/O 7 indicates erasure in progress)
    // There is no timeout at here, if it fails, leave it for the system watchdog to reset it.
    {

        UINT32 Data_DQ5,Data_DQ7;

        while((*Address & SR_WSM_READY) !=  (Data & SR_WSM_READY))
        {
            //check DQ 5
            Data_DQ5 = *Address ;
            if (Data_DQ5 & 0x00200020)
            {
                Data_DQ7= *Address ;
                if (((Data_DQ5 & 0x00000020) && ((Data_DQ7 & 0x00000080)!= (Data &0x000000080))) || ((Data_DQ5 & 0x00200000) && ((Data_DQ7 & 0x00800000) != (Data & 0x00800000))))
                {
                    // Error writing the address
                     break;
                }
            }
        }
    }
    // Exit "Autoselect" mode by writing reset '0xF0' to bus
    BaseAddress[0x0] = 0x00F000F0;

    FLASH_END_PROGRAMMING_FAST( "AM29DL_BS_32 WriteWord", Address );    
    //
    //
    ///////////////////////////////////
}
コード例 #17
0
BOOL __section("SectionForFlashOperations")I28F_16_BS_Driver::ReadProductID( void* context, FLASH_WORD& ManufacturerCode, FLASH_WORD& DeviceCode )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;

    volatile CHIP_WORD* BaseAddress = (CHIP_WORD *)config->BlockConfig.BlockDeviceInformation->Regions[0].Start;

    ChipReadOnly(config, FALSE, FLASH_PROTECTION_KEY);

    Action_ReadID( BaseAddress, ManufacturerCode, DeviceCode );

    ChipReadOnly( config, TRUE, FLASH_PROTECTION_KEY);

    return TRUE;
}
コード例 #18
0
/////////////////////////////////////////////////////////
// Description:
//    Reads data from a set of sectors
//
// Input:
//    StartSector - Starting Sector for the read
//    NumSectors  - Number of sectors to read
//    pSectorBuff - pointer to buffer to read the data into.
//                  Must be large enough to hold all of the data
//                  being read.
//
// Returns:
//   true if successful; false if not
//
// Remarks:
//   This function reads the number of sectors specified from the device.
//   
BOOL  M29W640FB_Flash_Driver::Read( void* context, ByteAddress StartSector, UINT32 NumBytes, BYTE * pSectorBuff)
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    int32_t wordsReadCount;
    uint32_t NumWords = NumBytes / 2;

    M29W640FB_WaitReady();
    wordsReadCount = Driver_Flash0.ReadData(StartSector, pSectorBuff, NumWords);	
    if(wordsReadCount != NumWords)
    {
        return FALSE;
    }

    return TRUE;
}
コード例 #19
0
BOOL SD_BS_Driver::Read(void *context, ByteAddress phyAddress, UINT32 NumBytes, BYTE *pSectorBuff)
{
	__IO SD_Error errorstatus = SD_OK;
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    UINT32 RangeIndex;
    UINT32 RegionIndex;
    UINT32 BytesPerSector;

    BLOCK_CONFIG* pConfig = (BLOCK_CONFIG*)context;
    
    if(pConfig->BlockDeviceInformation->FindRegionFromAddress(phyAddress, RegionIndex, RangeIndex))
    {
        ByteAddress StartSector = pConfig->BlockDeviceInformation->PhysicalToSectorAddress( &pConfig->BlockDeviceInformation->Regions[RegionIndex], phyAddress);

        BytesPerSector = pConfig->BlockDeviceInformation->BytesPerSector;

        CHIP_WORD *pBuf = (CHIP_WORD*)pSectorBuff;

        UINT32 offset = phyAddress - (StartSector * pConfig->BlockDeviceInformation->BytesPerSector);

       UINT32 bytes  = (NumBytes + offset > BytesPerSector ? BytesPerSector - offset : NumBytes);

		while(NumBytes > 0)
        {
            if(!ReadSector(StartSector, offset, bytes, pBuf, BytesPerSector))
            {
				errorstatus = SD_StopTransfer();
				return FALSE;
            }
            
            offset    = 0;
            pBuf      = (CHIP_WORD*)((UINT32)pBuf + bytes);
            NumBytes -= bytes;
            StartSector++;

            bytes = __min(BytesPerSector, NumBytes);
        }

		return TRUE;
    }
    else
    {
        return FALSE;
    }
		return TRUE;

}
コード例 #20
0
BOOL USB_BS_Driver::CPU_USB_IsBlockErased(void *context, ByteAddress phyAddress, UINT32 BlockLength)
{

    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    UINT32 RegionIndex;
    UINT32 RangeIndex;
    UINT32 SectorsPerBlock;
    UINT32 BytesPerSector;

    BLOCK_CONFIG* pConfig = (BLOCK_CONFIG*)context;

    // this is static buffer, as the driver is current tailor for SD, a page size is 2048 bytes.
    BYTE *pSectorBuff = s_sectorBuff;


    BYTE state_After_Erase = 0xff;//g_SH7264_USB_BL_Configuration.State_After_Erase ? 0xFF : 0x00;

    if(!pConfig->BlockDeviceInformation->FindRegionFromAddress(phyAddress, RegionIndex, RangeIndex))
        return FALSE;

    ByteAddress StartSector = pConfig->BlockDeviceInformation->PhysicalToSectorAddress( &pConfig->BlockDeviceInformation->Regions[RegionIndex], phyAddress);

    const BlockRegionInfo* pRegion = &pConfig->BlockDeviceInformation->Regions[RegionIndex];

    // as the input arg Sector may not be the startSector address of a block,
    // we need to recalculate it.
    BytesPerSector  = pConfig->BlockDeviceInformation->BytesPerSector;
    SectorsPerBlock = (pRegion->BytesPerBlock / BytesPerSector);

    StartSector = (StartSector / SectorsPerBlock) * SectorsPerBlock;
    
    for(UINT32 i = 0; i < SectorsPerBlock; i++)
    {
        CPU_USB_Read(context, StartSector, BytesPerSector, pSectorBuff);
        for(UINT32 j = 0; j < BytesPerSector; j++)
        {
            if(pSectorBuff[j] != state_After_Erase)
            {
                return FALSE;
            }
        }
    }
    return TRUE;
}
コード例 #21
0
/////////////////////////////////////////////////////////
// Description:
//    Check a block is erased or not.
// 
// Input:
//    BlockStartAddress - Logical Sector Address
//
// Returns:
//   true if it is erased, otherwise false
//
// Remarks:
//    Check  the block containing the sector address specified.
//    
BOOL M29W640FB_Flash_Driver::IsBlockErased( void* context, ByteAddress BlockStart, UINT32 BlockLength )
{
    const uint32_t bufLenWords = 128;
    const uint32_t bufLenBytes = bufLenWords * 2;
    uint16_t readBuffer[bufLenWords];
    uint32_t wordsReadCount;
    uint32_t numWords;
    uint32_t currentAddress = BlockStart;
    uint32_t endAddress = BlockStart + BlockLength;
    
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    while(currentAddress < endAddress)
    {
        /* The number of bytes to read will be equal to readBufLen unless the BlockLength is not a even multiple of readBufLen */
        if((endAddress - currentAddress) < bufLenBytes)
        {
            numWords = (endAddress - currentAddress) / 2;
        }
        else
        {
            numWords = bufLenWords;
        }
        
        /* Read data from flash */
        M29W640FB_WaitReady();
        wordsReadCount = Driver_Flash0.ReadData(currentAddress, readBuffer, numWords);
        if(wordsReadCount != numWords)
        {
            return FALSE;
        }
        
        currentAddress += wordsReadCount * 2;
        
        /* Validate the data we get back is all erased to 0xFF */
        for (int i = 0; i < wordsReadCount; i++) {
            if (readBuffer[i] != 0xFFFF)
            {
                return FALSE;
            }
        }
    }

    return TRUE;
}
コード例 #22
0
    /////////////////////////////////////////////////////////
    // Description:
    //    Reads data from a set of sectors
    //
    // Input:
    //    StartSector - Starting Sector for the read
    //    NumSectors  - Number of sectors to read
    //    pSectorBuff - pointer to buffer to read the data into.
    //                  Must be large enough to hold all of the data
    //                  being read.
    //
    // Returns:
    //   true if succesful; false if not
    //
    // Remarks:
    //   This function reads the number of sectors specified from the device.
    //   
BOOL  __section(SectionForFlashOperations)STM32_Flash_Driver::Read( void* context, ByteAddress StartSector, UINT32 NumBytes, BYTE * pSectorBuff)
{
    // XIP device does not need to read into a buffer
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    if (pSectorBuff == NULL) return FALSE;

    CHIP_WORD* ChipAddress = (CHIP_WORD *)StartSector;
    CHIP_WORD* EndAddress  = (CHIP_WORD *)(StartSector + NumBytes);
    CHIP_WORD *pBuf        = (CHIP_WORD *)pSectorBuff;

    while(ChipAddress < EndAddress)
    {
        *pBuf++ = *ChipAddress++;
    }

    return TRUE;
}
コード例 #23
0
    /////////////////////////////////////////////////////////
    // Description:
    //    Check a block is erased or not.
    // 
    // Input:
    //    BlockStartAddress - Logical Sector Address
    //
    // Returns:
    //   true if it is erassed, otherwise false
    //
    // Remarks:
    //    Check  the block containing the sector address specified.
    //    
BOOL __section(SectionForFlashOperations)STM32_Flash_Driver::IsBlockErased( void* context, ByteAddress BlockStart, UINT32 BlockLength )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    
    CHIP_WORD* ChipAddress = (CHIP_WORD *) BlockStart;
    CHIP_WORD* EndAddress  = (CHIP_WORD *)(BlockStart + BlockLength);
    
    while(ChipAddress < EndAddress)
    {
        if(*ChipAddress != 0xFFFF)
        {
            return FALSE;
        }
        ChipAddress++;
    }

    return TRUE;
}
コード例 #24
0
BOOL SF_BS_Driver::Read(void *context, ByteAddress phyAddress, UINT32 NumBytes, BYTE *pSectorBuff)
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    UINT32 RangeIndex;
    UINT32 RegionIndex;
    UINT32 BytesPerSector;

    MEMORY_MAPPED_SERIAL_BLOCK_CONFIG* pConfig = (MEMORY_MAPPED_SERIAL_BLOCK_CONFIG*)context;
    const BlockDeviceInfo *    deviceInfo = pConfig->BlockConfig.BlockDeviceInformation;
    
    if(deviceInfo->FindRegionFromAddress(phyAddress, RegionIndex, RangeIndex))
    {
        BytesPerSector = deviceInfo->BytesPerSector;
        SERIAL_WORD *pBuf = (SERIAL_WORD*)pSectorBuff;
        BlockRegionInfo* pRegion = (BlockRegionInfo*)&deviceInfo->Regions[RegionIndex];
        
        ByteAddress StartSector = phyAddress / deviceInfo->BytesPerSector;

        UINT32 offset = phyAddress - (StartSector * deviceInfo->BytesPerSector);

        UINT32 bytes  = (NumBytes + offset > BytesPerSector ? BytesPerSector - offset : NumBytes);
                
        while(NumBytes > 0)
        {
            if(!ReadSector(StartSector, offset, bytes, pBuf, BytesPerSector))
            {
                return FALSE;
            }
            
            offset    = 0;
            pBuf      = (SERIAL_WORD*)((UINT32)pBuf + bytes);
            NumBytes -= bytes;
            StartSector++;

            bytes = __min(BytesPerSector, NumBytes);
        }
        
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}
コード例 #25
0
void  SH7216_INTERNAL_FLASH_Driver::Action_ReadID( void* context, FLASH_WORD& ManufacturerCode, FLASH_WORD& DeviceCode )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    

    ///////////////////////////////////
    //
    //
    FLASH_BEGIN_PROGRAMMING_FAST();
 
    ManufacturerCode = 0x0001;
    DeviceCode       = 0x227E;  
 
    
    FLASH_END_PROGRAMMING_FAST( "SH7216 INTERNAL FLASH ReadProductID", BaseAddress );
    //
    //
    ///////////////////////////////////
}
コード例 #26
0
void __section("SectionForFlashOperations") I28F_16_BS_Driver::Action_Unlock( volatile CHIP_WORD* SectorCheck )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    ///////////////////////////////////
    //
    //
    FLASH_BEGIN_PROGRAMMING_FAST();

    SectorCheck = CPU_GetUncachableAddress( SectorCheck );

    *SectorCheck = LOCK_SETUP;
    *SectorCheck = LOCK_UNLOCK_BLOCK;
    *SectorCheck = ENTER_READ_ARRAY_MODE;

    FLASH_END_PROGRAMMING_FAST( "I28F_16 Unlock", NULL );
    //
    //
    ///////////////////////////////////
}
コード例 #27
0
void __section("SectionForFlashOperations") I28F_16_BS_Driver::Action_ClearStatusRegister( volatile CHIP_WORD* SectorCheck )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    ///////////////////////////////////
    //
    //
    FLASH_BEGIN_PROGRAMMING_FAST();

    SectorCheck = CPU_GetUncachableAddress( SectorCheck );

    // clear the status register for this block, just in case it has some residual error present
    *SectorCheck = CLEAR_STATUS_REGISTER;
    *SectorCheck = ENTER_READ_ARRAY_MODE;

    FLASH_END_PROGRAMMING_FAST( "I28F_16 ClearStatus", NULL );
    //
    //
    ///////////////////////////////////
}
コード例 #28
0
BOOL __section(SectionForFlashOperations) AM29DL_32_BS_Driver::ChipReadOnly(void* context, BOOL On, UINT32 ProtectionKey )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();
    
    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;

    if(ProtectionKey != FLASH_PROTECTION_KEY) { ASSERT(0); return FALSE; }

    config->ChipProtection = On ? 0 : ProtectionKey;

    CPU_EBIU_Memory_ReadOnly( config->Memory, On );

    if(config->BlockConfig.WriteProtectionPin.Pin != GPIO_PIN_NONE)
    {
        CPU_GPIO_SetPinState( config->BlockConfig.WriteProtectionPin.Pin, On ? config->BlockConfig.WriteProtectionPin.ActiveState: !config->BlockConfig.WriteProtectionPin.ActiveState );

    }

    return TRUE;
}
コード例 #29
0
BOOL  SH7216_INTERNAL_FLASH_Driver::IsBlockErased( void* context, ByteAddress address, UINT32 blockLength )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    address = CPU_GetUncachableAddress(address);

    volatile CHIP_WORD * ChipAddress = (volatile CHIP_WORD *) address;

    CHIP_WORD * EndAddress = (CHIP_WORD*)(address + blockLength);
    
    while(ChipAddress < EndAddress)
    {
        if( (*ChipAddress ) != (CHIP_WORD)0xFFFFFFFF)
        {
            return FALSE;   
        }
        ChipAddress ++;
    }
    return TRUE;
}
コード例 #30
0
BOOL __section(SectionForFlashOperations) AM29DL_32_BS_Driver::IsBlockErased( void* context, ByteAddress address, UINT32 blockLength )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    address = CPU_GetUncachableAddress(address);

    volatile CHIP_WORD * ChipAddress = (volatile CHIP_WORD *) address;

    CHIP_WORD * EndAddress = (CHIP_WORD*)(address + blockLength);
    
    while(ChipAddress < EndAddress)
    {
        if( (*ChipAddress ) != 0xFFFFFFFF)
        {
            return FALSE;   
        }
        ChipAddress ++;
    }
    return TRUE;
}