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

Go to the source code of this file.

Data Structures

struct  sam4l_chip_info
 
struct  sam4l_info
 

Macros

#define SAM4L_CHIPID   0x400E0740 /* Chip Identification */
 
#define SAM4L_CIDR   0x00 /* Chip ID Register (RO) */
 
#define SAM4L_EXID   0x04 /* Chip ID Extension Register (RO) */
 
#define SAM4L_FCMD   0x04 /* Flash Command Register (RW) */
 
#define SAM4L_FCMD_CPB   3 /* Clear Page Buffer */
 
#define SAM4L_FCMD_EA   6 /* Erase All */
 
#define SAM4L_FCMD_EAGPF   11 /* Erase all general-purpose fuse bits */
 
#define SAM4L_FCMD_EGPB   8 /* Erase general-purpose fuse bit */
 
#define SAM4L_FCMD_EP   2 /* Erase Page */
 
#define SAM4L_FCMD_EUP   14 /* Erase user page */
 
#define SAM4L_FCMD_HSDIS   17 /* High speed mode disable */
 
#define SAM4L_FCMD_HSEN   16 /* High speed mode enable */
 
#define SAM4L_FCMD_LP   4 /* Lock region containing given page */
 
#define SAM4L_FCMD_NOP   0 /* No Operation */
 
#define SAM4L_FCMD_PGPFB   10 /* Program general-purpose fuse byte */
 
#define SAM4L_FCMD_QPR   12 /* Quick page read */
 
#define SAM4L_FCMD_QPRUP   15 /* Quick page read (user page) */
 
#define SAM4L_FCMD_SSB   9 /* Set security fuses */
 
#define SAM4L_FCMD_UP   5 /* Unlock region containing given page */
 
#define SAM4L_FCMD_WGPB   7 /* Write general-purpose fuse bit */
 
#define SAM4L_FCMD_WP   1 /* Write Page */
 
#define SAM4L_FCMD_WUP   13 /* Write user page */
 
#define SAM4L_FCR   0x00 /* Flash Control Register (RW) */
 
#define SAM4L_FGPFRHI   0x14 /* Flash General Purpose Register High (RO) */
 
#define SAM4L_FGPFRLO   0x18 /* Flash General Purpose Register Low (RO) */
 
#define SAM4L_FLASH   ((uint32_t)0x00000000) /* Flash region */
 
#define SAM4L_FLASH_USER   0x00800000 /* Flash user page region */
 
#define SAM4L_FLASHCALW   0x400A0000 /* Flash controller */
 
#define SAM4L_FMCD_CMDKEY   0xA5UL /* 'key' to issue commands, see 14.10.2 */
 
#define SAM4L_FPR   0x0C /* Flash Parameter Register (RO) */
 
#define SAM4L_FSR   0x08 /* Flash Status Register (RO) */
 
#define SAM4L_FVR   0x10 /* Flash Version Register (RO) */
 
#define SAM4L_NUM_SECTORS   16
 
#define SMAP_BASE   0x400A3000
 
#define SMAP_SCR   (SMAP_BASE + 8)
 
#define SMAP_SCR_HCR   (1 << 1)
 

Functions

 COMMAND_HANDLER (sam4l_handle_reset_deassert)
 
 FLASH_BANK_COMMAND_HANDLER (sam4l_flash_bank_command)
 
static int sam4l_check_page_erased (struct flash_bank *bank, uint32_t pn, bool *is_erased_p)
 
static int sam4l_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static const struct sam4l_chip_infosam4l_find_chip_name (uint32_t id, uint32_t exid)
 
static int sam4l_flash_check_error (struct target *target, uint32_t *err)
 
static int sam4l_flash_command (struct target *target, uint8_t cmd, int page)
 
static int sam4l_flash_wait_until_ready (struct target *target)
 
static int sam4l_probe (struct flash_bank *bank)
 
static int sam4l_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int sam4l_protect_check (struct flash_bank *bank)
 
static int sam4l_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int sam4l_write_page (struct sam4l_info *chip, struct target *target, uint32_t address, const uint8_t *buf)
 
static int sam4l_write_page_partial (struct sam4l_info *chip, struct flash_bank *bank, uint32_t address, const uint8_t *buf, uint32_t page_offset, uint32_t nb)
 

