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

Go to the source code of this file.

Data Structures

struct  sim3x_info
 

Macros

#define CLKCTRL0_APBCLKG0_ALL   (0x4002D020)
 
#define CLKCTRL0_APBCLKG0_CLR   (0x4002D028)
 
#define CLKCTRL0_APBCLKG0_FLCTRLCEN_MASK   (0x40000000)
 
#define CLKCTRL0_APBCLKG0_SET   (0x4002D024)
 
#define CPUID_CHECK_VALUE   (0x410FC230)
 
#define CPUID_CHECK_VALUE_MASK   (0xFF0FFFF0)
 
#define DEVICEID0_DEVICEID0   (0x400490C0)
 
#define DEVICEID0_DEVICEID1   (0x400490D0)
 
#define DEVICEID0_DEVICEID2   (0x400490E0)
 
#define DEVICEID0_DEVICEID3   (0x400490F0)
 
#define FLASH_BASE_ADDRESS   (0x00000000)
 
#define FLASH_BUSY_TIMEOUT   (100)
 
#define FLASHCTRL0_CONFIG_ALL   (0x4002E000)
 
#define FLASHCTRL0_CONFIG_BUSYF_MASK   (0x00100000)
 
#define FLASHCTRL0_CONFIG_CLR   (0x4002E008)
 
#define FLASHCTRL0_CONFIG_ERASEEN_MASK   (0x00040000)
 
#define FLASHCTRL0_CONFIG_SET   (0x4002E004)
 
#define FLASHCTRL0_KEY   (0x4002E0C0)
 
#define FLASHCTRL0_KEY_INITIAL_UNLOCK   (0x000000A5)
 
#define FLASHCTRL0_KEY_MULTIPLE_LOCK   (0x0000005A)
 
#define FLASHCTRL0_KEY_MULTIPLE_UNLOCK   (0x000000F2)
 
#define FLASHCTRL0_KEY_SINGLE_UNLOCK   (0x000000F1)
 
#define FLASHCTRL0_WRADDR   (0x4002E0A0)
 
#define FLASHCTRL0_WRDATA   (0x4002E0B0)
 
#define LOCK_WORD_ADDRESS   (0x0003FFFC)
 
#define LOCK_WORD_MCU_UNLOCKED   (0xFFFFFFFF)
 
#define LOCK_WORD_MCU_UNLOCKED_BY_FIRMWARE   (0x00000000)
 
#define RSTSRC0_RESETEN_ALL   (0x4002D060)
 
#define RSTSRC0_RESETEN_CLR   (0x4002D068)
 
#define RSTSRC0_RESETEN_SET   (0x4002D064)
 
#define RSTSRC0_RESETEN_SWREN_MASK   (0x00000040)
 
#define RSTSRC0_RESETEN_VMONREN_MASK   (0x00000004)
 
#define SIM3X_AP   (0x0A)
 
#define SIM3X_AP_CRC   (0x0C)
 
#define SIM3X_AP_CTRL1   (0x00)
 
#define SIM3X_AP_CTRL1_MASS_ERASE_REQ   (0x00000001)
 
#define SIM3X_AP_CTRL1_RESET_REQ   (0x00000008)
 
#define SIM3X_AP_CTRL2   (0x04)
 
#define SIM3X_AP_DAP_IN   (0x14)
 
#define SIM3X_AP_DAP_OUT   (0x18)
 
#define SIM3X_AP_ID   (0xFC)
 
#define SIM3X_AP_ID_VALUE   (0x2430002)
 
#define SIM3X_AP_INIT_STAT   (0x10)
 
#define SIM3X_AP_INIT_STAT_LOCK   (0x00000004)
 
#define SIM3X_AP_LOCK   (0x08)
 
#define SIM3X_FLASH_PAGE_SIZE   1024
 
#define VMON0_CONTROL_ALL   (0x4002F000)
 
#define VMON0_CONTROL_CLR   (0x4002F008)
 
#define VMON0_CONTROL_SET   (0x4002F004)
 
#define VMON0_CONTROL_VMONEN_MASK   (0x80000000)
 
#define WDTIMER0_CONTROL_ALL   (0x40030000)
 
#define WDTIMER0_CONTROL_CLR   (0x40030008)
 
#define WDTIMER0_CONTROL_DBGMD_MASK   (0x00000002)
 
#define WDTIMER0_CONTROL_SET   (0x40030004)
 
#define WDTIMER0_KEY_ATTN   (0x000000A5)
 
#define WDTIMER0_KEY_DISABLE   (0x000000DD)
 
#define WDTIMER0_KEY_LOCK   (0x000000FF)
 
