[SOLVED] Failing to read USB peripheral registers

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [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:

    [img]https://lh4.googleusercontent.com/2aZL5Jddf9JpA3DPbZy20K5sn8G_m0B9r4P-XMqlUxOIj2Xrcqf_WCNe-55YFrWUL5KXxOAH4sanw-S0JtUV=w3360-h1764-rw[/img]


    Any ideas why this could be happening?
  • 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
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • 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:

    [img]https://lh3.googleusercontent.com/1TbM8IRNQX-mFEIaDT4bHb9eA_OZ-nwKzc0KQYe1tw_5Jj1frJWrvJSHLCzXKHmEfKJJVcDf43iSt1HwDzRY-lWggtkn4SvTzlPp0vQhm1LaF73ApgvUyR27U3FxTYDLfkr668Z51UdHW0sjG7oPuXdh-WAVi9wu13zyIsp68H5BgYjmxmHOs7KgBEqQ6YnzPNpC8VatE_EW8fbxqMFVaYvsTG0V_89Mm-KBvL24guANp-RWiPHtRD4MurtXlGfbxSwkFXn7NuZBHdyRki9OB-y-B08B336-QGB8rjSL7_SHawFQiX8amf9FkEuSloG2Fio_Q6-P_G2JJEkCXEpmg210iiDFUs4oMmojsRlrDXXXhwFAA-xQiK7Nvw0CZVUPhUcKk8-G8HSBWCE3FPoLDXzf7qRYIPrHDeD4_gWD_nvO2t43mNIi72U-AlnoTdIrjjIDSSf0L4W83xBXcfylmJpkzCWNm9qMIZzTCQhcN_vC4ff-f-HWHIkG4tnJCbK8WRPRBB51G1WYZh-CXLQXOWV_rYBl57h-_Ts-RLHg1liFV2Aq4be_USxiuCJUSMrv=w3360-h1764[/img]

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

    [img]https://lh3.googleusercontent.com/h9rvr04DdBI96bYJhpURulkOk18cf0Y5hvRmIWVb3tiZoB80Fsodap6ZHt9ksG9ID3RpfEMWWfAWi8iKA5TBoVkbotyuqHHnFCpFneYxFj3UY0qX-D5v1NVfTiBt9giBerRPQgK_-1aRRoihguKvmMNOCnCSkFFYG8OVn_MifF_vzdLB4Qm_bT2UQlAlTfzV23ZN3bTEBReLo_7SrWUd83phUUUF6JpNnzg7eb9TLkYRQ50Efe4Z7rl3MhVwjtlM8reSOe0yrOrNO-4nzEUrWCq2Zu7uHrbBSIs5vF3RTW7P2Z6FNOgdb9ECpiSd7-6C_dD-iXDGddN1O4Ga_uux6sl2qCRgSNaJIE3--GU1QGugksSCamhcCsnns48iGfv4ARvkp543kUn8G7wttV8DwxnHKCb3LneMP-1-k7cVlss7CHejGuM_440y1azi4G00C7SA0jxLX1kjOwiOzYQmTggY9bfuXWmFYAzTSVLHi3afRvfwEED-aJdGi_FH0O4IStax0wYs7ju_lk_t6PSj92RfZyyKQRsbvgpJrUGu3sSPRB8M_X_fAc5M7lI3pGbv=w3360-h1764[/img]

    The post was edited 1 time, last by donturner ().

  • 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.

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


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

    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
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Here's my .jdebug file:

    Source Code

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


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

    And my .user file:

    Source Code

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


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

    Source Code

    1. simType->SOPT2 = SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK;
    2. 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?
  • 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.
  • 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: 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
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • 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
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi,

    Great to hear that you are up and running again.
    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
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.