OpenOCD
psoc6.c File Reference
Include dependency graph for psoc6.c:

Go to the source code of this file.

Data Structures

struct  psoc6_target_info
 
struct  row_region
 
struct  timeout
 

Macros

#define IPC_ACQUIRE_SUCCESS_MSK   0x80000000u
 
#define IPC_ID   2u
 
#define IPC_INTR_ID   0u
 
#define IPC_INTR_STRUCT_SIZE   0x20u
 
#define IPC_LOCK_ACQUIRED_MSK   0x80000000u
 
#define IPC_STRUCT_SIZE   0x20u
 
#define IPC_TIMEOUT_MS   1000
 
#define MEM_BASE_IPC   0x40230000u
 
#define MEM_BASE_IPC_INTR   0x40231000u
 
#define MEM_BASE_MFLASH   0x10000000u
 
#define MEM_BASE_SFLASH   0x16000000u
 
#define MEM_BASE_WFLASH   0x14000000u
 
#define MEM_IPC(n)   (MEM_BASE_IPC + (n) * IPC_STRUCT_SIZE)
 
#define MEM_IPC_ACQUIRE(n)   (MEM_IPC(n) + 0x00u)
 
#define MEM_IPC_DATA(n)   (MEM_IPC(n) + 0x0Cu)
 
#define MEM_IPC_INTR(n)   (MEM_BASE_IPC_INTR + (n) * IPC_INTR_STRUCT_SIZE)
 
#define MEM_IPC_INTR_MASK(n)   (MEM_IPC_INTR(n) + 0x08u)
 
#define MEM_IPC_LOCK_STATUS(n)   (MEM_IPC(n) + 0x10u)
 
#define MEM_IPC_NOTIFY(n)   (MEM_IPC(n) + 0x08u)
 
#define MEM_WFLASH_SIZE   32768u
 
#define MFLASH_SECTOR_SIZE   (256u * 1024u)
 
#define PROTECTION_DEAD   0x04u
 
#define PROTECTION_NORMAL   0x02u
 
#define PROTECTION_SECURE   0x03u
 
#define PROTECTION_UNKNOWN   0x00u
 
#define PROTECTION_VIRGIN   0x01u
 
#define PSOC6_SPCIF_GEOMETRY   0x4025F00Cu
 
#define RAM_STACK_WA_SIZE   2048u
 
#define SFLASH_NUM_REGIONS   ARRAY_SIZE(safe_sflash_regions)
 
#define SROMAPI_CALL_TIMEOUT_MS   1500
 
#define SROMAPI_DATA_LOCATION_MSK   0x00000001u
 
#define SROMAPI_ERASEALL_REQ   0x0A000100u
 
#define SROMAPI_ERASEROW_REQ   0x1C000100u
 
#define SROMAPI_ERASESECTOR_REQ   0x14000100u
 
#define SROMAPI_PROGRAMROW_REQ   0x06000100u
 
#define SROMAPI_SIID_REQ   0x00000001u
 
#define SROMAPI_SIID_REQ_FAMILY_REVISION   (SROMAPI_SIID_REQ | 0x000u)
 
#define SROMAPI_SIID_REQ_SIID_PROTECTION   (SROMAPI_SIID_REQ | 0x100u)
 
#define SROMAPI_STAT_SUCCESS   0xA0000000u
 
#define SROMAPI_STATUS_MSK   0xF0000000u
 
#define SROMAPI_WRITEROW_REQ   0x05000100u
 
#define WFLASH_SECTOR_SIZE   (32u * 1024u)
 

Functions

static int call_sromapi (struct target *target, uint32_t req_and_params, uint32_t working_area, uint32_t *data_out)
 Invokes SROM API functions which are responsible for Flash operations. More...
 
 COMMAND_HANDLER (psoc6_handle_mass_erase_command)
 Performs Mass Erase operation. More...
 
 COMMAND_HANDLER (psoc6_handle_reset_halt)
 Simulates broken Vector Catch Function will try to determine entry point of user application. More...
 
 FLASH_BANK_COMMAND_HANDLER (psoc6_flash_bank_command)
 
static int get_silicon_id (struct target *target, uint32_t *si_id, uint8_t *protection)
 Retrieves SiliconID and Protection status of the target device. More...
 
