How to Read and Write Flash Addresses from Command Line?

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

How to Read and Write Flash Addresses from Command Line?

2,374 Views
james5
Contributor I

Hello everyone,

We are looking to add a serial number to flash memory of each MKL03Z32xxx4 device on the manufacturing line and to read out the unique 80-bit ID so that we can create our own lookup table between the two pieces of information.

To do so, I _think_ I need to use the redlinkserv command line utility and a custom connecting script.  But I don't know for sure and I'm not familiar with the script language.  Could someone suggest what I would need to do to:

1)  Read out the 80-bit UID and print it out to the console

2)  Take a command line parameter and write that 32-bit value to address 0x77FC (where the flash variable has been put in memory)?

Or maybe I'm way off.  What I'm trying to do is programatically do those two things so I can integrate into our manufacturing line and automate this process.  If there is a better way to do it then I'd love to hear it.  I am trying to stay away from having custom software running to support this, though that isn't out of the question (just seems like it shouldn't be necessary).

Thank you very much, I appreciate any help...

James.

Tags (1)
0 Kudos
Reply
8 Replies

2,133 Views
james5
Contributor I

OK, so I figured out half of this.

I have a connect script that I can pass to redlinkserv that will read out the UID and spit it out to the terminal.  So that is good. (NOTE there is a bug in the command help in specifying the connect script to call, see https://community.nxp.com/message/1174903).

The second part of writing flash is still TBD. I have forced the flash variable to a specific flash memory address but I need to be able to write that from the command line.  Anyone have any ideas on how to do that?

James

0 Kudos
Reply

2,134 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hi james@stratforddigital.ca‌,

If you check the help from the RedLinkServer, there are some commands that could be useful:

pastedImage_1.png

You could give it a try.

Best Regards,

Alexis Andalon

0 Kudos
Reply

2,134 Views
james5
Contributor I

Thanks Alexis.  I did find that in the command line help.

I have made some progress.  I'm currently having an issue in reading the PC register, or any of the core registers of the cortex (Cortex-M0+ Technical Reference Manual | Processor core registers summary – Arm Developer ).

I'm thinking that if I want to read R0 that I would use the command:

  i% = CMREADREG this 0

  Print "Reg[0] read as ";~i%

This always prints 0x00000000.  And the same for any other register index.

I have to be doing something wrong.  I have successfully read out the UID values (H, M, and L 32-bit words).  So in general the setup is good.  But I can't read these registers.  And when I try to write the script hangs completely and I have to disconnect target to reset.

What I am really trying to do is set the PC register (R15) to a local function that will program the flash.  But I can't reliably read and write to core registers at all.

James.

0 Kudos
Reply

2,134 Views
converse
Senior Contributor V

The IDE provides a bunch of scripts (.scp files) that do low-level manipulation of the part when starting a debug session. You can find these in the binaries/Scripts directory of the IDE install. Take a look at these scripts and they may give you a clue on how to achieve this.

Good luck!

0 Kudos
Reply

2,134 Views
james5
Contributor I

Thanks, that is how I started. I took the default kinetis connect script, left the pre-amble, and got it working to the point where I can print out the UID.  So in general things seem to be working OK.

But now I'm trying to read and write the registers and it's not working as expected.  I'm obviously missing something but I don't know what.

James.

0 Kudos
Reply

2,134 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Dear james@stratforddigital.ca,

The RedLink interface is only used to access the memory map (RAM and flash). As far as I know it can't be used to access the internal core registers.

Best Regards,

Alexis Andalon

0 Kudos
Reply

2,134 Views
james5
Contributor I

So what are the commands CMREADREG and CMWRITEREG for?

James

On Wed, Jul 24, 2019, 6:57 PM Alexis Andalon <admin@community.nxp.com>

0 Kudos
Reply

2,134 Views
Alexis_A
NXP TechSupport
NXP TechSupport

You're right James,

This commands looks like can read the internal register, what is the param that you're using? The MCUXpresso usually recognize this registers with the next notation:

r0 - r12

Could be the same with the redlink commands.

Best Regards,

Alexis Andalon

0 Kudos
Reply