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

Go to the source code of this file.

Data Structures

struct  samd_family
 
struct  samd_info
 
struct  samd_part
 

Macros

#define NVMUSERROW_SAM_E5_D5_MASK   ((uint64_t)0x7FFF00FF3C007FFF)
 
#define SAMD_CMDEX_KEY   0xA5UL
 
#define SAMD_DSU   0x41002000 /* Device Service Unit */
 
#define SAMD_DSU_CTRL_EXT   0x100 /* CTRL register, external access */
 
#define SAMD_DSU_DID   0x18 /* Device ID register */
 
#define SAMD_DSU_STATUSA   1 /* DSU status register */
 
#define SAMD_FAMILY_D   0x00
 
#define SAMD_FAMILY_E   0x03
 
#define SAMD_FLASH   0x00000000 /* physical Flash memory */
 
#define SAMD_GET_DEVSEL(id)   (id & 0xFF)
 
#define SAMD_GET_FAMILY(id)   (((id >> 23) & 0x1F))
 
#define SAMD_GET_PROCESSOR(id)   (id >> 28)
 
#define SAMD_GET_SERIES(id)   (((id >> 16) & 0x3F))
 
#define SAMD_NVM_CMD(n)   ((SAMD_CMDEX_KEY << 8) | (n & 0x7F))
 
#define SAMD_NVMCTRL   0x41004000 /* Non-volatile memory controller */
 
#define SAMD_NVMCTRL_PARAM   0x08 /* NVM parameters register */
 
#define SAMD_PAGE_SIZE_MAX   1024
 
#define SAMD_PROCESSOR_M0   0x01
 
#define SAMD_PROCESSOR_M4   0x06
 
#define SAMD_SERIES_51   0x06
 
#define SAMD_USER_ROW   0x00804000 /* User Row of Flash */
 
#define SAME5_NUM_PROT_BLOCKS   32
 
#define SAME5_NVM_CMD_EB   0x01 /* Erase Block */
 
#define SAME5_NVM_CMD_EP   0x00 /* Erase Page (User Page only) */
 
#define SAME5_NVM_CMD_LR   0x11 /* Lock Region */
 
#define SAME5_NVM_CMD_PBC   0x15 /* Page Buffer Clear */
 
#define SAME5_NVM_CMD_SSB   0x16 /* Set Security Bit */
 
#define SAME5_NVM_CMD_UR   0x12 /* Unlock Region */
 
#define SAME5_NVM_CMD_WP   0x03 /* Write Page */
 
#define SAME5_NVM_CMD_WQW   0x04 /* Write Quad Word */
 
#define SAME5_NVMCTRL_ADDR   0x14 /* NVM address register */
 
#define SAME5_NVMCTRL_CTRLA   0x00 /* NVM control A register */
 
#define SAME5_NVMCTRL_CTRLA_WMODE_MASK   0x30
 
#define SAME5_NVMCTRL_CTRLB   0x04 /* NVM control B register */
 
#define SAME5_NVMCTRL_INTFLAG   0x10 /* NVM interrupt flag register */
 
#define SAME5_NVMCTRL_INTFLAG_ADDRE   (1 << 1)
 
#define SAME5_NVMCTRL_INTFLAG_DONE   (1 << 0)
 
#define SAME5_NVMCTRL_INTFLAG_ECCDE   (1 << 5)
 
#define SAME5_NVMCTRL_INTFLAG_ECCSE   (1 << 4)
 
#define SAME5_NVMCTRL_INTFLAG_LOCKE   (1 << 3)
 
#define SAME5_NVMCTRL_INTFLAG_NVME   (1 << 6)
 
#define SAME5_NVMCTRL_INTFLAG_PROGE   (1 << 2)
 
#define SAME5_NVMCTRL_LOCK   0x18 /* NVM Lock section register */
 
#define SAME5_NVMCTRL_STATUS   0x12 /* NVM status register */
 
#define SAME5_PAC   0x40000000 /* Peripheral Access Control */
 
