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_DEVICE_DEF(id, pt, var, bcode, fsize, features)
 
#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 = 1 << 0 , NRF5_FEATURE_SERIES_52 = 1 << 1 , NRF5_FEATURE_BPROT = 1 << 2 , NRF5_FEATURE_ACL_PROT = 1 << 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_DEVICEID0 = NRF5_FICR_REG(0x060) ,
  NRF5_FICR_DEVICEID1 = NRF5_FICR_REG(0x064) , NRF5_FICR_ER0 = NRF5_FICR_REG(0x080) , NRF5_FICR_ER1 = NRF5_FICR_REG(0x084) , NRF5_FICR_ER2 = NRF5_FICR_REG(0x088) ,
  NRF5_FICR_ER3 = NRF5_FICR_REG(0x08C) , NRF5_FICR_IR0 = NRF5_FICR_REG(0x090) , NRF5_FICR_IR1 = NRF5_FICR_REG(0x094) , NRF5_FICR_IR2 = NRF5_FICR_REG(0x098) ,
  NRF5_FICR_IR3 = NRF5_FICR_REG(0x09C) , NRF5_FICR_DEVICEADDRTYPE = NRF5_FICR_REG(0x0A0) , NRF5_FICR_DEVICEADDR0 = NRF5_FICR_REG(0x0A4) , NRF5_FICR_DEVICEADDR1 = NRF5_FICR_REG(0x0A8) ,
  NRF51_FICR_OVERRIDEN = NRF5_FICR_REG(0x0AC) , NRF51_FICR_NRF_1MBIT0 = NRF5_FICR_REG(0x0B0) , NRF51_FICR_NRF_1MBIT1 = NRF5_FICR_REG(0x0B4) , NRF51_FICR_NRF_1MBIT2 = NRF5_FICR_REG(0x0B8) ,
  NRF51_FICR_NRF_1MBIT3 = NRF5_FICR_REG(0x0BC) , NRF51_FICR_NRF_1MBIT4 = NRF5_FICR_REG(0x0C0) , NRF51_FICR_BLE_1MBIT0 = NRF5_FICR_REG(0x0EC) , NRF51_FICR_BLE_1MBIT1 = NRF5_FICR_REG(0x0F0) ,
  NRF51_FICR_BLE_1MBIT2 = NRF5_FICR_REG(0x0F4) , NRF51_FICR_BLE_1MBIT3 = NRF5_FICR_REG(0x0F8) , NRF51_FICR_BLE_1MBIT4 = NRF5_FICR_REG(0x0FC) , 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) , NRF51_UICR_RBPCONF = NRF5_UICR_REG(0x004) , NRF51_UICR_XTALFREQ = NRF5_UICR_REG(0x008) ,
  NRF51_UICR_FWID = NRF5_UICR_REG(0x010)
}
 

Functions

 COMMAND_HANDLER (nrf5_handle_info_command)
 
 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_probed_chip_if_halted (struct flash_bank *bank, struct nrf5_info **chip)
 
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 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 []
 
static const struct nrf5_device_package nrf5_packages_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:123
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
Definition: rtt/rtt.c:32

Definition at line 157 of file nrf5.c.

◆ NRF5_DEVICE_DEF

#define NRF5_DEVICE_DEF (   id,
  pt,
  var,
  bcode,
  fsize,
  features 
)
Value:
{ \
.hwid = (id), \
.part = pt, \
.variant = var, \
.build_code = bcode, \
.flash_size_kb = (fsize), \
.features = features, \
}

Definition at line 167 of file nrf5.c.

◆ NRF5_FICR_REG

#define NRF5_FICR_REG (   offset)    (NRF5_FICR_BASE + offset)

Definition at line 32 of file nrf5.c.

◆ NRF5_NVMC_REG

#define NRF5_NVMC_REG (   offset)    (NRF5_NVMC_BASE + offset)

Definition at line 96 of file nrf5.c.

◆ NRF5_UICR_REG

#define NRF5_UICR_REG (   offset)    (NRF5_UICR_BASE + offset)

Definition at line 84 of file nrf5.c.

◆ WATCHDOG_REFRESH_REGISTER

#define WATCHDOG_REFRESH_REGISTER   0x40010600

Definition at line 22 of file nrf5.c.

◆ WATCHDOG_REFRESH_VALUE

