| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- #
- # Copyright (C) <2019-2021>
- # <Cypress Semiconductor Corporation (an Infineon company)>
- #
- # Common configuration for MXS40 family of microcontrollers.
- #
- source [find target/mxs40/migration.cfg]
- global _MXS40_COMMON_LOADED
- if [info exist _MXS40_COMMON_LOADED] return
- source [find mem_helper.tcl]
- source [find target/mxs40/cy_get_set_device_param.cfg]
- set _MXS40_COMMON_LOADED true
- ###############################################################################
- # Mapping between DIEs from the MPN database and their configuration files
- ###############################################################################
- set MXS40_DIE_CONFIG_DICT [dict create \
- PSoC6ABLE2 psoc6.cfg \
- PSoC6A256K psoc6_256k.cfg \
- PSoC6A512K psoc6_512k.cfg \
- PSoC6A2M psoc6_2m.cfg \
- ]
- ###############################################################################
- # Default speed an reset settings
- ###############################################################################
- if {[using_jtag]} {
- adapter speed 1000
- } else {
- adapter speed 2000
- }
- adapter srst delay 25
- adapter srst pulse_width 25
- ###############################################################################
- # Acquires the device in Test Mode
- ###############################################################################
- proc mxs40_acquire { target } {
- global _ENABLE_ACQUIRE
- if { $_ENABLE_ACQUIRE == 0 } {
- echo "*******************************************************************"
- echo "* Test Mode acquire disabled. Use 'set ENABLE_ACQUIRE 1' to enable"
- echo "*******************************************************************"
- return
- }
- # acquire will leave CPU in running state
- # openocd does not expect this
- # ignore possible error e.g. when listen window is disabled
- catch {kitprog3 acquire_psoc}
- # we need to re-examine and halt target manually
- ${target} arp_examine
- ${target} arp_poll
- if { [$target curstate] eq "reset" } {
- $target arp_poll
- }
- # Ensure target has stopped on WFI instruction
- set loops 2000
- while { $loops } {
- set sleeping [ expr {[mrw 0xE000EDF0] & 0x00040000} ]
- if { $sleeping } break
- set loops [ expr {$loops - 1} ]
- }
- if { $sleeping } {
- ${target} arp_halt
- ${target} arp_waitstate halted 100
- echo "** Device acquired successfully"
- return
- }
- puts stderr "********************************************"
- puts stderr "* Failed to acquire the device in Test Mode"
- puts stderr "********************************************"
- }
- add_usage_text mxs40_acquire "target"
- add_help_text mxs40_acquire "Acquires the device in Test Mode"
- ###############################################################################
- # Erases all non-virtual flash banks (in reverse order)
- ###############################################################################
- proc erase_all {} {
- lset banks [flash list]
- set banks_count [llength $banks]
- for {set i [expr {$banks_count - 1}]} { $i >= 0 } { set i [expr {$i - 1}]} {
- set bank [lindex $banks $i]
- set bank_name $bank(name)
- echo [format "Erasing flash bank \"%s\" (%d of %d)..." $bank_name [expr {$banks_count - $i}] $banks_count ]
- if { $bank_name != "virtual" } {
- flash erase_sector $i 0 last
- } else {
- echo "skipped (virtual)"
- }
- }
- }
- add_help_text erase_all "Erases all non-virtual flash banks (in reverse order, for SMIF compatibility)"
- ###############################################################################
- # Utility to make 'reset halt' work as reset;halt on a target
- # It does not prevent running code after reset
- ###############################################################################
- proc mxs40_reset_deassert_post { target_type target } {
- global _ENABLE_ACQUIRE
- global RESET_MODE
- # MXS40 cleared AP registers including TAR during reset
- # Force examine to synchronize OpenOCD target status
- $target arp_examine
- $target arp_poll
- # Exit if $target is supposed to be running after Reset
- if { $RESET_MODE eq "run" } return
- # Check if $target is a primary core (cm0 for TRAVEO™II)
- set is_primary_core [string match "*cm0" $target]
- if { $is_primary_core } {
- if { $_ENABLE_ACQUIRE } {
- mxs40_acquire $target
- } else {
- $target_type reset_halt sysresetreq
- }
- check_flashboot_version
- } else {
- if { [$target curstate] eq "reset" } {
- $target arp_poll
- }
- if { [$target curstate] eq "running" } {
- echo "** $target: Ran after reset and before halt..."
- $target arp_halt
- $target arp_waitstate halted 100
- }
- }
- }
- # Define check_flashboot_version if not already defined
- # It is used on PSoC6 only to detect pre-production chips
- if { [info proc check_flashboot_version] eq "" } {
- proc check_flashboot_version {} {}
- }
- ###############################################################################
- # Tries to detect SMIF geometry by parsing TOC2
- ###############################################################################
- proc detect_smif {{sflash_base 0x16000000}} {
- set cfg_ptr [mrw [mrw [ expr {$sflash_base + 62 * 512 + 0x0C} ]]]
- if { $cfg_ptr == 0 || $cfg_ptr == 0xFFFFFFFF || $cfg_ptr < 0x10000000 || $cfg_ptr > 0x10200000 } {
- echo "** SMIF configuration structure not found or invalid"
- return
- }
- set chip_num [mrw $cfg_ptr]
- set chip_cfg_arry_p [mrw [expr {$cfg_ptr + 4}]]
- echo ""
- for {set i 0} {$i < $chip_num} {incr i} {
- set chip_cfg [mrw [expr {$chip_cfg_arry_p + 4 * $i}]]
- set region_base [mrw [expr {$chip_cfg + 12}]]
- set region_size [mrw [expr {$chip_cfg + 16}]]
- set phys_cfg [mrw [expr {$chip_cfg + 24}]]
- set erase_size [mrw [expr {$phys_cfg + 24}]]
- set prgm_size [mrw [expr {$phys_cfg + 36}]]
- echo "### SMIF region #${i} - Erase Size: 0x[format %X $erase_size], Program Size: 0x[format %X $prgm_size]"
- echo "set SMIF_BANKS {1 {addr 0x[format %08X $region_base] size 0x[format %08X $region_size] psize 0x[format %X $prgm_size] esize 0x[format %X $erase_size]}}"
- }
- }
- add_usage_text detect_smif "sflash_base (optional, 0x16000000 by default)"
- add_help_text detect_smif "Detects SMIF regions and displays flash bank configuration"
- ###############################################################################
- # Overrides default init_reset procedure, stores reset mode in global variable
- ###############################################################################
- proc init_reset { mode } {
- global RESET_MODE
- set RESET_MODE $mode
- }
- ###############################################################################
- # Handles GDB extended 'restart' command
- ###############################################################################
- proc ocd_gdb_restart {target} {
- if [string match "*cm0" $target ] {
- reset init
- psoc6 reset_halt sysresetreq
- } else {
- reset run
- sleep 200
- psoc6 reset_halt sysresetreq
- }
- }
- ###############################################################################
- # Power dropout/restore handlers
- ###############################################################################
- proc power_dropout {} {
- if { [adapter name] eq "kitprog3" } {
- local_echo off
- set voltage [regexp -inline -- {[0-9]+\.[0-9]+} [kitprog3 get_power]]
- local_echo on
- puts stderr "Power dropout, target voltage: $voltage mV"
- }
- }
- proc power_restore {} {
- if { [adapter name] eq "kitprog3" } {
- local_echo off
- set voltage [regexp -inline -- {[0-9]+\.[0-9]+} [kitprog3 get_power]]
- local_echo on
- puts stderr "Power restore, target voltage: $voltage mV"
- }
- }
- ###############################################################################
- # KitProg3 acquire/power control stuff
- ###############################################################################
- global _ENABLE_ACQUIRE
- global _ENABLE_POWER_SUPPLY
- if {[using_jtag]} {
- set ENABLE_ACQUIRE 0
- echo "** Test Mode acquire disabled (not supported in JTAG mode)"
- }
- if { [adapter name] eq "kitprog3" } {
- if { [info exists ENABLE_ACQUIRE] } {
- if { ( $ENABLE_ACQUIRE != 0 ) && ( $ENABLE_ACQUIRE != 1 ) && ( $ENABLE_ACQUIRE != 2 ) } {
- puts stderr "** Invalid ENABLE_ACQUIRE value ($ENABLE_ACQUIRE). Allowed values are:"
- puts stderr "** 0 - Test Mode acquisition is disabled"
- puts stderr "** 1 - Enable acquisition using XRES method"
- puts stderr "** 2 - Enable acquisition using power-cycle method"
- terminate
- }
- if { $ENABLE_ACQUIRE == 2 && ![info exists ENABLE_POWER_SUPPLY] } {
- set ENABLE_POWER_SUPPLY default
- }
- set _ENABLE_ACQUIRE $ENABLE_ACQUIRE
- } else {
- set _ENABLE_ACQUIRE 1
- }
- if { [info exists ENABLE_POWER_SUPPLY] } {
- set _ENABLE_POWER_SUPPLY $ENABLE_POWER_SUPPLY
- } else {
- set _ENABLE_POWER_SUPPLY 0
- }
- } else {
- set _ENABLE_ACQUIRE 0
- set _ENABLE_POWER_SUPPLY 0
- echo "** Test Mode acquire not supported by selected adapter"
- }
- if { $_ENABLE_ACQUIRE } {
- echo "** Auto-acquire enabled, use \"set ENABLE_ACQUIRE 0\" to disable"
- }
- if { [string is integer $_ENABLE_POWER_SUPPLY]} {
- if { $_ENABLE_POWER_SUPPLY } {
- echo "** Enabling target power ($_ENABLE_POWER_SUPPLY mV) \"set ENABLE_POWER_SUPPLY 0\" to disable"
- kitprog3 power_config on $_ENABLE_POWER_SUPPLY
- }
- } elseif { $_ENABLE_POWER_SUPPLY == "default" } {
- echo "** Enabling target power (default voltage) \"set ENABLE_POWER_SUPPLY 0\" to disable"
- kitprog3 power_config on
- } else {
- puts stderr "Invalid ENABLE_POWER_SUPPLY value - '$_ENABLE_POWER_SUPPLY' (integer or 'default' expected)"
- terminate
- }
|