6626 Flash 指针方式读

wen sir · 16次点击 · 10小时前

6626 Flash 数据可以通过  SF 接口   drv_sf_read  和  Cache 地址 及NoCache 地址读取。 以下为示例,有几个注意事项


1- Cache 地址指针读取时,如果Flash被写或者擦除或者修改过。  可能读到Cache里的旧数据。保证不了一定实时反应在Flash中的情况。

如果drv_icache_invalidate()是可以清除刷新Cache,但同时也会导致前后8Kb Cache RAM 全清除了。

2-NoCache 地址指针,在应用中不要使用。

3- 会变化的数据,建议最好使用 drv_sf_read来读。 


void example_sf(void)
{
    //OM6XXX has internal SPI Flash,
    // its cachable address is located at [0x00400000,0x00800000),
    // and non-cachable address is in [0x50000000,0x51000000).
   
#define Test_addr  (200 * 1024)
#define Test_byte  (16)
    uint8_t m;
    volatile char *ptr_Cache;
    volatile char *ptr_NoCache;
    static uint8_t write_buf[100];
    /// Buffer that stored the data to be read
    static uint8_t read_buf[100];
    drv_sf_enable(OM_SF, 0);
    ptr_Cache = 0x00400000 + Test_addr;
    ptr_NoCache = 0x50000000 + Test_addr;
    OM_LOG_DEBUG("Addr ptr_Cache:0x%08X,ptr_NoCache:0x%08X", ptr_Cache, ptr_NoCache);
    for (int  loop = 0; loop < 20; loop++)
    {
        /* code */
        for (uint8_t i = 0; i < 100; i++)
        {
            write_buf[i] = loop + i;
        }
        /* inside flash */
        // Enable Flash
        // Erase 4k in 128k
        drv_sf_erase(OM_SF, 0, Test_addr, 4 * 1024);
        // Read 100 bytes in 128k, it should be all 0xFF
        drv_sf_read(OM_SF, 0, Test_addr, read_buf, Test_byte);
        OM_LOG_DEBUG_ARRAY_EX("\n1-erase and drv Read :", read_buf, Test_byte);
        OM_LOG_DEBUG_ARRAY_EX("2-*ptr_Cache read:", ptr_Cache, Test_byte);
        OM_LOG_DEBUG("3-*ptr_NoCache read");
        for (uint8_t m = 0; m < Test_byte; m++)
        {
            OM_LOG_DEBUG("%02X ", *(volatile uint8_t *)(ptr_NoCache + m));
        }
        // Write Test_byte bytes to 128k
        drv_sf_write(OM_SF, 0, Test_addr, write_buf, Test_byte);
        // Read Test_byte bytes in 128k, it should be same as write_buf
        drv_sf_read(OM_SF, 0, Test_addr, read_buf, Test_byte);
        OM_LOG_DEBUG_ARRAY_EX("\n4-write and drv Read :", read_buf, Test_byte);
        OM_LOG_DEBUG("5-*ptr_Cache read:");
        for (uint8_t m = 0; m < Test_byte; m++)
        {
            OM_LOG_DEBUG("%02X ", *(volatile uint8_t *)(ptr_Cache + m));
        }
        OM_LOG_DEBUG("\n6-*ptr_NoCache read:");
        for (uint8_t m = 0; m < Test_byte; m++)
        {
            OM_LOG_DEBUG("%02X ", *(volatile uint8_t *)(ptr_NoCache + m));
        }
        OM_LOG_DEBUG_ARRAY_EX("\n7-*ptr_Cache read:", ptr_Cache, Test_byte);
        OM_LOG_DEBUG("\n");
    }
    while (1);
}


      ===================  Log   ===========================

1-erase and drv Read :: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF [16bytes]

2-*ptr_Cache read:: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF [16bytes]

3-*ptr_NoCache readFF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 

4-write and drv Read :: 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 [16bytes]

5-*ptr_Cache read:12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 

6-*ptr_NoCache read:12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 

7-*ptr_Cache read:: 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 [16bytes]



1-erase and drv Read :: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF [16bytes]

2-*ptr_Cache read:: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF [16bytes]

3-*ptr_NoCache readFF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 

4-write and drv Read :: 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 [16bytes]

5-*ptr_Cache read:13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 

6-*ptr_NoCache read:13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 

7-*ptr_Cache read:: 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 [16bytes]


6626_SF_TEST-202506176887.c
被收藏 0  ∙  0 赞  
加入收藏
点赞
0 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站