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

Go to the source code of this file.

Data Structures

struct  nrf52_ficr_info
 
struct  nrf5_info::nrf5_bank
 
struct  nrf5_device_package
 
struct  nrf5_device_spec
 
struct  nrf5_info
 

Macros

#define NRF51_DEVICE_DEF(id, pt, var, bcode, fsize)
 
#define NRF5_FICR_REG(offset)   (NRF5_FICR_BASE + offset)
 
#define NRF5_NVMC_REG(offset)   (NRF5_NVMC_BASE + offset)
 
#define NRF5_UICR_REG(offset)   (NRF5_UICR_BASE + offset)
 
#define WATCHDOG_REFRESH_REGISTER   0x40010600
 
#define WATCHDOG_REFRESH_VALUE   0x6e524635
 

Enumerations

enum  { NRF5_FLASH_BASE = 0x00000000 }
 
enum  nrf5_features { NRF5_FEATURE_SERIES_51 = BIT(0) , NRF5_FEATURE_SERIES_52 = BIT(1) , NRF5_FEATURE_BPROT = BIT(2) , NRF5_FEATURE_ACL_PROT = BIT(3) }
 
enum  nrf5_ficr_registers {
  NRF5_FICR_BASE = 0x10000000 , NRF5_FICR_CODEPAGESIZE = NRF5_FICR_REG(0x010) , NRF5_FICR_CODESIZE = NRF5_FICR_REG(0x014) , NRF51_FICR_CLENR0 = NRF5_FICR_REG(0x028) ,
  NRF51_FICR_PPFC = NRF5_FICR_REG(0x02C) , NRF51_FICR_NUMRAMBLOCK = NRF5_FICR_REG(0x034) , NRF51_FICR_SIZERAMBLOCK0 = NRF5_FICR_REG(0x038) , NRF51_FICR_SIZERAMBLOCK1 = NRF5_FICR_REG(0x03C) ,
  NRF51_FICR_SIZERAMBLOCK2 = NRF5_FICR_REG(0x040) , NRF51_FICR_SIZERAMBLOCK3 = NRF5_FICR_REG(0x044) , NRF5_FICR_CONFIGID = NRF5_FICR_REG(0x05C) , NRF5_FICR_INFO_PART = NRF5_FICR_REG(0x100) ,
  NRF5_FICR_INFO_VARIANT = NRF5_FICR_REG(0x104) , NRF5_FICR_INFO_PACKAGE = NRF5_FICR_REG(0x108) , NRF5_FICR_INFO_RAM = NRF5_FICR_REG(0x10C) , NRF5_FICR_INFO_FLASH = NRF5_FICR_REG(0x110)
}
 
enum  nrf5_nvmc_config_bits { NRF5_NVMC_CONFIG_REN = 0x00 , NRF5_NVMC_CONFIG_WEN = 0x01 , NRF5_NVMC_CONFIG_EEN = 0x02 }
 
enum  nrf5_nvmc_registers {
  NRF5_NVMC_BASE = 0x4001E000 , NRF5_NVMC_READY = NRF5_NVMC_REG(0x400) , NRF5_NVMC_CONFIG = NRF5_NVMC_REG(0x504) , NRF5_NVMC_ERASEPAGE = NRF5_NVMC_REG(0x508) ,
  NRF5_NVMC_ERASEALL = NRF5_NVMC_REG(0x50C) , NRF5_NVMC_ERASEUICR = NRF5_NVMC_REG(0x514) , NRF5_BPROT_BASE = 0x40000000
}
 
enum  nrf5_uicr_registers { NRF5_UICR_BASE = 0x10001000 , NRF51_UICR_CLENR0 = NRF5_UICR_REG(0x000) }
 

Functions

 COMMAND_HANDLER (nrf5_handle_mass_erase_command)
 
 FLASH_BANK_COMMAND_HANDLER (nrf5_flash_bank_command)
 
static int get_nrf5_chip_type_str (const struct nrf5_info *chip, char *buf, unsigned int buf_size)
 
static int nrf5_auto_probe (struct flash_bank *bank)
 
static bool nrf5_bank_is_probed (const struct flash_bank *bank)
 
