Beispiel #1
0
static uint32_t flash_write(uint32_t addr, const uint8_t *buf, uint32_t len)
{
    if(FLASH_WriteSector(addr, buf, len) == FLASH_OK)
    {
        return BL_FLASH_OK;
    }
    else
    {
        return BL_FLASH_ERR;
    }
}
Beispiel #2
0
uint32_t FLASH_Test(uint32_t startAddr, uint32_t size)
{
    int addr, i,err;
    
    uint8_t *p;
    uint8_t buf[SECTOR_SIZE];
    
    FLASH_Init();
    
    for(i=0;i<SECTOR_SIZE;i++)
    {
        buf[i] = i % 0xFF;
    }
    
    for (addr = startAddr; addr<size; addr+=SECTOR_SIZE)
    {
        LIB_TRACE("program addr:0x%X ...", addr);
        err = FLASH_EraseSector(addr);
        err += FLASH_WriteSector(addr, buf, SECTOR_SIZE);
        if(err)
        {
            LIB_TRACE("issue command failed\r\n");
            return 1;
        }
        p = (uint8_t*)addr;
        LIB_TRACE("varify addr:0x%X ...", addr);
        for(i=0;i<SECTOR_SIZE;i++)
        {
            if(*p++ != (i%0xFF))
            {
                err++;
                LIB_TRACE("ERR:[%d]:0x%02X ", i, *p);
            }
        }
        if(!err)
            LIB_TRACE("OK\r\n");
        else
            LIB_TRACE("ERR\r\n");
    }
    return err;
}
Beispiel #3
0
static rt_size_t rt_dflash_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
{
    int i;
    uint8_t *p;
    
    rt_mutex_take(mutex, RT_WAITING_FOREVER);

    p = (uint8_t*)(StartAddr + pos * SectorSize);
    for(i=0;i<size;i++)
    {
        __disable_irq();
        FLASH_EraseSector((uint32_t)p);
        FLASH_WriteSector((uint32_t)p, buffer, SectorSize);
        __enable_irq();
        p += SectorSize;
    }
       
    rt_mutex_release(mutex);
    
    return size;
}