diff options
Diffstat (limited to 'keyboard/infinity/tool')
-rw-r--r-- | keyboard/infinity/tool/README | 103 | ||||
-rw-r--r-- | keyboard/infinity/tool/k20dx32_flash.cfg | 139 | ||||
-rw-r--r-- | keyboard/infinity/tool/openocd.cfg | 13 |
3 files changed, 255 insertions, 0 deletions
diff --git a/keyboard/infinity/tool/README b/keyboard/infinity/tool/README new file mode 100644 index 0000000000..698314e250 --- /dev/null +++ b/keyboard/infinity/tool/README @@ -0,0 +1,103 @@ +OpenOCD config files for Kinetis +================================ +http://nemuisan.blog.bai.ne.jp/?eid=192848#OPENOCD + +These are needed for debug and programing bootloader with SWD. To flash keyboard firmware use 'dfu-util'. + +Flash security of Freescale kinetis +----------------------------------- +If FSEC of flash config is changed accidentally SWD/JTAG you can't get debug access until doing 'mdm mass_erase' with JTAG, CMSIS-DAP or OpenSAD adapter. HLA(high level adapter) like stlink doesn't work for this. + + +Example +------- +Debug: + $ openocd -s tool -f tool/openocd.cfg + $ arm-none-eabi-gdb build/infinity.elf -ex "target remote localhost:3333" + +Flash bootloader: + $ openocd -s tool -f tool/openocd.cfg -c "mt_flash kiibohd_bootloader.bin" + + +Infinity SWD pinout +------------------- +SWD pins are placed next to reset button; SWD_CLK, SWD_DIO, GND, 5V from top. +Note that RESET is also needed to get full control with OpenOCD. + + -------- + | ___ o |CLK + ||RST| o |DIO + ||BTN| o |GND + | --- o |5V + -------- + + +Kinetis sercure state +---------------------- +openocd 0.9.0 + +Warn : *********** ATTENTION! ATTENTION! ATTENTION! ATTENTION! ********** +Warn : **** **** +Warn : **** Your Kinetis MCU is in secured state, which means that, **** +Warn : **** with exception for very basic communication, JTAG/SWD **** +Warn : **** interface will NOT work. In order to restore its **** +Warn : **** functionality please issue 'kinetis mdm mass_erase' **** +Warn : **** command, power cycle the MCU and restart OpenOCD. **** +Warn : **** **** +Warn : *********** ATTENTION! ATTENTION! ATTENTION! ATTENTION! ********** + + +Info : MDM: Chip is unsecured. Continuing. +target state: halted +target halted due to debug-request, current mode: Thread +xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc +auto erase enabled +Info : Probing flash info for bank 0 +Warn : flash configuration field erased, please reset the device +wrote 4096 bytes from file kiibohd_bootloader.bin in 2.442562s (1.638 KiB/s) +Info : MDM: Chip is unsecured. Continuing. + + + + +Open On-Chip Debugger 0.9.0-dev-00346-g3e1dfdc-dirty (2015-03-21-20:41) +Licensed under GNU GPL v2 +For bug reports, read + http://openocd.sourceforge.net/doc/doxygen/bugs.html +Info : only one transport option; autoselect 'cmsis-dap' +Kinetis MUST need Hardware SRST Control to Recover Secure-State! +adapter_nsrst_delay: 200 +srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst +Info : add flash_bank kinetis k20.pflash +cortex_m reset_config sysresetreq +adapter speed: 1000 kHz +srst_only separate srst_nogate srst_open_drain connect_assert_srst +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 : Connecting under reset +Info : DAP_SWJ Sequence (reset: 50+ '1' followed by 0) +Info : CMSIS-DAP: Interface ready +Info : clock speed 1000 kHz +Info : IDCODE 0x2ba01477 +Warn : Adapter returned success despite SSTICKYERR being set. +Warn : Adapter returned success despite SSTICKYERR being set. +Warn : Adapter returned success despite SSTICKYERR being set. +Warn : Adapter returned success despite SSTICKYERR being set. +Info : k20.cpu: hardware has 6 breakpoints, 4 watchpoints +Info : MDM: Chip is unsecured. Continuing. +Info : MDM: Chip is unsecured. Continuing. +target state: halted +target halted due to debug-request, current mode: Thread +xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc +auto erase enabled +Info : Probing flash info for bank 0 +Warn : flash configuration field erased, please reset the device +wrote 4096 bytes from file kiibohd_bootloader.bin in 2.446902s (1.635 KiB/s) +Info : MDM: Chip is unsecured. Continuing. +Info : Halt timed out, wake up GDB. +Error: timed out while waiting for target halted +Runtime Error: tool/k20dx32_flash.cfg:81: +in procedure 'mt_flash' +in procedure 'halt' called at file "tool/k20dx32_flash.cfg", line 81 diff --git a/keyboard/infinity/tool/k20dx32_flash.cfg b/keyboard/infinity/tool/k20dx32_flash.cfg new file mode 100644 index 0000000000..1e3deb0910 --- /dev/null +++ b/keyboard/infinity/tool/k20dx32_flash.cfg @@ -0,0 +1,139 @@ +# FreeScale Kinetis K20 devices with 32kB Flash and 8kB Local On-Chip SRAM, +# Nemuisan's Special for MK20DN32VFT5,MK20DX32VFT5,MK10DN32VFT5,MK10DX32VFT5 + + +# 0.8.0 has no these procs +proc using_jtag {} { + set _TRANSPORT [ transport select ] + expr { [ string first "jtag" $_TRANSPORT ] != -1 } +} + +proc using_swd {} { + set _TRANSPORT [ transport select ] + expr { [ string first "swd" $_TRANSPORT ] != -1 } +} + +proc using_hla {} { + set _TRANSPORT [ transport select ] + expr { [ string first "hla" $_TRANSPORT ] != -1 } +} + +source [find target/swj-dp.tcl] + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME k20 +} + +if { [info exists ENDIAN] } { + set _ENDIAN $ENDIAN +} else { + set _ENDIAN little +} + +if { [info exists CPUTAPID] } { + set _CPUTAPID $CPUTAPID +} else { + if { [using_jtag] } { + set _CPUTAPID 0x4BA00477 + } { + # this is the SW-DP tap id not the jtag tap id + set _CPUTAPID 0x2BA01477 + } +} + +# Work-area is a space in RAM used for flash programming +# By default use 8kB +if { [info exists WORKAREASIZE] == 0 } { + set _WORKAREASIZE 0x2000 +} + +# Select "srst_only", Nemuisan said so! +echo "Kinetis MUST need Hardware SRST Control to Recover Secure-State!" +adapter_nsrst_delay 200 +reset_config srst_only + +swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -chain-position $_TARGETNAME + +# 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 +# Uncomment when gone into s*ck'n secured state! +# kinetis mdm mass_erase +} + +# K20 has minimun 8kB of SRAM and starts at 1FFFF000. +$_TARGETNAME configure -work-area-phys 0x1FFFF000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -rtos auto + +# MK20DN32VFT5,MK20DX32VFT5,MK10DN32VFT5,MK10DX32VFT5 has 32kB of flash memory. +flash bank $_CHIPNAME.pflash kinetis 0x00000000 0x8000 0 4 $_TARGETNAME + + +proc mt_flash {IMGFILE} { + flash write_image erase $IMGFILE + reset run + halt + verify_image $IMGFILE + reset run + shutdown +} + +proc mt_flash_bin {IMGFILE OFFSET} { + flash write_image erase $IMGFILE $OFFSET bin + reset run + halt + verify_image $IMGFILE $OFFSET bin + reset run + shutdown +} + +proc mt_flash_hex {IMGFILE} { + flash write_image erase $IMGFILE 0 ihex + reset run + halt + verify_image $IMGFILE 0 ihex + reset run + shutdown +} + +proc mt_flash_srec {IMGFILE} { + flash write_image erase $IMGFILE 0 s19 + reset run + halt + verify_image $IMGFILE 0 s19 + reset run + shutdown +} + +proc mass_erase {} { + kinetis mdm mass_erase +} + +proc eraser {} { +# Verbose procedure confirmed erase routine + flash info 0 +# CAUTION! "flash erase_sector 0 0 last" goes into secure state!!! +# USE "mass_erase" command instead of +# flash erase_sector 0 0 last + mass_erase + shutdown +} + +#debug_level 3 +# HLA doesn't have cortex_m commands +if {![using_hla]} { + # if srst is not fitted use SYSRESETREQ to + # perform a soft reset + cortex_m reset_config sysresetreq +} +adapter_khz 1000 +reset_config srst_only srst_nogate connect_assert_srst +gdb_target_description disable +init +reset init diff --git a/keyboard/infinity/tool/openocd.cfg b/keyboard/infinity/tool/openocd.cfg new file mode 100644 index 0000000000..2b0a63b933 --- /dev/null +++ b/keyboard/infinity/tool/openocd.cfg @@ -0,0 +1,13 @@ +# mchack openocd +# https://github.com/mchck/mchck/wiki/Openocd +# +# adapter: frdm-kl05z with cmsis-dap firmware +# inteface: cmsis-dap +# transport: hla_swd +# target: MK20DX128VLF5 Freescale Kinetis + +# adapter/interface +source [find interface/cmsis-dap.cfg] + +# CPU +source [find k20dx32_flash.cfg] |