Problem with OpenOCD and CMSIS-DAP

ChibiOS public support forum for topics related to the Freescale Kinetis family of micro-controllers.

Moderator: utzig

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Problem with OpenOCD and CMSIS-DAP

Postby RoccoMarco » Mon Feb 22, 2016 10:27 am

Hi,
I am experimenting some issues trying to flash and run a Kinetis demo (RT-FREEDOM-KL25Z).

Well, I am usign CMSIS-DAP so I have created a new entry in external tools: it launches OpenOCD with this arguments:

Code: Select all

-c  "telnet_port 4444"  -s "C:\ChibiStudio\tools\openocd\scripts" -f "interface/cmsis-dap.cfg" -f "${file_prompt}"


Launching it on prompt I have chosen "target\kl25.cfg" I obtained

Code: Select all

Open On-Chip Debugger 0.10.0-dev-00200-gdb56a3b (2016-02-10-18:08)
Licensed under GNU GPL v2
For bug reports, read
   http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
Info : add flash_bank kinetis kl25.flash
adapter speed: 1000 kHz
none separate
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 1.0
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD IDCODE 0x0bc11477
Info : kl25.cpu: hardware has 2 breakpoints, 2 watchpoints
Info : MDM: Chip is unsecured. Continuing.


On flash and run I received this error

Code: Select all

symbol-file C:\\ChibiStudio\\chibios161\\demos\\KINETIS\\RT-FREEDOM-KL25Z\\build\\ch.elf
Reading symbols from C:\ChibiStudio\chibios161\demos\KINETIS\RT-FREEDOM-KL25Z\build\ch.elf...done.
set remotetimeout 20
monitor reset init
"monitor" command not supported by this target.
monitor sleep 50
"monitor" command not supported by this target.
load C:\\ChibiStudio\\chibios161\\demos\\KINETIS\\RT-FREEDOM-KL25Z\\build\\ch.elf
You can't do that when your target is `None'
tbreak main
Cannot access memory at address 0x5422
continue
The program is not being run.


Most likely there is something wrong with debug configuration and related commands. Any suggestions?

acr
Posts: 14
Joined: Tue Nov 18, 2014 3:52 am

Re: Problem with OpenOCD and CMSIS-DAP

Postby acr » Mon Feb 22, 2016 5:35 pm

u run target extended-remote localhost:3333 ?
before symbol-file ?

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: Problem with OpenOCD and CMSIS-DAP

Postby RoccoMarco » Mon Feb 22, 2016 5:54 pm

I have solved my problem. Actually the problem is due to non halted target. I have issued an halt editing the configuration file "target\klx.cfg"

Code: Select all

#
# Freescale Kinetis KL series devices
#

source [find target/swj-dp.tcl]

if { [info exists CHIPNAME] } {
    set _CHIPNAME $CHIPNAME
} else {
    set _CHIPNAME klx
}

# Work-area is a space in RAM used for flash programming
# By default use 4kB
if { [info exists WORKAREASIZE] } {
   set _WORKAREASIZE $WORKAREASIZE
} else {
   set _WORKAREASIZE 0x1000
}

if { [info exists CPUTAPID] } {
    set _CPUTAPID $CPUTAPID
} else {
    set _CPUTAPID 0x0bc11477
}

swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -chain-position $_CHIPNAME.cpu

# It is important that "kinetis mdm check_security" is called for
# 'examine-end' event and not 'eximine-start'. Calling it in 'examine-start'
# causes "kinetis mdm check_security" to fail the first time openocd
# calls it when it tries to connect after the CPU has been power-cycled.
$_CHIPNAME.cpu configure -event examine-end {
   kinetis mdm check_security
}

$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0

set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME kinetis 0 0 0 0 $_TARGETNAME

# Table 5-1. Clock Summary of KL25 Sub-Family Reference Manual
# specifies up to 1MHz for VLPR mode.
adapter_khz 1000

$_TARGETNAME configure -event gdb-attach {
  halt
}

reset_config srst_nogate

if {![using_hla]} {
   # if srst is not fitted use SYSRESETREQ to
   # perform a soft reset
   cortex_m reset_config sysresetreq
}

$_TARGETNAME configure -event reset-init {
    # Table 5-1. Clock Summary of KL25 Sub-Family Reference Manual
    # specifies up to 24MHz for run mode; Table 17 of Sub-Family Data
    # Sheet rev4 lists 25MHz as the maximum frequency.
    adapter_khz 24000
}


I have configured the event gdb-attach

Code: Select all

$_TARGETNAME configure -event gdb-attach {
  halt
}


Now debugger works correctly.

Anyway I found out another issue!
OpenOCD loses target control right after a the flash and run if optimization are enabled.
This is due to a wrong configuration of the memory section named ".cfmconfig" (flash memory from 0x0000_0400 to 0x0000_0410).

Opening ports/KINETIS/KL2x/hal_lld.c you can see that a configuration is attempted

Code: Select all

/*===========================================================================*/
/* Driver local variables and types.                                         */
/*===========================================================================*/