static int handle_reset_halt (struct target *target)
 Simulates broken Vector Catch Function will try to determine entry point of user application. More...
 
static int ipc_acquire (struct target *target, char ipc_id)
 Acquires IPC structure. More...
 
static int ipc_poll_lock_stat (struct target *target, uint32_t ipc_id, bool lock_expected)
 Waits for expected IPC lock status. More...
 
static bool is_mflash_bank (struct flash_bank *bank)
 Checks if given flash bank belongs to Main Flash. More...
 
static bool is_sflash_bank (struct flash_bank *bank)
 Checks if given flash bank belongs to Supervisory Flash. More...
 
static bool is_wflash_bank (struct flash_bank *bank)
 Checks if given flash bank belongs to Work Flash. More...
 
static const char * protection_to_str (uint8_t protection)
 Translates Protection status to string. More...
 
static int psoc6_auto_probe (struct flash_bank *bank)
 Probes target device only if it hasn't been probed yet. More...
 
static int psoc6_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 Performs Erase operation. More...
 
static int psoc6_erase_row (struct flash_bank *bank, struct working_area *wa, uint32_t addr)
 Erases single row (512b) on target device. More...
 
static int psoc6_erase_sector (struct flash_bank *bank, struct working_area *wa, uint32_t addr)
 Erases single sector (256k) on target device. More...
 
static int psoc6_get_info (struct flash_bank *bank, struct command_invocation *cmd)
 psoc6_get_info Displays human-readable information about acquired device More...
 
static int psoc6_probe (struct flash_bank *bank)
 Probes the device and populates related data structures with target flash geometry data. More...
 
