This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can i debug program in external ram?

hi, i want to debug program in external ram, it is my set, but it doesn't work. keil platform.
the external ram using bank1 ne3.

1. Optioin target
ROM1 checked, start 0x68000000, size 0x80000, select startup
RAM1 checked, start 0x68080000, size 0x20000

2. flash download
RAM for algorithm
start 0x68080000, size 0x2000

programming algorithm
start 0x68000000, size 0x00080000

debug initialize file

FUNC void Setup (void) {
        SP = _RDWORD(0x68000000);          // Setup Stack Pointer
  PC = _RDWORD(0x68000004);          // Setup Program Counter
  _WDWORD(0xE000ED08, 0x68000000);   // Setup Vector Table Offset Register
        _WDWORD(0x40021014, 0x00000100); // RCC->AHBENR FSMC Enable
        _WDWORD(0x40021018, 0x000001E0); // RCC->APB2ENR GPIOD GPIOE GPIOF GPIOG
        _WDWORD(0x40011400, 0xFFBBFFBB); // GPIOD CRL
        _WDWORD(0x40011404, 0xBBBBBBBB); // GPIOD CRH
        _WDWORD(0x40011800, 0xBFFFFFBB); // GPIOE CRL
        _WDWORD(0x40011804, 0xBBBBBBBB); // GPIOE CRH
        _WDWORD(0x40011C00, 0xFFBBBBBB); // GPIOF CRL
        _WDWORD(0x40011C04, 0xBBBBFFFF); // GPIOF CRH
        _WDWORD(0x40012000, 0xFFBBBBBB); // GPIOG CRL
        _WDWORD(0x40012004, 0xFFFFFBFF); // GPIOG CRH
        _WDWORD(0xA0000010, 0x00001011); // FSMC BCR3
        _WDWORD(0xA0000014, 0x00000300); // FSMC BTR3
        _WDWORD(0xA0000114, 0x0FFFFFFF); // FSMC BWTR3
}

SCB->VTOR = ((uint32_t)0x68000000);

  • You don't need a flash algorithm, it's RAM.

    Your code attempts to read PC/SP from memory it has not yet configured.

    You configure the debugger NOT to "Load Application at Startup"

    And have the debugger script "LOAD %L" the application AFTER it initializes the external RAM, and before it GOs to main() with "g,main"

    Try reviewing some of the .INI debugger script examples under the Boards/Examples tree (Keil uV 4.x)

  • i followed the example, but it has some problem.

    i add rtx, usb, in main, the first is USBD_Initiliaze(0), when i debug problem in external ram, the pc = 0xFFFFFFFF

    FUNC void Init_ExtSRam()
    {
            _WDWORD(0x40021014, 0x00000100); // RCC->AHBENR FSMC Enable
            _WDWORD(0x40021018, 0x000001E0); // RCC->APB2ENR GPIOD GPIOE GPIOF GPIOG
            _WDWORD(0x40011400, 0x44BB44BB); // GPIOD CRL
            _WDWORD(0x40011404, 0xBBBBBBBB); // GPIOD CRH
            _WDWORD(0x40011800, 0xB43888BB); // GPIOE CRL
            _WDWORD(0x40011804, 0xBBBBBBBB); // GPIOE CRH
            _WDWORD(0x40011C00, 0x44BBBBBB); // GPIOF CRL
            _WDWORD(0x40011C04, 0xBBBB4444); // GPIOF CRH
            _WDWORD(0x40012000, 0x44BBBBBB); // GPIOG CRL
            _WDWORD(0x40012004, 0x444B4B44); // GPIOG CRH
            _WDWORD(0xA0000010, 0x00001011); // FSMC BCR3
            _WDWORD(0xA0000014, 0x00000300); // FSMC BTR3
            _WDWORD(0xA0000114, 0x0FFFFFFF); // FSMC BWTR3
    }
    
    FUNC void Setup (void) {
            SP = _RDWORD(0x68000000);          // Setup Stack Pointer
      PC = _RDWORD(0x68000004);          // Setup Program Counter
      _WDWORD(0xE000ED08, 0x68000000);   // Setup Vector Table Offset Register
    
    }
    
    FUNC void OnResetExec (void)  {      // executes upon software RESET
      Init_ExtSRam();
            Setup();                           // Setup for Running
    }
    
    Init();
    Init_ExtSRam();
    load %L incremental
    
    Setup();                             // Setup for Running
    
    g, main
    

  • this method has many unknown problem, i have given up to use it.

  • Yes, I guess it take some effort to correctly configure the CPU and clocks, set up the GPIO and FSMC, but I'd hardly say the ordering or requirements are "unknown". You've basically got to do the same things as your current startup code is going to have to do.

    It's clearly easier to use internal RAM for such things.

  • There may be needs to configure some clocking too - if the external memory is DRAM and there isn't a refresh clock then the downloaded program can be garbled even before the debugger sets the PC and starts to run the program.

    As noted - same requirements as there is for normal startup sequence to put the machine in a state where this external RAM is fully usable.