#ifdef __CC_ARM
__attribute__ ((section(".ARM.__at_0x400")))
#else
__attribute__ ((section(".cfmconfig")))
#endif
const uint8_t _cfm[0x10] = {
  0xFF,  /* NV_BACKKEY3: KEY=0xFF */
  0xFF,  /* NV_BACKKEY2: KEY=0xFF */
  0xFF,  /* NV_BACKKEY1: KEY=0xFF */
  0xFF,  /* NV_BACKKEY0: KEY=0xFF */
  0xFF,  /* NV_BACKKEY7: KEY=0xFF */
  0xFF,  /* NV_BACKKEY6: KEY=0xFF */
  0xFF,  /* NV_BACKKEY5: KEY=0xFF */
  0xFF,  /* NV_BACKKEY4: KEY=0xFF */
  0xFF,  /* NV_FPROT3: PROT=0xFF */
  0xFF,  /* NV_FPROT2: PROT=0xFF */
  0xFF,  /* NV_FPROT1: PROT=0xFF */
  0xFF,  /* NV_FPROT0: PROT=0xFF */
  0x7E,  /* NV_FSEC: KEYEN=1,MEEN=3,FSLACC=3,SEC=2 */
  0xFF,  /* NV_FOPT: ??=1,??=1,FAST_INIT=1,LPBOOT1=1,RESET_PIN_CFG=1,
                      NMI_DIS=1,EZPORT_DIS=1,LPBOOT0=1 */
  0xFF,
  0xFF
};


Anyway without a volatile this is ignored when optimization are enabled. I have solved this problem editing hal_lld.h

Code: Select all

/*===========================================================================*/
/* Driver local variables and types.                                         */
/*===========================================================================*/

#ifdef __CC_ARM
volatile __attribute__ ((section(".ARM.__at_0x400")))
#else
volatile __attribute__ ((section(".cfmconfig")))
#endif
const uint8_t _cfm[0x10] = {
  0xFF,  /* NV_BACKKEY3: KEY=0xFF */
  0xFF,  /* NV_BACKKEY2: KEY=0xFF */
  0xFF,  /* NV_BACKKEY1: KEY=0xFF */
  0xFF,  /* NV_BACKKEY0: KEY=0xFF */
  0xFF,  /* NV_BACKKEY7: KEY=0xFF */
  0xFF,  /* NV_BACKKEY6: KEY=0xFF */
  0xFF,  /* NV_BACKKEY5: KEY=0xFF */
  0xFF,  /* NV_BACKKEY4: KEY=0xFF */
  0xFF,  /* NV_FPROT3: PROT=0xFF */
  0xFF,  /* NV_FPROT2: PROT=0xFF */
  0xFF,  /* NV_FPROT1: PROT=0xFF */
  0xFF,  /* NV_FPROT0: PROT=0xFF */
  0x7E,  /* NV_FSEC: KEYEN=1,MEEN=3,FSLACC=3,SEC=2 */
  0xFF,  /* NV_FOPT: ??=1,??=1,FAST_INIT=1,LPBOOT1=1,RESET_PIN_CFG=1,
                      NMI_DIS=1,EZPORT_DIS=1,LPBOOT0=1 */
  0xFF,
  0xFF
};


Ciao,
RM

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Problem with OpenOCD and CMSIS-DAP

Postby utzig » Mon Feb 22, 2016 8:49 pm

I could reproduce here. Enabling LTO is really removing the section. I'll update the hal_lld's for Kinetis to add volatile that works both with LTO yes/no. Good catch!

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: Problem with OpenOCD and CMSIS-DAP

Postby RoccoMarco » Mon Feb 22, 2016 9:25 pm

thanks utzig

flabbergast
Posts: 71
Joined: Sat Aug 22, 2015 1:22 pm

Re: Problem with OpenOCD and CMSIS-DAP

Postby flabbergast » Tue Feb 23, 2016 12:52 am

utzig wrote:I could reproduce here. Enabling LTO is really removing the section. I'll update the hal_lld's for Kinetis to add volatile that works both with LTO yes/no. Good catch!

I reported this last September here: viewtopic.php?f=26&t=2765#p22321 but I guess I drowned it with my other posts ;)
My solution was to add 'used' flag, but 'volatile' should work as well.

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Problem with OpenOCD and CMSIS-DAP

Postby utzig » Tue Feb 23, 2016 1:03 am

flabbergast wrote:I reported this last September here: viewtopic.php?f=26&t=2765#p22321 but I guess I drowned it with my other posts ;)
My solution was to add 'used' flag, but 'volatile' should work as well.


Actually I applied your suggestion to the K20x port. Just forgot to apply it too to KL2x! :P

Fixed now, thanks!

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Problem with OpenOCD and CMSIS-DAP

Postby utzig » Tue Feb 23, 2016 1:08 am

Ops, the change to K20x/hal_lld.c was just local, I forgot to commit at all... done now!


Return to “Kinetis Support”

Who is online

Users browsing this forum: No registered users and 4 guests