static const char * nrf5_decode_info_package (uint32_t package)
 
static int nrf5_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int nrf5_erase_all (struct nrf5_info *chip)
 
static int nrf5_erase_page (struct flash_bank *bank, struct nrf5_info *chip, struct flash_sector *sector)
 
static void nrf5_free_driver_priv (struct flash_bank *bank)
 
static struct nrf5_infonrf5_get_chip (struct target *target)
 
static int nrf5_get_ram_size (struct target *target, uint32_t *ram_size)
 
static int nrf5_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static bool nrf5_info_variant_to_str (uint32_t variant, char *bf)
 
static int nrf5_ll_flash_write (struct nrf5_info *chip, uint32_t address, const uint8_t *buffer, uint32_t bytes)
 
static int nrf5_nvmc_erase_enable (struct nrf5_info *chip)
 
static int nrf5_nvmc_generic_erase (struct nrf5_info *chip, uint32_t erase_register, uint32_t erase_value)
 
static int nrf5_nvmc_read_only (struct nrf5_info *chip)
 
static int nrf5_nvmc_write_enable (struct nrf5_info *chip)
 
static int nrf5_probe (struct flash_bank *bank)
 
static int nrf5_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int nrf5_protect_check (struct flash_bank *bank)
 
static int nrf5_protect_check_bprot (struct flash_bank *bank)
 
static int nrf5_protect_check_clenr0 (struct flash_bank *bank)
 
static int nrf5_protect_clenr0 (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int nrf5_read_ficr_info (struct nrf5_info *chip)
 
static int nrf5_wait_for_nvmc (struct nrf5_info *chip)
 
static int nrf5_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 

Variables

const struct flash_driver nrf5_flash nrf51_flash
 
static const struct nrf5_device_package nrf52_packages_table []
 
static const struct command_registration nrf5_command_handlers []
 
static const struct command_registration nrf5_exec_command_handlers []
 
const struct flash_driver nrf5_flash
 
static const struct nrf5_device_spec nrf5_known_devices_table []
 

Macro Definition Documentation

◆ NRF51_DEVICE_DEF

#define NRF51_DEVICE_DEF (   id,
  pt,
  var,
  bcode,
  fsize 
)
Value:
{ \
.hwid = (id), \
.part = pt, \
.variant = var, \
.build_code = bcode, \
.flash_size_kb = (fsize), \
.features = NRF5_FEATURE_SERIES_51, \
}
@ NRF5_FEATURE_SERIES_51
Definition: nrf5.c:98
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
Definition: rtt/rtt.c:32

Definition at line 132 of file nrf5.c.

◆ NRF5_FICR_REG

#define NRF5_FICR_REG (   offset)    (NRF5_FICR_BASE + offset)

Definition at line 33 of file nrf5.c.

◆ NRF5_NVMC_REG

#define NRF5_NVMC_REG (   offset)    (NRF5_NVMC_BASE + offset)

Definition at line 71 of file nrf5.c.

◆ NRF5_UICR_REG

#define NRF5_UICR_REG (   offset)    (NRF5_UICR_BASE + offset)

Definition at line 62 of file nrf5.c.

◆ WATCHDOG_REFRESH_REGISTER

#define WATCHDOG_REFRESH_REGISTER   0x40010600

Definition at line 23 of file nrf5.c.

◆ WATCHDOG_REFRESH_VALUE

#define WATCHDOG_REFRESH_VALUE   0x6e524635

Definition at line 24 of file nrf5.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NRF5_FLASH_BASE 

Definition at line 26 of file nrf5.c.

◆ nrf5_features

Enumerator
NRF5_FEATURE_SERIES_51 
NRF5_FEATURE_SERIES_52 
NRF5_FEATURE_BPROT 
NRF5_FEATURE_ACL_PROT 

Definition at line 97 of file nrf5.c.

◆ nrf5_ficr_registers