#define SAME5_PAGES_PER_BLOCK   16
 
#define SAME_SERIES_51   0x01
 
#define SAME_SERIES_53   0x03
 
#define SAME_SERIES_54   0x04
 

Functions

 COMMAND_HANDLER (samd_handle_reset_deassert)
 
 COMMAND_HANDLER (same5_handle_bootloader_command)
 
 COMMAND_HANDLER (same5_handle_chip_erase_command)
 
 COMMAND_HANDLER (same5_handle_userpage_command)
 
 FLASH_BANK_COMMAND_HANDLER (same5_flash_bank_command)
 
static const struct samd_familysamd_find_family (uint32_t id)
 Gives the family structure to specific device id. More...
 
static const struct samd_partsamd_find_part (uint32_t id)
 Gives the part structure to specific device id. More...
 
static int samd_get_flash_page_info (struct target *target, uint32_t *sizep, int *nump)
 
static int same5_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int same5_erase_block (struct target *target, uint32_t address)
 Erases a flash block or page at the given address. More...
 
static int same5_issue_nvmctrl_command (struct target *target, uint16_t cmd)
 
static int same5_modify_user_row (struct target *target, uint32_t value, uint8_t startb, uint8_t endb)
 Modifies the user row register to the given value. More...
 
static int same5_modify_user_row_masked (struct target *target, const uint8_t *data, const uint8_t *mask, uint32_t offset, uint32_t count)
 Modify the contents of the User Row in Flash. More...
 
static int same5_pre_write_check (struct target *target)
 
static int same5_probe (struct flash_bank *bank)
 
static int same5_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int same5_protect_check (struct flash_bank *bank)
 
static int same5_wait_and_check_error (struct target *target)
 
static int same5_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 

Variables

const struct flash_driver atsame5_flash
 
static const struct samd_part samd51_parts []
 
static const struct samd_family samd_families []
 
static const struct samd_part same51_parts []
 
static const struct samd_part same53_parts []
 
static const struct samd_part same54_parts []
 
static const struct command_registration same5_command_handlers []
 
static const struct command_registration same5_exec_command_handlers []
 

Macro Definition Documentation

◆ NVMUSERROW_SAM_E5_D5_MASK

#define NVMUSERROW_SAM_E5_D5_MASK   ((uint64_t)0x7FFF00FF3C007FFF)

Definition at line 96 of file atsame5.c.

◆ SAMD_CMDEX_KEY

#define SAMD_CMDEX_KEY   0xA5UL

Definition at line 54 of file atsame5.c.

◆ SAMD_DSU

#define SAMD_DSU   0x41002000 /* Device Service Unit */

Definition at line 39 of file atsame5.c.

◆ SAMD_DSU_CTRL_EXT

#define SAMD_DSU_CTRL_EXT   0x100 /* CTRL register, external access */

Definition at line 44 of file atsame5.c.

◆ SAMD_DSU_DID

#define SAMD_DSU_DID   0x18 /* Device ID register */

Definition at line 43 of file atsame5.c.

◆ SAMD_DSU_STATUSA

#define SAMD_DSU_STATUSA   1 /* DSU status register */

Definition at line 42 of file atsame5.c.

◆ SAMD_FAMILY_D

#define SAMD_FAMILY_D   0x00

Definition at line 82 of file atsame5.c.

◆ SAMD_FAMILY_E

#define SAMD_FAMILY_E   0x03

Definition at line 83 of file atsame5.c.

◆ SAMD_FLASH

#define SAMD_FLASH   0x00000000 /* physical Flash memory */

Definition at line 34 of file atsame5.c.

◆ SAMD_GET_DEVSEL

#define SAMD_GET_DEVSEL (   id)    (id & 0xFF)

Definition at line 93 of file atsame5.c.

◆ SAMD_GET_FAMILY

#define SAMD_GET_FAMILY (   id)    (((id >> 23) & 0x1F))

Definition at line 91 of file atsame5.c.

◆ SAMD_GET_PROCESSOR

#define SAMD_GET_PROCESSOR (   id)    (id >> 28)

