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

Go to the source code of this file.

Data Structures

struct  nrf51_device_spec
 
struct  nrf51_info
 

Macros

#define NRF51_FICR_REG(offset)   (NRF51_FICR_BASE + offset)
 
#define NRF51_NVMC_REG(offset)   (NRF51_NVMC_BASE + offset)
 
#define NRF51_UICR_REG(offset)   (NRF51_UICR_BASE + offset)
 

Enumerations

enum  { NRF51_FLASH_BASE = 0x00000000 }
 
enum  nrf51_ficr_registers {
  NRF51_FICR_BASE = 0x10000000, NRF51_FICR_CODEPAGESIZE = NRF51_FICR_REG(0x010), NRF51_FICR_CODESIZE = NRF51_FICR_REG(0x014), NRF51_FICR_CLENR0 = NRF51_FICR_REG(0x028),
  NRF51_FICR_PPFC = NRF51_FICR_REG(0x02C), NRF51_FICR_NUMRAMBLOCK = NRF51_FICR_REG(0x034), NRF51_FICR_SIZERAMBLOCK0 = NRF51_FICR_REG(0x038), NRF51_FICR_SIZERAMBLOCK1 = NRF51_FICR_REG(0x03C),
  NRF51_FICR_SIZERAMBLOCK2 = NRF51_FICR_REG(0x040), NRF51_FICR_SIZERAMBLOCK3 = NRF51_FICR_REG(0x044), NRF51_FICR_CONFIGID = NRF51_FICR_REG(0x05C), NRF51_FICR_DEVICEID0 = NRF51_FICR_REG(0x060),
  NRF51_FICR_DEVICEID1 = NRF51_FICR_REG(0x064), NRF51_FICR_ER0 = NRF51_FICR_REG(0x080), NRF51_FICR_ER1 = NRF51_FICR_REG(0x084), NRF51_FICR_ER2 = NRF51_FICR_REG(0x088),
  NRF51_FICR_ER3 = NRF51_FICR_REG(0x08C), NRF51_FICR_IR0 = NRF51_FICR_REG(0x090), NRF51_FICR_IR1 = NRF51_FICR_REG(0x094), NRF51_FICR_IR2 = NRF51_FICR_REG(0x098),
  NRF51_FICR_IR3 = NRF51_FICR_REG(0x09C), NRF51_FICR_DEVICEADDRTYPE = NRF51_FICR_REG(0x0A0), NRF51_FICR_DEVICEADDR0 = NRF51_FICR_REG(0x0A4), NRF51_FICR_DEVICEADDR1 = NRF51_FICR_REG(0x0A8),
  NRF51_FICR_OVERRIDEN = NRF51_FICR_REG(0x0AC), NRF51_FICR_NRF_1MBIT0 = NRF51_FICR_REG(0x0B0), NRF51_FICR_NRF_1MBIT1 = NRF51_FICR_REG(0x0B4), NRF51_FICR_NRF_1MBIT2 = NRF51_FICR_REG(0x0B8),
  NRF51_FICR_NRF_1MBIT3 = NRF51_FICR_REG(0x0BC), NRF51_FICR_NRF_1MBIT4 = NRF51_FICR_REG(0x0C0), NRF51_FICR_BLE_1MBIT0 = NRF51_FICR_REG(0x0EC), NRF51_FICR_BLE_1MBIT1 = NRF51_FICR_REG(0x0F0),
  NRF51_FICR_BLE_1MBIT2 = NRF51_FICR_REG(0x0F4), NRF51_FICR_BLE_1MBIT3 = NRF51_FICR_REG(0x0F8), NRF51_FICR_BLE_1MBIT4 = NRF51_FICR_REG(0x0FC)
}
 
enum  nrf51_nvmc_config_bits { NRF51_NVMC_CONFIG_REN = 0x00, NRF51_NVMC_CONFIG_WEN = 0x01, NRF51_NVMC_CONFIG_EEN = 0x02 }
 
enum  nrf51_nvmc_registers {
  NRF51_NVMC_BASE = 0x4001E000, NRF51_NVMC_READY = NRF51_NVMC_REG(0x400), NRF51_NVMC_CONFIG = NRF51_NVMC_REG(0x504), NRF51_NVMC_ERASEPAGE = NRF51_NVMC_REG(0x508),
  NRF51_NVMC_ERASEALL = NRF51_NVMC_REG(0x50C), NRF51_NVMC_ERASEUICR = NRF51_NVMC_REG(0x514)
}
 
