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

Go to the source code of this file.

Data Structures

struct  samv_flash_bank
 

Macros

#define OFFSET_EFC_FCR   4
 
#define OFFSET_EFC_FMR   0
 
#define OFFSET_EFC_FRR   12
 
#define OFFSET_EFC_FSR   8
 
#define REG_NAME_WIDTH   (12)
 
#define SAMV_CHIPID_CIDR   (0x400E0940)
 
#define SAMV_CONTROLLER_ADDR   (0x400e0c00)
 
#define SAMV_EFC_FCMD_CFB   (0xC) /* (EFC) Clear Fuse Bit */
 
#define SAMV_EFC_FCMD_CLB   (0x9) /* (EFC) Clear Lock Bit */
 
#define SAMV_EFC_FCMD_EA   (0x5) /* (EFC) Erase All */
 
#define SAMV_EFC_FCMD_EPA   (0x7) /* (EFC) Erase pages */
 
#define SAMV_EFC_FCMD_EWP   (0x3) /* (EFC) Erase Page and Write Page */
 
#define SAMV_EFC_FCMD_EWPL   (0x4) /* (EFC) Erase Page, Write Page then Lock*/
 
#define SAMV_EFC_FCMD_GETD   (0x0) /* (EFC) Get Flash Descriptor */
 
#define SAMV_EFC_FCMD_GFB   (0xD) /* (EFC) Get Fuse Bit */
 
#define SAMV_EFC_FCMD_GLB   (0xA) /* (EFC) Get Lock Bit */
 
#define SAMV_EFC_FCMD_SFB   (0xB) /* (EFC) Set Fuse Bit */
 
#define SAMV_EFC_FCMD_SLB   (0x8) /* (EFC) Set Lock Bit */
 
#define SAMV_EFC_FCMD_WP   (0x1) /* (EFC) Write Page */
 
#define SAMV_EFC_FCMD_WPL   (0x2) /* (EFC) Write Page and Lock */
 
#define SAMV_FLASH_BASE   0x00400000
 
#define SAMV_NUM_GPNVM_BITS   9
 
#define SAMV_PAGE_SIZE   512
 
#define SAMV_SECTOR_SIZE   16384
 

Functions

 COMMAND_HANDLER (samv_handle_gpnvm_command)
 
 FLASH_BANK_COMMAND_HANDLER (samv_flash_bank_command)
 
static int samv_auto_probe (struct flash_bank *bank)
 
static int samv_clear_gpnvm (struct target *target, unsigned gpnvm)
 
static int samv_efc_get_result (struct target *target, uint32_t *v)
 
static int samv_efc_get_status (struct target *target, uint32_t *v)
 
static int samv_efc_perform_command (struct target *target, unsigned command, unsigned argument, uint32_t *status)
 
static int samv_efc_start_command (struct target *target, unsigned command, unsigned argument)
 
static int samv_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int samv_erase_pages (struct target *target, int first_page, int num_pages, uint32_t *status)
 
static int samv_flash_lock (struct target *target, unsigned start_sector, unsigned end_sector)
 
static int samv_flash_unlock (struct target *target, unsigned start_sector, unsigned end_sector)
 
static int samv_get_device_id (struct flash_bank *bank, uint32_t *device_id)
 
static int samv_get_gpnvm (struct target *target, unsigned gpnvm, unsigned *out)
 
static int samv_get_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int samv_page_read (struct target *target, unsigned page_num, uint8_t *buf)
 
static int samv_page_write (struct target *target, unsigned pagenum, const uint8_t *buf)
 
static int samv_probe (struct flash_bank *bank)
 
static int samv_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int samv_protect_check (struct flash_bank *bank)
 
static int samv_set_gpnvm (struct target *target, unsigned gpnvm)
 
static int samv_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 

Variables

static const struct command_registration atsamv_command_handlers []
 
static const struct command_registration atsamv_exec_command_handlers []
 
const struct flash_driver atsamv_flash
 

Macro Definition Documentation

◆ OFFSET_EFC_FCR

#define OFFSET_EFC_FCR   4

Definition at line 45 of file atsamv.c.

◆ OFFSET_EFC_FMR

#define OFFSET_EFC_FMR   0

Definition at line 44 of file atsamv.c.

◆ OFFSET_EFC_FRR

#define OFFSET_EFC_FRR   12

Definition at line 47 of file atsamv.c.

◆ OFFSET_EFC_FSR

#define OFFSET_EFC_FSR   8

Definition at line 46 of file atsamv.c.

◆ REG_NAME_WIDTH

#define REG_NAME_WIDTH   (12)

Definition at line 28 of file atsamv.c.

◆ SAMV_CHIPID_CIDR

