I met a problem when I program flash. There is line containing 4 bytes to be programmed in the *.srec file. But the driver only supports 8 bytes write. Could I modify the following micro to 4 in file S32K142_features.h?
/* @brief P-Flash Erase sector command address alignment. */
#define FEATURE_FLS_PF_SECTOR_CMD_ADDRESS_ALIGMENT (8u)
/* @brief P-Flash Program check command address alignment. */
#define FEATURE_FLS_PF_CHECK_CMD_ADDRESS_ALIGMENT (8u)
Actually, I've tried to modify, but the function FLASH_DRV_Program() return error, because the FTFx_FSTAT equals to 160, and at the last of the function FLASH_DRV_CommandSequence() will check it. So I think the above two micro could not be modified easily.
/* Check if an error is occurred */
if ((FTFx_FSTAT & (FTFx_FSTAT_MGSTAT0_MASK | FTFx_FSTAT_FPVIOL_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_RDCOLERR_MASK)) != 0U)
ret = STATUS_ERROR;
Waiting for your reply!
If we check the MCU commands we can find the Program Phrase command which programs eight previously-erased bytes (the smallest portion that can be programmed). So, not driver, but MCU supports 8 bytes write.
The easiest solution for you is to modify and align .srec to 8 bytes.
For this purpose you can use srec_cat tool:
Examples, how to use it:
I hope it helps.
Thank you very much. I use the srec_cat tool modify the .srec file. The last line of converted file is 12Bytes, and I add 0xff and calculate the checksum. Now I can download successfully.
My app code stored in 0xe000 to 0x3ffff, event if the code not occupied full memory, but I should fill 0xff in the left empty memory, and calculate a CRC to store in 0x3fffe and 0x3ffff. I have generate the .srec file I needed, but when I download in flash, the function FLASH_DRV_VerifySection() will return STATUS_ERROR becaue FTFx_FSTAT equals to 160, the FTFx_FSTAT_ACCERR_MASK is set, the address is 0x3f020. I check the reference manual, as below.
If the parameter check fails, the FSTAT[ACCERR] (access error) flag is set.
ACCERR reports invalid instruction codes and out-of bounds addresses.
Is the address 0x3f020 protected address? I didn't protect this area. just protect 0x10000000 to 0x1000ffff for eeprom.
Waiting for your reply.
I try to set the different values for the third parameter, and the verify function will return error at different addresses.
Obviously, the third parameter effect the result. Could you please explain how should I set this parameter?
Based on my origianl setting, I try to program the flash at 0x3f000, length is 16Bytes, it's OK, but it's NOT OK at 0x3f010.
And I check the register FSEC, SEC is 10b, MCU security status is unsecure.
So I considered the reference factors, and do above test, but still can't find the solution. Could you please help me analyze this problem?
At first, I would like to mention that the driver uses flash commands which requirements are described in the RM rev 11.
1. I would like to start with program flash. The FLASH_DRV_Program function uses Program phrase command (184.108.40.206 Program Phrase command). The requirement is that the flash address Must be 64-bit aligned (Flash address [2:0] = 000)
That is why this address 0x3f000 works for you.
2. The FLASH_DRV_VerifySection uses Read 1s Section command (Table 36-34. Read 1s Section command FCCOB requirements). This command requires:
- 64-bit aligned (Flash address [2:0] = 000) for non-interleaved flash.
- number of double phrases which is third parameter of the FLASH_DRV_VerifySection() function. We know that the one phrase is 8B and the double phrase is 16B.
We can define:
#define FTFx_DPHRASE_SIZE 0x0010U
Let's say that I want to verify memory from the address from 0x0000 to 0x40000
address = 0x0000
size = 0x40000 => 256kB
number of double phrases = 0x40000/0x0010 => 0x4000 => 16
FLASH_DRV_VerifySection(&pSSDConfig, address, size / FTFx_DPHRASE_SIZE, 1u);
If you want to verify flash at 0x3f000, length is 16Bytes.
address = 0x3f000
size = 0x0010 => 16B
number of double phrases = 0x0010/0x0010 => 1
I hope it helps.
Thank you for your explanation. I understand how to use the function FLASH_DRV_VerifySection(); correctly, and I've program the app flash successfully.
I read the reference manual, and find that if there is access error or protection violation, the FSTAT register should be set as 0x30 to clear the error for next command, check the red rectangle in the attachment.
In the code, it clears the above errors before new command, but there is another condition (STATUS_SUCCESS == ret) before clear.
So if last command contains errors, it will not execute the next command. And this is not keeping with the flowchat.