Hello Daniel,
Thanks for your valuable reply!!!
We want to write the DFLASH in Dword aligned with induvial parameters as per our project need. So it will not work for us to erase sector. Please see the below function dflash_write_multiple from where we are writing the Dflash,
/**
* Hardware Abstraction Layer API for writing the multiple bytes value to Dflash memory locations
*
* @Param[in] address Dflash memory location address
* @Param[in] buffer Pointer for holding the Dflash write values
* @Param[in] no_of_bytes Number of bytes to be written to Dflash
* @retval hal_err_type_t Returns the status as <i>HAL_INIT_OK</i> or <i>HAL_GENERAL_ERROR</i>
*/
hal_err_type_t dflash_write_multiple(uint32_t address, uint8_t *buffer, uint8_t no_of_bytes)
{
hal_err_type_t ret = HAL_GENERAL_ERROR;
uint8_t domain_id = 0;
C40_Ip_VirtualSectorsType VirtualSector;
uint32_t total_bytes = 0;
uint32_t byte_pos_in_dword;
uint8_t buf16[16] = {0};
uint8_t buf128[128+16] = {0};
if(no_of_bytes > MAX_BYTES_ALLOWED)
{
return HAL_PARAM_MAX_ERROR;
}
if(address >= DFLASH_START_ADDRESS && address<= DFLASH_END_ADDRESS)
{
/* Get sector number */
VirtualSector = C40_Ip_GetSectorNumberFromAddress(address);
C40_Ip_ClearLock(VirtualSector,0);
if(no_of_bytes <= C40_WRITE_DOUBLE_WORD) /* Number bytes are 8 */
{
byte_pos_in_dword = address % C40_WRITE_DOUBLE_WORD; /* Check byte position in DWORD */
if((byte_pos_in_dword == 0) && (no_of_bytes == C40_WRITE_DOUBLE_WORD))
{
if(STATUS_C40_IP_SUCCESS == C40_Ip_MainInterfaceWrite(address, no_of_bytes, buffer, domain_id))
{
ret = HAL_OK;
while(STATUS_C40_IP_BUSY == C40_Ip_MainInterfaceWriteStatus());
}
}
else
{
if(STATUS_C40_IP_SUCCESS == C40_Ip_Read(address - byte_pos_in_dword, sizeof(buf16), buf16))
{
memcpy(&buf16[byte_pos_in_dword], buffer, no_of_bytes);
if(STATUS_C40_IP_SUCCESS == C40_Ip_MainInterfaceWrite(address - byte_pos_in_dword, sizeof(buf16), buf16, domain_id))
{
ret = HAL_OK;
while(STATUS_C40_IP_BUSY == C40_Ip_MainInterfaceWriteStatus());
}
}
}
}
else if(no_of_bytes > C40_WRITE_DOUBLE_WORD)
{
byte_pos_in_dword = address % C40_WRITE_DOUBLE_WORD; /* Check byte position in DWORD */
total_bytes = (no_of_bytes + byte_pos_in_dword) + \
(C40_WRITE_DOUBLE_WORD - byte_pos_in_dword) + \
(C40_WRITE_DOUBLE_WORD - (no_of_bytes%8));
if(STATUS_C40_IP_SUCCESS == C40_Ip_Read(address - byte_pos_in_dword, total_bytes, buf128))
{
memcpy(&buf128[byte_pos_in_dword], buffer, total_bytes);
if(STATUS_C40_IP_SUCCESS == C40_Ip_MainInterfaceWrite(address - byte_pos_in_dword, total_bytes, buf128, domain_id))
{
ret = HAL_OK;
while(STATUS_C40_IP_BUSY == C40_Ip_MainInterfaceWriteStatus());
}
}
}
}
return ret;
}
We are reading the Dflash in debug mode.
Thanks & Regards,
Sachin N