#define SAMV_CHIPID_CIDR   (0x400E0940)

Definition at line 49 of file atsamv.c.

◆ SAMV_CONTROLLER_ADDR

#define SAMV_CONTROLLER_ADDR   (0x400e0c00)

Definition at line 51 of file atsamv.c.

◆ SAMV_EFC_FCMD_CFB

#define SAMV_EFC_FCMD_CFB   (0xC) /* (EFC) Clear Fuse Bit */

Definition at line 41 of file atsamv.c.

◆ SAMV_EFC_FCMD_CLB

#define SAMV_EFC_FCMD_CLB   (0x9) /* (EFC) Clear Lock Bit */

Definition at line 38 of file atsamv.c.

◆ SAMV_EFC_FCMD_EA

#define SAMV_EFC_FCMD_EA   (0x5) /* (EFC) Erase All */

Definition at line 35 of file atsamv.c.

◆ SAMV_EFC_FCMD_EPA

#define SAMV_EFC_FCMD_EPA   (0x7) /* (EFC) Erase pages */

Definition at line 36 of file atsamv.c.

◆ SAMV_EFC_FCMD_EWP

#define SAMV_EFC_FCMD_EWP   (0x3) /* (EFC) Erase Page and Write Page */

Definition at line 33 of file atsamv.c.

◆ SAMV_EFC_FCMD_EWPL

#define SAMV_EFC_FCMD_EWPL   (0x4) /* (EFC) Erase Page, Write Page then Lock*/

Definition at line 34 of file atsamv.c.

◆ SAMV_EFC_FCMD_GETD

#define SAMV_EFC_FCMD_GETD   (0x0) /* (EFC) Get Flash Descriptor */

Definition at line 30 of file atsamv.c.

◆ SAMV_EFC_FCMD_GFB

#define SAMV_EFC_FCMD_GFB   (0xD) /* (EFC) Get Fuse Bit */

Definition at line 42 of file atsamv.c.

◆ SAMV_EFC_FCMD_GLB

#define SAMV_EFC_FCMD_GLB   (0xA) /* (EFC) Get Lock Bit */

Definition at line 39 of file atsamv.c.

◆ SAMV_EFC_FCMD_SFB

#define SAMV_EFC_FCMD_SFB   (0xB) /* (EFC) Set Fuse Bit */

Definition at line 40 of file atsamv.c.

◆ SAMV_EFC_FCMD_SLB

#define SAMV_EFC_FCMD_SLB   (0x8) /* (EFC) Set Lock Bit */

Definition at line 37 of file atsamv.c.

◆ SAMV_EFC_FCMD_WP

#define SAMV_EFC_FCMD_WP   (0x1) /* (EFC) Write Page */

Definition at line 31 of file atsamv.c.

◆ SAMV_EFC_FCMD_WPL

#define SAMV_EFC_FCMD_WPL   (0x2) /* (EFC) Write Page and Lock */

Definition at line 32 of file atsamv.c.

◆ SAMV_FLASH_BASE

#define SAMV_FLASH_BASE   0x00400000

Definition at line 54 of file atsamv.c.

◆ SAMV_NUM_GPNVM_BITS

#define SAMV_NUM_GPNVM_BITS   9

Definition at line 50 of file atsamv.c.

◆ SAMV_PAGE_SIZE

#define SAMV_PAGE_SIZE   512

Definition at line 53 of file atsamv.c.

◆ SAMV_SECTOR_SIZE

#define SAMV_SECTOR_SIZE   16384

Definition at line 52 of file atsamv.c.

Function Documentation

◆ COMMAND_HANDLER()

COMMAND_HANDLER ( samv_handle_gpnvm_command  )

Definition at line 582 of file atsamv.c.

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( samv_flash_bank_command  )

Definition at line 295 of file atsamv.c.

References bank, ERROR_OK, and LOG_INFO.

◆ samv_auto_probe()

static int samv_auto_probe ( struct flash_bank bank)
static

Definition at line 360 of file atsamv.c.

References bank, ERROR_OK, samv_flash_bank::probed, and samv_probe().

Referenced by samv_erase().

◆ samv_clear_gpnvm()

static int samv_clear_gpnvm ( struct target target,
unsigned  gpnvm 
)
static

◆ samv_efc_get_result()

static int samv_efc_get_result ( struct target target,
uint32_t *  v 
)
static

Definition at line 77 of file atsamv.c.

References OFFSET_EFC_FRR, SAMV_CONTROLLER_ADDR, and target_read_u32().

Referenced by samv_get_gpnvm(), and samv_protect_check().

◆ samv_efc_get_status()

static int samv_efc_get_status ( struct target target,
uint32_t *  v 
)
static

