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_ficr_map
 
struct  nrf5_info
 
struct  nrf5_map
 

Macros

#define NRF51_DEVICE_DEF(id, pt, var, bcode, fsize)
 
#define NRF5_FICR_REG(offset)   (NRF51_52_FICR_BASE + (offset))
 
#define NRF5_UICR_REG(offset)   (NRF51_52_UICR_BASE + (offset))
 
#define WATCHDOG_REFRESH_VALUE   0x6e524635
 

Enumerations

enum  { NRF5_FLASH_BASE = 0x00000000 }
 
enum  {
  NRF53APP_91_FICR_BASE = 0x00FF0000 , NRF53APP_91_UICR_BASE = 0x00FF8000 , NRF53NET_FLASH_BASE = 0x01000000 , NRF53NET_FICR_BASE = 0x01FF0000 ,
  NRF53NET_UICR_BASE = 0x01FF8000
}
 
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) ,
  NRF5_FEATURE_SERIES_53 = BIT(4) , NRF5_FEATURE_SERIES_91 = BIT(5) , NRF5_FEATURE_ERASE_BY_FLASH_WR = BIT(6)
}
 
enum  nrf5_ficr_registers {
  NRF51_52_FICR_BASE = 0x10000000 , 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)
}
 
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_READY = 0x400 , NRF5_NVMC_CONFIG = 0x504 , NRF5_NVMC_ERASEPAGE = 0x508 , NRF5_NVMC_ERASEALL = 0x50C ,
  NRF5_NVMC_ERASEUICR = 0x514 , NRF5_BPROT_BASE = 0x40000000
}
 
