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

Go to the source code of this file.

Data Structures

struct  pic32mx_devs_s
 
struct  pic32mx_flash_bank
 

Macros

#define MX_17X_27X   2 /* PIC32mx17x/27x */
 
#define MX_1XX_2XX   1 /* PIC32mx1xx/2xx */
 
#define NVMCON_LVDERR   (1 << 12)
 
#define NVMCON_LVDSTAT   (1 << 11)
 
#define NVMCON_NVMERR   (1 << 13)
 
#define NVMCON_NVMWR   (1 << 15)
 
#define NVMCON_NVMWREN   (1 << 14)
 
#define NVMCON_OP_NOP   0x0
 
#define NVMCON_OP_PAGE_ERASE   0x4
 
#define NVMCON_OP_PFM_ERASE   0x5
 
#define NVMCON_OP_ROW_PROG   0x3
 
#define NVMCON_OP_WORD_PROG   0x1
 
#define NVMKEY1   0xAA996655
 
#define NVMKEY2   0x556699AA
 
#define PIC32MX_BMXBOOTSZ   0xBF882070
 
#define PIC32MX_BMXDRMSZ   0xBF882040
 
#define PIC32MX_BMXPFMSZ   0xBF882060
 
#define PIC32MX_DEVCFG0   0xBFC02FFC
 
#define PIC32MX_DEVCFG0_1XX_2XX   0xBFC00BFC
 
#define PIC32MX_DEVCFG1   0xBFC02FF8
 
#define PIC32MX_DEVCFG2   0xBFC02FF4
 
#define PIC32MX_DEVCFG3   0xBFC02FF0
 
#define PIC32MX_DEVID   0xBF80F220
 
#define PIC32MX_MANUF_ID   0x029
 
#define PIC32MX_NVMADDR   0xBF80F420
 
#define PIC32MX_NVMADDRCLR   0xBF80F424
 
#define PIC32MX_NVMADDRINV   0xBF80F42C
 
#define PIC32MX_NVMADDRSET   0xBF80F428
 
#define PIC32MX_NVMCON   0xBF80F400
 
#define PIC32MX_NVMCONCLR   0xBF80F404
 
#define PIC32MX_NVMCONINV   0xBF80F40C
 
#define PIC32MX_NVMCONSET   0xBF80F408
 
#define PIC32MX_NVMDATA   0xBF80F430
 
#define PIC32MX_NVMKEY   0xBF80F410
 
#define PIC32MX_NVMSRCADDR   0xBF80F440
 
#define PIC32MX_PHYS_BOOT_FLASH   0x1FC00000
 
#define PIC32MX_PHYS_PERIPHERALS   0x1F800000
 
#define PIC32MX_PHYS_PGM_FLASH   0x1D000000
 
#define PIC32MX_PHYS_RAM   0x00000000
 
#define virt2phys(v)   ((v) & 0x1FFFFFFF)
 

Functions

 COMMAND_HANDLER (pic32mx_handle_pgm_word_command)
 
 COMMAND_HANDLER (pic32mx_handle_unlock_command)
 
 FLASH_BANK_COMMAND_HANDLER (pic32mx_flash_bank_command)
 
static int pic32mx_auto_probe (struct flash_bank *bank)
 
static int pic32mx_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static uint32_t pic32mx_get_flash_status (struct flash_bank *bank)
 
static int pic32mx_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int pic32mx_nvm_exec (struct flash_bank *bank, uint32_t op, uint32_t timeout)
 
static int pic32mx_probe (struct flash_bank *bank)
 
static int pic32mx_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int pic32mx_protect_check (struct flash_bank *bank)
 
static uint32_t pic32mx_wait_status_busy (struct flash_bank *bank, int timeout)
 
