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

Go to the source code of this file.

Data Structures

struct  efm32_family_data
 
struct  efm32_info
 
struct  efm32x_flash_chip
 

Macros

#define EFM32_FLASH_BASE   0
 
#define EFM32_FLASH_ERASE_TMO   100
 
#define EFM32_FLASH_WDATAREADY_TMO   100
 
#define EFM32_FLASH_WRITE_TMO   100
 
#define EFM32_MSC_DEV_INFO   (EFM32_MSC_INFO_BASE+0x8000)
 
#define EFM32_MSC_DI_FLASH_SZ   (EFM32_MSC_DEV_INFO+0x1f8)
 
#define EFM32_MSC_DI_PAGE_SIZE   (EFM32_MSC_DEV_INFO+0x1e7)
 
#define EFM32_MSC_DI_PART_FAMILY   (EFM32_MSC_DEV_INFO+0x1fe)
 
#define EFM32_MSC_DI_PART_NUM   (EFM32_MSC_DEV_INFO+0x1fc)
 
#define EFM32_MSC_DI_PROD_REV   (EFM32_MSC_DEV_INFO+0x1ff)
 
#define EFM32_MSC_DI_RAM_SZ   (EFM32_MSC_DEV_INFO+0x1fa)
 
#define EFM32_MSC_INFO_BASE   0x0fe00000
 
#define EFM32_MSC_LOCK_BITS   (EFM32_MSC_INFO_BASE+0x4000)
 
#define EFM32_MSC_LOCK_BITS_EXTRA   (EFM32_MSC_LOCK_BITS+LOCKWORDS_SZ)
 
#define EFM32_MSC_LOCK_LOCKKEY   0x1b71
 
#define EFM32_MSC_REG_ADDRB   0x010
 
#define EFM32_MSC_REG_LOCK   0x03c
 
#define EFM32_MSC_REG_LOCK_SERIES1   0x040
 
#define EFM32_MSC_REG_STATUS   0x01c
 
#define EFM32_MSC_REG_WDATA   0x018
 
#define EFM32_MSC_REG_WRITECMD   0x00c
 
#define EFM32_MSC_REG_WRITECTRL   0x008
 
#define EFM32_MSC_REGBASE   0x400c0000
 
#define EFM32_MSC_REGBASE_SERIES1   0x400e0000
 
#define EFM32_MSC_STATUS_BUSY_MASK   0x1
 
#define EFM32_MSC_STATUS_ERASEABORTED_MASK   0x20
 
#define EFM32_MSC_STATUS_INVADDR_MASK   0x4
 
#define EFM32_MSC_STATUS_LOCKED_MASK   0x2
 
#define EFM32_MSC_STATUS_WDATAREADY_MASK   0x8
 
#define EFM32_MSC_STATUS_WORDTIMEOUT_MASK   0x10
 
#define EFM32_MSC_USER_DATA   EFM32_MSC_INFO_BASE
 
#define EFM32_MSC_WRITECMD_ERASEPAGE_MASK   0x2
 
#define EFM32_MSC_WRITECMD_LADDRIM_MASK   0x1
 
#define EFM32_MSC_WRITECMD_WRITEONCE_MASK   0x8
 
#define EFM32_MSC_WRITECTRL_WREN_MASK   0x1
 
#define EFM_FAMILY_ID_GIANT_GECKO   72
 
#define EFM_FAMILY_ID_LEOPARD_GECKO   74
 
#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 (efm32x_handle_debuglock_command)
 
static int efm32x_auto_probe (struct flash_bank *bank)
 
static int efm32x_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int efm32x_erase_page (struct flash_bank *bank, uint32_t addr)
 
static void efm32x_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 efm32x_get_bank_index (target_addr_t base)
 
static int efm32x_get_flash_size (struct flash_bank *bank, uint16_t *flash_sz)
 
static int efm32x_get_page_lock (struct flash_bank *bank, size_t page)
 
static int efm32x_get_part_family (struct flash_bank *bank, uint8_t *pfamily)
 
static int efm32x_get_part_num (struct flash_bank *bank, uint16_t *pnum)
 
static int efm32x_get_prod_rev (struct flash_bank *bank, uint8_t *prev)
 
static int efm32x_get_ram_size (struct flash_bank *bank, uint16_t *ram_sz)
 
static int efm32x_msc_lock (struct flash_bank *bank, int lock)
 
static int efm32x_priv_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t addr, uint32_t count)
 
static int efm32x_probe (struct flash_bank *bank)
 
static int efm32x_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int efm32x_protect_check (struct flash_bank *bank)
 
static int efm32x_read_info (struct flash_bank *bank)
 
