公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
guohai1
Level 1
Level 1
First reply posted 5 sign-ins First question asked

你好,我现在在对xmc7200codeflash区写数据的时候发现只能按512Bytes大小写去,但数据手册里描述的支持64bits写入。SDK里面的Cy_Flash_ProgramRow里面的函数里:

flashContext.opcode = CY_FLASH_OPCODE_PROGRAM_ROW | CY_FLASH_BLOCKING_MODE;
flashContext.arg1   = CY_FLASH_DATA_LOC_SRAM;(CY_FLASH_DATA_LOC_SRAM=0x100,这个字段不是定义数据长度的么?)
flashContext.arg2   = rowAddr;
flashContext.arg3   = (uint32_t)data;
 
请问如果我要写长度64bits的数据应该如何操作呢?
0 点赞
1 解答
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

在MTB Tool里面有示例工程 Code_Flash_Sector_Data_Updating,这个工程打开以后,你可以搜索到API:

cy_en_flashdrv_status_t Cy_Flash_ProgramRow(uint32_t rowAddr, const uint32_t* data)

这个函数在文件cy_flash_v2.c的文件里面,函数体里面有一段是对这个配置的,配置的是256BIT。

 

    /* Checks whether the input parameters are valid */
    if(Cy_Flash_WorkBoundsCheck(rowAddr) == CY_FLASH_IN_BOUNDS)
    {
        flash_programrow_config.dataSize = CY_FLASH_PROGRAMROW_DATA_SIZE_32BIT;
    }
    else if(Cy_Flash_MainBoundsCheck(rowAddr) == CY_FLASH_IN_BOUNDS)
    {
        prog_length = ADDRESS_LENGTH_256_BIT;
        data_length = DATA_LENGTH_256_BIT;
        flash_programrow_config.dataSize = CY_FLASH_PROGRAMROW_DATA_SIZE_256BIT;
    }
    else
    {
        /* empty else statement. */
    }

 

这个里面你如果要改成64bit就通过这个地方改。对应的寄存器地址是:0x4024F000

现在你看到512个字节,是因为调用的函数是program_row,按照行来写的。如果不按照行来写,你要自己去修改一下program_row的函数。

修改define这一部分截图如下:

#define ADDRESS_LENGTH_32_BIT (4U)
#define ADDRESS_LENGTH_64_BIT (8U)

#define ADDRESS_LENGTH_256_BIT (32U)
#define DATA_LENGTH_32_BIT (1U)
#define DATA_LENGTH_64_BIT (2U)

#define DATA_LENGTH_256_BIT (8U)

把programrow的函数改成下面这样:

/* Checks whether the input parameters are valid */
    if(Cy_Flash_WorkBoundsCheck(rowAddr) == CY_FLASH_IN_BOUNDS)
    {
        flash_programrow_config.dataSize = CY_FLASH_PROGRAMROW_DATA_SIZE_32BIT;
    }
    else if(Cy_Flash_MainBoundsCheck(rowAddr) == CY_FLASH_IN_BOUNDS)
    {
        prog_length = ADDRESS_LENGTH_64_BIT;
        data_length = DATA_LENGTH_64_BIT;
        flash_programrow_config.dataSize = CY_FLASH_PROGRAMROW_DATA_SIZE_64BIT;
    }
    else
    {
        /* empty else statement. */
    }
    for(uint32_t i_addr = rowAddr;  i_addr < rowAddr + CY_FLASH_SIZEOF_ROW; i_addr+=prog_length)
    {
        flash_programrow_config.destAddr = (const uint32_t *)i_addr;
        flash_programrow_config.dataAddr = (const uint32_t *)(data);
        result = Cy_Flash_Program(&flash_programrow_config, CY_FLASH_DRIVER_BLOCKING);
        if(result != CY_FLASH_DRV_SUCCESS)
        {
            break;
        }
        data+=data_length;
    }
    return (result);

在main函数里面直接用这个函数去写:

printf("Target sector erase finished! \r\n\n");

    printf("Target sector program start.. \r\n");
    /* Programming code flash target sector */
   // result = cyhal_flash_program(&cyhal_flash, TEST_TARGET_ADDR, (uint32_t*)write_buff);
    result = Cy_Flash_ProgramRow(TEST_TARGET_ADDR,(uint32_t*)write_buff);
    
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

我测试过可以成功。

在原帖中查看解决方案

0 点赞
1 回复
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

在MTB Tool里面有示例工程 Code_Flash_Sector_Data_Updating,这个工程打开以后,你可以搜索到API:

cy_en_flashdrv_status_t Cy_Flash_ProgramRow(uint32_t rowAddr, const uint32_t* data)

这个函数在文件cy_flash_v2.c的文件里面,函数体里面有一段是对这个配置的,配置的是256BIT。

 

    /* Checks whether the input parameters are valid */
    if(Cy_Flash_WorkBoundsCheck(rowAddr) == CY_FLASH_IN_BOUNDS)
    {
        flash_programrow_config.dataSize = CY_FLASH_PROGRAMROW_DATA_SIZE_32BIT;
    }
    else if(Cy_Flash_MainBoundsCheck(rowAddr) == CY_FLASH_IN_BOUNDS)
    {
        prog_length = ADDRESS_LENGTH_256_BIT;
        data_length = DATA_LENGTH_256_BIT;
        flash_programrow_config.dataSize = CY_FLASH_PROGRAMROW_DATA_SIZE_256BIT;
    }
    else
    {
        /* empty else statement. */
    }

 

这个里面你如果要改成64bit就通过这个地方改。对应的寄存器地址是:0x4024F000

现在你看到512个字节,是因为调用的函数是program_row,按照行来写的。如果不按照行来写,你要自己去修改一下program_row的函数。

修改define这一部分截图如下:

#define ADDRESS_LENGTH_32_BIT (4U)
#define ADDRESS_LENGTH_64_BIT (8U)

#define ADDRESS_LENGTH_256_BIT (32U)
#define DATA_LENGTH_32_BIT (1U)
#define DATA_LENGTH_64_BIT (2U)

#define DATA_LENGTH_256_BIT (8U)

把programrow的函数改成下面这样:

/* Checks whether the input parameters are valid */
    if(Cy_Flash_WorkBoundsCheck(rowAddr) == CY_FLASH_IN_BOUNDS)
    {
        flash_programrow_config.dataSize = CY_FLASH_PROGRAMROW_DATA_SIZE_32BIT;
    }
    else if(Cy_Flash_MainBoundsCheck(rowAddr) == CY_FLASH_IN_BOUNDS)
    {
        prog_length = ADDRESS_LENGTH_64_BIT;
        data_length = DATA_LENGTH_64_BIT;
        flash_programrow_config.dataSize = CY_FLASH_PROGRAMROW_DATA_SIZE_64BIT;
    }
    else
    {
        /* empty else statement. */
    }
    for(uint32_t i_addr = rowAddr;  i_addr < rowAddr + CY_FLASH_SIZEOF_ROW; i_addr+=prog_length)
    {
        flash_programrow_config.destAddr = (const uint32_t *)i_addr;
        flash_programrow_config.dataAddr = (const uint32_t *)(data);
        result = Cy_Flash_Program(&flash_programrow_config, CY_FLASH_DRIVER_BLOCKING);
        if(result != CY_FLASH_DRV_SUCCESS)
        {
            break;
        }
        data+=data_length;
    }
    return (result);

在main函数里面直接用这个函数去写:

printf("Target sector erase finished! \r\n\n");

    printf("Target sector program start.. \r\n");
    /* Programming code flash target sector */
   // result = cyhal_flash_program(&cyhal_flash, TEST_TARGET_ADDR, (uint32_t*)write_buff);
    result = Cy_Flash_ProgramRow(TEST_TARGET_ADDR,(uint32_t*)write_buff);
    
    if (result != CY_RSLT_SUCCESS)
    {
        CY_ASSERT(0);
    }

我测试过可以成功。

0 点赞