Monday, December 11th 2017, 4:54am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

donturner

Beginner

Date of registration: Jul 15th 2016

Posts: 14

1

Sunday, December 3rd 2017, 10:35pm

[SOLVED] Failing to read USB peripheral registers

I'm building a USB device using a Freescale Kinetis MK20DX256XXX7 MCU. I'm using J-Link EDU (V10 API version 6.20h) and Ozone (2.52d) on Mac OSX (10.12.6) to debug the app and to read the memory-mapped peripheral registers.

When I try to read the USB0 peripheral most of the entries appear as 0xAA and do not update even when I write to them:




Any ideas why this could be happening?

SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 430

2

Monday, December 4th 2017, 9:12am

Hello,

Thank you for your inquiry.
It sounds like the memory area you are trying to read/write can't be accessed at the time by J-Link.
Are you setting some kind of flash security with your application?
Do you use any low power modes, that might disable or inhibit the debug connection to J-Link?
Is the issue reproducible on an eval board. If yes then how?

Best regards,
Nino

donturner

Beginner

Date of registration: Jul 15th 2016

Posts: 14

3

Monday, December 4th 2017, 1:29pm

I'm not using any flash security or memory protection in my app. I also tried using the JLinkExe terminal but was unable to read the memory using the following command:

`J-Link>mem32 4007209C 1
Could not read memory.`


If I use Eclipse with the GNU-ARM MCU eclipse plugin (gnu-mcu-eclipse.github.io) I am able to read the registers correctly:



Here's my Eclipse debug settings. Could the "set mem inaccessible-by-default off" have something do with it?

This post has been edited 1 times, last edit by "donturner" (Dec 4th 2017, 1:31pm)


SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 430

4

Monday, December 4th 2017, 2:24pm

Hello,

How is your Ozone setup?
Could you post your .jdebug and .user file?
Do you have any memory windows open that are trying read form inaccessible memory?
If so close all memory windows.

Is the peripheral you want to edit clocked/configured?
If not then J-Link might not be able to access the register.

Quoted

`J-Link>mem32 4007209C 1
Could not read memory.`


This was only reproducible when the USB0 periphery was not clocked.

Quoted

Could the "set mem inaccessible-by-default off" have something do with it?


I could not find any conclusive documentary about that setting but it is possible that Eclipse works around that issue by doing some setup in the background.

Best regards,
Nino

donturner

Beginner

Date of registration: Jul 15th 2016

Posts: 14

5

Monday, December 4th 2017, 2:50pm

Here's my .jdebug file:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void OnProjectLoad (void) {
  //
  // Dialog-generated settings
  //
  Project.SetDevice ("MK20DX256xxx7");
  Project.SetHostIF ("USB", "");
  Project.SetTargetIF ("SWD");
  Project.SetTIFSpeed ("1 MHz");
  Project.AddSvdFile ("/Users/donturner/PCode/Packages/Keil/Kinetis_K20_DFP/1.6.0/SVD/MK20D7.svd");
 
  //
  // User settings
  //
  File.Open ("/Users/donturner/PCode/workspace-clion/uflare4/cmake-build-debug/uflare4.elf");
}


Note that the MK20D7.svd file is the same one I'm using in Eclipse.

