CODE FLASH S7-G2 - Custom board

Hello,

 

My requirement is to store a bunch(1000 samples) of sensor values on flash in case the network fails during transmission. I use a custom S7-G2 board and so far I manage to store something on the data flash and it works fine. But I' intend to use code flash and there seems to be a problem with the api to erase even with configuration settings having code flash enabled even with the same addressing given in the example. Does the addressing change with the different S7g2 processors?

Also, where can I find more details on addressing of this flash memory block.

#define FLASH_CF_32KB_BLOCK64 (0x001D0000)
#define FLASH_CF_BLOCK_SIZE_32KB (32 * 1024)

err = g_flash.p_api->erase(g_flash.p_ctrl, FLASH_CF_32KB_BLOCK64, 1 );

  • What is the problem, does the API return an error, or does the flash block not get erased?

     

  • In reply to Jeremy:

    The API does not return an error. It works somehow now.

     

    My code is 

     

    void server_multiplication(void)
    {
    C2RESULT res;

    /* start the link, fail if error */
    // c2_failerr("start link", c2_start(CFG_MY_ADDR, CFG_MY_FLAGS));

    // TIMES_RESPONSE resp;
    ssp_err_t err;
    uint8_t read[BLOCK_SIZE];

    uint8_t read1[BLOCK_SIZE];


    uint32_t write[BLOCK_SIZE];

    for(int j=0;j<BLOCK_SIZE;j++)
    {
    write[j] = WRITE_DF_BYTES;
    read[j] = CLEAR_READ_BUFFER;
    read1[j] = CLEAR_READ_BUFFER;
    }
    while(true)
    {

    int status;

    if(flash_hp_init()==1)
    {
    C2PRINT("\n Flash init successfull");
    }

     

     


    err = g_flash.p_api->erase(g_flash.p_ctrl, FLASH_DF_64B_BLOCK1, 1 );

    err = g_flash.p_api->erase(g_flash.p_ctrl, FLASH_CF_32KB_BLOCK64, 1 );

    if(err != SSP_SUCCESS)
    {
    error_trap("g_flash.p_api->erase", err);
    }

     

    C2PRINT("\n Erase - data flash successful");

    err = g_flash.p_api->erase(g_flash.p_ctrl, FLASH_DF_64B_BLOCK1, 1 );

    C2PRINT("\n Erase - code flash successful");

    g_flash.p_api->write(g_flash.p_ctrl, (uint32_t) write, FLASH_DF_64B_BLOCK1, FLASH_DF_BLOCK_SIZE);

    g_flash.p_api->write(g_flash.p_ctrl, (uint32_t) write, FLASH_CF_32KB_BLOCK64, FLASH_DF_BLOCK_SIZE);

    C2PRINT("\n Write successful");


    C2PRINT("\n Read init");

    err = g_flash.p_api->read(g_flash.p_ctrl, read, FLASH_DF_64B_BLOCK1, FLASH_DF_BLOCK_SIZE);

    C2PRINT("\n Read complete \n");


    for(int i = 0;i<FLASH_DF_BLOCK_SIZE;i++)
    {


    C2PRINTF("%x ",*(read+i));
    if((i+1)%8==0)
    {
    C2PRINT("\n");
    }


    }


    err = g_flash.p_api->read(g_flash.p_ctrl, read, FLASH_CF_32KB_BLOCK64, BLOCK_SIZE);

    for(int i = 0; i < BLOCK_SIZE; i++)
    {
    C2PRINTF("%x ",*(read+i));
    if((i+1)%8==0)
    {
    C2PRINT("\n");
    }
    }


    break;
    }


    }

     

     

    But I'm getting the following output. Should not be the data read from data flash read block and code flash read block be the same?

     

     

    TIA. Regards,

    surender

  • In reply to suren:

    Programming of the code flash has to be done in 256 byte units :-

    So the write to code flash you attempt fails :-

    g_flash.p_api->write(g_flash.p_ctrl, (uint32_t) write, FLASH_CF_32KB_BLOCK64, FLASH_DF_BLOCK_SIZE);

     

    and you don't check the return value of the API call, so you don't know it has failed.

  • Hi The Address Should not Change with a custom BSP. The BSP only Edits The XML Pin Configuration File.