#define WDTIMER0_KEY_RESET   (0x000000CC)
 
#define WDTIMER0_KEY_START   (0x000000EE)
 
#define WDTIMER0_KEY_WRITE   (0x000000F1)
 
#define WDTIMER0_STATUS_ALL   (0x40030010)
 
#define WDTIMER0_STATUS_CLR   (0x40030018)
 
#define WDTIMER0_STATUS_KEYSTS_MASK   (0x00000001)
 
#define WDTIMER0_STATUS_PRIVSTS_MASK   (0x00000002)
 
#define WDTIMER0_STATUS_SET   (0x40030014)
 
#define WDTIMER0_THRESHOLD   (0x40030020)
 
#define WDTIMER0_WDTKEY   (0x40030030)
 

Functions

static int ap_poll_register (struct adiv5_dap *dap, unsigned int reg, uint32_t mask, uint32_t value, int timeout)
 
static int ap_read_register (struct adiv5_dap *dap, unsigned int reg, uint32_t *result)
 
static int ap_write_register (struct adiv5_dap *dap, unsigned int reg, uint32_t value)
 reg 31:8 - no effect reg 7:4 - bank reg 3:2 - register reg 1:0 - no effect More...
 
 COMMAND_HANDLER (sim3x_lock)
 
 COMMAND_HANDLER (sim3x_mass_erase)
 
 FLASH_BANK_COMMAND_HANDLER (sim3x_flash_bank_command)
 
static int sim3x_auto_probe (struct flash_bank *bank)
 
static int sim3x_erase_page (struct flash_bank *bank, uint32_t addr)
 
static int sim3x_flash_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int sim3x_flash_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int sim3x_flash_lock_check (struct flash_bank *bank)
 
static int sim3x_flash_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int sim3x_flash_protect_check (struct flash_bank *bank)
 
static int sim3x_flash_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int sim3x_init (struct flash_bank *bank)
 
static int sim3x_parse_part_info (struct sim3x_info *sim3x_info)
 
static int sim3x_probe (struct flash_bank *bank)
 
static int sim3x_read_deviceid (struct flash_bank *bank)
 
static int sim3x_read_info (struct flash_bank *bank)
 
static int sim3x_write_block (struct flash_bank *bank, const uint8_t *buf, uint32_t offset, uint32_t count)
 

Variables

static const struct command_registration sim3x_command_handlers []
 
static const struct command_registration sim3x_exec_command_handlers []
 
const struct flash_driver sim3x_flash
 

Macro Definition Documentation

◆ CLKCTRL0_APBCLKG0_ALL

#define CLKCTRL0_APBCLKG0_ALL   (0x4002D020)

Definition at line 72 of file sim3x.c.

◆ CLKCTRL0_APBCLKG0_CLR

#define CLKCTRL0_APBCLKG0_CLR   (0x4002D028)

Definition at line 74 of file sim3x.c.

◆ CLKCTRL0_APBCLKG0_FLCTRLCEN_MASK

#define CLKCTRL0_APBCLKG0_FLCTRLCEN_MASK   (0x40000000)

Definition at line 75 of file sim3x.c.

◆ CLKCTRL0_APBCLKG0_SET

#define CLKCTRL0_APBCLKG0_SET   (0x4002D024)

Definition at line 73 of file sim3x.c.

◆ CPUID_CHECK_VALUE

#define CPUID_CHECK_VALUE   (0x410FC230)

Definition at line 29 of file sim3x.c.

◆ CPUID_CHECK_VALUE_MASK

#define CPUID_CHECK_VALUE_MASK   (0xFF0FFFF0)

Definition at line 30 of file sim3x.c.

◆ DEVICEID0_DEVICEID0

#define DEVICEID0_DEVICEID0   (0x400490C0)

Definition at line 23 of file sim3x.c.

◆ DEVICEID0_DEVICEID1

#define DEVICEID0_DEVICEID1   (0x400490D0)

Definition at line 24 of file sim3x.c.

◆ DEVICEID0_DEVICEID2

#define DEVICEID0_DEVICEID2   (0x400490E0)

Definition at line 25 of file sim3x.c.

◆ DEVICEID0_DEVICEID3

#define DEVICEID0_DEVICEID3   (0x400490F0)

Definition at line 26 of file sim3x.c.

◆ FLASH_BASE_ADDRESS

#define FLASH_BASE_ADDRESS   (0x00000000)

Definition at line 33 of file sim3x.c.

◆ FLASH_BUSY_TIMEOUT

#define FLASH_BUSY_TIMEOUT   (100)