Variables

static const struct command_registration at91sam4l_command_handlers []
 
static const struct command_registration at91sam4l_exec_command_handlers []
 
const struct flash_driver at91sam4l_flash
 
static const struct sam4l_chip_info sam4l_known_chips []
 
static const uint16_t sam4l_page_sizes [8] = { 32, 64, 128, 256, 512, 1024, 2048, 4096 }
 
static const uint16_t sam4l_ram_sizes [16] = { 48, 1, 2, 6, 24, 4, 80, 160, 8, 16, 32, 64, 128, 256, 96, 512 }
 

Macro Definition Documentation

◆ SAM4L_CHIPID

#define SAM4L_CHIPID   0x400E0740 /* Chip Identification */

Definition at line 31 of file at91sam4l.c.

◆ SAM4L_CIDR

#define SAM4L_CIDR   0x00 /* Chip ID Register (RO) */

Definition at line 43 of file at91sam4l.c.

◆ SAM4L_EXID

#define SAM4L_EXID   0x04 /* Chip ID Extension Register (RO) */

Definition at line 44 of file at91sam4l.c.

◆ SAM4L_FCMD

#define SAM4L_FCMD   0x04 /* Flash Command Register (RW) */

Definition at line 35 of file at91sam4l.c.

◆ SAM4L_FCMD_CPB

#define SAM4L_FCMD_CPB   3 /* Clear Page Buffer */

Definition at line 50 of file at91sam4l.c.

◆ SAM4L_FCMD_EA

#define SAM4L_FCMD_EA   6 /* Erase All */

Definition at line 53 of file at91sam4l.c.

◆ SAM4L_FCMD_EAGPF

#define SAM4L_FCMD_EAGPF   11 /* Erase all general-purpose fuse bits */

Definition at line 58 of file at91sam4l.c.

◆ SAM4L_FCMD_EGPB

#define SAM4L_FCMD_EGPB   8 /* Erase general-purpose fuse bit */

Definition at line 55 of file at91sam4l.c.

◆ SAM4L_FCMD_EP

#define SAM4L_FCMD_EP   2 /* Erase Page */

Definition at line 49 of file at91sam4l.c.

◆ SAM4L_FCMD_EUP

#define SAM4L_FCMD_EUP   14 /* Erase user page */

Definition at line 61 of file at91sam4l.c.

◆ SAM4L_FCMD_HSDIS

#define SAM4L_FCMD_HSDIS   17 /* High speed mode disable */

Definition at line 64 of file at91sam4l.c.

◆ SAM4L_FCMD_HSEN

#define SAM4L_FCMD_HSEN   16 /* High speed mode enable */

Definition at line 63 of file at91sam4l.c.

◆ SAM4L_FCMD_LP

#define SAM4L_FCMD_LP   4 /* Lock region containing given page */

Definition at line 51 of file at91sam4l.c.

◆ SAM4L_FCMD_NOP

#define SAM4L_FCMD_NOP   0 /* No Operation */

Definition at line 47 of file at91sam4l.c.

◆ SAM4L_FCMD_PGPFB

#define SAM4L_FCMD_PGPFB   10 /* Program general-purpose fuse byte */

Definition at line 57 of file at91sam4l.c.

◆ SAM4L_FCMD_QPR

#define SAM4L_FCMD_QPR   12 /* Quick page read */

Definition at line 59 of file at91sam4l.c.

◆ SAM4L_FCMD_QPRUP

#define SAM4L_FCMD_QPRUP   15 /* Quick page read (user page) */

Definition at line 62 of file at91sam4l.c.

◆ SAM4L_FCMD_SSB

#define SAM4L_FCMD_SSB   9 /* Set security fuses */

Definition at line 56 of file at91sam4l.c.

◆ SAM4L_FCMD_UP

#define SAM4L_FCMD_UP   5 /* Unlock region containing given page */

Definition at line 52 of file at91sam4l.c.

◆ SAM4L_FCMD_WGPB

#define SAM4L_FCMD_WGPB   7 /* Write general-purpose fuse bit */

Definition at line 54 of file at91sam4l.c.

◆ SAM4L_FCMD_WP

#define SAM4L_FCMD_WP   1 /* Write Page */

Definition at line 48 of file at91sam4l.c.