Definition at line 90 of file atsame5.c.

◆ SAMD_GET_SERIES

#define SAMD_GET_SERIES (   id)    (((id >> 16) & 0x3F))

Definition at line 92 of file atsame5.c.

◆ SAMD_NVM_CMD

#define SAMD_NVM_CMD (   n)    ((SAMD_CMDEX_KEY << 8) | (n & 0x7F))

Definition at line 55 of file atsame5.c.

◆ SAMD_NVMCTRL

#define SAMD_NVMCTRL   0x41004000 /* Non-volatile memory controller */

Definition at line 40 of file atsame5.c.

◆ SAMD_NVMCTRL_PARAM

#define SAMD_NVMCTRL_PARAM   0x08 /* NVM parameters register */

Definition at line 48 of file atsame5.c.

◆ SAMD_PAGE_SIZE_MAX

#define SAMD_PAGE_SIZE_MAX   1024

Definition at line 32 of file atsame5.c.

◆ SAMD_PROCESSOR_M0

#define SAMD_PROCESSOR_M0   0x01

Definition at line 80 of file atsame5.c.

◆ SAMD_PROCESSOR_M4

#define SAMD_PROCESSOR_M4   0x06

Definition at line 81 of file atsame5.c.

◆ SAMD_SERIES_51

#define SAMD_SERIES_51   0x06

Definition at line 84 of file atsame5.c.

◆ SAMD_USER_ROW

#define SAMD_USER_ROW   0x00804000 /* User Row of Flash */

Definition at line 35 of file atsame5.c.

◆ SAME5_NUM_PROT_BLOCKS

#define SAME5_NUM_PROT_BLOCKS   32

Definition at line 31 of file atsame5.c.

◆ SAME5_NVM_CMD_EB

#define SAME5_NVM_CMD_EB   0x01 /* Erase Block */

Definition at line 59 of file atsame5.c.

◆ SAME5_NVM_CMD_EP

#define SAME5_NVM_CMD_EP   0x00 /* Erase Page (User Page only) */

Definition at line 58 of file atsame5.c.

◆ SAME5_NVM_CMD_LR

#define SAME5_NVM_CMD_LR   0x11 /* Lock Region */

Definition at line 62 of file atsame5.c.

◆ SAME5_NVM_CMD_PBC

#define SAME5_NVM_CMD_PBC   0x15 /* Page Buffer Clear */

Definition at line 64 of file atsame5.c.

◆ SAME5_NVM_CMD_SSB

#define SAME5_NVM_CMD_SSB   0x16 /* Set Security Bit */

Definition at line 65 of file atsame5.c.

◆ SAME5_NVM_CMD_UR

#define SAME5_NVM_CMD_UR   0x12 /* Unlock Region */

Definition at line 63 of file atsame5.c.

◆ SAME5_NVM_CMD_WP

#define SAME5_NVM_CMD_WP   0x03 /* Write Page */

Definition at line 60 of file atsame5.c.

◆ SAME5_NVM_CMD_WQW

#define SAME5_NVM_CMD_WQW   0x04 /* Write Quad Word */

Definition at line 61 of file atsame5.c.

◆ SAME5_NVMCTRL_ADDR

#define SAME5_NVMCTRL_ADDR   0x14 /* NVM address register */

Definition at line 51 of file atsame5.c.

◆ SAME5_NVMCTRL_CTRLA

#define SAME5_NVMCTRL_CTRLA   0x00 /* NVM control A register */

Definition at line 46 of file atsame5.c.

◆ SAME5_NVMCTRL_CTRLA_WMODE_MASK

#define SAME5_NVMCTRL_CTRLA_WMODE_MASK   0x30

Definition at line 68 of file atsame5.c.

◆ SAME5_NVMCTRL_CTRLB

#define SAME5_NVMCTRL_CTRLB   0x04 /* NVM control B register */

Definition at line 47 of file atsame5.c.

◆ SAME5_NVMCTRL_INTFLAG

