mk64 read from flash 0xE5FF8 causes busfault

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mk64 read from flash 0xE5FF8 causes busfault

1,059 Views
theadib
Contributor I

Hi,
i have a board running MK64FN01M similar to what FRDM_k64 has.

I do store settings on the flash on the last bytes I store a CRC.
For one sector on the board I get Bus faults when reading that section

the code calls a simple memcpy from 0xE5FF8 to RAM with length of 8 bytes.
This function in this code is called before with different memory sections.
only on those location the code crashes.
When I move this sector to other location, then it works.


Any ideas why that specific memory migth be problematic?

Thanks, Adib

0 Kudos
Reply
7 Replies

1,024 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @theadib 

Please first erase the entire sector, then write your settings data (including the CRC) aligned to 8-byte boundaries. Do not perform partial updates on the same 8-byte phrase. After that, proceed with the read operation.
 

BR

Alice

0 Kudos
Reply

997 Views
theadib
Contributor I
Hello Alice, thanks for your reply.
The Bus fault happens during read operation (memcpy from flash location)
What could cause Bus fault using regular flash address?
There was no write operation before.
Is it possible to persistently "block/protect" flash from reading.
My program was working on other devices ok.
Any ideas?
Thanks, Adib
0 Kudos
Reply

978 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @theadib 

There is the FSEC register. The SEC bits in FSEC determine whether the MCU is in a secure or unsecure state. While this controls the entire MCU, in your case only some memory cannot be read, so I don’t think this is the reason.
It’s possible that an error occurred during the previous write operation, so I recommend erasing the memory first, then reading it again to check whether it works properly.
 
Thank you.
 
BR
Alice
 
0 Kudos
Reply

279 Views
theadib
Contributor I

Hi @Alice_Yang 

sorry for bothering you ...
I now traced down the root cause to a double write to the same address with the same data.
This should not happen in a bug-free code
However,
the second write returns an error code
but then even a read to that sector causes that BUS_FAULT trap.

Is there a possibility to check the sector status before an access causes the whole program to crash?
So that I then can properly erase the sector again and put the sector in a correct state.
???
I have checked the FSFE description in the Reference manual section 29.4.10.2 Flash commands.
But I see not a command that can "test" a sector from a program memory. 
Am I missing something here?

That way I could make more resilient application to check the Flash status after reboot.


Thanks in advance,

Adib


0 Kudos
Reply

250 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @theadib 

After launch the Erase Flash Sector command, the FRFE erases the selected flash, then verifies that it is erase.   If the erase-verify fails the FSTAT[MGSTAT0] bit is set. The CCIF flag is set after the Erase Flash Sector operation
completes. The Erase Flash Sector command is suspendable (see the FCNFG[ERSSUSP] bit and Figure 29-11). 

Alice_Yang_0-1767953891145.png

 

BR

Alice

0 Kudos
Reply

377 Views
theadib
Contributor I

Hi @Alice_Yang ,

maybe this problem with some weird behaviour I recognize using my SEGGER JLink.

When I connect to my MK64FN1MOVLQ12 using MK64FN1M0XXX12 in JLink, then:

device MK64FN1MoXXX12

if SWD

speed 1000

connect

erase
loadbin imagefile.bin 0

usually the JLink claims the device is protected after erase.
and presents this attached dialogue.

I would have expected the device is unprotected and unsecured after erase command.

What should be the preferred sequence using JLink to completely erase the flash and load new image?


 Thanks in advance

0 Kudos
Reply

253 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @theadib 

When using J-Link to erase, there are two options for the same chip. Please choose the device name without “allow security”; this way, it won’t be secured after the erase.

Alice_Yang_0-1767951588914.png

Thank you. 

 

BR