◆ SAM4L_FCMD_WUP

#define SAM4L_FCMD_WUP   13 /* Write user page */

Definition at line 60 of file at91sam4l.c.

◆ SAM4L_FCR

#define SAM4L_FCR   0x00 /* Flash Control Register (RW) */

Definition at line 34 of file at91sam4l.c.

◆ SAM4L_FGPFRHI

#define SAM4L_FGPFRHI   0x14 /* Flash General Purpose Register High (RO) */

Definition at line 39 of file at91sam4l.c.

◆ SAM4L_FGPFRLO

#define SAM4L_FGPFRLO   0x18 /* Flash General Purpose Register Low (RO) */

Definition at line 40 of file at91sam4l.c.

◆ SAM4L_FLASH

#define SAM4L_FLASH   ((uint32_t)0x00000000) /* Flash region */

Definition at line 28 of file at91sam4l.c.

◆ SAM4L_FLASH_USER

#define SAM4L_FLASH_USER   0x00800000 /* Flash user page region */

Definition at line 29 of file at91sam4l.c.

◆ SAM4L_FLASHCALW

#define SAM4L_FLASHCALW   0x400A0000 /* Flash controller */

Definition at line 30 of file at91sam4l.c.

◆ SAM4L_FMCD_CMDKEY

#define SAM4L_FMCD_CMDKEY   0xA5UL /* 'key' to issue commands, see 14.10.2 */

Definition at line 66 of file at91sam4l.c.

◆ SAM4L_FPR

#define SAM4L_FPR   0x0C /* Flash Parameter Register (RO) */

Definition at line 37 of file at91sam4l.c.

◆ SAM4L_FSR

#define SAM4L_FSR   0x08 /* Flash Status Register (RO) */

Definition at line 36 of file at91sam4l.c.

◆ SAM4L_FVR

#define SAM4L_FVR   0x10 /* Flash Version Register (RO) */

Definition at line 38 of file at91sam4l.c.

◆ SAM4L_NUM_SECTORS

#define SAM4L_NUM_SECTORS   16

Definition at line 25 of file at91sam4l.c.

◆ SMAP_BASE

#define SMAP_BASE   0x400A3000

Definition at line 70 of file at91sam4l.c.

◆ SMAP_SCR

#define SMAP_SCR   (SMAP_BASE + 8)

Definition at line 72 of file at91sam4l.c.

◆ SMAP_SCR_HCR

#define SMAP_SCR_HCR   (1 << 1)

Definition at line 73 of file at91sam4l.c.

Function Documentation

◆ COMMAND_HANDLER()

COMMAND_HANDLER ( sam4l_handle_reset_deassert  )

Definition at line 622 of file at91sam4l.c.

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( sam4l_flash_bank_command  )

◆ sam4l_check_page_erased()

static int sam4l_check_page_erased ( struct flash_bank bank,
uint32_t  pn,
bool *  is_erased_p 
)
static

◆ sam4l_erase()

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

◆ sam4l_find_chip_name()

static const struct sam4l_chip_info* sam4l_find_chip_name ( uint32_t  id,
uint32_t  exid 
)
static

Definition at line 218 of file at91sam4l.c.

References ARRAY_SIZE, sam4l_chip_info::exid, NULL, and sam4l_known_chips.

Referenced by sam4l_probe().

◆ sam4l_flash_check_error()

static int sam4l_flash_check_error ( struct target target,
uint32_t *  err 
)
static

Definition at line 139 of file at91sam4l.c.

References ERROR_OK, SAM4L_FLASHCALW, SAM4L_FSR, and target_read_u32().

Referenced by sam4l_flash_command().

◆ sam4l_flash_command()

static int sam4l_flash_command ( struct target target,
uint8_t  cmd,
int  page 
)
static

◆ sam4l_flash_wait_until_ready()

static int sam4l_flash_wait_until_ready ( struct target target)
static

Definition at line 125 of file at91sam4l.c.

References ERROR_OK, SAM4L_FLASHCALW, SAM4L_FSR, and target_read_u32().

Referenced by sam4l_flash_command().

◆ sam4l_probe()

◆ sam4l_protect()

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

◆ sam4l_protect_check()

static int sam4l_protect_check ( struct flash_bank bank)
static

◆ sam4l_write()

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