Enumerator
NRF5_FICR_BASE 
NRF5_FICR_CODEPAGESIZE 
NRF5_FICR_CODESIZE 
NRF51_FICR_CLENR0 
NRF51_FICR_PPFC 
NRF51_FICR_NUMRAMBLOCK 
NRF51_FICR_SIZERAMBLOCK0 
NRF51_FICR_SIZERAMBLOCK1 
NRF51_FICR_SIZERAMBLOCK2 
NRF51_FICR_SIZERAMBLOCK3 
NRF5_FICR_CONFIGID 
NRF5_FICR_INFO_PART 
NRF5_FICR_INFO_VARIANT 
NRF5_FICR_INFO_PACKAGE 
NRF5_FICR_INFO_RAM 
NRF5_FICR_INFO_FLASH 

Definition at line 30 of file nrf5.c.

◆ nrf5_nvmc_config_bits

Enumerator
NRF5_NVMC_CONFIG_REN 
NRF5_NVMC_CONFIG_WEN 
NRF5_NVMC_CONFIG_EEN 

Definition at line 82 of file nrf5.c.

◆ nrf5_nvmc_registers

Enumerator
NRF5_NVMC_BASE 
NRF5_NVMC_READY 
NRF5_NVMC_CONFIG 
NRF5_NVMC_ERASEPAGE 
NRF5_NVMC_ERASEALL 
NRF5_NVMC_ERASEUICR 
NRF5_BPROT_BASE 

Definition at line 67 of file nrf5.c.

◆ nrf5_uicr_registers

Enumerator
NRF5_UICR_BASE 
NRF51_UICR_CLENR0 

Definition at line 58 of file nrf5.c.

Function Documentation

◆ COMMAND_HANDLER()

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( nrf5_flash_bank_command  )

◆ get_nrf5_chip_type_str()

◆ nrf5_auto_probe()

static int nrf5_auto_probe ( struct flash_bank bank)
static

Definition at line 828 of file nrf5.c.

References bank, ERROR_OK, nrf5_bank_is_probed(), and nrf5_probe().

◆ nrf5_bank_is_probed()

static bool nrf5_bank_is_probed ( const struct flash_bank bank)
static

Definition at line 243 of file nrf5.c.

References bank.

Referenced by nrf5_auto_probe().

◆ nrf5_decode_info_package()

static const char* nrf5_decode_info_package ( uint32_t  package)
static

Definition at line 558 of file nrf5.c.

References ARRAY_SIZE, nrf5_device_package::code, and nrf52_packages_table.

Referenced by get_nrf5_chip_type_str().

◆ nrf5_erase()

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

◆ nrf5_erase_all()

static int nrf5_erase_all ( struct nrf5_info chip)
static

Definition at line 836 of file nrf5.c.

References LOG_DEBUG, NRF5_NVMC_ERASEALL, and nrf5_nvmc_generic_erase().

Referenced by COMMAND_HANDLER().

◆ nrf5_erase_page()

◆ nrf5_free_driver_priv()

static void nrf5_free_driver_priv ( struct flash_bank bank)
static

Definition at line 1092 of file nrf5.c.

References bank, NULL, and nrf5_info::refcount.

◆ nrf5_get_chip()

static struct nrf5_info* nrf5_get_chip ( struct target target)
static

◆ nrf5_get_ram_size()

static int nrf5_get_ram_size ( struct target target,
uint32_t *  ram_size 
)
static

◆ nrf5_info()

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

◆ nrf5_info_variant_to_str()

static bool nrf5_info_variant_to_str ( uint32_t  variant,
char *  bf 
)
static

Definition at line 543 of file nrf5.c.

References h_u32_to_be().

Referenced by get_nrf5_chip_type_str().

◆ nrf5_ll_flash_write()

◆ nrf5_nvmc_erase_enable()

static int nrf5_nvmc_erase_enable ( struct nrf5_info chip)
static

◆ nrf5_nvmc_generic_erase()

static int nrf5_nvmc_generic_erase ( struct nrf5_info chip,
uint32_t  erase_register,
uint32_t  erase_value 
)
static

◆ nrf5_nvmc_read_only()

static int nrf5_nvmc_read_only ( struct nrf5_info chip)
static

◆ nrf5_nvmc_write_enable()

static int nrf5_nvmc_write_enable ( struct nrf5_info chip)
static

◆ nrf5_probe()

◆ nrf5_protect()

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

◆ nrf5_protect_check()