Definition at line 56 of file sim3x.c.

◆ FLASHCTRL0_CONFIG_ALL

#define FLASHCTRL0_CONFIG_ALL   (0x4002E000)

Definition at line 41 of file sim3x.c.

◆ FLASHCTRL0_CONFIG_BUSYF_MASK

#define FLASHCTRL0_CONFIG_BUSYF_MASK   (0x00100000)

Definition at line 45 of file sim3x.c.

◆ FLASHCTRL0_CONFIG_CLR

#define FLASHCTRL0_CONFIG_CLR   (0x4002E008)

Definition at line 43 of file sim3x.c.

◆ FLASHCTRL0_CONFIG_ERASEEN_MASK

#define FLASHCTRL0_CONFIG_ERASEEN_MASK   (0x00040000)

Definition at line 44 of file sim3x.c.

◆ FLASHCTRL0_CONFIG_SET

#define FLASHCTRL0_CONFIG_SET   (0x4002E004)

Definition at line 42 of file sim3x.c.

◆ FLASHCTRL0_KEY

#define FLASHCTRL0_KEY   (0x4002E0C0)

Definition at line 50 of file sim3x.c.

◆ FLASHCTRL0_KEY_INITIAL_UNLOCK

#define FLASHCTRL0_KEY_INITIAL_UNLOCK   (0x000000A5)

Definition at line 51 of file sim3x.c.

◆ FLASHCTRL0_KEY_MULTIPLE_LOCK

#define FLASHCTRL0_KEY_MULTIPLE_LOCK   (0x0000005A)

Definition at line 54 of file sim3x.c.

◆ FLASHCTRL0_KEY_MULTIPLE_UNLOCK

#define FLASHCTRL0_KEY_MULTIPLE_UNLOCK   (0x000000F2)

Definition at line 53 of file sim3x.c.

◆ FLASHCTRL0_KEY_SINGLE_UNLOCK

#define FLASHCTRL0_KEY_SINGLE_UNLOCK   (0x000000F1)

Definition at line 52 of file sim3x.c.

◆ FLASHCTRL0_WRADDR

#define FLASHCTRL0_WRADDR   (0x4002E0A0)

Definition at line 47 of file sim3x.c.

◆ FLASHCTRL0_WRDATA

#define FLASHCTRL0_WRDATA   (0x4002E0B0)

Definition at line 48 of file sim3x.c.

◆ LOCK_WORD_ADDRESS

#define LOCK_WORD_ADDRESS   (0x0003FFFC)

Definition at line 34 of file sim3x.c.

◆ LOCK_WORD_MCU_UNLOCKED

#define LOCK_WORD_MCU_UNLOCKED   (0xFFFFFFFF)

Definition at line 36 of file sim3x.c.

◆ LOCK_WORD_MCU_UNLOCKED_BY_FIRMWARE

#define LOCK_WORD_MCU_UNLOCKED_BY_FIRMWARE   (0x00000000)

Definition at line 38 of file sim3x.c.

◆ RSTSRC0_RESETEN_ALL

#define RSTSRC0_RESETEN_ALL   (0x4002D060)

Definition at line 59 of file sim3x.c.

◆ RSTSRC0_RESETEN_CLR

#define RSTSRC0_RESETEN_CLR   (0x4002D068)

Definition at line 61 of file sim3x.c.

◆ RSTSRC0_RESETEN_SET

#define RSTSRC0_RESETEN_SET   (0x4002D064)

Definition at line 60 of file sim3x.c.

◆ RSTSRC0_RESETEN_SWREN_MASK

#define RSTSRC0_RESETEN_SWREN_MASK   (0x00000040)

Definition at line 63 of file sim3x.c.

◆ RSTSRC0_RESETEN_VMONREN_MASK

#define RSTSRC0_RESETEN_VMONREN_MASK   (0x00000004)

Definition at line 62 of file sim3x.c.

◆ SIM3X_AP

#define SIM3X_AP   (0x0A)

Definition at line 100 of file sim3x.c.

◆ SIM3X_AP_CRC

#define SIM3X_AP_CRC   (0x0C)

Definition at line 105 of file sim3x.c.

◆ SIM3X_AP_CTRL1

#define SIM3X_AP_CTRL1   (0x00)

Definition at line 102 of file sim3x.c.

◆ SIM3X_AP_CTRL1_MASS_ERASE_REQ

#define SIM3X_AP_CTRL1_MASS_ERASE_REQ   (0x00000001)

Definition at line 114 of file sim3x.c.

◆ SIM3X_AP_CTRL1_RESET_REQ

#define SIM3X_AP_CTRL1_RESET_REQ   (0x00000008)