#define SAME5_NVMCTRL_INTFLAG   0x10 /* NVM interrupt flag register */

Definition at line 49 of file atsame5.c.

◆ SAME5_NVMCTRL_INTFLAG_ADDRE

#define SAME5_NVMCTRL_INTFLAG_ADDRE   (1 << 1)

Definition at line 71 of file atsame5.c.

◆ SAME5_NVMCTRL_INTFLAG_DONE

#define SAME5_NVMCTRL_INTFLAG_DONE   (1 << 0)

Definition at line 70 of file atsame5.c.

◆ SAME5_NVMCTRL_INTFLAG_ECCDE

#define SAME5_NVMCTRL_INTFLAG_ECCDE   (1 << 5)

Definition at line 75 of file atsame5.c.

◆ SAME5_NVMCTRL_INTFLAG_ECCSE

#define SAME5_NVMCTRL_INTFLAG_ECCSE   (1 << 4)

Definition at line 74 of file atsame5.c.

◆ SAME5_NVMCTRL_INTFLAG_LOCKE

#define SAME5_NVMCTRL_INTFLAG_LOCKE   (1 << 3)

Definition at line 73 of file atsame5.c.

◆ SAME5_NVMCTRL_INTFLAG_NVME

#define SAME5_NVMCTRL_INTFLAG_NVME   (1 << 6)

Definition at line 76 of file atsame5.c.

◆ SAME5_NVMCTRL_INTFLAG_PROGE

#define SAME5_NVMCTRL_INTFLAG_PROGE   (1 << 2)

Definition at line 72 of file atsame5.c.

◆ SAME5_NVMCTRL_LOCK

#define SAME5_NVMCTRL_LOCK   0x18 /* NVM Lock section register */

Definition at line 52 of file atsame5.c.

◆ SAME5_NVMCTRL_STATUS

#define SAME5_NVMCTRL_STATUS   0x12 /* NVM status register */

Definition at line 50 of file atsame5.c.

◆ SAME5_PAC

#define SAME5_PAC   0x40000000 /* Peripheral Access Control */

Definition at line 37 of file atsame5.c.

◆ SAME5_PAGES_PER_BLOCK

#define SAME5_PAGES_PER_BLOCK   16

Definition at line 30 of file atsame5.c.

◆ SAME_SERIES_51

#define SAME_SERIES_51   0x01

Definition at line 85 of file atsame5.c.

◆ SAME_SERIES_53

#define SAME_SERIES_53   0x03

Definition at line 86 of file atsame5.c.

◆ SAME_SERIES_54

#define SAME_SERIES_54   0x04

Definition at line 87 of file atsame5.c.

Function Documentation

◆ COMMAND_HANDLER() [1/4]

COMMAND_HANDLER ( samd_handle_reset_deassert  )

Definition at line 863 of file atsame5.c.

◆ COMMAND_HANDLER() [2/4]

◆ COMMAND_HANDLER() [3/4]

COMMAND_HANDLER ( same5_handle_chip_erase_command  )

◆ COMMAND_HANDLER() [4/4]

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( same5_flash_bank_command  )

◆ samd_find_family()

static const struct samd_family* samd_find_family ( uint32_t  id)
static

Gives the family structure to specific device id.

Parameters
idThe id of the device.
Returns
On failure NULL, otherwise a pointer to the structure.

Definition at line 191 of file atsame5.c.

References ARRAY_SIZE, samd_family::family, NULL, samd_family::processor, samd_families, SAMD_GET_FAMILY, SAMD_GET_PROCESSOR, SAMD_GET_SERIES, and samd_family::series.

Referenced by samd_find_part().

◆ samd_find_part()

static const struct samd_part* samd_find_part ( uint32_t  id)
static

Gives the part structure to specific device id.

Parameters
idThe id of the device.
Returns
On failure NULL, otherwise a pointer to the structure.

Definition at line 212 of file atsame5.c.

References samd_family::family, NULL, samd_find_family(), and SAMD_GET_DEVSEL.

Referenced by same5_probe().

◆ samd_get_flash_page_info()

