Programmershield, openocd Photon & P1, part 2

I recently posted a thread on how to use openOCD with the programmer shield and open OCD.
That led me in the right direction, by using the script in the shield repository: https://github.com/spark/shields/tree/master/photon-shields/programmer-shield
as well as i am able to follow most of the steps in this excellent written guide
https://medium.com/@jvanier/5-steps-to-setup-and-use-a-debugger-with-the-particle-photon-ad0e0fb43a34

I can follow the 5 step guide, until i have loaded the application in the GDB debugger, (i use the GDB in eclipse), and am able to step through the initial parts of the program, in the system firmware. Also i can set a breakpoint in my own application, at the setup() function, should be first thing the CPU encounters after exiting the system firmware.

Once i leave the flash/eeprom functions in the system firmware, which is debug-able, the CPU jumps to my own application, i can see this from the led, that the apllication is blinking, as the only function currently

Well, in short when i GDB “continue” after setting a breakpoint in the setup() function then connection is lost to the target, like JTAG becomes disabled when running my own “user app”.
My app is build using USE_SWD_TJAG=y, thus i am (perhaps naively) assuming the pins are not modified, before entering setup() and loop()?

I can see the UserLed (D7) is shared with JTAG_TMS, but it seems the pin is preserved as input, in the Photons formware.

I experience exact same behaviour with a P1 module, mounted on my custom PCB

Any ideas are more than welcome, if it helps i can share my eclipse/GDB settings ?

best rgds
Morten Opprud

Here are a few questions to get to the bottom of this.

Can you share exactly how you build the application? Did you do make clean to make sure everything is recompiled with debug support?

As long as you don’t use pin D7 in your code, it’s OK that it is shared with one of the JTAG pins.

Are you able to step through the tinker app by building the develop firmware without specifying an APP or APPDIR var to make so it takes user/src/application.cpp. What if you put some of your own code in application.cpp?

When you say “connection is lost to the target”, do you get a message saying so?

Can you still hit pause (or Ctrl-C if you use GDB on the command line) and see that the execution pauses?

After you set the breakpoint in setup, do you reset the target with monitor reset halt? What do you see after that command?

1 Like

Thanks for your reply, i have outlined the steps below :

in the main folder:

make clean all PARTICLE_DEVELOP=1 PLATFORM=photon USE_SWD_JTAG=y

make program-dfu PARTICLE_DEVELOP=1 PLATFORM=photon USE_SWD_JTAG=y

I cannot connect using openocd after DFU update and reset (seems like JTAG pins are disabled), so i put the photon i DFU mode, and im able to connect.

$ /usr/local/Cellar/open-ocd/0.9.0/bin/openocd -f ../misc/utils/spark.cfg -c "gdb_port 3333"
Open On-Chip Debugger 0.9.0 (2015-05-28-12:05)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
none separate
cortex_m reset_config sysresetreq
Info : clock speed 1000 kHz
Info : JTAG tap: stm32f2x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Info : JTAG tap: stm32f2x.bs tap/device found: 0x06411041 (mfg: 0x020, part: 0x6411, ver: 0x0)
Info : stm32f2x.cpu: hardware has 6 breakpoints, 4 watchpoints

Then

$ telnet localhost 4444
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reset halt
JTAG tap: stm32f2x.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
JTAG tap: stm32f2x.bs tap/device found: 0x06411041 (mfg: 0x020, part: 0x6411, ver: 0x0)
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08002d6c msp: 0x20020000
> 

And

$ arm-none-eabi-gdb -ex "target remote localhost:3333" ../build/target/user-part/platform-6-m/user-part.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.8.0.20150604-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ../build/target/user-part/platform-6-m/user-part.elf...done.
Remote debugging using localhost:3333
0x08002d6c in ?? ()
(gdb) break setup()
Breakpoint 1 at 0x80a02f0: file src/application.cpp, line 40.
(gdb) info break
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x080a02f0 in setup() at src/application.cpp:40
(gdb) 

After this

Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