Definition at line 115 of file sim3x.c.

◆ SIM3X_AP_CTRL2

#define SIM3X_AP_CTRL2   (0x04)

Definition at line 103 of file sim3x.c.

◆ SIM3X_AP_DAP_IN

#define SIM3X_AP_DAP_IN   (0x14)

Definition at line 108 of file sim3x.c.

◆ SIM3X_AP_DAP_OUT

#define SIM3X_AP_DAP_OUT   (0x18)

Definition at line 109 of file sim3x.c.

◆ SIM3X_AP_ID

#define SIM3X_AP_ID   (0xFC)

Definition at line 111 of file sim3x.c.

◆ SIM3X_AP_ID_VALUE

#define SIM3X_AP_ID_VALUE   (0x2430002)

Definition at line 119 of file sim3x.c.

◆ SIM3X_AP_INIT_STAT

#define SIM3X_AP_INIT_STAT   (0x10)

Definition at line 107 of file sim3x.c.

◆ SIM3X_AP_INIT_STAT_LOCK

#define SIM3X_AP_INIT_STAT_LOCK   (0x00000004)

Definition at line 117 of file sim3x.c.

◆ SIM3X_AP_LOCK

#define SIM3X_AP_LOCK   (0x08)

Definition at line 104 of file sim3x.c.

◆ SIM3X_FLASH_PAGE_SIZE

#define SIM3X_FLASH_PAGE_SIZE   1024

Definition at line 121 of file sim3x.c.

◆ VMON0_CONTROL_ALL

#define VMON0_CONTROL_ALL   (0x4002F000)

Definition at line 66 of file sim3x.c.

◆ VMON0_CONTROL_CLR

#define VMON0_CONTROL_CLR   (0x4002F008)

Definition at line 68 of file sim3x.c.

◆ VMON0_CONTROL_SET

#define VMON0_CONTROL_SET   (0x4002F004)

Definition at line 67 of file sim3x.c.

◆ VMON0_CONTROL_VMONEN_MASK

#define VMON0_CONTROL_VMONEN_MASK   (0x80000000)

Definition at line 69 of file sim3x.c.

◆ WDTIMER0_CONTROL_ALL

#define WDTIMER0_CONTROL_ALL   (0x40030000)

Definition at line 78 of file sim3x.c.

◆ WDTIMER0_CONTROL_CLR

#define WDTIMER0_CONTROL_CLR   (0x40030008)

Definition at line 80 of file sim3x.c.

◆ WDTIMER0_CONTROL_DBGMD_MASK

#define WDTIMER0_CONTROL_DBGMD_MASK   (0x00000002)

Definition at line 81 of file sim3x.c.

◆ WDTIMER0_CONTROL_SET

#define WDTIMER0_CONTROL_SET   (0x40030004)

Definition at line 79 of file sim3x.c.

◆ WDTIMER0_KEY_ATTN

#define WDTIMER0_KEY_ATTN   (0x000000A5)

Definition at line 92 of file sim3x.c.

◆ WDTIMER0_KEY_DISABLE

#define WDTIMER0_KEY_DISABLE   (0x000000DD)

Definition at line 95 of file sim3x.c.

◆ WDTIMER0_KEY_LOCK

#define WDTIMER0_KEY_LOCK   (0x000000FF)

Definition at line 97 of file sim3x.c.

◆ WDTIMER0_KEY_RESET

#define WDTIMER0_KEY_RESET   (0x000000CC)

Definition at line 94 of file sim3x.c.

◆ WDTIMER0_KEY_START

#define WDTIMER0_KEY_START   (0x000000EE)

Definition at line 96 of file sim3x.c.

◆ WDTIMER0_KEY_WRITE

#define WDTIMER0_KEY_WRITE   (0x000000F1)

Definition at line 93 of file sim3x.c.

◆ WDTIMER0_STATUS_ALL

#define WDTIMER0_STATUS_ALL   (0x40030010)

Definition at line 83 of file sim3x.c.

◆ WDTIMER0_STATUS_CLR

#define WDTIMER0_STATUS_CLR   (0x40030018)

Definition at line 85 of file sim3x.c.

◆ WDTIMER0_STATUS_KEYSTS_MASK

#define WDTIMER0_STATUS_KEYSTS_MASK   (0x00000001)

Definition at line 86 of file sim3x.c.

◆ WDTIMER0_STATUS_PRIVSTS_MASK

#define WDTIMER0_STATUS_PRIVSTS_MASK   (0x00000002)

Definition at line 87 of file sim3x.c.

◆ WDTIMER0_STATUS_SET