static int efm32x_read_lock_data (struct flash_bank *bank)
 
static int efm32x_read_reg_u32 (struct flash_bank *bank, target_addr_t offset, uint32_t *value)
 
static int efm32x_set_page_lock (struct flash_bank *bank, size_t page, int set)
 
static int efm32x_set_reg_bits (struct flash_bank *bank, uint32_t reg, uint32_t bitmask, int set)
 
static int efm32x_set_wren (struct flash_bank *bank, int write_enable)
 
static int efm32x_wait_status (struct flash_bank *bank, int timeout, uint32_t wait_mask, int wait_for_set)
 
static int efm32x_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int efm32x_write_block (struct flash_bank *bank, const uint8_t *buf, uint32_t address, uint32_t count)
 
static int efm32x_write_lock_data (struct flash_bank *bank)
 
static int efm32x_write_only_lockbits (struct flash_bank *bank)
 
static int efm32x_write_reg_u32 (struct flash_bank *bank, target_addr_t offset, uint32_t value)
 
static int efm32x_write_word (struct flash_bank *bank, uint32_t addr, uint32_t val)
 
 FLASH_BANK_COMMAND_HANDLER (efm32x_flash_bank_command)
 
static int get_efm32x_info (struct flash_bank *bank, struct command_invocation *cmd)
 

Variables

static const struct efm32_family_data efm32_families []
 
const struct flash_driver efm32_flash
 
static const struct command_registration efm32x_command_handlers []
 
static const struct command_registration efm32x_exec_command_handlers []
 

Macro Definition Documentation

◆ EFM32_FLASH_BASE

#define EFM32_FLASH_BASE   0

Definition at line 40 of file efm32.c.

◆ EFM32_FLASH_ERASE_TMO

#define EFM32_FLASH_ERASE_TMO   100

Definition at line 36 of file efm32.c.

◆ EFM32_FLASH_WDATAREADY_TMO

#define EFM32_FLASH_WDATAREADY_TMO   100

Definition at line 37 of file efm32.c.

◆ EFM32_FLASH_WRITE_TMO

#define EFM32_FLASH_WRITE_TMO   100

Definition at line 38 of file efm32.c.

◆ EFM32_MSC_DEV_INFO

#define EFM32_MSC_DEV_INFO   (EFM32_MSC_INFO_BASE+0x8000)

Definition at line 50 of file efm32.c.

◆ EFM32_MSC_DI_FLASH_SZ

#define EFM32_MSC_DI_FLASH_SZ   (EFM32_MSC_DEV_INFO+0x1f8)

Definition at line 54 of file efm32.c.

◆ EFM32_MSC_DI_PAGE_SIZE

#define EFM32_MSC_DI_PAGE_SIZE   (EFM32_MSC_DEV_INFO+0x1e7)

Definition at line 53 of file efm32.c.

◆ EFM32_MSC_DI_PART_FAMILY

#define EFM32_MSC_DI_PART_FAMILY   (EFM32_MSC_DEV_INFO+0x1fe)

Definition at line 57 of file efm32.c.

◆ EFM32_MSC_DI_PART_NUM

#define EFM32_MSC_DI_PART_NUM   (EFM32_MSC_DEV_INFO+0x1fc)

Definition at line 56 of file efm32.c.

◆ EFM32_MSC_DI_PROD_REV

#define EFM32_MSC_DI_PROD_REV   (EFM32_MSC_DEV_INFO+0x1ff)

Definition at line 58 of file efm32.c.

◆ EFM32_MSC_DI_RAM_SZ

#define EFM32_MSC_DI_RAM_SZ   (EFM32_MSC_DEV_INFO+0x1fa)

Definition at line 55 of file efm32.c.

◆ EFM32_MSC_INFO_BASE

#define EFM32_MSC_INFO_BASE   0x0fe00000

Definition at line 45 of file efm32.c.

◆ EFM32_MSC_LOCK_BITS

#define EFM32_MSC_LOCK_BITS   (EFM32_MSC_INFO_BASE+0x4000)

Definition at line 48 of file efm32.c.

◆ EFM32_MSC_LOCK_BITS_EXTRA

#define EFM32_MSC_LOCK_BITS_EXTRA   (EFM32_MSC_LOCK_BITS+LOCKWORDS_SZ)

Definition at line 49 of file efm32.c.

◆ EFM32_MSC_LOCK_LOCKKEY

#define EFM32_MSC_LOCK_LOCKKEY   0x1b71

Definition at line 79 of file efm32.c.

◆ EFM32_MSC_REG_ADDRB

#define EFM32_MSC_REG_ADDRB   0x010

