cancel
Showing results for 
Search instead for 
Did you mean: 

Load and start a programm in RAM with USB DFU

clkr
Associate

Hi,

we try to load a small program to RAM area starting from address 0x20008000 with STMCubeIDE and USB DFU and select start address 0x20008000 ( In debugger we can see that program is load to 0x20008000).
The download is successful, even so setting start address is successful, but the start of program is not successful.

If we download and start the same program with ozone debugger there is no issue. It runs as expected.

Used controller: STM32L45x/L46x, MCU, Flash size 512.

Is there any idea what I can check?

Best Regards,
Claus

1 ACCEPTED SOLUTION

Accepted Solutions
clkr
Associate

We found the issue, by using the debugger:

  1. Load program to ram by STMCube (but do not start the program)
  2. Attach debugger and stop execution.
  3. Set Program counter and stack pointer manually. Set link register value 0
  4. Single step through program in RAM.

It turns out that USB interrupt and other interrupts still active. We disabled those interrupts first and was able to run the program in RAM

View solution in original post

4 REPLIES 4
Pavel A.
Evangelist III

 with ozone debugger there is no issue. It runs as expected

Debuggers for Cortex-M are smart, they know how to load and run stuff in the RAM (they use this ability for themselves, to program the internal and external flash). The built-in DFU bootloader is not that smart => use a debugger to run your program, or a debugger-like utility such as Segger J-Run.

Check Watchdog, if the loader started it you'll need to keep kicking it.

Do a simple test, where you startup a UART in Reset_Handler (pins, clocks, peripheral, in assembler), spin in a loop waiting on TXE, kicking watchdog, output characters. See it work, or see how long it runs without kicking the watchdog. Confirm code is running.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
clkr
Associate

We found the issue, by using the debugger:

  1. Load program to ram by STMCube (but do not start the program)
  2. Attach debugger and stop execution.
  3. Set Program counter and stack pointer manually. Set link register value 0
  4. Single step through program in RAM.

It turns out that USB interrupt and other interrupts still active. We disabled those interrupts first and was able to run the program in RAM

@clkr 

I'm trying to do the same thing and I was hoping you could explain exactly what you did in your program for it to run after the DFU download.  

I've put a post here regarding my progress:

Modifying Option Byte Value from Program Running in SRAM and Loaded using dfu-util 

https://community.st.com/t5/stm32-mcus-products/modifying-option-byte-value-from-program-running-in-sram-and/td-p/791112

and I'm wondering if you could explain what else I should be doing.  

Could I have the USB (and other) interrupts active and what is the best way to disable them?

Thanx for any help you can provide.

myke