From here the Photon boots, the tinker program runs, and GDB becomes unresponsive, no (gdb) promt

After a while i get

Ckeep_alive() was not invoked in the 1000ms timelimit. GDB alive packet not sent! (60106). Workaround: increase "set remotetimeout" in GDB

If i restart/reset it all, and im am quick, while the Photon boots (breathing white), after being connected in DFU mode and a reset halt i can:

(gdb) continue
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x0806bec4 in ?? ()
(gdb) continue
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x0806bea8 in ?? ()
(gdb) 

I tracked this to be some EEprom/Flash routines, probably for reading / writing system or config variables, after boot completes (blue flashing from the RGB begins) GDB is not responding again

So to me it looks the
system-part1.elf and system-part2.elf are build with JTAG pins set correctly, and the user application, in this case tinker is not… But, well without knowing the details of the drivers, and the CPU, yet, i have not been able to spot anywhere the JTAG pins are overwritten ?

//morten

Do this in the modules folder otherwise only the user application module will be rebuilt and flashed, not the 2 system modules + the user module.

Just to verify, do you connect the USB to the Photon, put it in DFU mode, do make program-dfu then connect the USB to the Programmer Shield before launching OpenOCD?

1 Like

USB on photon when DFU, and on debug shield when debugging, correct :wink:

When i do the above in modules, well the whole thing rebuilds.
Still after DFU’ing and boot, i cannot connect JTAG to the running target and need to put it in DFU mode to be allowed to connect.
To me that indicates something is blocking JTAG pins when building my user-application.

The USE_SWD_JTAG=y is included in system-part1, system-part2 and the user application, as the below log shows:

mortens-iMac:modules mortenjakobsen$ make program-dfu PARTICLE_DEVELOP=1 PLATFORM=photon USE_SWD_JTAG=y 
program-dfu
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C /Users/mortenjakobsen/workspace/photon/gitCheckout/modules/photon/system-part1/ program-dfu  USE_SWD_JTAG=y PLATFORM=photon PARTICLE_DEVELOP=1
Building target: ../../../build/target/system-part1/platform-6-m/system-part1.elf
Invoking: ARM GCC C++ Linker
mkdir -p ../../../build/target/system-part1/platform-6-m/
arm-none-eabi-g++ -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DUSE_SWD_JTAG -fno-builtin -DSYSTEM_VERSION_STRING=0.4.4 -DRELEASE_BUILD -Werror -I../../../modules/photon/system-part1/inc -I../../../communication/lib/tropicssl/include -I../../../communication/src -I../../../services/inc -I../../../platform/shared/inc -I../../../platform/MCU/STM32F2xx/CMSIS/Include -I../../../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../../../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../../../platform/MCU/shared/STM32/inc -I../../../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../../../hal/inc -I../../../hal/shared -I../../../hal/src/photon -I../../../hal/src/stm32f2xx -I../../../hal/src/photon/api -I../../../dynalib/inc -I../../../rt-dynalib/inc -I. -MD -MP -MF ../../../build/target/system-part1/platform-6-m/system-part1.elf.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=5 -DMODULE_FUNCTION=4 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=0,0,0 -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb ../../../build/target/system-part1/platform-6-m/../../../modules/photon/system-part1/src/import_rt.o ../../../build/target/system-part1/platform-6-m/../../../modules/photon/system-part1/src/init_dynalib.o ../../../build/target/system-part1/platform-6-m/../../../modules/photon/system-part1/src/module_info.o ../../../build/target/system-part1/platform-6-m/../../../modules/photon/system-part1/src/module_system_part1.o ../../../build/target/system-part1/platform-6-m/../../../modules/photon/system-part1/src/wiced_stubs.o ../../../build/target/system-part1/platform-6-m/../../../modules/photon/system-part1/src/wifi_dynalib.o   --output ../../../build/target/system-part1/platform-6-m/system-part1.elf  -L../../../build/target/communication/platform-6-m-prod-6/ -L../../../build/target/hal-dynalib/platform-6-m/ -L../../../build/target/services/platform-6-m/ -L../../../build/target/platform/platform-6-m/ -Wl,--whole-archive -lcommunication -lhal-dynalib -lservices -lplatform -Wl,--no-whole-archive -L../../../build/arm/linker --specs=nano.specs -lnosys ../../../hal/src/photon/lib/resources.a ../../../build/target/hal/platform-6-m/src/photon/resources.o -T../../../modules/photon/system-part1/linker.ld -L../../../modules/photon/system-part2 -Wl,--defsym,PLATFORM_DFU=0x8020000 -Wl,-Map,../../../build/target/system-part1/platform-6-m/system-part1.map -nostartfiles -Xlinker --gc-sections