enum  nrf5_uicr_registers { NRF51_52_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 nrf51_52_partno_check (struct nrf5_info *chip)
 
static int nrf51_get_ram_size (struct target *target, uint32_t *ram_size)
 
static int nrf51_protect_check_clenr0 (struct flash_bank *bank)
 
static int nrf51_protect_clenr0 (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int nrf52_protect_check_bprot (struct flash_bank *bank)
 
static int nrf53_91_partno_check (struct nrf5_info *chip)
 
static int nrf5_auto_probe (struct flash_bank *bank)
 
static bool nrf5_bank_is_probed (const struct flash_bank *bank)
 
static bool nrf5_bank_is_uicr (const struct nrf5_bank *nbank)
 
static bool nrf5_chip_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_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_chip_type_str (const struct nrf5_info *chip, char *buf, unsigned int buf_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, bool swap)
 
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_read_only (struct nrf5_info *chip)
 
static int nrf5_nvmc_read_u32 (struct nrf5_info *chip, uint32_t reg_offset, uint32_t *value)
 
static int nrf5_nvmc_write_enable (struct nrf5_info *chip)
 
static int nrf5_nvmc_write_u32 (struct nrf5_info *chip, uint32_t reg_offset, uint32_t value)
 
static int nrf5_probe (struct flash_bank *bank)
 
static int nrf5_probe_chip (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_read_ficr_info_part (struct nrf5_info *chip, const struct nrf5_map *map, const struct nrf5_ficr_map *ficr_offsets)
 
static int nrf5_read_ficr_more_info (struct nrf5_info *chip)
 
static int nrf5_setup_bank (struct flash_bank *bank)
 
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

static const struct nrf5_ficr_map nrf51_52_ficr_offsets
 
static const struct nrf5_map nrf51_52_map
 
const struct flash_driver nrf5_flash nrf51_flash
 
static const struct nrf5_device_package nrf52_packages_table []
 
static const struct nrf5_ficr_map nrf53_91_ficr_offsets
 
static const struct nrf5_map nrf53app_91_map
 
static const struct nrf5_map nrf53net_map
 
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_ficr_map nrf91new_ficr_offsets
 

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:78
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
Definition: rtt/rtt.c:32

Definition at line 144 of file nrf5.c.

◆ NRF5_FICR_REG

#define NRF5_FICR_REG (   offset)    (NRF51_52_FICR_BASE + (offset))

Definition at line 32 of file nrf5.c.

◆ NRF5_UICR_REG

#define NRF5_UICR_REG (   offset)    (NRF51_52_UICR_BASE + (offset))

Definition at line 47 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.

◆ anonymous enum

anonymous enum
Enumerator
NRF53APP_91_FICR_BASE 
NRF53APP_91_UICR_BASE 
NRF53NET_FLASH_BASE 
NRF53NET_FICR_BASE 
NRF53NET_UICR_BASE 

Definition at line 308 of file nrf5.c.

◆ nrf5_features

Enumerator
NRF5_FEATURE_SERIES_51 
NRF5_FEATURE_SERIES_52 
NRF5_FEATURE_BPROT 
NRF5_FEATURE_ACL_PROT 
NRF5_FEATURE_SERIES_53 
NRF5_FEATURE_SERIES_91 
NRF5_FEATURE_ERASE_BY_FLASH_WR 

Definition at line 77 of file nrf5.c.

◆ nrf5_ficr_registers

Enumerator
NRF51_52_FICR_BASE 
NRF51_FICR_CLENR0 
NRF51_FICR_PPFC 
NRF51_FICR_NUMRAMBLOCK 
NRF51_FICR_SIZERAMBLOCK0 
NRF51_FICR_SIZERAMBLOCK1 
NRF51_FICR_SIZERAMBLOCK2 
NRF51_FICR_SIZERAMBLOCK3 

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 62 of file nrf5.c.

◆ nrf5_nvmc_registers

Enumerator
NRF5_NVMC_READY 
NRF5_NVMC_CONFIG 
NRF5_NVMC_ERASEPAGE 
NRF5_NVMC_ERASEALL 
NRF5_NVMC_ERASEUICR 
NRF5_BPROT_BASE 

Definition at line 52 of file nrf5.c.

◆ nrf5_uicr_registers

Enumerator
NRF51_52_UICR_BASE 
NRF51_UICR_CLENR0 

Definition at line 43 of file nrf5.c.

Function Documentation

◆ COMMAND_HANDLER()

◆ FLASH_BANK_COMMAND_HANDLER()

◆ nrf51_52_partno_check()

◆ nrf51_get_ram_size()

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

◆ nrf51_protect_check_clenr0()

static int nrf51_protect_check_clenr0 ( struct flash_bank bank)
static

◆ nrf51_protect_clenr0()

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

◆ nrf52_protect_check_bprot()

static int nrf52_protect_check_bprot ( struct flash_bank bank)
static

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

◆ nrf53_91_partno_check()

◆ nrf5_auto_probe()

static int nrf5_auto_probe ( struct flash_bank bank)
static

◆ nrf5_bank_is_probed()

static bool nrf5_bank_is_probed ( const struct flash_bank bank)
static

Definition at line 345 of file nrf5.c.

References bank.

Referenced by nrf5_auto_probe().

◆ nrf5_bank_is_uicr()

static bool nrf5_bank_is_uicr ( const struct nrf5_bank *  nbank)
static

Definition at line 358 of file nrf5.c.

References nrf5_info::bank.

Referenced by nrf5_protect(), and nrf5_protect_check().

◆ nrf5_chip_is_probed()

static bool nrf5_chip_is_probed ( const struct flash_bank bank)
static

Definition at line 351 of file nrf5.c.

References bank, and nrf5_info::chip_probed.

Referenced by nrf5_auto_probe().

◆ nrf5_decode_info_package()

static const char* nrf5_decode_info_package ( uint32_t  package)
static

Definition at line 656 of file nrf5.c.

References ARRAY_SIZE, nrf5_device_package::code, and nrf52_packages_table.

Referenced by nrf5_get_chip_type_str().

◆ nrf5_erase()

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

◆ nrf5_erase_page()

◆ nrf5_free_driver_priv()

static void nrf5_free_driver_priv ( struct flash_bank bank)
static

Definition at line 1335 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_chip_type_str()

◆ nrf5_info()

◆ nrf5_info_variant_to_str()

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

Definition at line 636 of file nrf5.c.

References h_u32_to_be(), and h_u32_to_le().

Referenced by nrf5_get_chip_type_str().

◆ nrf5_ll_flash_write()

◆ nrf5_nvmc_erase_enable()

static int nrf5_nvmc_erase_enable ( struct nrf5_info chip)
static

◆ nrf5_nvmc_read_only()

static int nrf5_nvmc_read_only ( struct nrf5_info chip)
static

◆ nrf5_nvmc_read_u32()

static int nrf5_nvmc_read_u32 ( struct nrf5_info chip,
uint32_t  reg_offset,
uint32_t *  value 
)
static

Definition at line 364 of file nrf5.c.

References nrf5_info::map, nrf5_map::nvmc_base, nrf5_info::target, and target_read_u32().

Referenced by nrf5_wait_for_nvmc().

◆ nrf5_nvmc_write_enable()

static int nrf5_nvmc_write_enable ( struct nrf5_info chip)
static

◆ nrf5_nvmc_write_u32()

static int nrf5_nvmc_write_u32 ( struct nrf5_info chip,
uint32_t  reg_offset,
uint32_t  value 
)
static

◆ nrf5_probe()

static int nrf5_probe ( struct flash_bank bank)
static

Definition at line 1039 of file nrf5.c.

References bank, ERROR_OK, nrf5_probe_chip(), and nrf5_setup_bank().

◆ nrf5_probe_chip()

◆ nrf5_protect()

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

◆ nrf5_protect_check()

◆ nrf5_read_ficr_info_part()

static int nrf5_read_ficr_info_part ( struct nrf5_info chip,
const struct nrf5_map map,
const struct nrf5_ficr_map ficr_offsets 
)
static

◆ nrf5_read_ficr_more_info()

◆ nrf5_setup_bank()

◆ nrf5_wait_for_nvmc()

◆ nrf5_write()

Variable Documentation

◆ nrf51_52_ficr_offsets

const struct nrf5_ficr_map nrf51_52_ficr_offsets
static
Initial value:
= {
.codepagesize = 0x10,
.codesize = 0x14,
.configid = 0x5c,
.info_part = 0x100,
.info_variant = 0x104,
.info_package = 0x108,
.info_ram = 0x10c,
.info_flash = 0x110,
}

Definition at line 1 of file nrf5.c.

Referenced by nrf5_probe_chip().

◆ nrf51_52_map

const struct nrf5_map nrf51_52_map
static
Initial value:
= {
.flash_base = NRF5_FLASH_BASE,
.ficr_base = NRF51_52_FICR_BASE,
.uicr_base = NRF51_52_UICR_BASE,
.nvmc_base = 0x4001E000,
.watchdog_refresh_addr = 0x40010600,
}
@ NRF51_52_UICR_BASE
Definition: nrf5.c:44
@ NRF5_FLASH_BASE
Definition: nrf5.c:26
@ NRF51_52_FICR_BASE
Definition: nrf5.c:30

Definition at line 1 of file nrf5.c.

Referenced by nrf5_probe_chip().

◆ 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:612
static int nrf5_auto_probe(struct flash_bank *bank)
Definition: nrf5.c:1049
static int nrf5_probe(struct flash_bank *bank)
Definition: nrf5.c:1039
static const struct command_registration nrf5_command_handlers[]
Definition: nrf5.c:1495
static int nrf5_protect_check(struct flash_bank *bank)
Definition: nrf5.c:531
static int nrf5_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: nrf5.c:1223
static int nrf5_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: nrf5.c:698
static int nrf5_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: nrf5.c:1283
static void nrf5_free_driver_priv(struct flash_bank *bank)
Definition: nrf5.c:1335

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().

◆ nrf53_91_ficr_offsets

const struct nrf5_ficr_map nrf53_91_ficr_offsets
static
Initial value:
= {
.codepagesize = 0x220,
.codesize = 0x224,
.configid = 0x200,
.info_part = 0x20c,
.info_variant = 0x210,
.info_package = 0x214,
.info_ram = 0x218,
.info_flash = 0x21c,
}

Definition at line 1 of file nrf5.c.

Referenced by nrf5_probe_chip().

◆ nrf53app_91_map

const struct nrf5_map nrf53app_91_map
static
Initial value:
= {
.flash_base = NRF5_FLASH_BASE,
.ficr_base = NRF53APP_91_FICR_BASE,
.uicr_base = NRF53APP_91_UICR_BASE,
.nvmc_base = 0x50039000,
.watchdog_refresh_addr = 0x50018600,
}
@ NRF53APP_91_FICR_BASE
Definition: nrf5.c:309
@ NRF53APP_91_UICR_BASE
Definition: nrf5.c:310

Definition at line 1 of file nrf5.c.

Referenced by nrf5_probe_chip().

◆ nrf53net_map

const struct nrf5_map nrf53net_map
static
Initial value:
= {
.flash_base = NRF53NET_FLASH_BASE,
.ficr_base = NRF53NET_FICR_BASE,
.uicr_base = NRF53NET_UICR_BASE,
.nvmc_base = 0x41080000,
.watchdog_refresh_addr = 0x41080000,
}
@ NRF53NET_FLASH_BASE
Definition: nrf5.c:311
@ NRF53NET_UICR_BASE
Definition: nrf5.c:313
@ NRF53NET_FICR_BASE
Definition: nrf5.c:312

Definition at line 1 of file nrf5.c.

Referenced by nrf5_probe_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:253
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration nrf5_exec_command_handlers[]
Definition: nrf5.c:1484
const char * name
Definition: command.h:235

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

◆ nrf91new_ficr_offsets

const struct nrf5_ficr_map nrf91new_ficr_offsets
static
Initial value:
= {
.codepagesize = 0x220,
.codesize = 0x224,
.configid = 0x200,
.info_part = 0x140,
.info_variant = 0x148,
.info_package = 0x214,
.info_ram = 0x218,
.info_flash = 0x21c,
}

Definition at line 1 of file nrf5.c.

Referenced by nrf5_probe_chip().