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

Go to the source code of this file.

Data Structures

struct  efm32_dev_info_addr
 
struct  efm32_family_data
 
struct  efm32_flash_chip
 
struct  efm32_info
 
struct  efm32_msc_offset
 

Macros

#define EFM32_CMU_REG_CLKEN1_SET   0x50009068
 
#define EFM32_DI_PART_FAMILY   (EFM32_MSC_INFO_BASE + 0x81fe)
 
#define EFM32_DI_PARTINFO_FAMILY_MASK   0x00ff0000
 
#define EFM32_DI_PARTINFO_NUM_MASK   0x0000ffff
 
#define EFM32_DI_PARTINFO_PAGE_SZ_MASK   0x000000ff
 
#define EFM32_DI_PARTINFO_PAGE_SZ_UD_MASK   0x0000ff00
 
#define EFM32_DI_PARTINFO_TYPE_MASK   0x3f000000
 
#define EFM32_FLASH_BASE_V1   0x00000000
 
#define EFM32_FLASH_BASE_V2   0x08000000
 
#define EFM32_FLASH_OPERATION_TIMEOUT   100
 
#define EFM32_MSC_INFO_BASE   0x0fe00000
 
#define EFM32_MSC_LOCK_BITS   (EFM32_MSC_INFO_BASE + 0x4000)
 
#define EFM32_MSC_LOCK_BITS_EXTRA   (EFM32_MSC_INFO_BASE + 0x4200)
 
#define EFM32_MSC_LOCK_LOCKKEY   0x1b71
 
#define EFM32_MSC_STATUS_BUSY_MASK   0x0001
 
#define EFM32_MSC_STATUS_INVADDR_MASK   0x0004
 
#define EFM32_MSC_STATUS_LOCKED_MASK   0x0002
 
#define EFM32_MSC_STATUS_WDATAREADY_MASK   0x0008
 
#define EFM32_MSC_USER_DATA   (EFM32_MSC_INFO_BASE + 0x0000)
 
#define EFM32_MSC_WRITECMD_ERASEPAGE_MASK   0x0002
 
#define EFM32_MSC_WRITECMD_LADDRIM_MASK   0x0001
 
#define EFM32_MSC_WRITECMD_WRITEONCE_MASK   0x0008
 
#define EFM32_MSC_WRITECTRL_WREN_MASK   0x0001
 
#define LOCKWORDS_SZ   512
 

Enumerations

enum  efm32_bank_index { EFM32_BANK_INDEX_MAIN , EFM32_BANK_INDEX_USER_DATA , EFM32_BANK_INDEX_LOCK_BITS , EFM32_N_BANKS }
 

Functions

 COMMAND_HANDLER (efm32_handle_debuglock_command)
 
static int efm32_auto_probe (struct flash_bank *bank)
 
static int efm32_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int efm32_erase_page (struct flash_bank *bank, uint32_t addr)
 
static void efm32_free_driver_priv (struct flash_bank *bank)
 Remove flash structure corresponding to this bank, if and only if it's not used by any others. More...
 
static int efm32_get_bank_index (target_addr_t base)
 
static int efm32_get_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int efm32_get_page_lock (struct flash_bank *bank, size_t page)
 
static char * efm32_get_str_identifier (struct efm32_info *efm32_mcu_info, char *buf, size_t len)
 
static int efm32_msc_clock_enable (struct flash_bank *bank)
 
static int efm32_msc_lock (struct flash_bank *bank, int lock)
 
static int efm32_priv_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t addr, uint32_t count)
 
static int efm32_probe (struct flash_bank *bank)
 
static int efm32_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int efm32_protect_check (struct flash_bank *bank)
 
static int efm32_read_info (struct flash_bank *bank)
 
static int efm32_read_lock_data (struct flash_bank *bank)
 
static int efm32_read_reg_u32 (struct flash_bank *bank, target_addr_t offset, uint32_t *value)
 
static int efm32_set_page_lock (struct flash_bank *bank, size_t page, int set)
 
static int efm32_set_reg_bits (struct flash_bank *bank, uint32_t reg, uint32_t bitmask, int set)
 
static int efm32_set_wren (struct flash_bank *bank, int write_enable)
 
static int efm32_wait_status (struct flash_bank *bank, int timeout_ms, uint32_t wait_mask, bool wait_for_set)
 
static int efm32_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int efm32_write_block (struct flash_bank *bank, const uint8_t *buf, uint32_t address, uint32_t count)
 
static int efm32_write_lock_data (struct flash_bank *bank)
 
static int efm32_write_only_lockbits (struct flash_bank *bank)
 