#define WDTIMER0_STATUS_SET   (0x40030014)

Definition at line 84 of file sim3x.c.

◆ WDTIMER0_THRESHOLD

#define WDTIMER0_THRESHOLD   (0x40030020)

Definition at line 89 of file sim3x.c.

◆ WDTIMER0_WDTKEY

#define WDTIMER0_WDTKEY   (0x40030030)

Definition at line 91 of file sim3x.c.

Function Documentation

◆ ap_poll_register()

static int ap_poll_register ( struct adiv5_dap dap,
unsigned int  reg,
uint32_t  mask,
uint32_t  value,
int  timeout 
)
static

Definition at line 915 of file sim3x.c.

References alive_sleep(), ap_read_register(), adiv5_ap::dap, ERROR_FAIL, ERROR_OK, LOG_DEBUG, and mask.

Referenced by COMMAND_HANDLER().

◆ ap_read_register()

static int ap_read_register ( struct adiv5_dap dap,
unsigned int  reg,
uint32_t *  result 
)
static

◆ ap_write_register()

static int ap_write_register ( struct adiv5_dap dap,
unsigned int  reg,
uint32_t  value 
)
static

reg 31:8 - no effect reg 7:4 - bank reg 3:2 - register reg 1:0 - no effect

Definition at line 862 of file sim3x.c.

References adiv5_ap::dap, dap_get_ap(), dap_put_ap(), dap_queue_ap_write(), dap_run(), ERROR_FAIL, ERROR_OK, LOG_DEBUG, and SIM3X_AP.

Referenced by COMMAND_HANDLER().

◆ COMMAND_HANDLER() [1/2]

◆ COMMAND_HANDLER() [2/2]

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( sim3x_flash_bank_command  )

◆ sim3x_auto_probe()

static int sim3x_auto_probe ( struct flash_bank bank)
static

Definition at line 813 of file sim3x.c.

References bank, ERROR_OK, sim3x_info::need_init, sim3x_info::probed, and sim3x_probe().

◆ sim3x_erase_page()

◆ sim3x_flash_erase()

◆ sim3x_flash_info()

◆ sim3x_flash_lock_check()

static int sim3x_flash_lock_check ( struct flash_bank bank)
static

◆ sim3x_flash_protect()

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

◆ sim3x_flash_protect_check()

static int sim3x_flash_protect_check ( struct flash_bank bank)
static

◆ sim3x_flash_write()

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

◆ sim3x_init()

◆ sim3x_parse_part_info()

static int sim3x_parse_part_info ( struct sim3x_info sim3x_info)
static

◆ sim3x_probe()

◆ sim3x_read_deviceid()

◆ sim3x_read_info()

static int sim3x_read_info ( struct flash_bank bank)
static

◆ sim3x_write_block()

Variable Documentation

◆ sim3x_command_handlers

const struct command_registration sim3x_command_handlers[]
static
Initial value:
= {
{
.name = "sim3x",
.mode = COMMAND_ANY,
.help = "sim3x flash command group",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration sim3x_exec_command_handlers[]
Definition: sim3x.c:1065

Definition at line 977 of file sim3x.c.

◆ sim3x_exec_command_handlers

const struct command_registration sim3x_exec_command_handlers[]
static
Initial value:
= {
{
.name = "mass_erase",
.mode = COMMAND_EXEC,
.help = "Erase the complete flash",
.usage = "",
.handler = sim3x_mass_erase,
},
{
.name = "lock",
.mode = COMMAND_EXEC,
.help = "Locks the flash. Unlock by mass erase",
.usage = "",
.handler = sim3x_lock,
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 977 of file sim3x.c.

◆ sim3x_flash

const struct flash_driver sim3x_flash
Initial value:
= {
.name = "sim3x",
.flash_bank_command = sim3x_flash_bank_command,
.protect = sim3x_flash_protect,
.probe = sim3x_probe,
.auto_probe = sim3x_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = sim3x_flash_protect_check,
.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 sim3x_auto_probe(struct flash_bank *bank)
Definition: sim3x.c:813
static int sim3x_flash_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: sim3x.c:465
static int sim3x_flash_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: sim3x.c:827
static const struct command_registration sim3x_command_handlers[]
Definition: sim3x.c:1083
static int sim3x_flash_protect_check(struct flash_bank *bank)
Definition: sim3x.c:539
static int sim3x_probe(struct flash_bank *bank)
Definition: sim3x.c:776
static int sim3x_flash_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: sim3x.c:562
static int sim3x_flash_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: sim3x.c:270

Definition at line 977 of file sim3x.c.