25 #define SAM4L_NUM_SECTORS 16
28 #define SAM4L_FLASH ((uint32_t)0x00000000)
29 #define SAM4L_FLASH_USER 0x00800000
30 #define SAM4L_FLASHCALW 0x400A0000
31 #define SAM4L_CHIPID 0x400E0740
34 #define SAM4L_FCR 0x00
35 #define SAM4L_FCMD 0x04
36 #define SAM4L_FSR 0x08
37 #define SAM4L_FPR 0x0C
38 #define SAM4L_FVR 0x10
39 #define SAM4L_FGPFRHI 0x14
40 #define SAM4L_FGPFRLO 0x18
43 #define SAM4L_CIDR 0x00
44 #define SAM4L_EXID 0x04
47 #define SAM4L_FCMD_NOP 0
48 #define SAM4L_FCMD_WP 1
49 #define SAM4L_FCMD_EP 2
50 #define SAM4L_FCMD_CPB 3
51 #define SAM4L_FCMD_LP 4
52 #define SAM4L_FCMD_UP 5
53 #define SAM4L_FCMD_EA 6
54 #define SAM4L_FCMD_WGPB 7
55 #define SAM4L_FCMD_EGPB 8
56 #define SAM4L_FCMD_SSB 9
57 #define SAM4L_FCMD_PGPFB 10
58 #define SAM4L_FCMD_EAGPF 11
59 #define SAM4L_FCMD_QPR 12
60 #define SAM4L_FCMD_WUP 13
61 #define SAM4L_FCMD_EUP 14
62 #define SAM4L_FCMD_QPRUP 15
63 #define SAM4L_FCMD_HSEN 16
64 #define SAM4L_FCMD_HSDIS 17
66 #define SAM4L_FMCD_CMDKEY 0xA5UL
70 #define SMAP_BASE 0x400A3000
72 #define SMAP_SCR (SMAP_BASE + 8)
73 #define SMAP_SCR_HCR (1 << 1)
84 { 0xAB0B0AE0, 0x1400000F,
"ATSAM4LC8C" },
85 { 0xAB0A09E0, 0x0400000F,
"ATSAM4LC4C" },
86 { 0xAB0A07E0, 0x0400000F,
"ATSAM4LC2C" },
87 { 0xAB0B0AE0, 0x1300000F,
"ATSAM4LC8B" },
88 { 0xAB0A09E0, 0x0300000F,
"ATSAM4LC4B" },
89 { 0xAB0A07E0, 0x0300000F,
"ATSAM4LC2B" },
90 { 0xAB0B0AE0, 0x1200000F,
"ATSAM4LC8A" },
91 { 0xAB0A09E0, 0x0200000F,
"ATSAM4LC4A" },
92 { 0xAB0A07E0, 0x0200000F,
"ATSAM4LC2A" },
93 { 0xAB0B0AE0, 0x14000002,
"ATSAM4LS8C" },
94 { 0xAB0A09E0, 0x04000002,
"ATSAM4LS4C" },
95 { 0xAB0A07E0, 0x04000002,
"ATSAM4LS2C" },
96 { 0xAB0B0AE0, 0x13000002,
"ATSAM4LS8B" },
97 { 0xAB0A09E0, 0x03000002,
"ATSAM4LS4B" },
98 { 0xAB0A07E0, 0x03000002,
"ATSAM4LS2B" },
99 { 0xAB0B0AE0, 0x12000002,
"ATSAM4LS8A" },
100 { 0xAB0A09E0, 0x02000002,
"ATSAM4LS4A" },
101 { 0xAB0A07E0, 0x02000002,
"ATSAM4LS2A" },
105 static const uint16_t
sam4l_ram_sizes[16] = { 48, 1, 2, 6, 24, 4, 80, 160, 8, 16, 32, 64, 128, 256, 96, 512 };
127 volatile unsigned int t = 0;
134 }
while (res ==
ERROR_OK && !(st & (1<<0)) && ++t < 10);
147 *err = st & ((1<<3) | (1<<2));
186 LOG_ERROR(
"%s got error status 0x%08" PRIx32, __func__, err);
197 " invalid bank address (try 0x%08" PRIx32
198 "[at91sam4l series] )",
204 chip = calloc(1,
sizeof(*chip));
206 LOG_ERROR(
"No memory for flash bank chip info");
213 bank->driver_priv = chip;
241 LOG_ERROR(
"Quick page read %" PRIu32
" failed", pn);
253 *is_erased_p = !!(st & (1<<5));
275 LOG_ERROR(
"Couldn't read extended chip ID");
284 switch (0xF & (
id >> 8)) {
295 LOG_ERROR(
"Unknown flash size (chip ID is %08" PRIx32
"), assuming 128K",
id);
303 LOG_ERROR(
"Couldn't read Flash parameters");
322 bank->sectors = calloc(
bank->num_sectors, (
sizeof((
bank->sectors)[0])));
328 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
332 bank->sectors[i].is_erased = -1;
333 bank->sectors[i].is_protected = -1;
339 LOG_INFO(
"SAM4L MCU: %s (Rev %c) (%" PRIu32
"KB Flash with %d %" PRIu32
"B pages, %" PRIu32
"KB RAM)",
368 for (
unsigned int i = 0; i <
bank->num_sectors; i++)
369 bank->sectors[i].is_protected = !!(st & (1<<i));
391 if (first >=
bank->num_sectors || last >=
bank->num_sectors) {
392 LOG_ERROR(
"Protect range %u - %u not valid (%u sectors total)", first, last,
400 for (
unsigned int i = first; i <= last; i++) {
406 LOG_ERROR(
"Can't %slock region containing page %d", set ?
"" :
"un", i);
432 if (first >=
bank->num_sectors || last >=
bank->num_sectors) {
433 LOG_ERROR(
"Erase range %u - %u not valid (%u sectors total)", first, last,
439 if ((first == 0) && ((last + 1) ==
bank->num_sectors)) {
448 LOG_DEBUG(
"Erasing sectors %u through %u...\n", first, last);
451 for (
unsigned int i = first; i <= last; i++) {
455 bool is_erased =
false;
469 LOG_DEBUG(
"Page %u was not erased.", pn);
482 uint32_t address,
const uint8_t *buf)
486 LOG_DEBUG(
"sam4l_write_page address=%08" PRIx32, address);
491 LOG_ERROR(
"%s: can't clear page buffer", __func__);
517 uint32_t page_offset, uint32_t nb)
524 LOG_DEBUG(
"sam4l_write_page_partial address=%08" PRIx32
" nb=%08" PRIx32, address, nb);
526 assert(page_offset + nb < chip->
page_size);
527 assert((address % chip->
page_size) == 0);
538 memcpy(pg + (page_offset % chip->
page_size), buf, nb);
596 for (
int i = 0; i < np; i++) {
658 .
name =
"smap_reset_deassert",
659 .handler = sam4l_handle_reset_deassert,
661 .help =
"deassert internal reset held by SMAP",
671 .help =
"at91sam4l flash command group",
681 .flash_bank_command = sam4l_flash_bank_command,
static struct aice_port_param_s param
static const uint16_t sam4l_ram_sizes[16]
const struct flash_driver at91sam4l_flash
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 const struct sam4l_chip_info sam4l_known_chips[]
static const uint16_t sam4l_page_sizes[8]
#define SAM4L_FMCD_CMDKEY
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_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static const struct command_registration at91sam4l_command_handlers[]
#define SAM4L_NUM_SECTORS
static int sam4l_flash_check_error(struct target *target, uint32_t *err)
FLASH_BANK_COMMAND_HANDLER(sam4l_flash_bank_command)
static int sam4l_write_page(struct sam4l_info *chip, struct target *target, uint32_t address, const uint8_t *buf)
COMMAND_HANDLER(sam4l_handle_reset_deassert)
static const struct sam4l_chip_info * sam4l_find_chip_name(uint32_t id, uint32_t exid)
static int sam4l_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static const struct command_registration at91sam4l_exec_command_handlers[]
static int sam4l_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
static int sam4l_check_page_erased(struct flash_bank *bank, uint32_t pn, bool *is_erased_p)
static int sam4l_protect_check(struct flash_bank *bank)
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_FLASH_BANK_NOT_PROBED
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 enum reset_types jtag_reset_config
enum reset_types jtag_get_reset_config(void)
The JTAG interface can be implemented with a software or hardware fifo.
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
const struct sam4l_chip_info * details
unsigned int pages_per_sector
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_examine_one(struct target *target)
Examine the specified target, letting it perform any Initialisation that requires JTAG access.
int target_poll(struct target *target)
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
int target_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Read count items of size bytes from the memory of target at the address given.
struct target * get_current_target(struct command_context *cmd_ctx)
#define ERROR_TARGET_NOT_HALTED
static bool target_was_examined(struct target *target)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.