static int efm32_write_reg_u32 (struct flash_bank *bank, target_addr_t offset, uint32_t value)
 
static int efm32_write_word (struct flash_bank *bank, uint32_t addr, uint32_t val)
 
 FLASH_BANK_COMMAND_HANDLER (efm32_flash_bank_command)
 

Variables

static const struct command_registration efm32_command_handlers []
 
static const struct efm32_dev_info_addr efm32_dev_info_addr []
 
static const struct command_registration efm32_exec_command_handlers []
 
static const struct efm32_family_data efm32_families []
 
const struct flash_driver efm32_flash
 
static const uint8_t efm32_flash_write_code_s0_s1 []
 
static const uint8_t efm32_flash_write_code_s2 []
 
static const struct efm32_msc_offset efm32_msc_offset []
 

Macro Definition Documentation

◆ EFM32_CMU_REG_CLKEN1_SET

#define EFM32_CMU_REG_CLKEN1_SET   0x50009068

Definition at line 174 of file efm32.c.

◆ EFM32_DI_PART_FAMILY

#define EFM32_DI_PART_FAMILY   (EFM32_MSC_INFO_BASE + 0x81fe)

Definition at line 73 of file efm32.c.

◆ EFM32_DI_PARTINFO_FAMILY_MASK

#define EFM32_DI_PARTINFO_FAMILY_MASK   0x00ff0000

Definition at line 63 of file efm32.c.

◆ EFM32_DI_PARTINFO_NUM_MASK

#define EFM32_DI_PARTINFO_NUM_MASK   0x0000ffff

Definition at line 62 of file efm32.c.

◆ EFM32_DI_PARTINFO_PAGE_SZ_MASK

#define EFM32_DI_PARTINFO_PAGE_SZ_MASK   0x000000ff

Definition at line 66 of file efm32.c.

◆ EFM32_DI_PARTINFO_PAGE_SZ_UD_MASK

#define EFM32_DI_PARTINFO_PAGE_SZ_UD_MASK   0x0000ff00

Definition at line 67 of file efm32.c.

◆ EFM32_DI_PARTINFO_TYPE_MASK

#define EFM32_DI_PARTINFO_TYPE_MASK   0x3f000000

Definition at line 64 of file efm32.c.

◆ EFM32_FLASH_BASE_V1

#define EFM32_FLASH_BASE_V1   0x00000000

Definition at line 48 of file efm32.c.

◆ EFM32_FLASH_BASE_V2

#define EFM32_FLASH_BASE_V2   0x08000000

Definition at line 49 of file efm32.c.

◆ EFM32_FLASH_OPERATION_TIMEOUT

#define EFM32_FLASH_OPERATION_TIMEOUT   100

Definition at line 46 of file efm32.c.

◆ EFM32_MSC_INFO_BASE

#define EFM32_MSC_INFO_BASE   0x0fe00000

Definition at line 54 of file efm32.c.

◆ EFM32_MSC_LOCK_BITS

#define EFM32_MSC_LOCK_BITS   (EFM32_MSC_INFO_BASE + 0x4000)

Definition at line 56 of file efm32.c.

◆ EFM32_MSC_LOCK_BITS_EXTRA

#define EFM32_MSC_LOCK_BITS_EXTRA   (EFM32_MSC_INFO_BASE + 0x4200)

Definition at line 57 of file efm32.c.

◆ EFM32_MSC_LOCK_LOCKKEY

#define EFM32_MSC_LOCK_LOCKKEY   0x1b71

Definition at line 121 of file efm32.c.

◆ EFM32_MSC_STATUS_BUSY_MASK

#define EFM32_MSC_STATUS_BUSY_MASK   0x0001

Definition at line 115 of file efm32.c.

◆ EFM32_MSC_STATUS_INVADDR_MASK

#define EFM32_MSC_STATUS_INVADDR_MASK   0x0004

Definition at line 117 of file efm32.c.

◆ EFM32_MSC_STATUS_LOCKED_MASK

#define EFM32_MSC_STATUS_LOCKED_MASK   0x0002

Definition at line 116 of file efm32.c.

◆ EFM32_MSC_STATUS_WDATAREADY_MASK

#define EFM32_MSC_STATUS_WDATAREADY_MASK   0x0008

Definition at line 118 of file efm32.c.

◆ EFM32_MSC_USER_DATA

#define EFM32_MSC_USER_DATA   (EFM32_MSC_INFO_BASE + 0x0000)

Definition at line 55 of file efm32.c.

◆ EFM32_MSC_WRITECMD_ERASEPAGE_MASK