Definition at line 68 of file efm32.c.

◆ EFM32_MSC_REG_LOCK

#define EFM32_MSC_REG_LOCK   0x03c

Definition at line 77 of file efm32.c.

◆ EFM32_MSC_REG_LOCK_SERIES1

#define EFM32_MSC_REG_LOCK_SERIES1   0x040

Definition at line 78 of file efm32.c.

◆ EFM32_MSC_REG_STATUS

#define EFM32_MSC_REG_STATUS   0x01c

Definition at line 70 of file efm32.c.

◆ EFM32_MSC_REG_WDATA

#define EFM32_MSC_REG_WDATA   0x018

Definition at line 69 of file efm32.c.

◆ EFM32_MSC_REG_WRITECMD

#define EFM32_MSC_REG_WRITECMD   0x00c

Definition at line 64 of file efm32.c.

◆ EFM32_MSC_REG_WRITECTRL

#define EFM32_MSC_REG_WRITECTRL   0x008

Definition at line 62 of file efm32.c.

◆ EFM32_MSC_REGBASE

#define EFM32_MSC_REGBASE   0x400c0000

Definition at line 60 of file efm32.c.

◆ EFM32_MSC_REGBASE_SERIES1

#define EFM32_MSC_REGBASE_SERIES1   0x400e0000

Definition at line 61 of file efm32.c.

◆ EFM32_MSC_STATUS_BUSY_MASK

#define EFM32_MSC_STATUS_BUSY_MASK   0x1

Definition at line 71 of file efm32.c.

◆ EFM32_MSC_STATUS_ERASEABORTED_MASK

#define EFM32_MSC_STATUS_ERASEABORTED_MASK   0x20

Definition at line 76 of file efm32.c.

◆ EFM32_MSC_STATUS_INVADDR_MASK

#define EFM32_MSC_STATUS_INVADDR_MASK   0x4

Definition at line 73 of file efm32.c.

◆ EFM32_MSC_STATUS_LOCKED_MASK

#define EFM32_MSC_STATUS_LOCKED_MASK   0x2

Definition at line 72 of file efm32.c.

◆ EFM32_MSC_STATUS_WDATAREADY_MASK

#define EFM32_MSC_STATUS_WDATAREADY_MASK   0x8

Definition at line 74 of file efm32.c.

◆ EFM32_MSC_STATUS_WORDTIMEOUT_MASK

#define EFM32_MSC_STATUS_WORDTIMEOUT_MASK   0x10

Definition at line 75 of file efm32.c.

◆ EFM32_MSC_USER_DATA

#define EFM32_MSC_USER_DATA   EFM32_MSC_INFO_BASE

Definition at line 47 of file efm32.c.

◆ EFM32_MSC_WRITECMD_ERASEPAGE_MASK

#define EFM32_MSC_WRITECMD_ERASEPAGE_MASK   0x2

Definition at line 66 of file efm32.c.

◆ EFM32_MSC_WRITECMD_LADDRIM_MASK

#define EFM32_MSC_WRITECMD_LADDRIM_MASK   0x1

Definition at line 65 of file efm32.c.

◆ EFM32_MSC_WRITECMD_WRITEONCE_MASK

#define EFM32_MSC_WRITECMD_WRITEONCE_MASK   0x8

Definition at line 67 of file efm32.c.

◆ EFM32_MSC_WRITECTRL_WREN_MASK

#define EFM32_MSC_WRITECTRL_WREN_MASK   0x1

Definition at line 63 of file efm32.c.

◆ EFM_FAMILY_ID_GIANT_GECKO

#define EFM_FAMILY_ID_GIANT_GECKO   72

Definition at line 33 of file efm32.c.

◆ EFM_FAMILY_ID_LEOPARD_GECKO

#define EFM_FAMILY_ID_LEOPARD_GECKO   74

Definition at line 34 of file efm32.c.

◆ LOCKWORDS_SZ

#define LOCKWORDS_SZ   512

Definition at line 43 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 81 of file efm32.c.

Function Documentation

◆ COMMAND_HANDLER()

◆ efm32x_auto_probe()

static int efm32x_auto_probe ( struct flash_bank bank)
static

◆ efm32x_erase()

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

◆ efm32x_erase_page()

◆ efm32x_free_driver_priv()

static void efm32x_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 374 of file efm32.c.

References bank, NULL, and efm32x_flash_chip::refcount.

◆ efm32x_get_bank_index()

static int efm32x_get_bank_index ( target_addr_t  base)
static

Definition at line 88 of file efm32.c.

Referenced by efm32x_auto_probe(), efm32x_probe(), and FLASH_BANK_COMMAND_HANDLER().

