OpenOCD
|
Go to the source code of this file.
Data Structures | |
struct | psoc6_target_info |
struct | row_region |
struct | timeout |
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_area * | g_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 [] |
#define MEM_IPC | ( | n | ) | (MEM_BASE_IPC + (n) * IPC_STRUCT_SIZE) |
#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 SFLASH_NUM_REGIONS ARRAY_SIZE(safe_sflash_regions) |
#define SROMAPI_SIID_REQ_FAMILY_REVISION (SROMAPI_SIID_REQ | 0x000u) |
#define SROMAPI_SIID_REQ_SIID_PROTECTION (SROMAPI_SIID_REQ | 0x100u) |
|
static |
Invokes SROM API functions which are responsible for Flash operations.
target | current target |
req_and_params | request id of the function to invoke |
working_area | address of memory buffer in target's memory space for SROM API parameters |
data_out | pointer to variable which will be populated with execution status |
Definition at line 316 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 | ( | psoc6_handle_mass_erase_command | ) |
Performs Mass Erase operation.
Definition at line 861 of file psoc6.c.
References bank, CALL_COMMAND_HANDLER, CMD_ARGC, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and psoc6_erase().
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.
Definition at line 970 of file psoc6.c.
References CMD_ARGC, CMD_CTX, ERROR_COMMAND_SYNTAX_ERROR, get_current_target(), and handle_reset_halt().
FLASH_BANK_COMMAND_HANDLER | ( | psoc6_flash_bank_command | ) |
Definition at line 979 of file psoc6.c.
References bank, CMD_ARGC, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and psoc6_target_info::is_probed.
|
static |
Retrieves SiliconID and Protection status of the target device.
target | current target |
si_id | pointer to variable, will be populated with SiliconID |
protection | pointer to variable, will be populated with protection status |
Definition at line 378 of file psoc6.c.
References call_sromapi(), ERROR_OK, protection, sromalgo_prepare(), sromalgo_release(), SROMAPI_SIID_REQ_FAMILY_REVISION, and SROMAPI_SIID_REQ_SIID_PROTECTION.
Referenced by psoc6_get_info(), and psoc6_protect_check().
|
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.
target | current target |
Definition at line 887 of file psoc6.c.
References AIRCR_SYSRESETREQ, AIRCR_VECTKEY, AIRCR_VECTRESET, arm::arch, armv7m_common::arm, ARM_ARCH_V6M, BKPT_HARD, breakpoint_add(), breakpoint_remove(), 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().
|
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.
target | current target |
ipc_id | ipc_id IPC index to acquire. IPC #2 is dedicated for DAP access |
Definition at line 268 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().
|
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
target | current target |
ipc_id | IPC index to poll. IPC #2 is dedicated for DAP access |
lock_expected | expected lock status |
Definition at line 222 of file psoc6.c.
References arm::arch, armv7m_common::arm, ARM_ARCH_V6M, 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(), target_to_armv7m(), timeout_expired(), and timeout_init().
Referenced by call_sromapi(), and ipc_acquire().
|
inlinestatic |
Checks if given flash bank belongs to Main Flash.
bank | current flash bank |
Definition at line 539 of file psoc6.c.
References bank, and MEM_BASE_MFLASH.
Referenced by psoc6_probe().
|
static |
Checks if given flash bank belongs to Supervisory Flash.
bank | current flash bank |
Definition at line 514 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().
|
inlinestatic |
Checks if given flash bank belongs to Work Flash.
bank | current flash bank |
Definition at line 529 of file psoc6.c.
References bank, and MEM_BASE_WFLASH.
Referenced by psoc6_erase(), and psoc6_probe().
|
static |
Translates Protection status to string.
protection | protection value |
Definition at line 463 of file psoc6.c.
References protection, PROTECTION_DEAD, PROTECTION_NORMAL, PROTECTION_SECURE, PROTECTION_UNKNOWN, and PROTECTION_VIRGIN.
Referenced by psoc6_get_info().
|
static |
Probes target device only if it hasn't been probed yet.
bank | current flash bank |
Definition at line 620 of file psoc6.c.
References bank, ERROR_OK, psoc6_target_info::is_probed, and psoc6_probe().
|
static |
Performs Erase operation.
Function will try to use biggest erase block possible to speedup the operation.
bank | current flash bank |
first | first sector to erase |
last | last sector to erase |
Definition at line 700 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().
|
static |
Erases single row (512b) on target device.
bank | current flash bank |
wa | working area for SROM API parameters |
addr | starting address of the flash row |
Definition at line 669 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().
|
static |
Erases single sector (256k) on target device.
bank | current flash bank |
wa | working area for SROM API parameters |
addr | starting address of the sector |
Definition at line 640 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().
|
static |
psoc6_get_info Displays human-readable information about acquired device
bank | current flash bank |
cmd | pointer to command invocation instance |
Definition at line 486 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.
|
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)
bank | current flash bank |
Definition at line 552 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().
|
static |
Performs Program operation.
bank | current flash bank |
buffer | pointer to the buffer with data |
offset | starting offset in flash bank |
count | number of bytes in buffer |
Definition at line 817 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().
|
static |
Programs single Flash Row.
bank | current flash bank |
addr | address of the flash row |
buffer | pointer to the buffer with data |
is_sflash | true if current flash bank belongs to Supervisory Flash |
Definition at line 760 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().
|
static |
Dummy function, Life Cycle transition is not currently supported.
Definition at line 446 of file psoc6.c.
References bank, ERROR_OK, and LOG_WARNING.
|
static |
Translates Protection status to openocd-friendly boolean value.
bank | current flash bank |
Definition at line 413 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.
|
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.
target | target for the algorithm |
Definition at line 134 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().
|
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.
target | current target |
Definition at line 186 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().
|
static |
Returns true if given struct timeout
structure has expired.
to | pointer to struct timeout structure |
Definition at line 121 of file psoc6.c.
References timeout::start_time, timeout::timeout_ms, and timeval_ms().
Referenced by ipc_acquire(), and ipc_poll_lock_stat().
|
static |
Initializes struct timeout
structure with given timeout value.
to | pointer to struct timeout structure |
timeout_ms | timeout, in milliseconds |
Definition at line 110 of file psoc6.c.
References timeout::start_time, timeout::timeout_ms, and timeval_ms().
Referenced by ipc_acquire(), and ipc_poll_lock_stat().
|
static |
Definition at line 102 of file psoc6.c.
Referenced by sromalgo_prepare(), and sromalgo_release().
|
static |
Definition at line 102 of file psoc6.c.
Referenced by sromalgo_prepare(), and sromalgo_release().
|
static |
|
static |
const struct flash_driver psoc6_flash |
|
static |
Definition at line 1 of file psoc6.c.
Referenced by is_sflash_bank(), and psoc6_probe().