static int psoc6_program (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 Performs Program operation. More...
 
static int psoc6_program_row (struct flash_bank *bank, uint32_t addr, const uint8_t *buffer, bool is_sflash)
 Programs single Flash Row. More...
 
static int psoc6_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 Dummy function, Life Cycle transition is not currently supported. More...
 
static int psoc6_protect_check (struct flash_bank *bank)
 Translates Protection status to openocd-friendly boolean value. More...
 
static int sromalgo_prepare (struct target *target)
 Starts pseudo flash algorithm and leaves it running. More...
 
static void sromalgo_release (struct target *target)
 Stops running flash algorithm and releases associated resources. More...
 
static bool timeout_expired (struct timeout *to)
 Returns true if given struct timeout structure has expired. More...
 
static void timeout_init (struct timeout *to, long timeout_ms)
 Initializes struct timeout structure with given timeout value. More...
 

Variables

static struct armv7m_algorithm g_armv7m_info
 
static struct working_areag_stack_area
 
static const struct command_registration psoc6_command_handlers []
 
static const struct command_registration psoc6_exec_command_handlers []
 
const struct flash_driver psoc6_flash
 
static const struct row_region safe_sflash_regions []
 

Macro Definition Documentation

◆ IPC_ACQUIRE_SUCCESS_MSK

#define IPC_ACQUIRE_SUCCESS_MSK   0x80000000u

Definition at line 55 of file psoc6.c.

◆ IPC_ID

#define IPC_ID   2u

Definition at line 58 of file psoc6.c.

◆ IPC_INTR_ID

#define IPC_INTR_ID   0u

Definition at line 59 of file psoc6.c.

◆ IPC_INTR_STRUCT_SIZE

#define IPC_INTR_STRUCT_SIZE   0x20u

Definition at line 52 of file psoc6.c.

◆ IPC_LOCK_ACQUIRED_MSK

#define IPC_LOCK_ACQUIRED_MSK   0x80000000u

Definition at line 56 of file psoc6.c.

◆ IPC_STRUCT_SIZE

#define IPC_STRUCT_SIZE   0x20u

Definition at line 44 of file psoc6.c.

◆ IPC_TIMEOUT_MS

#define IPC_TIMEOUT_MS   1000

Definition at line 60 of file psoc6.c.

◆ MEM_BASE_IPC

#define MEM_BASE_IPC   0x40230000u

Definition at line 43 of file psoc6.c.

◆ MEM_BASE_IPC_INTR

#define MEM_BASE_IPC_INTR   0x40231000u

Definition at line 51 of file psoc6.c.

◆ MEM_BASE_MFLASH

#define MEM_BASE_MFLASH   0x10000000u

Definition at line 30 of file psoc6.c.

◆ MEM_BASE_SFLASH

#define MEM_BASE_SFLASH   0x16000000u

Definition at line 33 of file psoc6.c.

◆ MEM_BASE_WFLASH

#define MEM_BASE_WFLASH   0x14000000u

Definition at line 31 of file psoc6.c.

◆ MEM_IPC

#define MEM_IPC (   n)    (MEM_BASE_IPC + (n) * IPC_STRUCT_SIZE)

Definition at line 45 of file psoc6.c.

◆ MEM_IPC_ACQUIRE

#define MEM_IPC_ACQUIRE (   n)    (MEM_IPC(n) + 0x00u)

Definition at line 46 of file psoc6.c.

◆ MEM_IPC_DATA

#define MEM_IPC_DATA (   n)    (MEM_IPC(n) + 0x0Cu)

Definition at line 48 of file psoc6.c.

◆ MEM_IPC_INTR

#define MEM_IPC_INTR (   n)    (MEM_BASE_IPC_INTR + (n) * IPC_INTR_STRUCT_SIZE)

Definition at line 53 of file psoc6.c.

◆ MEM_IPC_INTR_MASK

#define MEM_IPC_INTR_MASK (   n)    (MEM_IPC_INTR(n) + 0x08u)

Definition at line 54 of file psoc6.c.

◆ MEM_IPC_LOCK_STATUS

#define MEM_IPC_LOCK_STATUS (   n)    (MEM_IPC(n) + 0x10u)

Definition at line 49 of file psoc6.c.

◆ MEM_IPC_NOTIFY

#define MEM_IPC_NOTIFY (   n)    (MEM_IPC(n) + 0x08u)

Definition at line 47 of file psoc6.c.

◆ MEM_WFLASH_SIZE

#define MEM_WFLASH_SIZE   32768u

Definition at line 32 of file psoc6.c.

◆ MFLASH_SECTOR_SIZE

#define MFLASH_SECTOR_SIZE   (256u * 1024u)

Definition at line 27 of file psoc6.c.

◆ PROTECTION_DEAD

#define PROTECTION_DEAD   0x04u

Definition at line 41 of file psoc6.c.

◆ PROTECTION_NORMAL

#define PROTECTION_NORMAL   0x02u

Definition at line 39 of file psoc6.c.

◆ PROTECTION_SECURE

#define PROTECTION_SECURE   0x03u

Definition at line 40 of file psoc6.c.

◆ PROTECTION_UNKNOWN

#define PROTECTION_UNKNOWN   0x00u

Definition at line 37 of file psoc6.c.

◆ PROTECTION_VIRGIN

#define PROTECTION_VIRGIN   0x01u

Definition at line 38 of file psoc6.c.

◆ PSOC6_SPCIF_GEOMETRY

#define PSOC6_SPCIF_GEOMETRY   0x4025F00Cu

Definition at line 35 of file psoc6.c.

◆ RAM_STACK_WA_SIZE

#define RAM_STACK_WA_SIZE   2048u

Definition at line 34 of file psoc6.c.

◆ SFLASH_NUM_REGIONS

#define SFLASH_NUM_REGIONS   ARRAY_SIZE(safe_sflash_regions)

Definition at line 101 of file psoc6.c.

◆ SROMAPI_CALL_TIMEOUT_MS

#define SROMAPI_CALL_TIMEOUT_MS   1500

Definition at line 74 of file psoc6.c.

◆ SROMAPI_DATA_LOCATION_MSK

#define SROMAPI_DATA_LOCATION_MSK   0x00000001u

Definition at line 73 of file psoc6.c.

◆ SROMAPI_ERASEALL_REQ

#define SROMAPI_ERASEALL_REQ   0x0A000100u

Definition at line 68 of file psoc6.c.

◆ SROMAPI_ERASEROW_REQ

#define SROMAPI_ERASEROW_REQ   0x1C000100u

Definition at line 69 of file psoc6.c.

◆ SROMAPI_ERASESECTOR_REQ

#define SROMAPI_ERASESECTOR_REQ   0x14000100u

Definition at line 67 of file psoc6.c.

◆ SROMAPI_PROGRAMROW_REQ

#define SROMAPI_PROGRAMROW_REQ   0x06000100u

Definition at line 66 of file psoc6.c.

◆ SROMAPI_SIID_REQ

#define SROMAPI_SIID_REQ   0x00000001u

Definition at line 62 of file psoc6.c.

◆ SROMAPI_SIID_REQ_FAMILY_REVISION

#define SROMAPI_SIID_REQ_FAMILY_REVISION   (SROMAPI_SIID_REQ | 0x000u)

Definition at line 63 of file psoc6.c.

◆ SROMAPI_SIID_REQ_SIID_PROTECTION

#define SROMAPI_SIID_REQ_SIID_PROTECTION   (SROMAPI_SIID_REQ | 0x100u)

Definition at line 64 of file psoc6.c.

◆ SROMAPI_STAT_SUCCESS

#define SROMAPI_STAT_SUCCESS   0xA0000000u

Definition at line 72 of file psoc6.c.

◆ SROMAPI_STATUS_MSK

#define SROMAPI_STATUS_MSK   0xF0000000u

Definition at line 71 of file psoc6.c.

◆ SROMAPI_WRITEROW_REQ

#define SROMAPI_WRITEROW_REQ   0x05000100u

Definition at line 65 of file psoc6.c.

◆ WFLASH_SECTOR_SIZE

#define WFLASH_SECTOR_SIZE   (32u * 1024u)

Definition at line 28 of file psoc6.c.

Function Documentation

◆ call_sromapi()

static int call_sromapi ( struct target target,
uint32_t  req_and_params,
uint32_t  working_area,
uint32_t *  data_out 
)
static

Invokes SROM API functions which are responsible for Flash operations.


Parameters
targetcurrent target
req_and_paramsrequest id of the function to invoke
working_areaaddress of memory buffer in target's memory space for SROM API parameters
data_outpointer to variable which will be populated with execution status
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 315 of file psoc6.c.

References ERROR_OK, ERROR_TARGET_FAILURE, ipc_acquire(), IPC_ID, IPC_INTR_ID, ipc_poll_lock_stat(), LOG_ERROR, MEM_IPC_DATA, MEM_IPC_INTR_MASK, MEM_IPC_NOTIFY, SROMAPI_DATA_LOCATION_MSK, SROMAPI_STAT_SUCCESS, SROMAPI_STATUS_MSK, target_read_u32(), and target_write_u32().

Referenced by get_silicon_id(), psoc6_erase_row(), psoc6_erase_sector(), and psoc6_program_row().

◆ COMMAND_HANDLER() [1/2]

COMMAND_HANDLER ( psoc6_handle_mass_erase_command  )

Performs Mass Erase operation.


Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 860 of file psoc6.c.

References bank, CALL_COMMAND_HANDLER, CMD_ARGC, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and psoc6_erase().

◆ COMMAND_HANDLER() [2/2]

COMMAND_HANDLER ( psoc6_handle_reset_halt  )

Simulates broken Vector Catch Function will try to determine entry point of user application.


If it succeeds it will set HW breakpoint at that address, issue SW Reset and remove the breakpoint afterwards. In case of CM0, SYSRESETREQ is used. This allows to reset all peripherals. Boot code will reset CM4 anyway, so using SYSRESETREQ is safe here. In case of CM4, VECTRESET is used instead of SYSRESETREQ to not disturb CM0 core.

Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 968 of file psoc6.c.

References CMD_ARGC, CMD_CTX, ERROR_COMMAND_SYNTAX_ERROR, get_current_target(), and handle_reset_halt().

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( psoc6_flash_bank_command  )

Definition at line 977 of file psoc6.c.

References bank, CMD_ARGC, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and psoc6_target_info::is_probed.

◆ get_silicon_id()

static int get_silicon_id ( struct target target,
uint32_t *  si_id,
uint8_t *  protection 
)
static

Retrieves SiliconID and Protection status of the target device.


Parameters
targetcurrent target
si_idpointer to variable, will be populated with SiliconID
protectionpointer to variable, will be populated with protection status
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 377 of file psoc6.c.

References call_sromapi(), ERROR_OK, sromalgo_prepare(), sromalgo_release(), SROMAPI_SIID_REQ_FAMILY_REVISION, and SROMAPI_SIID_REQ_SIID_PROTECTION.

Referenced by psoc6_get_info(), and psoc6_protect_check().

◆ handle_reset_halt()

static int handle_reset_halt ( struct target target)
static

Simulates broken Vector Catch Function will try to determine entry point of user application.


If it succeeds it will set HW breakpoint at that address, issue SW Reset and remove the breakpoint afterwards. In case of CM0, SYSRESETREQ is used. This allows to reset all peripherals. Boot code will reset CM4 anyway, so using SYSRESETREQ is safe here. In case of CM4, VECTRESET is used instead of SYSRESETREQ to not disturb CM0 core.

Parameters
targetcurrent target
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 886 of file psoc6.c.

References AIRCR_SYSRESETREQ, AIRCR_VECTKEY, AIRCR_VECTRESET, BKPT_HARD, breakpoint_add(), breakpoint_remove(), target::coreid, adiv5_ap::dap, dap_dp_init(), armv7m_common::debug_ap, ERROR_OK, IPC_TIMEOUT_MS, LOG_INFO, mem_ap_write_atomic_u32(), NVIC_AIRCR, target::state, target_halt(), TARGET_HALTED, target_read_u32(), target_to_armv7m(), and target_wait_state().

Referenced by COMMAND_HANDLER().

◆ ipc_acquire()

static int ipc_acquire ( struct target target,
char  ipc_id 
)
static

Acquires IPC structure.


PSoC6 uses IPC structures for inter-core communication. Same IPCs are used to invoke SROM API. IPC structure must be locked prior to invoking any SROM API. This ensures nothing else in the system will use same IPC thus corrupting our data. This function locks the IPC.

Parameters
targetcurrent target
ipc_idipc_id IPC index to acquire. IPC #2 is dedicated for DAP access
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 267 of file psoc6.c.

References ERROR_OK, IPC_ACQUIRE_SUCCESS_MSK, ipc_poll_lock_stat(), IPC_TIMEOUT_MS, keep_alive(), LOG_ERROR, MEM_IPC_ACQUIRE, target_read_u32(), target_write_u32(), timeout_expired(), and timeout_init().

Referenced by call_sromapi().

◆ ipc_poll_lock_stat()

static int ipc_poll_lock_stat ( struct target target,
uint32_t  ipc_id,
bool  lock_expected 
)
static

Waits for expected IPC lock status.


PSoC6 uses IPC structures for inter-core communication. Same IPCs are used to invoke SROM API. IPC structure must be locked prior to invoking any SROM API. This ensures nothing else in the system will use same IPC thus corrupting our data. Locking is performed by ipc_acquire(), this function ensures that IPC is actually in expected state

Parameters
targetcurrent target
ipc_idIPC index to poll. IPC #2 is dedicated for DAP access
lock_expectedexpected lock status
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 223 of file psoc6.c.

References target::coreid, ERROR_OK, ERROR_TARGET_TIMEOUT, IPC_LOCK_ACQUIRED_MSK, IPC_TIMEOUT_MS, keep_alive(), LOG_ERROR, LOG_WARNING, MEM_IPC_LOCK_STATUS, target_read_u32(), timeout_expired(), and timeout_init().

Referenced by call_sromapi(), and ipc_acquire().

◆ is_mflash_bank()

static bool is_mflash_bank ( struct flash_bank bank)
inlinestatic

Checks if given flash bank belongs to Main Flash.


Parameters
bankcurrent flash bank
Returns
true if flash bank belongs to Main Flash

Definition at line 538 of file psoc6.c.

References bank, and MEM_BASE_MFLASH.

Referenced by psoc6_probe().

◆ is_sflash_bank()

static bool is_sflash_bank ( struct flash_bank bank)
static

Checks if given flash bank belongs to Supervisory Flash.


Parameters
bankcurrent flash bank
Returns
true if flash bank belongs to Supervisory Flash

Definition at line 513 of file psoc6.c.

References row_region::addr, bank, safe_sflash_regions, and SFLASH_NUM_REGIONS.

Referenced by psoc6_erase(), psoc6_probe(), and psoc6_program().

◆ is_wflash_bank()

static bool is_wflash_bank ( struct flash_bank bank)
inlinestatic

Checks if given flash bank belongs to Work Flash.


Parameters
bankcurrent flash bank
Returns
true if flash bank belongs to Work Flash

Definition at line 528 of file psoc6.c.

References bank, and MEM_BASE_WFLASH.

Referenced by psoc6_erase(), and psoc6_probe().

◆ protection_to_str()

static const char* protection_to_str ( uint8_t  protection)
static

Translates Protection status to string.


Parameters
protectionprotection value
Returns
pointer to const string describing protection status

Definition at line 462 of file psoc6.c.

References psoc6_target_info::protection, PROTECTION_DEAD, PROTECTION_NORMAL, PROTECTION_SECURE, PROTECTION_UNKNOWN, and PROTECTION_VIRGIN.

Referenced by psoc6_get_info().

◆ psoc6_auto_probe()

static int psoc6_auto_probe ( struct flash_bank bank)
static

Probes target device only if it hasn't been probed yet.


Parameters
bankcurrent flash bank
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 619 of file psoc6.c.

References bank, ERROR_OK, psoc6_target_info::is_probed, and psoc6_probe().

◆ psoc6_erase()

static int psoc6_erase ( struct flash_bank bank,
unsigned int  first,
unsigned int  last 
)
static

Performs Erase operation.


Function will try to use biggest erase block possible to speedup the operation.

Parameters
bankcurrent flash bank
firstfirst sector to erase
lastlast sector to erase
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 699 of file psoc6.c.

References bank, ERROR_OK, is_sflash_bank(), is_wflash_bank(), LOG_INFO, MFLASH_SECTOR_SIZE, psoc6_erase_row(), psoc6_erase_sector(), psoc6_target_info::row_sz, sector_size, sromalgo_prepare(), sromalgo_release(), target_alloc_working_area(), target_free_working_area(), and WFLASH_SECTOR_SIZE.

Referenced by COMMAND_HANDLER().

◆ psoc6_erase_row()

static int psoc6_erase_row ( struct flash_bank bank,
struct working_area wa,
uint32_t  addr 
)
static

Erases single row (512b) on target device.


Parameters
bankcurrent flash bank
waworking area for SROM API parameters
addrstarting address of the flash row
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 668 of file psoc6.c.

References addr, working_area::address, bank, call_sromapi(), ERROR_OK, LOG_DEBUG, LOG_ERROR, SROMAPI_ERASEROW_REQ, and target_write_u32().

Referenced by psoc6_erase().

◆ psoc6_erase_sector()

static int psoc6_erase_sector ( struct flash_bank bank,
struct working_area wa,
uint32_t  addr 
)
static

Erases single sector (256k) on target device.


Parameters
bankcurrent flash bank
waworking area for SROM API parameters
addrstarting address of the sector
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 639 of file psoc6.c.

References addr, working_area::address, bank, call_sromapi(), ERROR_OK, LOG_DEBUG, LOG_ERROR, SROMAPI_ERASESECTOR_REQ, and target_write_u32().

Referenced by psoc6_erase().

◆ psoc6_get_info()

static int psoc6_get_info ( struct flash_bank bank,
struct command_invocation cmd 
)
static

psoc6_get_info Displays human-readable information about acquired device


Parameters
bankcurrent flash bank
cmdpointer to command invocation instance
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 485 of file psoc6.c.

References bank, cmd, command_print_sameline(), ERROR_FAIL, ERROR_OK, get_silicon_id(), psoc6_target_info::is_probed, psoc6_target_info::main_flash_sz, psoc6_target_info::protection, protection_to_str(), and psoc6_target_info::silicon_id.

◆ psoc6_probe()

static int psoc6_probe ( struct flash_bank bank)
static

Probes the device and populates related data structures with target flash geometry data.


This is done in non-intrusive way, no SROM API calls are involved so GDB can safely attach to a running target. Function assumes that size of Work Flash is 32kB (true for all current part numbers)

Parameters
bankcurrent flash bank
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 551 of file psoc6.c.

References addr, bank, ERROR_FLASH_BANK_INVALID, ERROR_OK, is_mflash_bank(), psoc6_target_info::is_probed, is_sflash_bank(), is_wflash_bank(), LOG_ERROR, psoc6_target_info::main_flash_sz, MEM_WFLASH_SIZE, NULL, PSOC6_SPCIF_GEOMETRY, psoc6_target_info::row_sz, safe_sflash_regions, SFLASH_NUM_REGIONS, row_region::size, and target_read_u32().

Referenced by psoc6_auto_probe().

◆ psoc6_program()

static int psoc6_program ( struct flash_bank bank,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

Performs Program operation.


Parameters
bankcurrent flash bank
bufferpointer to the buffer with data
offsetstarting offset in flash bank
countnumber of bytes in buffer
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 816 of file psoc6.c.

References bank, buffer, count, ERROR_OK, is_sflash_bank(), LOG_ERROR, MIN, offset, psoc6_program_row(), psoc6_target_info::row_sz, sromalgo_prepare(), and sromalgo_release().

◆ psoc6_program_row()

static int psoc6_program_row ( struct flash_bank bank,
uint32_t  addr,
const uint8_t *  buffer,
bool  is_sflash 
)
static

Programs single Flash Row.


Parameters
bankcurrent flash bank
addraddress of the flash row
bufferpointer to the buffer with data
is_sflashtrue if current flash bank belongs to Supervisory Flash
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 759 of file psoc6.c.

References addr, working_area::address, bank, buffer, call_sromapi(), ERROR_OK, LOG_DEBUG, psoc6_target_info::row_sz, SROMAPI_PROGRAMROW_REQ, SROMAPI_WRITEROW_REQ, target_alloc_working_area(), target_free_working_area(), target_write_buffer(), and target_write_u32().

Referenced by psoc6_program().

◆ psoc6_protect()

static int psoc6_protect ( struct flash_bank bank,
int  set,
unsigned int  first,
unsigned int  last 
)
static

Dummy function, Life Cycle transition is not currently supported.


Returns
ERROR_OK always

Definition at line 445 of file psoc6.c.

References bank, ERROR_OK, and LOG_WARNING.

◆ psoc6_protect_check()

static int psoc6_protect_check ( struct flash_bank bank)
static

Translates Protection status to openocd-friendly boolean value.


Parameters
bankcurrent flash bank
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 412 of file psoc6.c.

References bank, ERROR_OK, get_silicon_id(), psoc6_target_info::protection, PROTECTION_DEAD, PROTECTION_NORMAL, PROTECTION_SECURE, PROTECTION_UNKNOWN, PROTECTION_VIRGIN, and psoc6_target_info::silicon_id.

◆ sromalgo_prepare()

static int sromalgo_prepare ( struct target target)
static

Starts pseudo flash algorithm and leaves it running.


Function allocates working area for algorithm code and CPU stack, adjusts stack pointer, uploads and starts the algorithm. Algorithm (a basic infinite loop) runs asynchronously while driver performs Flash operations.

Parameters
targettarget for the algorithm
Returns
ERROR_OK in case of success, ERROR_XXX code otherwise

Definition at line 135 of file psoc6.c.

References working_area::address, ARM_MODE_THREAD, ARMV7M_COMMON_MAGIC, buf_set_u32(), armv7m_algorithm::common_magic, armv7m_algorithm::core_mode, destroy_reg_param(), ERROR_OK, g_armv7m_info, g_stack_area, init_reg_param(), NULL, PARAM_OUT, RAM_STACK_WA_SIZE, working_area::size, target_alloc_working_area(), target_free_working_area(), target_start_algorithm(), target_write_u32(), and reg_param::value.

Referenced by get_silicon_id(), psoc6_erase(), and psoc6_program().

◆ sromalgo_release()

static void sromalgo_release ( struct target target)
static

Stops running flash algorithm and releases associated resources.


This function is also used for cleanup in case of errors so g_stack_area may be NULL. These cases have to be handled gracefully.

Parameters
targetcurrent target

Definition at line 187 of file psoc6.c.

References ERROR_OK, g_armv7m_info, g_stack_area, IPC_TIMEOUT_MS, NULL, target::running_alg, target_free_working_area(), target_halt(), and target_wait_algorithm().

Referenced by get_silicon_id(), psoc6_erase(), and psoc6_program().

◆ timeout_expired()

static bool timeout_expired ( struct timeout to)
static

Returns true if given struct timeout structure has expired.


Parameters
topointer to struct timeout structure
Returns
true if timeout expired

Definition at line 122 of file psoc6.c.

References timeout::start_time, timeout::timeout_ms, and timeval_ms().

Referenced by ipc_acquire(), and ipc_poll_lock_stat().

◆ timeout_init()

static void timeout_init ( struct timeout to,
long  timeout_ms 
)
static

Initializes struct timeout structure with given timeout value.


Parameters
topointer to struct timeout structure
timeout_mstimeout, in milliseconds

Definition at line 111 of file psoc6.c.

References timeout::start_time, timeout::timeout_ms, and timeval_ms().

Referenced by ipc_acquire(), and ipc_poll_lock_stat().

Variable Documentation

◆ g_armv7m_info

struct armv7m_algorithm g_armv7m_info
static

Definition at line 103 of file psoc6.c.

Referenced by sromalgo_prepare(), and sromalgo_release().

◆ g_stack_area

struct working_area* g_stack_area
static

Definition at line 103 of file psoc6.c.

Referenced by sromalgo_prepare(), and sromalgo_release().

◆ psoc6_command_handlers

const struct command_registration psoc6_command_handlers[]
static
Initial value:
= {
{
.name = "psoc6",
.mode = COMMAND_ANY,
.help = "PSoC 6 flash command group",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration psoc6_exec_command_handlers[]
Definition: psoc6.c:992

Definition at line 977 of file psoc6.c.

◆ psoc6_exec_command_handlers

const struct command_registration psoc6_exec_command_handlers[]
static
Initial value:
= {
{
.name = "mass_erase",
.handler = psoc6_handle_mass_erase_command,
.mode = COMMAND_EXEC,
.usage = "bank",
.help = "Erases entire Main Flash",
},
{
.name = "reset_halt",
.handler = psoc6_handle_reset_halt,
.mode = COMMAND_EXEC,
.usage = "",
.help = "Tries to simulate broken Vector Catch",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 977 of file psoc6.c.

◆ psoc6_flash

const struct flash_driver psoc6_flash
Initial value:
= {
.name = "psoc6",
.flash_bank_command = psoc6_flash_bank_command,
.erase = psoc6_erase,
.protect = psoc6_protect,
.write = psoc6_program,
.probe = psoc6_probe,
.auto_probe = psoc6_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = psoc6_protect_check,
.info = psoc6_get_info,
.free_driver_priv = default_flash_free_driver_priv,
}
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
static int psoc6_probe(struct flash_bank *bank)
Probes the device and populates related data structures with target flash geometry data.
Definition: psoc6.c:551
static int psoc6_auto_probe(struct flash_bank *bank)
Probes target device only if it hasn't been probed yet.
Definition: psoc6.c:619
static int psoc6_program(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Performs Program operation.
Definition: psoc6.c:816
static int psoc6_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Performs Erase operation.
Definition: psoc6.c:699
static int psoc6_protect_check(struct flash_bank *bank)
Translates Protection status to openocd-friendly boolean value.
Definition: psoc6.c:412
static int psoc6_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Dummy function, Life Cycle transition is not currently supported.
Definition: psoc6.c:445
static int psoc6_get_info(struct flash_bank *bank, struct command_invocation *cmd)
psoc6_get_info Displays human-readable information about acquired device
Definition: psoc6.c:485
static const struct command_registration psoc6_command_handlers[]
Definition: psoc6.c:1010

Definition at line 977 of file psoc6.c.

◆ safe_sflash_regions

const struct row_region safe_sflash_regions[]
static
Initial value:
= {
{0x16000800, 0x800},
{0x16001A00, 0x200},
{0x16005A00, 0xC00},
{0x16007C00, 0x400},
}

Definition at line 1 of file psoc6.c.

Referenced by is_sflash_bank(), and psoc6_probe().