#define EFM32_MSC_WRITECMD_ERASEPAGE_MASK   0x0002

Definition at line 108 of file efm32.c.

◆ EFM32_MSC_WRITECMD_LADDRIM_MASK

#define EFM32_MSC_WRITECMD_LADDRIM_MASK   0x0001

Definition at line 107 of file efm32.c.

◆ EFM32_MSC_WRITECMD_WRITEONCE_MASK

#define EFM32_MSC_WRITECMD_WRITEONCE_MASK   0x0008

Definition at line 109 of file efm32.c.

◆ EFM32_MSC_WRITECTRL_WREN_MASK

#define EFM32_MSC_WRITECTRL_WREN_MASK   0x0001

Definition at line 104 of file efm32.c.

◆ LOCKWORDS_SZ

#define LOCKWORDS_SZ   512

Definition at line 52 of file efm32.c.

Enumeration Type Documentation

◆ efm32_bank_index

Enumerator
EFM32_BANK_INDEX_MAIN 
EFM32_BANK_INDEX_USER_DATA 
EFM32_BANK_INDEX_LOCK_BITS 
EFM32_N_BANKS 

Definition at line 176 of file efm32.c.

Function Documentation

◆ COMMAND_HANDLER()

◆ efm32_auto_probe()

static int efm32_auto_probe ( struct flash_bank bank)
static

Definition at line 1247 of file efm32.c.

References bank, efm32_get_bank_index(), efm32_probe(), and ERROR_OK.

◆ efm32_erase()

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

◆ efm32_erase_page()

◆ efm32_free_driver_priv()

static void efm32_free_driver_priv ( struct flash_bank bank)
static

Remove flash structure corresponding to this bank, if and only if it's not used by any others.

Definition at line 455 of file efm32.c.

References bank, and NULL.

◆ efm32_get_bank_index()

static int efm32_get_bank_index ( target_addr_t  base)
static

Definition at line 183 of file efm32.c.

Referenced by efm32_auto_probe(), efm32_probe(), and FLASH_BANK_COMMAND_HANDLER().

◆ efm32_get_info()

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

◆ efm32_get_page_lock()

static int efm32_get_page_lock ( struct flash_bank bank,
size_t  page 
)
static

◆ efm32_get_str_identifier()

static char* efm32_get_str_identifier ( struct efm32_info efm32_mcu_info,
char *  buf,
size_t  len 
)
static

◆ efm32_msc_clock_enable()

◆ efm32_msc_lock()

static int efm32_msc_lock ( struct flash_bank bank,
int  lock 
)
static

◆ efm32_priv_write()

◆ efm32_probe()

◆ efm32_protect()

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

◆ efm32_protect_check()

◆ efm32_read_info()

◆ efm32_read_lock_data()

static int efm32_read_lock_data ( struct flash_bank bank)
static

Definition at line 680 of file efm32.c.

References bank, EFM32_MSC_LOCK_BITS, ERROR_OK, LOG_ERROR, NULL, and target_read_u32().

Referenced by efm32_protect(), and efm32_protect_check().

◆ efm32_read_reg_u32()

static int efm32_read_reg_u32 ( struct flash_bank bank,
target_addr_t  offset,
uint32_t *  value 
)
static

◆ efm32_set_page_lock()

static int efm32_set_page_lock ( struct flash_bank bank,
size_t  page,
int  set 
)
static

Definition at line 833 of file efm32.c.

References bank, BIT, EFM32_FLASH_BASE_V1, EFM32_FLASH_BASE_V2, ERROR_FAIL, ERROR_OK, LOG_ERROR, and mask.

Referenced by efm32_protect().

◆ efm32_set_reg_bits()

static int efm32_set_reg_bits ( struct flash_bank bank,
uint32_t  reg,
uint32_t  bitmask,
int  set 
)
static

Definition at line 515 of file efm32.c.

References bank, efm32_read_reg_u32(), efm32_write_reg_u32(), and ERROR_OK.

Referenced by efm32_erase_page(), efm32_set_wren(), and efm32_write_word().

◆ efm32_set_wren()

static int efm32_set_wren ( struct flash_bank bank,
int  write_enable 
)
static

◆ efm32_wait_status()

static int efm32_wait_status ( struct flash_bank bank,
int  timeout_ms,
uint32_t  wait_mask,
bool  wait_for_set 
)
static

◆ efm32_write()

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

◆ efm32_write_block()

◆ efm32_write_lock_data()

◆ efm32_write_only_lockbits()

static int efm32_write_only_lockbits ( struct flash_bank bank)
static

Definition at line 756 of file efm32.c.