#define WATCHDOG_REFRESH_VALUE   0x6e524635

Definition at line 23 of file nrf5.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NRF5_FLASH_BASE 

Definition at line 25 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 122 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_DEVICEID0 
NRF5_FICR_DEVICEID1 
NRF5_FICR_ER0 
NRF5_FICR_ER1 
NRF5_FICR_ER2 
NRF5_FICR_ER3 
NRF5_FICR_IR0 
NRF5_FICR_IR1 
NRF5_FICR_IR2 
NRF5_FICR_IR3 
NRF5_FICR_DEVICEADDRTYPE 
NRF5_FICR_DEVICEADDR0 
NRF5_FICR_DEVICEADDR1 
NRF51_FICR_OVERRIDEN 
NRF51_FICR_NRF_1MBIT0 
NRF51_FICR_NRF_1MBIT1 
NRF51_FICR_NRF_1MBIT2 
NRF51_FICR_NRF_1MBIT3 
NRF51_FICR_NRF_1MBIT4 
NRF51_FICR_BLE_1MBIT0 
NRF51_FICR_BLE_1MBIT1 
NRF51_FICR_BLE_1MBIT2 
NRF51_FICR_BLE_1MBIT3 
NRF51_FICR_BLE_1MBIT4 
NRF5_FICR_INFO_PART 
NRF5_FICR_INFO_VARIANT 
NRF5_FICR_INFO_PACKAGE 
NRF5_FICR_INFO_RAM 
NRF5_FICR_INFO_FLASH 

Definition at line 29 of file nrf5.c.

◆ nrf5_nvmc_config_bits

Enumerator
NRF5_NVMC_CONFIG_REN 
NRF5_NVMC_CONFIG_WEN 
NRF5_NVMC_CONFIG_EEN 

Definition at line 107 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 92 of file nrf5.c.

◆ nrf5_uicr_registers

Enumerator
NRF5_UICR_BASE 
NRF51_UICR_CLENR0 
NRF51_UICR_RBPCONF 
NRF51_UICR_XTALFREQ 
NRF51_UICR_FWID 

Definition at line 80 of file nrf5.c.

Function Documentation

◆ COMMAND_HANDLER() [1/2]

◆ COMMAND_HANDLER() [2/2]

◆ 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 869 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 282 of file nrf5.c.

References bank.

Referenced by nrf5_auto_probe(), and nrf5_get_probed_chip_if_halted().

◆ nrf5_decode_info_package()

static const char* nrf5_decode_info_package ( uint32_t  package)
static

Definition at line 608 of file nrf5.c.

References ARRAY_SIZE, nrf5_device_package::code, and nrf5_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 877 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 1122 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_probed_chip_if_halted()

static int nrf5_get_probed_chip_if_halted ( struct flash_bank bank,
struct nrf5_info **  chip 
)
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 593 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 462 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:570
static int nrf5_auto_probe(struct flash_bank *bank)
Definition: nrf5.c:869
static int nrf5_probe(struct flash_bank *bank)
Definition: nrf5.c:755
static const struct command_registration nrf5_command_handlers[]
Definition: nrf5.c:1398
static int nrf5_protect_check(struct flash_bank *bank)
Definition: nrf5.c:489
static int nrf5_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: nrf5.c:1024
static int nrf5_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: nrf5.c:642
static int nrf5_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: nrf5.c:1080
static void nrf5_free_driver_priv(struct flash_bank *bank)
Definition: nrf5.c:1122

Definition at line 1 of file nrf5.c.

Referenced by nrf5_get_chip().

◆ 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:247
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration nrf5_exec_command_handlers[]
Definition: nrf5.c:1380
const char * name
Definition: command.h:229

Definition at line 1248 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 = "",
},
{
.name = "info",
.handler = nrf5_handle_info_command,
.mode = COMMAND_EXEC,
.help = "Show FICR and UICR info.",
.usage = "",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 1248 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 1248 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().

◆ nrf5_packages_table

const struct nrf5_device_package nrf5_packages_table[]
static
Initial value:
= {
{ 0x2000, "QF" },
{ 0x2001, "CH" },
{ 0x2002, "CI" },
{ 0x2005, "CK" },
}

Definition at line 1 of file nrf5.c.

Referenced by nrf5_decode_info_package().