0

Newlines in memory and nrfjprog --memrd

eliotstock gravatar image

asked 2018-01-13 18:39:34 +0100

Hi. My application uses an in-RAM log which I then read back to a terminal on the host using nrfjprog like this:

$/Users/eliot/dev/nRF5x_tools/nrfjprog/nrfjprog -c 1000 --family NRF52 --memrd 0x20002284 --n 0x400
0x20002284: 2D2D2D0A 0A2D2D2D 74752044 52206C69   |.------.D util R|
0x20002294: 74657365 61657220 736E6F73 440A0D3A   |eset reasons:..D|
0x200022A4: 69747520 2020206C 20555043 6B636F6C   | util   CPU lock|
0x200022B4: 0A0D7075 74732049 20657461 45534552   |up..I state RESE|
0x200022C4: 490A0D54 72777020 6D676D5F 6E492074   |T..I pwr_mgmt In|
0x200022D4: 0A0D7469 6F702044 20726577 72616843   |it..D power Char|
0x200022E4: 73206567 65746174 4843203A 45475241   |ge state: CHARGE|
0x200022F4: 4154535F 4E5F4554 435F544F 47524148   |_STATE_NOT_CHARG|
0x20002304: 0D474E49 7020440A 7265776F 61745320   |ING..D power Sta|

I can then make this a bit more readable using:

/Users/eliot/dev/nRF5x_tools/nrfjprog/nrfjprog -c 1000 --family NRF52 --memrd 0x20002284 --n 0x9000 | grep -o \|.*\| | tr -d '|'
.------.D util R
eset reasons:..D
 util   CPU lock
up..I state RESE
T..I pwr_mgmt In
it..D power Char
ge state: CHARGE
_STATE_NOT_CHARG
ING..D power Sta

But what I'd really like is the newlines I know are in that memory at the end of each log line to be preserved on the output, plus to be able to remove the newlines that nrfjprog adds. How do I do that?

edit retag flag offensive close delete report spam

1 answer

Sort by » oldest newest most voted
1
simtind gravatar image

answered 2018-01-15 14:50:11 +0100

Hi! I would try using pynrfjprog instead. To achieve the same functionality you could do something along the lines of the code below, and put it into a python script that can be run from command line:

from pynrfjprog import API
api = API.API('NRF52')
api.open()
api.connect_to_emu_without_snr(jlink_speed_khz=1000)
buffer = api.read(0x20002284, 0x9000)
api.close()

# buffer is a list of numbers, to decode it into a string we turn it into a bytearray and run decode.
# Any non-ASCII characters are ignored (shows up as \XX) when errors argument is set as below.
buffer = bytearray(buffer).decode('ASCII', errors='ignore')
print(buffer)

pynrfjprog is available as a pip package, install it with "pip install pynrfjprog".

edit flag offensive delete publish link more

Comments

Fantastic, thank you!

Eliot Stock ( 2018-01-17 12:48:59 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Recent questions

Question Tools

1 follower

Stats

Asked: 2018-01-13 18:39:34 +0100

Seen: 40 times

Last updated: jan. 15