Invoking: ARM GNU Create Flash Image
arm-none-eabi-objcopy -O binary ../../../build/target/system-part1/platform-6-m/system-part1.elf ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc
if [ -s ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc ]; then \
	head -c $((`stat -f%z ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc` - 38)) ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc > ../../../build/target/system-part1/platform-6-m/system-part1.bin.no_crc && \
	tail -c 38 ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc > ../../../build/target/system-part1/platform-6-m/system-part1.bin.crc_block && \
	test "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20280078563412" = `xxd -p -c 500 ../../../build/target/system-part1/platform-6-m/system-part1.bin.crc_block` && \
	shasum -a 256 ../../../build/target/system-part1/platform-6-m/system-part1.bin.no_crc | cut -c 1-65 | xxd -r -p | dd bs=1 of=../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc seek=$((`stat -f%z ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc` - 38)) conv=notrunc  && \
	head -c $((`stat -f%z ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc` - 4)) ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc > ../../../build/target/system-part1/platform-6-m/system-part1.bin.no_crc && \
	 crc32 ../../../build/target/system-part1/platform-6-m/system-part1.bin.no_crc | cut -c 1-10 | xxd -r -p | dd bs=1 of=../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc seek=$((`stat -f%z ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc` - 4)) conv=notrunc ;\
	fi
32+0 records in
32+0 records out
32 bytes transferred in 0.018866 secs (1696 bytes/sec)
4+0 records in
4+0 records out
4 bytes transferred in 0.048937 secs (82 bytes/sec)
[ ! -f ../../../build/target/system-part1/platform-6-m/system-part1.bin ] || rm ../../../build/target/system-part1/platform-6-m/system-part1.bin
mv ../../../build/target/system-part1/platform-6-m/system-part1.bin.pre_crc ../../../build/target/system-part1/platform-6-m/system-part1.bin

dfu-suffix -v 2B04 -p D006 -a ../../../build/target/system-part1/platform-6-m/system-part1.dfu
dfu-suffix (dfu-util) 0.8

