This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Keil uVision 5 NRF52840 ERROR: flash download failed - "Cortex M4"

I have seen this problem posted several times in these forums but none of the existing solutions sit right with me.  

I have an NRF52840 (using a UBlox BMD-340 dev board).  I am using the S140 soft device (v.7.2.0).

I'm using Keil uVision 5.  

---

I am able to build applications in Keil as normal.

I am able to use nrfjprog to program my application and soft device and get it to run without issue.

I am not, however, able to program my uBlox BMD-340 from Keil to debug.  During the 'erase' step, it fails.

**JLink Warning: T-bit of XPSR is 0 but should be 1. Changed to 1.

On an interesting side note:  I AM able to program (using Keil) example applications like Blinky, so I'm wondering if there is something wrong with my custom project file.

For what it's worth, I was able to debug/program last week with my custom project.  Keil seems to like to change things in the project without me knowing about it, so it is completely reasonable that Keil nuked something or changed something behind the scenes, but I don't know how to figure out what that something might be.  

  • Edvin,

    I figured out my issue, but I'm not sure why it fails. 

    I tried to implement Monitor Mode Debugging and based on my JlinkSettings.ini it'll either 'fail to erase' or work as expected.  

    ---- This works

    [BREAKPOINTS]
    ForceImpTypeAny = 0
    ShowInfoWin = 1
    EnableFlashBP = 2
    BPDuringExecution = 0
    [CFI]
    CFISize = 0x00
    CFIAddr = 0x00
    [CPU]
    MonModeVTableAddr = 0xFFFFFFFF
    MonModeDebug = 0
    MaxNumAPs = 0
    LowPowerHandlingMode = 0
    OverrideMemMap = 0
    AllowSimulation = 1
    ScriptFile=""
    [FLASH]
    CacheExcludeSize = 0x00
    CacheExcludeAddr = 0x00
    MinNumBytesFlashDL = 0
    SkipProgOnCRCMatch = 1
    VerifyDownload = 1
    AllowCaching = 1
    EnableFlashDL = 2
    Override = 0
    Device="ARM7"
    [GENERAL]
    WorkRAMSize = 0x20000
    WorkRAMAddr = 0x20000000
    RAMUsageLimit = 0x00
    [SWO]
    SWOLogFile=""
    [MEM]
    RdOverrideOrMask = 0x00
    RdOverrideAndMask = 0xFFFFFFFF
    RdOverrideAddr = 0xFFFFFFFF
    WrOverrideOrMask = 0x00
    WrOverrideAndMask = 0xFFFFFFFF
    WrOverrideAddr = 0xFFFFFFFF

    ---  This doesn't allow me to erase

    [CPU]
    MonModeVTableAddr = 0x27000
    MonModeDebug = 1

    Do you know anything about Monitor Mode Debugging?  I'm wondering if my MonModeVTableAddr is wrong if I'm running an application with a soft device.  

  • I have never tested monitor mode debugging before, but a colleague of mine wrote a guide on how to get it up and running. Perhaps you can try that?

    Please remember that Monitor Mode Debugging is an external project/property. If you are struggling to get it up and running, then you would need to contact Segger (who wrote it). 

    Best regards,

    Edvin

  • This seems to be an issue with Keil or at least how Keil interacts with the JLink Settings.  The guide you posted is the guide I used, but I changed by address from 0x26000 to 0x27000 because the NRF52840's vector table is at 0x27000.  

Related