◆ sam4l_write_page()

static int sam4l_write_page ( struct sam4l_info chip,
struct target target,
uint32_t  address,
const uint8_t *  buf 
)
static

◆ sam4l_write_page_partial()

static int sam4l_write_page_partial ( struct sam4l_info chip,
struct flash_bank bank,
uint32_t  address,
const uint8_t *  buf,
uint32_t  page_offset,
uint32_t  nb 
)
static

Variable Documentation

◆ at91sam4l_command_handlers

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

Definition at line 622 of file at91sam4l.c.

◆ at91sam4l_exec_command_handlers

const struct command_registration at91sam4l_exec_command_handlers[]
static
Initial value:
= {
{
.name = "smap_reset_deassert",
.handler = sam4l_handle_reset_deassert,
.mode = COMMAND_EXEC,
.help = "deassert internal reset held by SMAP",
.usage = "",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 622 of file at91sam4l.c.

◆ at91sam4l_flash

const struct flash_driver at91sam4l_flash
Initial value:
= {
.name = "at91sam4l",
.flash_bank_command = sam4l_flash_bank_command,
.erase = sam4l_erase,
.protect = sam4l_protect,
.write = sam4l_write,
.probe = sam4l_probe,
.auto_probe = sam4l_probe,
.erase_check = default_flash_blank_check,
.protect_check = sam4l_protect_check,
.free_driver_priv = default_flash_free_driver_priv,
}
static int sam4l_probe(struct flash_bank *bank)
Definition: at91sam4l.c:258
static int sam4l_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: at91sam4l.c:547
static const struct command_registration at91sam4l_command_handlers[]
Definition: at91sam4l.c:667
static int sam4l_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: at91sam4l.c:414
static int sam4l_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: at91sam4l.c:374
static int sam4l_protect_check(struct flash_bank *bank)
Definition: at91sam4l.c:346
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 622 of file at91sam4l.c.

◆ sam4l_known_chips

const struct sam4l_chip_info sam4l_known_chips[]
static
Initial value:
= {
{ 0xAB0B0AE0, 0x1400000F, "ATSAM4LC8C" },
{ 0xAB0A09E0, 0x0400000F, "ATSAM4LC4C" },
{ 0xAB0A07E0, 0x0400000F, "ATSAM4LC2C" },
{ 0xAB0B0AE0, 0x1300000F, "ATSAM4LC8B" },
{ 0xAB0A09E0, 0x0300000F, "ATSAM4LC4B" },
{ 0xAB0A07E0, 0x0300000F, "ATSAM4LC2B" },
{ 0xAB0B0AE0, 0x1200000F, "ATSAM4LC8A" },
{ 0xAB0A09E0, 0x0200000F, "ATSAM4LC4A" },
{ 0xAB0A07E0, 0x0200000F, "ATSAM4LC2A" },
{ 0xAB0B0AE0, 0x14000002, "ATSAM4LS8C" },
{ 0xAB0A09E0, 0x04000002, "ATSAM4LS4C" },
{ 0xAB0A07E0, 0x04000002, "ATSAM4LS2C" },
{ 0xAB0B0AE0, 0x13000002, "ATSAM4LS8B" },
{ 0xAB0A09E0, 0x03000002, "ATSAM4LS4B" },
{ 0xAB0A07E0, 0x03000002, "ATSAM4LS2B" },
{ 0xAB0B0AE0, 0x12000002, "ATSAM4LS8A" },
{ 0xAB0A09E0, 0x02000002, "ATSAM4LS4A" },
{ 0xAB0A07E0, 0x02000002, "ATSAM4LS2A" },
}

Definition at line 1 of file at91sam4l.c.

Referenced by sam4l_find_chip_name().

◆ sam4l_page_sizes

const uint16_t sam4l_page_sizes[8] = { 32, 64, 128, 256, 512, 1024, 2048, 4096 }
static

Definition at line 108 of file at91sam4l.c.

Referenced by sam4l_probe().

◆ sam4l_ram_sizes

const uint16_t sam4l_ram_sizes[16] = { 48, 1, 2, 6, 24, 4, 80, 160, 8, 16, 32, 64, 128, 256, 96, 512 }
static

Definition at line 105 of file at91sam4l.c.

Referenced by sam4l_probe().