static int samd_get_flash_page_info ( struct target target,
uint32_t *  sizep,
int *  nump 
)
static

◆ same5_erase()

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

◆ same5_erase_block()

static int same5_erase_block ( struct target target,
uint32_t  address 
)
static

Erases a flash block or page at the given address.

Parameters
targetPointer to the target structure.
addressThe address of the row.
Returns
On success ERROR_OK, on failure an errorcode.

Definition at line 424 of file atsame5.c.

References ERROR_FAIL, ERROR_OK, LOG_ERROR, SAMD_NVMCTRL, SAMD_USER_ROW, same5_issue_nvmctrl_command(), SAME5_NVM_CMD_EB, SAME5_NVM_CMD_EP, SAME5_NVMCTRL_ADDR, and target_write_u32().

Referenced by same5_erase(), and same5_modify_user_row_masked().

◆ same5_issue_nvmctrl_command()

static int same5_issue_nvmctrl_command ( struct target target,
uint16_t  cmd 
)
static

◆ same5_modify_user_row()

static int same5_modify_user_row ( struct target target,
uint32_t  value,
uint8_t  startb,
uint8_t  endb 
)
static

Modifies the user row register to the given value.

Parameters
targetPointer to the target structure.
valueThe value to write.
startbThe bit-offset by which the given value is shifted.
endbThe bit-offset of the last bit in value to write.
Returns
On success ERROR_OK, on failure an errorcode.

Definition at line 553 of file atsame5.c.

References buf_set_u32(), and same5_modify_user_row_masked().

Referenced by COMMAND_HANDLER().

◆ same5_modify_user_row_masked()

static int same5_modify_user_row_masked ( struct target target,
const uint8_t *  data,
const uint8_t *  mask,
uint32_t  offset,
uint32_t  count 
)
static

Modify the contents of the User Row in Flash.

The User Row itself has a size of one page and contains a combination of "fuses" and calibration data. Bits which have a value of zero in the mask will not be changed.

Parameters
targetPointer to the target structure.
dataPointer to the value to write.
maskPointer to bitmask, 0 -> value stays untouched.
offsetOffset in user row where new data will be applied.
countSize of buffer and mask in bytes.
Returns
On success ERROR_OK, on failure an errorcode.

Definition at line 482 of file atsame5.c.

References changed, count, ERROR_OK, LOG_ERROR, mask, NULL, offset, samd_info::page_size, samd_get_flash_page_info(), SAMD_PAGE_SIZE_MAX, SAMD_USER_ROW, same5_erase_block(), same5_issue_nvmctrl_command(), SAME5_NVM_CMD_WQW, same5_pre_write_check(), target_read_memory(), and target_write_memory().

Referenced by COMMAND_HANDLER(), same5_modify_user_row(), and same5_protect().

◆ same5_pre_write_check()

static int same5_pre_write_check ( struct target target)
static

◆ same5_probe()

◆ same5_protect()

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

◆ same5_protect_check()

static int same5_protect_check ( struct flash_bank bank)
static

Definition at line 227 of file atsame5.c.

References bank, ERROR_OK, SAMD_NVMCTRL, SAME5_NVMCTRL_LOCK, and target_read_u32().

Referenced by same5_probe(), and same5_protect().

◆ same5_wait_and_check_error()

◆ same5_write()

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

Variable Documentation

◆ atsame5_flash

const struct flash_driver atsame5_flash
Initial value:
= {
.name = "atsame5",
.flash_bank_command = same5_flash_bank_command,
.erase = same5_erase,
.protect = same5_protect,
.write = same5_write,
.probe = same5_probe,
.auto_probe = same5_probe,
.erase_check = default_flash_blank_check,
.protect_check = same5_protect_check,
.free_driver_priv = default_flash_free_driver_priv,
}
static int same5_protect_check(struct flash_bank *bank)
Definition: atsame5.c:227
static int same5_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: atsame5.c:567
static int same5_probe(struct flash_bank *bank)
Definition: atsame5.c:266
static int same5_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: atsame5.c:619
static const struct command_registration same5_command_handlers[]
Definition: atsame5.c:939
static int same5_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: atsame5.c:647
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.