Alice

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2268337%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Emk64%20read%20from%20flash%200xE5FF8%20causes%20busfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2268337%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3CBR%20%2F%3Ei%20have%20a%20board%20running%20MK64FN01M%20similar%20to%20what%20FRDM_k64%20has.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20do%20store%20settings%20on%20the%20flash%20on%20the%20last%20bytes%20I%20store%20a%20CRC.%3CBR%20%2F%3EFor%20one%20sector%20on%20the%20board%20I%20get%20Bus%20faults%20when%20reading%20that%20section%3C%2FP%3E%3CP%3Ethe%20code%20calls%20a%20simple%20memcpy%20from%200xE5FF8%20to%20RAM%20with%20length%20of%208%20bytes.%3CBR%20%2F%3EThis%20function%20in%20this%20code%20is%20called%20before%20with%20different%20memory%20sections.%3CBR%20%2F%3Eonly%20on%20those%20location%20the%20code%20crashes.%3CBR%20%2F%3EWhen%20I%20move%20this%20sector%20to%20other%20location%2C%20then%20it%20works.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EAny%20ideas%20why%20that%20specific%20memory%20migth%20be%20problematic%3F%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%2C%20Adib%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2268406%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20mk64%20read%20from%20flash%200xE5FF8%20causes%20busfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2268406%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F251352%22%20target%3D%22_blank%22%3E%40theadib%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3EPlease%20first%20erase%20the%20entire%20sector%2C%20then%20write%20your%20settings%20data%20(including%20the%20CRC)%20aligned%20to%208-byte%20boundaries.%20Do%20not%20perform%20partial%20updates%20on%20the%20same%208-byte%20phrase.%20After%20that%2C%20proceed%20with%20the%20read%20operation.%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EAlice%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2268713%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20mk64%20read%20from%20flash%200xE5FF8%20causes%20busfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2268713%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EHello%20Alice%2C%20thanks%20for%20your%20reply.%3CBR%20%2F%3EThe%20Bus%20fault%20happens%20during%20read%20operation%20(memcpy%20from%20flash%20location)%3CBR%20%2F%3EWhat%20could%20cause%20Bus%20fault%20using%20regular%20flash%20address%3F%3CBR%20%2F%3EThere%20was%20no%20write%20operation%20before.%3CBR%20%2F%3EIs%20it%20possible%20to%20persistently%20%22block%2Fprotect%22%20flash%20from%20reading.%3CBR%20%2F%3EMy%20program%20was%20working%20on%20other%20devices%20ok.%3CBR%20%2F%3EAny%20ideas%3F%3CBR%20%2F%3EThanks%2C%20Adib%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2268780%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20mk64%20read%20from%20flash%200xE5FF8%20causes%20busfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2268780%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F251352%22%20target%3D%22_blank%22%3E%40theadib%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3EThere%20is%20the%20FSEC%20register.%20The%20SEC%20bits%20in%20FSEC%20determine%20whether%20the%20MCU%20is%20in%20a%20secure%20or%20unsecure%20state.%20While%20this%20controls%20the%20entire%20MCU%2C%20in%20your%20case%20only%20some%20memory%20cannot%20be%20read%2C%20so%20I%20don%E2%80%99t%20think%20this%20is%20the%20reason.%3C%2FDIV%3E%0A%3CDIV%3EIt%E2%80%99s%20possible%20that%20an%20error%20occurred%20during%20the%20previous%20write%20operation%2C%20so%20I%20recommend%20erasing%20the%20memory%20first%2C%20then%20reading%20it%20again%20to%20check%20whether%20it%20works%20properly.%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EThank%20you.%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EBR%3C%2FDIV%3E%0A%3CDIV%3EAlice%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2288933%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20mk64%20read%20from%20flash%200xE5FF8%20causes%20busfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2288933%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F27788%22%20target%3D%22_blank%22%3E%40Alice_Yang%3C%2FA%3E%26nbsp%3B%2C%3CBR%20%2F%3E%3CBR%20%2F%3Emaybe%20this%20problem%20with%20some%20weird%20behaviour%20I%20recognize%20using%20my%20SEGGER%20JLink.%3CBR%20%2F%3E%3CBR%20%2F%3EWhen%20I%20connect%20to%20my%20MK64FN1MOVLQ12%20using%20MK64FN1M0XXX12%20in%20JLink%2C%20then%3A%3C%2FP%3E%3CP%3Edevice%20MK64FN1MoXXX12%3C%2FP%3E%3CP%3Eif%20SWD%3C%2FP%3E%3CP%3Espeed%201000%3C%2FP%3E%3CP%3Econnect%3C%2FP%3E%3CP%3Eerase%3CBR%20%2F%3Eloadbin%20imagefile.bin%200%3CBR%20%2F%3E%3CBR%20%2F%3Eusually%20the%20JLink%20claims%20the%20device%20is%20protected%20after%20erase.%3CBR%20%2F%3Eand%20presents%20this%20attached%20dialogue.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20would%20have%20expected%20the%20device%20is%20unprotected%20and%20unsecured%20after%20erase%20command.%3CBR%20%2F%3E%3CBR%20%2F%3EWhat%20should%20be%20the%20preferred%20sequence%20using%20JLink%20to%20completely%20erase%20the%20flash%20and%20load%20new%20image%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3BThanks%20in%20advance%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2290471%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20mk64%20read%20from%20flash%200xE5FF8%20causes%20busfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2290471%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F27788%22%20target%3D%22_blank%22%3E%40Alice_Yang%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3Esorry%20for%20bothering%20you%20...%3CBR%20%2F%3EI%20now%20traced%20down%20the%20root%20cause%20to%20a%20double%20write%20to%20the%20same%20address%20with%20the%20same%20data.%3CBR%20%2F%3EThis%20should%20not%20happen%20in%20a%20bug-free%20code%20%3CLI-EMOJI%20id%3D%22lia_winking-face%22%20title%3D%22%3Awinking_face%3A%22%3E%3C%2FLI-EMOJI%3E%3CBR%20%2F%3EHowever%2C%3CBR%20%2F%3Ethe%20second%20write%20returns%20an%20error%20code%3CBR%20%2F%3Ebut%20then%20even%20a%20read%20to%20that%20sector%20causes%20that%20BUS_FAULT%20trap.%3CBR%20%2F%3E%3CBR%20%2F%3EIs%20there%20a%20possibility%20to%20check%20the%20sector%20status%20before%20an%20access%20causes%20the%20whole%20program%20to%20crash%3F%3CBR%20%2F%3ESo%20that%20I%20then%20can%20properly%20erase%20the%20sector%20again%20and%20put%20the%20sector%20in%20a%20correct%20state.%3CBR%20%2F%3E%3F%3F%3F%3CBR%20%2F%3EI%20have%20checked%20the%20FSFE%20description%20in%20the%20Reference%20manual%20section%26nbsp%3B29.4.10.2%20Flash%20commands.%3CBR%20%2F%3EBut%20I%20see%20not%20a%20command%20that%20can%20%22test%22%20a%20sector%20from%20a%20program%20memory.%26nbsp%3B%3CBR%20%2F%3EAm%20I%20missing%20something%20here%3F%3CBR%20%2F%3E%3CBR%20%2F%3EThat%20way%20I%20could%20make%20more%20resilient%20application%20to%20check%20the%20Flash%20status%20after%20reboot.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20in%20advance%2C%3CBR%20%2F%3E%3CBR%20%2F%3EAdib%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2290960%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20mk64%20read%20from%20flash%200xE5FF8%20causes%20busfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2290960%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F251352%22%20target%3D%22_blank%22%3E%40theadib%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20launch%20the%20Erase%20Flash%20Sector%20command%2C%20the%20FRFE%20erases%20the%20selected%20flash%2C%20then%20verifies%20that%20it%20is%20erase.%26nbsp%3B%26nbsp%3B%20If%20the%20erase-verify%20fails%20the%26nbsp%3BFSTAT%5BMGSTAT0%5D%20bit%20is%20set.%26nbsp%3BThe%20CCIF%20flag%20is%20set%20after%20the%20Erase%20Flash%20Sector%20operation%3CBR%20%2F%3Ecompletes.%20The%20Erase%20Flash%20Sector%20command%20is%20suspendable%20(see%20the%20FCNFG%5BERSSUSP%5D%20bit%20and%20Figure%2029-11).%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Alice_Yang_0-1767953891145.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Alice_Yang_0-1767953891145.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Alice_Yang_0-1767953891145.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F372306i71ADD6A366C57CBB%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Alice_Yang_0-1767953891145.png%22%20alt%3D%22Alice_Yang_0-1767953891145.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EAlice%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2290845%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20mk64%20read%20from%20flash%200xE5FF8%20causes%20busfault%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2290845%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F251352%22%20target%3D%22_blank%22%3E%40theadib%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%3EWhen%20using%20J-Link%20to%20erase%2C%20there%20are%20two%20options%20for%20the%20same%20chip.%20Please%20choose%20the%20device%20name%20without%20%E2%80%9Callow%20security%E2%80%9D%3B%20this%20way%2C%20it%20won%E2%80%99t%20be%20secured%20after%20the%20erase.%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Alice_Yang_0-1767951588914.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Alice_Yang_0-1767951588914.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F372303i81758EFC9ABBC95B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Alice_Yang_0-1767951588914.png%22%20alt%3D%22Alice_Yang_0-1767951588914.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThank%20you.%26nbsp%3B%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EAlice%3C%2FP%3E%3C%2FLINGO-BODY%3E