Copyright 2011-2012 Stefan Schmidt, 2013-2014 Tormod Volden
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Suffix successfully added to file
Serial device PARTICLE_SERIAL_DEV : not available
Flashing using dfu:
dfu-util -d 0x2B04:0xD006 -a 0 -s 0x8020000 -D ../../../build/target/system-part1/platform-6-m/system-part1.dfu
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Deducing device DFU version from functional descriptor length
Opening DFU capable USB device...
ID 2b04:d006
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 4096
DfuSe interface name: "Internal Flash   "
Downloading to address = 0x08020000, size = 248924
Download	[=========================] 100%       248924 bytes
Download done.
File downloaded successfully
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C /Users/mortenjakobsen/workspace/photon/gitCheckout/modules/photon/system-part2/ program-dfu  USE_SWD_JTAG=y PLATFORM=photon PARTICLE_DEVELOP=1
Building target: ../../../build/target/system-part2/platform-6-m/system-part2.elf
Invoking: ARM GCC C++ Linker
mkdir -p ../../../build/target/system-part2/platform-6-m/
arm-none-eabi-g++ -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DUSE_SWD_JTAG -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -fno-builtin -DSYSTEM_VERSION_STRING=0.4.4 -DRELEASE_BUILD -Werror -I../../../modules/photon/user-part/inc -I../../../modules/photon/system-part1/inc -I../../../dynalib/inc -I../../../services/inc -I../../../hal/inc -I../../../hal/shared -I../../../hal/src/photon -I../../../hal/src/stm32f2xx -I../../../hal/src/photon/api -I../../../platform/shared/inc -I../../../platform/MCU/STM32F2xx/CMSIS/Include -I../../../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../../../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../../../platform/MCU/shared/STM32/inc -I../../../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../../../system/inc -I../../../wiring/inc -I../../../communication/lib/tropicssl/include -I../../../communication/src -I../../../rt-dynalib/inc -I. -MD -MP -MF ../../../build/target/system-part2/platform-6-m/system-part2.elf.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DSPARK_WIRING_NO_I2C -DSPARK_WIRING_NO_SPI -DMODULE_VERSION=5 -DMODULE_FUNCTION=4 -DMODULE_INDEX=2 -DMODULE_DEPENDENCY=4,1,5 -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb ../../../build/target/system-part2/platform-6-m/./src/export_rt.o ../../../build/target/system-part2/platform-6-m/./src/import_part1.o ../../../build/target/system-part2/platform-6-m/./src/import_user.o ../../../build/target/system-part2/platform-6-m/./src/import_wifi_resources.o ../../../build/target/system-part2/platform-6-m/./src/module_info.o ../../../build/target/system-part2/platform-6-m/./src/module_system_part2.o ../../../build/target/system-part2/platform-6-m/./src/export_system.o  --output ../../../build/target/system-part2/platform-6-m/system-part2.elf  -L../../../build/target/services-dynalib/arm/ -L../../../build/target/platform/platform-6-m/ -L../../../build/target/hal/platform-6-m/ -L../../../build/target/system/platform-6-m/ -L../../../build/target/communication-dynalib/platform-6-m/ -L../../../build/target/wiring/platform-6-m/ -Wl,--whole-archive -lservices-dynalib -lsystem -lwiring -lcommunication-dynalib -lhal -lplatform -Wl,--no-whole-archive -L../../../build/arm/linker --specs=nano.specs -lnosys -Wl,--whole-archive ../../../hal/src/photon/lib/Lib_SPI_Flash_Library_BCM9WCDUSI09.a ../../../hal/src/photon/lib/Lib_HTTP_Server.a ../../../hal/src/photon/lib/Lib_Wiced_RO_FS.a ../../../hal/src/photon/lib/Lib_base64.a ../../../hal/src/photon/lib/Lib_Ring_Buffer.a ../../../hal/src/photon/lib/Lib_TLV.a ../../../hal/src/photon/lib/STM32F2xx_Peripheral_Libraries.a ../../../hal/src/photon/lib/common_GCC.a ../../../hal/src/photon/lib/FreeRTOS/WICED.a ../../../hal/src/photon/lib/FreeRTOS/Platform_BCM9WCDUSI09.a ../../../hal/src/photon/lib/FreeRTOS/Lib_DHCP_Server.a ../../../hal/src/photon/lib/FreeRTOS/Lib_DNS.a ../../../hal/src/photon/lib/FreeRTOS/Lib_DNS_Redirect_Daemon.a ../../../hal/src/photon/lib/FreeRTOS/STM32F2xx.a ../../../hal/src/photon/lib/FreeRTOS/STM32F2xx_Peripheral_Drivers.a ../../../hal/src/photon/lib/FreeRTOS/FreeRTOS.a ../../../hal/src/photon/lib/FreeRTOS/LwIP.a ../../../hal/src/photon/lib/FreeRTOS/WWD_FreeRTOS_Interface_BCM9WCDUSI09.a ../../../hal/src/photon/lib/FreeRTOS/WICED_FreeRTOS_Interface.a ../../../hal/src/photon/lib/FreeRTOS/WWD_LwIP_Interface_FreeRTOS.a ../../../hal/src/photon/lib/FreeRTOS/WICED_LwIP_Interface.a ../../../hal/src/photon/lib/FreeRTOS/WWD_for_SDIO_FreeRTOS.a ../../../hal/src/photon/lib/FreeRTOS/Wiced_Network_LwIP_FreeRTOS.a -Wl,--no-whole-archive -L../../../modules/photon/system-part1 -L../../../modules/photon/user-part -T./linker.ld -Wl,--defsym,PLATFORM_DFU=0x8060000 -Wl,-Map,../../../build/target/system-part2/platform-6-m/system-part2.map -nostartfiles -Xlinker --gc-sections