Definition at line 863 of file atsame5.c.

◆ samd51_parts

const struct samd_part samd51_parts[]
static
Initial value:
= {
{ 0x00, "SAMD51P20A", 1024, 256 },
{ 0x01, "SAMD51P19A", 512, 192 },
{ 0x02, "SAMD51N20A", 1024, 256 },
{ 0x03, "SAMD51N19A", 512, 192 },
{ 0x04, "SAMD51J20A", 1024, 256 },
{ 0x05, "SAMD51J19A", 512, 192 },
{ 0x06, "SAMD51J18A", 256, 128 },
{ 0x07, "SAMD51G19A", 512, 192 },
{ 0x08, "SAMD51G18A", 256, 128 },
}

Definition at line 1 of file atsame5.c.

◆ samd_families

const struct samd_family samd_families[]
static
Initial value:
= {
}
static const struct samd_part same51_parts[]
Definition: atsame5.c:121
#define SAMD_PROCESSOR_M4
Definition: atsame5.c:81
#define SAMD_FAMILY_E
Definition: atsame5.c:83
#define SAMD_FAMILY_D
Definition: atsame5.c:82
#define SAME_SERIES_53
Definition: atsame5.c:86
static const struct samd_part same53_parts[]
Definition: atsame5.c:132
static const struct samd_part same54_parts[]
Definition: atsame5.c:144
#define SAME_SERIES_54
Definition: atsame5.c:87
static const struct samd_part samd51_parts[]
Definition: atsame5.c:108
#define SAMD_SERIES_51
Definition: atsame5.c:84
#define SAME_SERIES_51
Definition: atsame5.c:85
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57

Definition at line 1 of file atsame5.c.

Referenced by samd_find_family().

◆ same51_parts

const struct samd_part same51_parts[]
static
Initial value:
= {
{ 0x00, "SAME51N20A", 1024, 256 },
{ 0x01, "SAME51N19A", 512, 192 },
{ 0x02, "SAME51J19A", 512, 192 },
{ 0x03, "SAME51J18A", 256, 128 },
{ 0x04, "SAME51J20A", 1024, 256 },
{ 0x05, "SAME51G19A", 512, 192 },
{ 0x06, "SAME51G18A", 256, 128 },
}

Definition at line 1 of file atsame5.c.

◆ same53_parts

const struct samd_part same53_parts[]
static
Initial value:
= {
{ 0x02, "SAME53N20A", 1024, 256 },
{ 0x03, "SAME53N19A", 512, 192 },
{ 0x04, "SAME53J20A", 1024, 256 },
{ 0x05, "SAME53J19A", 512, 192 },
{ 0x06, "SAME53J18A", 256, 128 },
{ 0x55, "LAN9255/ZMX020", 1024, 256 },
{ 0x56, "LAN9255/ZMX019", 512, 192 },
{ 0x57, "LAN9255/ZMX018", 256, 128 },
}

Definition at line 1 of file atsame5.c.

◆ same54_parts

const struct samd_part same54_parts[]
static
Initial value:
= {
{ 0x00, "SAME54P20A", 1024, 256 },
{ 0x01, "SAME54P19A", 512, 192 },
{ 0x02, "SAME54N20A", 1024, 256 },
{ 0x03, "SAME54N19A", 512, 192 },
}

Definition at line 1 of file atsame5.c.

◆ same5_command_handlers

const struct command_registration same5_command_handlers[]
static
Initial value:
= {
{
.name = "atsame5",
.mode = COMMAND_ANY,
.help = "atsame5 flash command group",
.usage = "",
},
}
static const struct command_registration same5_exec_command_handlers[]
Definition: atsame5.c:900
#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

Definition at line 863 of file atsame5.c.

◆ same5_exec_command_handlers

const struct command_registration same5_exec_command_handlers[]
static

Definition at line 863 of file atsame5.c.