I am following the flash_erase_program_verifiy example with a FRDMK82F board.
I am not sure what I am missing, I suppose I should be able to read back the exact values that have been programmed; i.e. the contents of buffer = {0, 1, 2, 3 ...}
Before the end, I added the following lines to the source file:
uint32_t readback[BUFFER_LEN]; /* Buffer for program */
result = FLASH_ReadOnce(&flashDriver, destAdrss, readback, sizeof(buffer));
if (kStatus_FLASH_Success != result)
{
error_trap();
}
for (i = 0; i < BUFFER_LEN; i++)
{
PRINTF("%d %x %x\r\n", i, buffer[i], readback[i]);
}
and the output I get is the following:
Flash Example Start
Flash Information:
Total Program Flash Size: 256 KB, Hex: (0x40000)
Program Flash Sector Size: 4 KB, Hex: (0x1000)
There is no D-Flash (FlexNVM) on this Device.
There is no Enhanced EEPROM (EEE) on this Device.
Flash is UNSECURE!
Erase a sector of flash
Successfully Erased Sector 0x3f000 -> 0x40000
Program a buffer to a sector of flash
Successfully Programmed and Verified Location 0x3f000 -> 0x3f010
0 0 ffffffff
1 1 2002ffac
2 2 ffffffff
3 3 2002ff3c
End of Flash Example
If anyone could shed some light on this matter, it would be appreciated.
Original Attachment has been moved to: flash_erase_program_verify.c.zip
Hi Javier,
I've attached the code of the FLASH_ReadOnce function and you can see the exactly meaning of the kind of parameters, I don't think the usage of your demo is compatible with it.
status_t FLASH_ReadOnce(flash_config_t *config, uint32_t index, uint32_t *dst, uint32_t lengthInBytes)
{
status_t returnCode;
if ((config == NULL) || (dst == NULL))
{
return kStatus_FLASH_InvalidArgument;
}
/* pass paramters to FTFx */
kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_1_2(FTFx_READ_ONCE, index, 0xFFFFU);
/* calling flash command sequence function to execute the command */
returnCode = flash_command_sequence(config);
if (kStatus_FLASH_Success == returnCode)
{
*dst = kFCCOBx[1];
/* Note: Have to seperate the first index from the rest if it equals 0
* to avoid a pointless comparison of unsigned int to 0 compiler warning */
#if FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT
#if FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT
if (((index == FLASH_PROGRAM_ONCE_MIN_ID_8BYTES) ||
/* Range check */
((index >= FLASH_PROGRAM_ONCE_MIN_ID_8BYTES + 1) && (index <= FLASH_PROGRAM_ONCE_MAX_ID_8BYTES))) &&
(lengthInBytes == 8))
#endif /* FLASH_PROGRAM_ONCE_IS_4BYTES_UNIT_SUPPORT */
{
*(dst + 1) = kFCCOBx[2];
}
#endif /* FLASH_PROGRAM_ONCE_IS_8BYTES_UNIT_SUPPORT */
}
return returnCode;
}
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ping,
Thanks for the quick answer and then pointers. I went and looked more carefully to the API description.
It states:
Read Program Once Field through parameters
This function reads the read once feild with given index and length.
If I understand correctly, it means that I do not read the actual data back, but whatever this field is and means. I suppose this given that there are Flash_Program, Flash_ProgramOnce, and Flash_ReadOnce functions. What I would expect then is a Flash_Read function, but I don't think is there, is it?
Does it mean that I cannot read the flash at all? I'm fairly new to this, so I may be missing something very obvious.
Thanks in advance.
Hi Javier,
Thanks for your reply.
In your code, the second parameter is the destAdree instead of the index. I think it's not correct.
For instance, to read the 0x80~0x83, you can use the following code.
uint32_t readback[4]; /* Buffer for program */
result = FLASH_ReadOnce(&flashDriver, 0x20, readback, sizeof(readback));
if (kStatus_FLASH_Success != result)
{
error_trap();
}
Hope it helps.
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ping,
Thanks for the pointers. I think I complicated the issue too much. In the end, I solved it by doing a simple memcpy:
// Read expected signature here.
PRINTF("DATA_ADDR: %x\r\n", DATA_ADDR);
uint8_t data[DATA_SIZE];
memcpy(data, (uint8_t*)DATA_ADDR, DATA_SIZE);
because I was not interested in the Read Once field, but in the data itself.
Thanks again for the help!