Invoking: ARM GNU Create Flash Image
arm-none-eabi-objcopy -O binary ../../../build/target/system-part2/platform-6-m/system-part2.elf ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc
if [ -s ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc ]; then \
	head -c $((`stat -f%z ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc` - 38)) ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc > ../../../build/target/system-part2/platform-6-m/system-part2.bin.no_crc && \
	tail -c 38 ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc > ../../../build/target/system-part2/platform-6-m/system-part2.bin.crc_block && \
	test "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20280078563412" = `xxd -p -c 500 ../../../build/target/system-part2/platform-6-m/system-part2.bin.crc_block` && \
	shasum -a 256 ../../../build/target/system-part2/platform-6-m/system-part2.bin.no_crc | cut -c 1-65 | xxd -r -p | dd bs=1 of=../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc seek=$((`stat -f%z ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc` - 38)) conv=notrunc  && \
	head -c $((`stat -f%z ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc` - 4)) ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc > ../../../build/target/system-part2/platform-6-m/system-part2.bin.no_crc && \
	 crc32 ../../../build/target/system-part2/platform-6-m/system-part2.bin.no_crc | cut -c 1-10 | xxd -r -p | dd bs=1 of=../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc seek=$((`stat -f%z ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc` - 4)) conv=notrunc ;\
	fi
32+0 records in
32+0 records out
32 bytes transferred in 0.018669 secs (1714 bytes/sec)
4+0 records in
4+0 records out
4 bytes transferred in 0.048763 secs (82 bytes/sec)
[ ! -f ../../../build/target/system-part2/platform-6-m/system-part2.bin ] || rm ../../../build/target/system-part2/platform-6-m/system-part2.bin
mv ../../../build/target/system-part2/platform-6-m/system-part2.bin.pre_crc ../../../build/target/system-part2/platform-6-m/system-part2.bin

dfu-suffix -v 2B04 -p D006 -a ../../../build/target/system-part2/platform-6-m/system-part2.dfu
dfu-suffix (dfu-util) 0.8

Copyright 2011-2012 Stefan Schmidt, 2013-2014 Tormod Volden
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Suffix successfully added to file
Serial device PARTICLE_SERIAL_DEV : not available
Flashing using dfu:
dfu-util -d 0x2B04:0xD006 -a 0 -s 0x8060000 -D ../../../build/target/system-part2/platform-6-m/system-part2.dfu
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Deducing device DFU version from functional descriptor length
Opening DFU capable USB device...
ID 2b04:d006
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 4096
DfuSe interface name: "Internal Flash   "
Downloading to address = 0x08060000, size = 152540
Download	[=========================] 100%       152540 bytes
Download done.
File downloaded successfully
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C /Users/mortenjakobsen/workspace/photon/gitCheckout/modules/photon/user-part/ program-dfu  USE_SWD_JTAG=y PLATFORM=photon PARTICLE_DEVELOP=1
dfu-suffix -v 2B04 -p D006 -a ../../../build/target/user-part/platform-6-m/user-part.dfu
dfu-suffix (dfu-util) 0.8

Copyright 2011-2012 Stefan Schmidt, 2013-2014 Tormod Volden
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Suffix successfully added to file
Serial device PARTICLE_SERIAL_DEV : not available
Flashing using dfu:
dfu-util -d 0x2B04:0xD006 -a 0 -s 0x80A0000:leave -D ../../../build/target/user-part/platform-6-m/user-part.dfu
dfu-util 0.8

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2014 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to dfu-util@lists.gnumonks.org