References bank, EFM32_MSC_LOCK_BITS, efm32_priv_write(), and LOCKWORDS_SZ.

Referenced by efm32_erase(), and efm32_write_lock_data().

◆ efm32_write_reg_u32()

static int efm32_write_reg_u32 ( struct flash_bank bank,
target_addr_t  offset,
uint32_t  value 
)
static

◆ efm32_write_word()

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( efm32_flash_bank_command  )

Variable Documentation

◆ efm32_command_handlers

const struct command_registration efm32_command_handlers[]
static
Initial value:
= {
{
.name = "efm32",
.mode = COMMAND_ANY,
.help = "Silicon Labs (EFM32 and EFR32) flash command group",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:256
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration efm32_exec_command_handlers[]
Definition: efm32.c:1344

Definition at line 1306 of file efm32.c.

◆ efm32_dev_info_addr

Initial value:
= {
[0] = {
.part_num = EFM32_MSC_INFO_BASE + 0x81fc,
.part_rev = EFM32_MSC_INFO_BASE + 0x81ff,
.part_info = 0x00000000,
.page_size = EFM32_MSC_INFO_BASE + 0x81e7,
.flash_sz = EFM32_MSC_INFO_BASE + 0x81f8,
.ram_sz = EFM32_MSC_INFO_BASE + 0x81fa,
},
[1] = {
.part_num = EFM32_MSC_INFO_BASE + 0x81fc,
.part_rev = EFM32_MSC_INFO_BASE + 0x81ff,
.part_info = 0x0000000,
.page_size = EFM32_MSC_INFO_BASE + 0x81e7,
.flash_sz = EFM32_MSC_INFO_BASE + 0x81f8,
.ram_sz = EFM32_MSC_INFO_BASE + 0x81fa,
},
[2] = {
.part_num = 0x00000000,
.part_rev = EFM32_MSC_INFO_BASE + 0x8002,
.part_info = EFM32_MSC_INFO_BASE + 0x8004,
.page_size = EFM32_MSC_INFO_BASE + 0x8008,
.flash_sz = EFM32_MSC_INFO_BASE + 0x800c,
.ram_sz = EFM32_MSC_INFO_BASE + 0x800e,
},
}
#define EFM32_MSC_INFO_BASE
Definition: efm32.c:54

Definition at line 1 of file efm32.c.

◆ efm32_exec_command_handlers

const struct command_registration efm32_exec_command_handlers[]
static
Initial value:
= {
{
.name = "debuglock",
.handler = efm32_handle_debuglock_command,
.mode = COMMAND_EXEC,
.usage = "bank_id",
.help = "Lock the debug interface of the device.",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 1306 of file efm32.c.

◆ efm32_families

const struct efm32_family_data efm32_families[]
static

Definition at line 183 of file efm32.c.

Referenced by efm32_read_info().

◆ efm32_flash

const struct flash_driver efm32_flash
Initial value:
= {
.name = "efm32",
.flash_bank_command = efm32_flash_bank_command,
.erase = efm32_erase,
.protect = efm32_protect,
.write = efm32_write,
.probe = efm32_probe,
.auto_probe = efm32_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = efm32_protect_check,
.info = efm32_get_info,
.free_driver_priv = efm32_free_driver_priv,
}
static int efm32_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: efm32.c:636
static int efm32_protect_check(struct flash_bank *bank)
Definition: efm32.c:1259
static int efm32_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: efm32.c:1134
static int efm32_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: efm32.c:853
static int efm32_probe(struct flash_bank *bank)
Definition: efm32.c:1179
static int efm32_auto_probe(struct flash_bank *bank)
Definition: efm32.c:1247
static void efm32_free_driver_priv(struct flash_bank *bank)
Remove flash structure corresponding to this bank, if and only if it's not used by any others.
Definition: efm32.c:455
static int efm32_get_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: efm32.c:1287
static const struct command_registration efm32_command_handlers[]
Definition: efm32.c:1355
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.

Definition at line 183 of file efm32.c.

Referenced by FLASH_BANK_COMMAND_HANDLER().

◆ efm32_flash_write_code_s0_s1

const uint8_t efm32_flash_write_code_s0_s1[]
static
Initial value:
= {
}

Definition at line 129 of file efm32.c.

◆ efm32_flash_write_code_s2

const uint8_t efm32_flash_write_code_s2[]
static
Initial value:
= {
}

Definition at line 133 of file efm32.c.

◆ efm32_msc_offset

const struct efm32_msc_offset efm32_msc_offset[]
static

Definition at line 133 of file efm32.c.