Fill unused flash with invalid instruction

cancel
Showing results for 
Search instead for 
Did you mean: 

Fill unused flash with invalid instruction

834 Views
riccardolalli
Contributor I

Hello everyone,

My binary images don't occupy the whole flash memory and they come with holes too, so I would like to fill them with some kind of value that makes the mcu reset if executed by accident.

It needs to work with S32K14x family, but if it works with S32K11x is a bonus.

I followed this thread https://community.nxp.com/thread/453969 but now I'm unsure about which value I should use.

I have found the UDF instruction to be a good candidate, but I don't understand the difference between its T1 (16bit) and T2 (32bit) encodings.

is the T1 version (0xDExx) ok for my purposes?

Are there any flaws with this approach?

Thank you very much,

Riccardo

0 Kudos
4 Replies

619 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Riccardo,

Have you considered using Memory Protection Unit?

Regards,

Daniel

0 Kudos

618 Views
riccardolalli
Contributor I

Hello Daniel,

Thanks for the support.

I didn't think about MPU! However I was thinking of filling empty space with some data pattern because I also need to compute a checksum over the image so I thought I could kill two birds with one stone.

0 Kudos

618 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Riccardo,

I don't think there is a standard for this.

But AN4779 EMC Design Tips for Kinetis E Family, Cortex M0+, recommends the undefined branch instruction that you are considering 0xDExx. 

Checking ARM®v7-M Architecture Reference Manual, I see that only Encoding T1 has the UNDEFINED variant of that instruction. I have tried that on S32K144, it seems to be working, it triggers CFSR[UNDEFINSTR].

pastedImage_2.png

If you don't use Supervisor Call, I think you can use __asm__("svc #0x00") as well.

pastedImage_3.png

pastedImage_1.png

And trigger SW reset from that exception instead of the fault exception. 

Regards,

Daniel

0 Kudos

618 Views
riccardolalli
Contributor I

Thank you, I'll try both of them.

Regards,

Riccardo

0 Kudos