Deducing device DFU version from functional descriptor length
Opening DFU capable USB device...
ID 2b04:d006
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 4096
DfuSe interface name: "Internal Flash   "
Downloading to address = 0x080a0000, size = 4740
Download	[=========================] 100%         4740 bytes
Download done.
File downloaded successfully
dfu-util: Error during download get_status
make[1]: *** [program-dfu] Error 74

You’re doing the right thing. Maybe @AndyW has a thought here?

If you clone a fresh copy of the firmware repo, rebuild and flash tinker with make all program-dfu PARTICLE_DEVELOP=1 PLATFORM=photon USE_SWD_JTAG=y are you then able to connect GDB to the running target?

I don’t - and sadly probably won’t have a chance to test until early next week.

To summarize:

  • you can connect with GDB in DFU mode and interrupt/step/continue/inspect (even though you’ve got no symbolic info the low level transactions work) ?
    If so, then that proves that the gdb/openocd/ftdi pieces are all configured correctly.
  • from what you state, it looks to me like you are using the correct make directives, but when you load those binaries via dfu, the jtag port does not work.

I’m puzzled, it looks like it should work. My best guess is that it’ll be something simple.

Hi @opprud

You are sure you don’t touch D7 in your user code, right?

But surely if JTAG mode is enabled inside the STM32, the physical pin is disconnected from the usual D7 circuitry ?

Anything else would be close to madness, really. It should not matter what you try and do to D7 from firmware, because D7 is no longer connected to that pin.

Cue someone telling me that this is the biggest oversight the ST chip designers made…

To summarise, I CAN positively

  1. run openocd, connect to the target, when it is in DFU (flashing yellow).
  2. Telnet + reset halt- and observe the device resets
  3. GDB from command line or eclipse, step load symbolics, either system-part1.elf , system-part2.elf, or user-part.elf,
  4. step, continue, break etc ONLY as long as the led is blinking white, which i assume is when the system-stuff runs (flash/eeprom routines etc, consuming a bit of time…)
  5. When my own app or tinker start, which i can see by the led changing color, blinking blue in the case of tinker, i loose GDB, thus my current conclusion is that when the user part takes over, it somehow disables, or changes functions of the JTAG pins…

I am not doing anything to make use of the D7, i will investigate a bit more if tinker or the example hw_serial2 is doing so…

I will pull a fresh repos via git, and try again, to make sure…

Latest observation, just when i loose GDB connection, and the user app runs, the Green LED on the programmer shield turns on, indicating that something pulls JTAG_TCK/D6 high, i will investigate further.

Thanks for the many comments and responses btw :wink:

//morten

1 Like

I haven’t tampered with D7, but i still lack an overview of the firmware, and what’s happening just before entering setup() and loop()

JTAG signals looks as below

when GDB+openocd is connected in DFU mode + during boot (healthy tag comm)

when i get cut off - user app takes over TDI(D5) and TMS(D7) are taken high.

Furthermore i tried adding pull-ups 10K on TRST, TDI TMS, and pulldown on TCK - no change in behaviour or levels measured…

Tried repulling the git repository, rebuilding+flashing tinker… same-same…

3 Likes

Actually, I’m not seeing the preprocessor logic from the core moved over to the photon (everything shown is from commit f381b65 on the develop branch):

$ find . -type f -name "*.h*" -exec fgrep -l JTAG {} \;
./hal/src/photon/platforms/BCM9WCDUSI14/platform.h
./hal/src/photon/platforms/BCM9WCDUSI09/platform.h
./hal/src/photon/wiced/platform/MCU/STM32F2xx/peripherals/libraries/inc/stm32f2xx_gpio.h
./hal/inc/core_hal.h
./platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc/stm32f2xx_gpio.h
./platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc/stm32f10x_gpio.h
./platform/MCU/STM32F1xx/CMSIS/Device/ST/Include/stm32f10x.h