And my .user file:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
OpenWindow="Memory1", DockArea=BOTTOM, x=1, y=0, w=557, h=316, FilterBarShown=0, 
OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=1, w=717, h=107, FilterBarShown=0, ExecCountersShown=0
OpenWindow="Registers", DockArea=RIGHT, x=0, y=2, w=717, h=293, FilterBarShown=0, 
OpenWindow="Console", DockArea=BOTTOM, x=2, y=0, w=607, h=316, FilterBarShown=0, 
OpenWindow="Global Data", DockArea=RIGHT, x=0, y=3, w=717, h=141, FilterBarShown=1, 
OpenWindow="Local Data", DockArea=RIGHT, x=0, y=0, w=717, h=93, FilterBarShown=0, 
OpenWindow="Call Stack", DockArea=LEFT, x=0, y=1, w=519, h=144, FilterBarShown=0, 
OpenWindow="Terminal", DockArea=BOTTOM, x=0, y=0, w=514, h=316, FilterBarShown=0, 
OpenWindow="Code Profile", DockArea=LEFT, x=0, y=0, w=519, h=492, FilterBarShown=1, 
OpenToolbar="Debug", Floating=0, x=0, y=0
TableHeader="Registers", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Address";"Description"], ColWidths=[120;80;77;425]
TableHeader="Global Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Access";"Namespace"], ColWidths=[172;104;84;39;255;63;78]
TableHeader="Local Data", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Location";"Size";"Type";"Access"], ColWidths=[132;10;84;10;526;88]
TableHeader="Call Stack", SortCol="Function", SortOrder="ASCENDING", VisibleCols=["Function";"Stack Info";"Source"], ColWidths=[107;105;307]
TableHeader="Code Profile", SortCol="File / Function", SortOrder="ASCENDING", VisibleCols=["File / Function";"Source Coverage";"Inst. Coverage";"Run Count";"Fetch Count";"Load"], ColWidths=[178;106;105;73;81;84]


The USB0 peripheral is being clocked, here's the relevant code:

Source code

1
2
simType->SOPT2 = SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK;
simType->SCGC4 = SIM_SCGC4_USBOTG_MASK;


And I'm also getting USB interrupts which would indicate that my code is able to write to the USB peripheral successfully - I'm just unable to read its registers in Ozone or in JLinkExe.

Which board are you testing on? I also have a FRDM-K22F and a FRDM-K66F which I could test on if that would help?

donturner

Beginner

Date of registration: Jul 15th 2016

Posts: 14

6

Tuesday, December 5th 2017, 11:03am

I think I found the problem.

Ozone doesn't update registers which are not currently shown on the screen.

Steps to reproduce:

- Open Ozone
- Ensure that the registers view is *closed*
- Write a value to an MCU register. In my case I wrote 0xDE to USB0->BDTPAGE1
- Open the register view and look at the value

Expected result

- Value for USB0->BDTPAGE1 is shown as 0xDE

Actual result

- Value for USB0->BDTPAGE1 is shown as 0xAA

I would expect Ozone to update the register values when I open the register view and open a particular peripheral.

I found that if I pop out the register view and maximise it on a second screen then everything works as expected - as long as the registers I want to monitor are actually on the screen the values update fine.

An additional confusing behaviour is that Ozone uses 0xAA as the default value for registers which haven't been read. 0xAA is a valid value so it's impossible to know at a glance whether Ozone is telling you correct information or just hasn't updated the value.

SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 430

7

Tuesday, December 5th 2017, 1:03pm

Hello,

Thank you for providing a reproduction scenario.
I was able to reproduce the behaviour with a XTWR-K20D72M Board.

The issue seems to be that the register window accesses the register as a 16 bit register instead of 8 bit as it actually is.
This lead to the 0xAA value which actually is the sequence J-Link is getting from the target when reading inaccessible memory (or in this case wrong accessed memory).

We will check if the error handling of the 0xAA value can be improved.
For the issue itself we are currently working on a fix which should be available in the next release version planned for this week.

To verify that your issue is actually related to the behaviour we are seeing here could you provide a J-Link log file for the not working and working case?
How to enable the log file is described here: https://wiki.segger.com/Enable_J-Link_log_file

As a workaround you can use the popped out window or the memory window for now.

Best regards,
Nino

SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 430

8

Tuesday, December 5th 2017, 5:20pm

Hello,

Quick follow up.
The new Ozone version has been release and is available here.

Does it solve the issue you were seeing?

Best regards,
Nino

donturner

Beginner

Date of registration: Jul 15th 2016

Posts: 14

9

Wednesday, December 6th 2017, 11:05pm

Amazing!! That's solved the issue - thanks so much for getting this fixed so quickly. Excellent work on the forum and from your software engineers.

I can stop using Eclipse now :)

SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 430

10

Thursday, December 7th 2017, 9:37am

Hi,

Great to hear that you are up and running again.

Quoted

I can stop using Eclipse now

I wish much more people would see it this way. Far less support cases globally that way :P

We will consider this case as solved now.

Best regards,
Nino