◆ efm32x_get_flash_size()

static int efm32x_get_flash_size ( struct flash_bank bank,
uint16_t *  flash_sz 
)
static

Definition at line 203 of file efm32.c.

References bank, EFM32_MSC_DI_FLASH_SZ, and target_read_u16().

Referenced by efm32x_read_info().

◆ efm32x_get_page_lock()

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

◆ efm32x_get_part_family()

static int efm32x_get_part_family ( struct flash_bank bank,
uint8_t *  pfamily 
)
static

Definition at line 218 of file efm32.c.

References bank, EFM32_MSC_DI_PART_FAMILY, and target_read_u8().

Referenced by efm32x_read_info().

◆ efm32x_get_part_num()

static int efm32x_get_part_num ( struct flash_bank bank,
uint16_t *  pnum 
)
static

Definition at line 213 of file efm32.c.

References bank, EFM32_MSC_DI_PART_NUM, and target_read_u16().

Referenced by efm32x_read_info().

◆ efm32x_get_prod_rev()

static int efm32x_get_prod_rev ( struct flash_bank bank,
uint8_t *  prev 
)
static

Definition at line 223 of file efm32.c.

References bank, EFM32_MSC_DI_PROD_REV, and target_read_u8().

Referenced by efm32x_read_info().

◆ efm32x_get_ram_size()

static int efm32x_get_ram_size ( struct flash_bank bank,
uint16_t *  ram_sz 
)
static

Definition at line 208 of file efm32.c.

References bank, EFM32_MSC_DI_RAM_SZ, and target_read_u16().

Referenced by efm32x_read_info().

◆ efm32x_msc_lock()

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

◆ efm32x_priv_write()

◆ efm32x_probe()

◆ efm32x_protect()

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

◆ efm32x_protect_check()

static int efm32x_protect_check ( struct flash_bank bank)
static

◆ efm32x_read_info()

◆ efm32x_read_lock_data()

static int efm32x_read_lock_data ( struct flash_bank bank)
static

◆ efm32x_read_reg_u32()

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

◆ efm32x_set_page_lock()

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

Definition at line 682 of file efm32.c.

References bank, EFM32_FLASH_BASE, ERROR_FAIL, ERROR_OK, efm32x_flash_chip::lb_page, LOG_ERROR, and mask.

Referenced by efm32x_protect().

◆ efm32x_set_reg_bits()

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

◆ efm32x_set_wren()

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

◆ efm32x_wait_status()

static int efm32x_wait_status ( struct flash_bank bank,
int  timeout,
uint32_t  wait_mask,
int  wait_for_set 
)
static

◆ efm32x_write()

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

◆ efm32x_write_block()

◆ efm32x_write_lock_data()

◆ efm32x_write_only_lockbits()

static int efm32x_write_only_lockbits ( struct flash_bank bank)
static

◆ efm32x_write_reg_u32()

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

◆ efm32x_write_word()

◆ FLASH_BANK_COMMAND_HANDLER()

◆ get_efm32x_info()

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

Variable Documentation

◆ efm32_families

const struct efm32_family_data efm32_families[]
static

Definition at line 88 of file efm32.c.

Referenced by efm32x_read_info().

◆ efm32_flash

const struct flash_driver efm32_flash
Initial value:
= {
.name = "efm32",
.flash_bank_command = efm32x_flash_bank_command,
.erase = efm32x_erase,
.protect = efm32x_protect,
.write = efm32x_write,
.probe = efm32x_probe,
.auto_probe = efm32x_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = efm32x_protect_check,
.info = get_efm32x_info,
.free_driver_priv = efm32x_free_driver_priv,
}
static int efm32x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: efm32.c:499
static int efm32x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: efm32.c:704
static int efm32x_auto_probe(struct flash_bank *bank)
Definition: efm32.c:1101
static int efm32x_protect_check(struct flash_bank *bank)
Definition: efm32.c:1113
static const struct command_registration efm32x_command_handlers[]
Definition: efm32.c:1200
static void efm32x_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:374
static int efm32x_probe(struct flash_bank *bank)
Definition: efm32.c:1048
static int efm32x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: efm32.c:1038
static int get_efm32x_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: efm32.c:1137
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 88 of file efm32.c.

Referenced by FLASH_BANK_COMMAND_HANDLER().

◆ efm32x_command_handlers

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

Definition at line 1153 of file efm32.c.

◆ efm32x_exec_command_handlers

const struct command_registration efm32x_exec_command_handlers[]
static
Initial value:
= {
{
.name = "debuglock",
.handler = efm32x_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 1153 of file efm32.c.