./hal/inc/core_hal.h is where the makefile-defined symbol USE_SWD_JTAG gets mapped onto SWD_*_{EN,DIS}ABLE:

./hal/inc/core_hal.h: * Use the JTAG IOs as standard GPIOs (D3 to D7)
./hal/inc/core_hal.h: * Note that once the JTAG IOs are disabled, the connection with the host debugger
./hal/inc/core_hal.h: * is lost and cannot be re-established as long as the JTAG IOs remain disabled.
./hal/inc/core_hal.h:#ifdef USE_SWD_JTAG
./hal/inc/core_hal.h:#define SWD_JTAG_ENABLE
./hal/inc/core_hal.h:#define SWD_ENABLE_JTAG_DISABLE
./hal/inc/core_hal.h:#define SWD_JTAG_DISABLE
./hal/inc/core_hal.h: * During JTAG program/debug, the Watchdog counting is disabled by debug configuration

SWD_JTAG_DISABLE and it’s friends are used in HAL_Core_Config() to enable/disable the JTAG pins.

Absolutely zero of this logic shows up in the hal/photon code.

I have not used GDB to debug applications on the photon yet, but I did it a lot on the core.
@jvanier I cannot understand how it worked for you on the photon, unless some recent commit removed every trace of this from the photon hal code.

1 Like

just tried removing below lines 165 -167 in hal/src/stm32f2xx/core_hal_stm32f2xx.c

    //Wiring pins default to inputs
#if !defined(USE_SWD_JTAG) && !defined(USE_SWD)
#if 0	//removed setting to inputs
    for (pin_t pin=0; pin<=19; pin++)
        HAL_Pin_Mode(pin, INPUT);
#endif

that makes a difference, the RGB isn’t on etc… but I AM ABLE TO DEBUG :wink: :wink: attach etc… now i just miss loading all the symbolics from the elf files into eclipse’s debugger and so on…

sofar its just a hack, guess the init of pins to input is there for a reason, but i’m over the first bump …!

thanks for any inputs ;-), hope they can be used by others in the community…

1 Like

I haven’t tried a debugger build in the last 2 weeks. I’ll check later tonight to see if it still works for me.

I remember looking at those lines when I made a change to the RGB onChange handler but I didn’t have to change them for compatibility with the debugger.

1 Like

So, that needs fixing properly - JTAG/SWD should only modify the settings for the required pins, not everything.

At least I see now that it doesn’t bounce the logic through SWD_JTAG_ENABLE like the core does.

“!defined(USE_SWD_JTAG) && !defined(USE_SWD)” should equate to false, but the makefile tree is not passing USE_SWD_JTAG flag to the gcc command lines for that branch of the source tree.

Glad you’re up and running, but I’m still curious how this ever worked.

Obviously someone needs to spend some quality time fixing both the makefiles and the source in core_hal_stm32f2xx.c

1 Like

Using D7 in application code does stop jtag from working. This gets me every once in a while when I’m not paying attention.

1 Like

git blame says that that part of core_hal_stm32f2xx.c has not changed since the end of July.

However, I’m confident that when these issues are addressed it’ll work just as advertised, so the past behaviour will be of little interest.

< slightly off topic > I still want to find a way to smash the 3 .elf files together into a single one that we can feed to gdb; but it won’t be this weekend. < /slightly off topic >

That’s crazy. If we can’t disable that, ST are morons [not that I feel strongly about this]

I’m not seeing the build problem.

If I add a #error inside

#if !defined(USE_SWD_JTAG) && !defined(USE_SWD)
#error not building with JTAG
    for (pin_t pin=0; pin<=19; pin++)
        HAL_Pin_Mode(pin, INPUT);
#endif

then from modules build with USE_SWD_JTAG=n, the error appears as expected. If I build then with USE_SWD_JTAG=y, the error disappears, so the flags are definitely being passed down. This is building from the modules directory.