Definition at line 71 of file atsamv.c.

References OFFSET_EFC_FSR, SAMV_CONTROLLER_ADDR, and target_read_u32().

Referenced by samv_efc_perform_command(), and samv_efc_start_command().

◆ samv_efc_perform_command()

static int samv_efc_perform_command ( struct target target,
unsigned  command,
unsigned  argument,
uint32_t *  status 
)
static

◆ samv_efc_start_command()

static int samv_efc_start_command ( struct target target,
unsigned  command,
unsigned  argument 
)
static

◆ samv_erase()

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

◆ samv_erase_pages()

static int samv_erase_pages ( struct target target,
int  first_page,
int  num_pages,
uint32_t *  status 
)
static

Definition at line 138 of file atsamv.c.

References SAMV_EFC_FCMD_EPA, samv_efc_perform_command(), and status.

Referenced by samv_erase().

◆ samv_flash_lock()

static int samv_flash_lock ( struct target target,
unsigned  start_sector,
unsigned  end_sector 
)
static

◆ samv_flash_unlock()

static int samv_flash_unlock ( struct target target,
unsigned  start_sector,
unsigned  end_sector 
)
static

◆ samv_get_device_id()

static int samv_get_device_id ( struct flash_bank bank,
uint32_t *  device_id 
)
static

Definition at line 304 of file atsamv.c.

References bank, SAMV_CHIPID_CIDR, and target_read_u32().

Referenced by samv_probe().

◆ samv_get_gpnvm()

static int samv_get_gpnvm ( struct target target,
unsigned  gpnvm,
unsigned *  out 
)
static

◆ samv_get_info()

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

Definition at line 569 of file atsamv.c.

References bank, cmd, command_print_sameline(), ERROR_OK, samv_flash_bank::probed, and samv_probe().

◆ samv_page_read()

static int samv_page_read ( struct target target,
unsigned  page_num,
uint8_t *  buf 
)
static

Definition at line 423 of file atsamv.c.

References addr, ERROR_OK, LOG_ERROR, SAMV_FLASH_BASE, SAMV_PAGE_SIZE, and target_read_memory().

Referenced by samv_write().

◆ samv_page_write()

static int samv_page_write ( struct target target,
unsigned  pagenum,
const uint8_t *  buf 
)
static

◆ samv_probe()

◆ samv_protect()

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

◆ samv_protect_check()

static int samv_protect_check ( struct flash_bank bank)
static

Definition at line 275 of file atsamv.c.

References bank, ERROR_OK, NULL, SAMV_EFC_FCMD_GLB, samv_efc_get_result(), and samv_efc_perform_command().

Referenced by samv_probe().

◆ samv_set_gpnvm()

static int samv_set_gpnvm ( struct target target,
unsigned  gpnvm 
)
static

◆ samv_write()

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

Variable Documentation

◆ atsamv_command_handlers

const struct command_registration atsamv_command_handlers[]
static
Initial value:
= {
{
.name = "atsamv",
.mode = COMMAND_ANY,
.help = "atsamv flash command group",
.usage = "",
},
}
static const struct command_registration atsamv_exec_command_handlers[]
Definition: atsamv.c:665
#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 582 of file atsamv.c.

◆ atsamv_exec_command_handlers

const struct command_registration atsamv_exec_command_handlers[]
static
Initial value:
= {
{
.name = "gpnvm",
.handler = samv_handle_gpnvm_command,
.mode = COMMAND_EXEC,
.usage = "[('clr'|'set'|'show') bitnum]",
.help = "Without arguments, shows all bits in the gpnvm "
"register. Otherwise, clears, sets, or shows one "
"General Purpose Non-Volatile Memory (gpnvm) bit.",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 582 of file atsamv.c.

◆ atsamv_flash

const struct flash_driver atsamv_flash
Initial value:
= {
.name = "atsamv",
.flash_bank_command = samv_flash_bank_command,
.erase = samv_erase,
.protect = samv_protect,
.write = samv_write,
.probe = samv_probe,
.auto_probe = samv_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = samv_protect_check,
.info = samv_get_info,
.free_driver_priv = default_flash_free_driver_priv,
}
static int samv_protect_check(struct flash_bank *bank)
Definition: atsamv.c:275
static int samv_auto_probe(struct flash_bank *bank)
Definition: atsamv.c:360
static const struct command_registration atsamv_command_handlers[]
Definition: atsamv.c:678
static int samv_get_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: atsamv.c:569
static int samv_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: atsamv.c:406
static int samv_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: atsamv.c:462
static int samv_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: atsamv.c:368
static int samv_probe(struct flash_bank *bank)
Definition: atsamv.c:309
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 582 of file atsamv.c.