static int pic32mx_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int pic32mx_write_block (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int pic32mx_write_word (struct flash_bank *bank, uint32_t address, uint32_t word)
 

Variables

static const struct command_registration pic32mx_command_handlers []
 
static const struct pic32mx_devs_s pic32mx_devs []
 
static const struct command_registration pic32mx_exec_command_handlers []
 
const struct flash_driver pic32mx_flash
 
static uint32_t pic32mx_flash_write_code []
 

Macro Definition Documentation

◆ MX_17X_27X

#define MX_17X_27X   2 /* PIC32mx17x/27x */

Definition at line 84 of file pic32mx.c.

◆ MX_1XX_2XX

#define MX_1XX_2XX   1 /* PIC32mx1xx/2xx */

Definition at line 83 of file pic32mx.c.

◆ NVMCON_LVDERR

#define NVMCON_LVDERR   (1 << 12)

Definition at line 62 of file pic32mx.c.

◆ NVMCON_LVDSTAT

#define NVMCON_LVDSTAT   (1 << 11)

Definition at line 63 of file pic32mx.c.

◆ NVMCON_NVMERR

#define NVMCON_NVMERR   (1 << 13)

Definition at line 61 of file pic32mx.c.

◆ NVMCON_NVMWR

#define NVMCON_NVMWR   (1 << 15)

Definition at line 59 of file pic32mx.c.

◆ NVMCON_NVMWREN

#define NVMCON_NVMWREN   (1 << 14)

Definition at line 60 of file pic32mx.c.

◆ NVMCON_OP_NOP

#define NVMCON_OP_NOP   0x0

Definition at line 68 of file pic32mx.c.

◆ NVMCON_OP_PAGE_ERASE

#define NVMCON_OP_PAGE_ERASE   0x4

Definition at line 65 of file pic32mx.c.

◆ NVMCON_OP_PFM_ERASE

#define NVMCON_OP_PFM_ERASE   0x5

Definition at line 64 of file pic32mx.c.

◆ NVMCON_OP_ROW_PROG

#define NVMCON_OP_ROW_PROG   0x3

Definition at line 66 of file pic32mx.c.

◆ NVMCON_OP_WORD_PROG

#define NVMCON_OP_WORD_PROG   0x1

Definition at line 67 of file pic32mx.c.

◆ NVMKEY1

#define NVMKEY1   0xAA996655

Definition at line 80 of file pic32mx.c.

◆ NVMKEY2

#define NVMKEY2   0x556699AA

Definition at line 81 of file pic32mx.c.

◆ PIC32MX_BMXBOOTSZ

#define PIC32MX_BMXBOOTSZ   0xBF882070

Definition at line 50 of file pic32mx.c.

◆ PIC32MX_BMXDRMSZ

#define PIC32MX_BMXDRMSZ   0xBF882040

Definition at line 51 of file pic32mx.c.

◆ PIC32MX_BMXPFMSZ

#define PIC32MX_BMXPFMSZ   0xBF882060

Definition at line 49 of file pic32mx.c.

◆ PIC32MX_DEVCFG0

#define PIC32MX_DEVCFG0   0xBFC02FFC

Definition at line 43 of file pic32mx.c.

◆ PIC32MX_DEVCFG0_1XX_2XX

#define PIC32MX_DEVCFG0_1XX_2XX   0xBFC00BFC

Definition at line 42 of file pic32mx.c.

◆ PIC32MX_DEVCFG1

#define PIC32MX_DEVCFG1   0xBFC02FF8

Definition at line 44 of file pic32mx.c.

◆ PIC32MX_DEVCFG2

#define PIC32MX_DEVCFG2   0xBFC02FF4

Definition at line 45 of file pic32mx.c.

◆ PIC32MX_DEVCFG3

#define PIC32MX_DEVCFG3   0xBFC02FF0

Definition at line 46 of file pic32mx.c.

◆ PIC32MX_DEVID

#define PIC32MX_DEVID   0xBF80F220

Definition at line 47 of file pic32mx.c.

◆ PIC32MX_MANUF_ID

#define PIC32MX_MANUF_ID   0x029

Definition at line 24 of file pic32mx.c.

◆ PIC32MX_NVMADDR

#define PIC32MX_NVMADDR   0xBF80F420

Definition at line 71 of file pic32mx.c.

◆ PIC32MX_NVMADDRCLR

#define PIC32MX_NVMADDRCLR   0xBF80F424

Definition at line 72 of file pic32mx.c.

◆ PIC32MX_NVMADDRINV

#define PIC32MX_NVMADDRINV   0xBF80F42C

Definition at line 74 of file pic32mx.c.

◆ PIC32MX_NVMADDRSET

#define PIC32MX_NVMADDRSET   0xBF80F428

Definition at line 73 of file pic32mx.c.

◆ PIC32MX_NVMCON

#define PIC32MX_NVMCON   0xBF80F400

Definition at line 55 of file pic32mx.c.

◆ PIC32MX_NVMCONCLR

#define PIC32MX_NVMCONCLR   0xBF80F404

Definition at line 56 of file pic32mx.c.

◆ PIC32MX_NVMCONINV

#define PIC32MX_NVMCONINV   0xBF80F40C

Definition at line 58 of file pic32mx.c.

◆ PIC32MX_NVMCONSET

#define PIC32MX_NVMCONSET   0xBF80F408

Definition at line 57 of file pic32mx.c.

◆ PIC32MX_NVMDATA

#define PIC32MX_NVMDATA   0xBF80F430

Definition at line 75 of file pic32mx.c.

◆ PIC32MX_NVMKEY

#define PIC32MX_NVMKEY   0xBF80F410

Definition at line 70 of file pic32mx.c.

◆ PIC32MX_NVMSRCADDR

#define PIC32MX_NVMSRCADDR   0xBF80F440

Definition at line 76 of file pic32mx.c.

◆ PIC32MX_PHYS_BOOT_FLASH

#define PIC32MX_PHYS_BOOT_FLASH   0x1FC00000

Definition at line 31 of file pic32mx.c.

◆ PIC32MX_PHYS_PERIPHERALS

#define PIC32MX_PHYS_PERIPHERALS   0x1F800000

Definition at line 30 of file pic32mx.c.

◆ PIC32MX_PHYS_PGM_FLASH

#define PIC32MX_PHYS_PGM_FLASH   0x1D000000

Definition at line 29 of file pic32mx.c.

◆ PIC32MX_PHYS_RAM

#define PIC32MX_PHYS_RAM   0x00000000

Definition at line 28 of file pic32mx.c.

◆ virt2phys

#define virt2phys (   v)    ((v) & 0x1FFFFFFF)

Definition at line 38 of file pic32mx.c.

Function Documentation

◆ COMMAND_HANDLER() [1/2]

◆ COMMAND_HANDLER() [2/2]

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( pic32mx_flash_bank_command  )

Definition at line 193 of file pic32mx.c.

References bank, CMD_ARGC, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and pic32mx_info().

◆ pic32mx_auto_probe()

static int pic32mx_auto_probe ( struct flash_bank bank)
static

Definition at line 784 of file pic32mx.c.

References bank, ERROR_OK, pic32mx_info(), and pic32mx_probe().

◆ pic32mx_erase()

◆ pic32mx_get_flash_status()

static uint32_t pic32mx_get_flash_status ( struct flash_bank bank)
static

Definition at line 209 of file pic32mx.c.

References bank, PIC32MX_NVMCON, status, and target_read_u32().

Referenced by pic32mx_wait_status_busy().

◆ pic32mx_info()

◆ pic32mx_nvm_exec()

static int pic32mx_nvm_exec ( struct flash_bank bank,
uint32_t  op,
uint32_t  timeout 
)
static

◆ pic32mx_probe()

◆ pic32mx_protect()

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

Definition at line 350 of file pic32mx.c.

References bank, ERROR_OK, ERROR_TARGET_NOT_HALTED, LOG_ERROR, target::state, and TARGET_HALTED.

◆ pic32mx_protect_check()

◆ pic32mx_wait_status_busy()

static uint32_t pic32mx_wait_status_busy ( struct flash_bank bank,
int  timeout 
)
static

Definition at line 219 of file pic32mx.c.

References alive_sleep(), bank, LOG_DEBUG, NVMCON_NVMWR, pic32mx_get_flash_status(), and status.

Referenced by pic32mx_nvm_exec().

◆ pic32mx_write()

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

◆ pic32mx_write_block()

◆ pic32mx_write_word()

static int pic32mx_write_word ( struct flash_bank bank,
uint32_t  address,
uint32_t  word 
)
static

Variable Documentation

◆ pic32mx_command_handlers

const struct command_registration pic32mx_command_handlers[]
static
Initial value:
= {
{
.name = "pic32mx",
.mode = COMMAND_ANY,
.help = "pic32mx 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 pic32mx_exec_command_handlers[]
Definition: pic32mx.c:921

Definition at line 862 of file pic32mx.c.

◆ pic32mx_devs

const struct pic32mx_devs_s pic32mx_devs[]
static

Referenced by pic32mx_info(), and pic32mx_probe().

◆ pic32mx_exec_command_handlers

const struct command_registration pic32mx_exec_command_handlers[]
static
Initial value:
= {
{
.name = "pgm_word",
.usage = "<addr> <value> <bank>",
.handler = pic32mx_handle_pgm_word_command,
.mode = COMMAND_EXEC,
.help = "program a word",
},
{
.name = "unlock",
.handler = pic32mx_handle_unlock_command,
.mode = COMMAND_EXEC,
.usage = "bank_id",
.help = "Unlock/Erase entire device.",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 862 of file pic32mx.c.

◆ pic32mx_flash

const struct flash_driver pic32mx_flash
Initial value:
= {
.name = "pic32mx",
.flash_bank_command = pic32mx_flash_bank_command,
.erase = pic32mx_erase,
.protect = pic32mx_protect,
.write = pic32mx_write,
.probe = pic32mx_probe,
.auto_probe = pic32mx_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = pic32mx_protect_check,
.info = pic32mx_info,
.free_driver_priv = default_flash_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.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
static const struct command_registration pic32mx_command_handlers[]
Definition: pic32mx.c:939
static int pic32mx_protect_check(struct flash_bank *bank)
Definition: pic32mx.c:256
static int pic32mx_probe(struct flash_bank *bank)
Definition: pic32mx.c:679
static int pic32mx_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: pic32mx.c:312
static int pic32mx_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: pic32mx.c:350
static int pic32mx_auto_probe(struct flash_bank *bank)
Definition: pic32mx.c:784
static int pic32mx_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: pic32mx.c:792
static int pic32mx_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: pic32mx.c:596

Definition at line 862 of file pic32mx.c.

◆ pic32mx_flash_write_code

uint32_t pic32mx_flash_write_code[]
static

Definition at line 365 of file pic32mx.c.

Referenced by pic32mx_write_block().