enum  nrf51_uicr_registers {
  NRF51_UICR_BASE = 0x10001000, NRF51_UICR_SIZE = 0x100, NRF51_UICR_CLENR0 = NRF51_UICR_REG(0x000), NRF51_UICR_RBPCONF = NRF51_UICR_REG(0x004),
  NRF51_UICR_XTALFREQ = NRF51_UICR_REG(0x008), NRF51_UICR_FWID = NRF51_UICR_REG(0x010)
}
 

Functions

 COMMAND_HANDLER (nrf51_handle_mass_erase_command)
 
 FLASH_BANK_COMMAND_HANDLER (nrf51_flash_bank_command)
 
static int nrf51_auto_probe (struct flash_bank *bank)
 
static int nrf51_bank_is_probed (struct flash_bank *bank)
 
static int nrf51_code_flash_write (struct flash_bank *bank, struct nrf51_info *chip, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int nrf51_erase (struct flash_bank *bank, int first, int last)
 
static int nrf51_erase_all (struct nrf51_info *chip)
 
static int nrf51_erase_page (struct flash_bank *bank, struct nrf51_info *chip, struct flash_sector *sector)
 
static struct flash_sectornrf51_find_sector_by_address (struct flash_bank *bank, uint32_t address)
 
static int nrf51_get_probed_chip_if_halted (struct flash_bank *bank, struct nrf51_info **chip)
 
static int nrf51_info (struct flash_bank *bank, char *buf, int buf_size)
 
static int nrf51_ll_flash_write (struct nrf51_info *chip, uint32_t offset, const uint8_t *buffer, uint32_t bytes)
 
static int nrf51_nvmc_erase_enable (struct nrf51_info *chip)
 
static int nrf51_nvmc_generic_erase (struct nrf51_info *chip, uint32_t erase_register, uint32_t erase_value)
 
static int nrf51_nvmc_read_only (struct nrf51_info *chip)
 
static int nrf51_nvmc_write_enable (struct nrf51_info *chip)
 
static int nrf51_probe (struct flash_bank *bank)
 
static int nrf51_protect (struct flash_bank *bank, int set, int first, int last)
 
static int nrf51_protect_check (struct flash_bank *bank)
 
static int nrf51_uicr_flash_write (struct flash_bank *bank, struct nrf51_info *chip, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int nrf51_wait_for_nvmc (struct nrf51_info *chip)
 
static int nrf51_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int nrf51_write_pages (struct flash_bank *bank, uint32_t start, uint32_t end, const uint8_t *buffer)
 

Variables

static const struct command_registration nrf51_command_handlers []
 
static const struct command_registration nrf51_exec_command_handlers []
 
struct flash_driver nrf51_flash
 
static const uint8_t nrf51_flash_write_code []
 
static const struct nrf51_device_spec nrf51_known_devices_table []
 

Macro Definition Documentation

#define NRF51_FICR_REG (   offset)    (NRF51_FICR_BASE + offset)

Definition at line 37 of file nrf51.c.

#define NRF51_NVMC_REG (   offset)    (NRF51_NVMC_BASE + offset)

Definition at line 93 of file nrf51.c.

#define NRF51_UICR_REG (   offset)    (NRF51_UICR_BASE + offset)

Definition at line 81 of file nrf51.c.

Enumeration Type Documentation

anonymous enum
Enumerator
NRF51_FLASH_BASE 

Definition at line 30 of file nrf51.c.

Enumerator
NRF51_FICR_BASE 
NRF51_FICR_CODEPAGESIZE 
NRF51_FICR_CODESIZE 
NRF51_FICR_CLENR0 
NRF51_FICR_PPFC 
NRF51_FICR_NUMRAMBLOCK 
NRF51_FICR_SIZERAMBLOCK0 
NRF51_FICR_SIZERAMBLOCK1 
NRF51_FICR_SIZERAMBLOCK2 
NRF51_FICR_SIZERAMBLOCK3 
NRF51_FICR_CONFIGID 
NRF51_FICR_DEVICEID0 
NRF51_FICR_DEVICEID1 
NRF51_FICR_ER0 
NRF51_FICR_ER1 
NRF51_FICR_ER2 
NRF51_FICR_ER3 
NRF51_FICR_IR0 
NRF51_FICR_IR1 
NRF51_FICR_IR2 
NRF51_FICR_IR3 
NRF51_FICR_DEVICEADDRTYPE 
NRF51_FICR_DEVICEADDR0 
NRF51_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 

Definition at line 34 of file nrf51.c.

Enumerator
NRF51_NVMC_CONFIG_REN 
NRF51_NVMC_CONFIG_WEN 
NRF51_NVMC_CONFIG_EEN 

Definition at line 102 of file nrf51.c.

Enumerator
NRF51_NVMC_BASE 
NRF51_NVMC_READY 
NRF51_NVMC_CONFIG 
NRF51_NVMC_ERASEPAGE 
NRF51_NVMC_ERASEALL 
NRF51_NVMC_ERASEUICR 

Definition at line 89 of file nrf51.c.

Enumerator
NRF51_UICR_BASE 
NRF51_UICR_SIZE 
NRF51_UICR_CLENR0 
NRF51_UICR_RBPCONF 
NRF51_UICR_XTALFREQ 
NRF51_UICR_FWID 

Definition at line 75 of file nrf51.c.

Function Documentation

static int nrf51_auto_probe ( struct flash_bank bank)
static

Definition at line 745 of file nrf51.c.

References ERROR_OK, nrf51_bank_is_probed(), nrf51_probe(), and nrf51_info::probed.

static int nrf51_bank_is_probed ( struct flash_bank bank)
static
static int nrf51_code_flash_write ( struct flash_bank bank,
struct nrf51_info chip,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static
static int nrf51_erase ( struct flash_bank bank,
int  first,
int  last 
)
static
static int nrf51_erase_all ( struct nrf51_info chip)
static

Definition at line 768 of file nrf51.c.

References LOG_DEBUG, NRF51_NVMC_ERASEALL, and nrf51_nvmc_generic_erase().

Referenced by COMMAND_HANDLER().

static struct flash_sector* nrf51_find_sector_by_address ( struct flash_bank bank,
uint32_t  address 
)
static
static int nrf51_get_probed_chip_if_halted ( struct flash_bank bank,
struct nrf51_info **  chip 
)
static
static int nrf51_nvmc_erase_enable ( struct nrf51_info chip)
static
static int nrf51_nvmc_generic_erase ( struct nrf51_info chip,
uint32_t  erase_register,
uint32_t  erase_value 
)
static
static int nrf51_nvmc_read_only ( struct nrf51_info chip)
static
static int nrf51_nvmc_write_enable ( struct nrf51_info chip)
static
static int nrf51_protect ( struct flash_bank bank,
int  set,
int  first,
int  last 
)
static
static int nrf51_uicr_flash_write ( struct flash_bank bank,
struct nrf51_info chip,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static
static int nrf51_write ( struct flash_bank bank,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

Variable Documentation

const struct command_registration nrf51_command_handlers[]
static
Initial value:
= {
{
.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:222
static const struct command_registration nrf51_exec_command_handlers[]
Definition: nrf51.c:1338

Definition at line 1348 of file nrf51.c.

const struct command_registration nrf51_exec_command_handlers[]
static
Initial value:
= {
{
.name = "mass_erase",
.handler = nrf51_handle_mass_erase_command,
.mode = COMMAND_EXEC,
.help = "Erase all flash contents of the chip.",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:222

Definition at line 1338 of file nrf51.c.

struct flash_driver nrf51_flash
Initial value:
= {
.name = "nrf51",
.flash_bank_command = nrf51_flash_bank_command,
.info = nrf51_info,
.erase = nrf51_erase,
.protect = nrf51_protect,
.write = nrf51_write,
.probe = nrf51_probe,
.auto_probe = nrf51_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = nrf51_protect_check,
}
static int nrf51_erase(struct flash_bank *bank, int first, int last)
Definition: nrf51.c:993
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 nrf51_protect_check(struct flash_bank *bank)
Definition: nrf51.c:559
static int nrf51_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: nrf51.c:1102
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
static int nrf51_probe(struct flash_bank *bank)
Definition: nrf51.c:650
static int nrf51_auto_probe(struct flash_bank *bank)
Definition: nrf51.c:745
static int nrf51_info(struct flash_bank *bank, char *buf, int buf_size)
Definition: nrf51.c:1214
static const struct command_registration nrf51_command_handlers[]
Definition: nrf51.c:1348
static int nrf51_protect(struct flash_bank *bank, int set, int first, int last)
Definition: nrf51.c:595

Definition at line 1359 of file nrf51.c.

const uint8_t nrf51_flash_write_code[]
static
Initial value:
= {
0x0d, 0x68,
0x00, 0x2d,
0x0b, 0xd0,
0x4c, 0x68,
0xac, 0x42,
0xf9, 0xd0,
0x20, 0xcc,
0x20, 0xc3,
0x94, 0x42,
0x01, 0xd3,
0x0c, 0x46,
0x08, 0x34,
0x4c, 0x60,
0x04, 0x38,
0xf0, 0xd1,
0x00, 0xbe
}

Definition at line 825 of file nrf51.c.

Referenced by nrf51_ll_flash_write().

const struct nrf51_device_spec nrf51_known_devices_table[]
static

Definition at line 141 of file nrf51.c.