◆ nrf5_protect_check_bprot()

static int nrf5_protect_check_bprot ( struct flash_bank bank)
static

Definition at line 406 of file nrf5.c.

References ARRAY_SIZE, bank, bit(), ERROR_OK, NRF5_BPROT_BASE, nrf5_info::target, and target_read_u32().

Referenced by nrf5_protect_check().

◆ nrf5_protect_check_clenr0()

static int nrf5_protect_check_clenr0 ( struct flash_bank bank)
static

◆ nrf5_protect_clenr0()

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

◆ nrf5_read_ficr_info()

◆ nrf5_wait_for_nvmc()

◆ nrf5_write()

Variable Documentation

◆ nrf51_flash

const struct flash_driver nrf51_flash
Initial value:
= {
.name = "nrf51",
.commands = nrf5_command_handlers,
.flash_bank_command = nrf5_flash_bank_command,
.info = nrf5_info,
.erase = nrf5_erase,
.protect = nrf5_protect,
.write = nrf5_write,
.probe = nrf5_probe,
.auto_probe = nrf5_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = nrf5_protect_check,
.free_driver_priv = nrf5_free_driver_priv,
}
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.
static int nrf5_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: nrf5.c:517
static int nrf5_auto_probe(struct flash_bank *bank)
Definition: nrf5.c:828
static int nrf5_probe(struct flash_bank *bank)
Definition: nrf5.c:711
static const struct command_registration nrf5_command_handlers[]
Definition: nrf5.c:1238
static int nrf5_protect_check(struct flash_bank *bank)
Definition: nrf5.c:433
static int nrf5_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: nrf5.c:983
static int nrf5_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: nrf5.c:592
static int nrf5_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: nrf5.c:1045
static void nrf5_free_driver_priv(struct flash_bank *bank)
Definition: nrf5.c:1092

Definition at line 1 of file nrf5.c.

Referenced by FLASH_BANK_COMMAND_HANDLER(), and nrf5_get_chip().

◆ nrf52_packages_table

const struct nrf5_device_package nrf52_packages_table[]
static
Initial value:
= {
{ 0x2000, "QF" },
{ 0x2001, "CH" },
{ 0x2002, "CI" },
{ 0x2003, "QC" },
{ 0x2004, "QI/CA" },
{ 0x2005, "CK" },
{ 0x2007, "QD" },
{ 0x2008, "CJ" },
{ 0x2009, "CF" },
}

Definition at line 1 of file nrf5.c.

Referenced by nrf5_decode_info_package().

◆ nrf5_command_handlers

const struct command_registration nrf5_command_handlers[]
static
Initial value:
= {
{
.name = "nrf5",
.mode = COMMAND_ANY,
.help = "nrf5 flash command group",
.usage = "",
},
{
.name = "nrf51",
.mode = COMMAND_ANY,
.help = "nrf51 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 nrf5_exec_command_handlers[]
Definition: nrf5.c:1227
const char * name
Definition: command.h:235

Definition at line 1175 of file nrf5.c.

◆ nrf5_exec_command_handlers

const struct command_registration nrf5_exec_command_handlers[]
static
Initial value:
= {
{
.name = "mass_erase",
.handler = nrf5_handle_mass_erase_command,
.mode = COMMAND_EXEC,
.help = "Erase all flash contents of the chip.",
.usage = "",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 1175 of file nrf5.c.

◆ nrf5_flash

const struct flash_driver nrf5_flash
Initial value:
= {
.name = "nrf5",
.commands = nrf5_command_handlers,
.flash_bank_command = nrf5_flash_bank_command,
.info = nrf5_info,
.erase = nrf5_erase,
.protect = nrf5_protect,
.write = nrf5_write,
.probe = nrf5_probe,
.auto_probe = nrf5_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = nrf5_protect_check,
.free_driver_priv = nrf5_free_driver_priv,
}

Definition at line 1175 of file nrf5.c.

Referenced by nrf5_get_chip().

◆ nrf5_known_devices_table

const struct nrf5_device_spec nrf5_known_devices_table[]
static

Definition at line 1 of file nrf5.c.

Referenced by nrf5_probe().