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

Go to the source code of this file.

Data Structures

struct  stm32h7x_flash_bank
 
struct  stm32h7x_part_info
 
struct  stm32h7x_rev
 

Macros

#define DBGMCU_IDCODE_REGISTER   0x5C001000
 
#define DEVID_STM32H72_H73XX   0x483
 
#define DEVID_STM32H74_H75XX   0x450
 
#define DEVID_STM32H7A_H7BXX   0x480
 
#define FLASH_ACR   0x00
 
#define FLASH_BANK0_ADDRESS   0x08000000
 
#define FLASH_BANK1_ADDRESS   0x08100000
 
#define FLASH_BER   (1 << 3)
 
#define FLASH_BSY   (1 << 0) /* Operation in progress */
 
#define FLASH_CCR   0x14
 
#define FLASH_CR   0x0C
 
#define FLASH_DBECCERR   (1 << 26) /* Double ECC error */
 
#define FLASH_ERASE_TIMEOUT   10000
 
#define FLASH_ERROR
 
#define FLASH_FW   (1 << 6)
 
#define FLASH_INCERR   (1 << 21) /* Inconsistency error */
 
#define FLASH_KEYR   0x04
 
#define FLASH_LOCK   (1 << 0)
 
#define FLASH_OPERR   (1 << 22) /* Operation error */
 
#define FLASH_OPTCCR   0x24
 
#define FLASH_OPTCR   0x18
 
#define FLASH_OPTKEYR   0x08
 
#define FLASH_OPTSR_CUR   0x1C
 
#define FLASH_OPTSR_PRG   0x20
 
#define FLASH_PG   (1 << 1)
 
#define FLASH_PGSERR   (1 << 18) /* Programming sequence error */
 
#define FLASH_PSIZE_16   (1 << 4)
 
#define FLASH_PSIZE_32   (2 << 4)
 
#define FLASH_PSIZE_64   (3 << 4)
 
#define FLASH_PSIZE_8   (0 << 4)
 
#define FLASH_QW   (1 << 2) /* Operation queue in progress */
 
#define FLASH_RDPERR   (1 << 23) /* Read Protection error */
 
#define FLASH_RDSERR   (1 << 24) /* Secure Protection error */
 
#define FLASH_REG_BASE_B0   0x52002000
 
#define FLASH_REG_BASE_B1   0x52002100
 
#define FLASH_SER   (1 << 2)
 
#define FLASH_SNECCERR   (1 << 25) /* Single ECC error */
 
#define FLASH_SR   0x10
 
#define FLASH_START   (1 << 7)
 
#define FLASH_STRBERR   (1 << 19) /* Strobe error */
 
#define FLASH_WPSN_CUR   0x38
 
#define FLASH_WPSN_PRG   0x3C
 
#define FLASH_WRITE_TIMEOUT   5
 
#define FLASH_WRPERR   (1 << 17) /* Write protection error */
 
#define KEY1   0x45670123
 
#define KEY2   0xCDEF89AB
 
#define OPT_BSY   (1 << 0)
 
#define OPT_CLR_OPTCHANGEERR   (1 << 30)
 
#define OPT_LOCK   (1 << 0)
 
#define OPT_OPTCHANGEERR   (1 << 30)
 
#define OPT_RDP_MASK   (0xff << OPT_RDP_POS)
 
#define OPT_RDP_POS   8
 
#define OPT_START   (1 << 1)
 
#define OPTKEY1   0x08192A3B
 
#define OPTKEY2   0x4C5D6E7F
 

Enumerations

enum  stm32h7x_opt_rdp { OPT_RDP_L0 = 0xaa , OPT_RDP_L1 = 0x00 , OPT_RDP_L2 = 0xcc }
 

Functions

 COMMAND_HANDLER (stm32x_handle_lock_command)
 
 COMMAND_HANDLER (stm32x_handle_mass_erase_command)
 
 COMMAND_HANDLER (stm32x_handle_option_read_command)
 
 COMMAND_HANDLER (stm32x_handle_option_write_command)
 
 COMMAND_HANDLER (stm32x_handle_unlock_command)
 
 FLASH_BANK_COMMAND_HANDLER (stm32x_flash_bank_command)
 
static uint32_t stm32h74_h75xx_compute_flash_cr (uint32_t cmd, int snb)
 
static uint32_t stm32h7a_h7bxx_compute_flash_cr (uint32_t cmd, int snb)
 
static int stm32x_auto_probe (struct flash_bank *bank)
 
static int stm32x_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static uint32_t stm32x_get_flash_reg (struct flash_bank *bank, uint32_t reg_offset)
 
static int stm32x_get_flash_status (struct flash_bank *bank, uint32_t *status)
 
static int stm32x_get_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int stm32x_lock_option_reg (struct flash_bank *bank)
 
static int stm32x_lock_reg (struct flash_bank *bank)
 
static int stm32x_mass_erase (struct flash_bank *bank)
 
static int stm32x_modify_option (struct flash_bank *bank, uint32_t reg_offset, uint32_t value, uint32_t mask)
 
static int stm32x_probe (struct flash_bank *bank)
 
static int stm32x_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int stm32x_protect_check (struct flash_bank *bank)
 
static int stm32x_read_flash_reg (struct flash_bank *bank, uint32_t reg_offset, uint32_t *value)
 
static int stm32x_read_id_code (struct flash_bank *bank, uint32_t *id)
 
static int stm32x_set_rdp (struct flash_bank *bank, enum stm32h7x_opt_rdp new_rdp)
 
static int stm32x_unlock_option_reg (struct flash_bank *bank)
 
static int stm32x_unlock_reg (struct flash_bank *bank)
 
static int stm32x_wait_flash_op_queue (struct flash_bank *bank, int timeout)
 
static int stm32x_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int stm32x_write_block (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int stm32x_write_flash_reg (struct flash_bank *bank, uint32_t reg_offset, uint32_t value)
 
static int stm32x_write_option (struct flash_bank *bank, uint32_t reg_offset, uint32_t value)
 

Variables

static const struct stm32h7x_rev stm32h72_h73xx_revs []
 
static const struct stm32h7x_rev stm32h74_h75xx_revs []
 
static const struct stm32h7x_rev stm32h7a_h7bxx_revs []
 
static const struct command_registration stm32h7x_command_handlers []
 
static const struct command_registration stm32h7x_exec_command_handlers []
 
const struct flash_driver stm32h7x_flash
 
static const struct stm32h7x_part_info stm32h7x_parts []
 

Macro Definition Documentation

◆ DBGMCU_IDCODE_REGISTER

#define DBGMCU_IDCODE_REGISTER   0x5C001000

Definition at line 86 of file stm32h7x.c.

◆ DEVID_STM32H72_H73XX

#define DEVID_STM32H72_H73XX   0x483

Definition at line 95 of file stm32h7x.c.

◆ DEVID_STM32H74_H75XX

#define DEVID_STM32H74_H75XX   0x450

Definition at line 93 of file stm32h7x.c.

◆ DEVID_STM32H7A_H7BXX

#define DEVID_STM32H7A_H7BXX   0x480

Definition at line 94 of file stm32h7x.c.

◆ FLASH_ACR

#define FLASH_ACR   0x00

Definition at line 23 of file stm32h7x.c.

◆ FLASH_BANK0_ADDRESS

#define FLASH_BANK0_ADDRESS   0x08000000

Definition at line 87 of file stm32h7x.c.

◆ FLASH_BANK1_ADDRESS

#define FLASH_BANK1_ADDRESS   0x08100000

Definition at line 88 of file stm32h7x.c.

◆ FLASH_BER

#define FLASH_BER   (1 << 3)

Definition at line 41 of file stm32h7x.c.

◆ FLASH_BSY

#define FLASH_BSY   (1 << 0) /* Operation in progress */

Definition at line 50 of file stm32h7x.c.

◆ FLASH_CCR

#define FLASH_CCR   0x14

Definition at line 28 of file stm32h7x.c.

◆ FLASH_CR

#define FLASH_CR   0x0C

Definition at line 26 of file stm32h7x.c.

◆ FLASH_DBECCERR

#define FLASH_DBECCERR   (1 << 26) /* Double ECC error */

Definition at line 60 of file stm32h7x.c.

◆ FLASH_ERASE_TIMEOUT

#define FLASH_ERASE_TIMEOUT   10000

Definition at line 17 of file stm32h7x.c.

◆ FLASH_ERROR

#define FLASH_ERROR
Value:
#define FLASH_OPERR
Definition: stm32h7x.c:56
#define FLASH_INCERR
Definition: stm32h7x.c:55
#define FLASH_RDSERR
Definition: stm32h7x.c:58
#define FLASH_WRPERR
Definition: stm32h7x.c:52
#define FLASH_STRBERR
Definition: stm32h7x.c:54
#define FLASH_DBECCERR
Definition: stm32h7x.c:60
#define FLASH_PGSERR
Definition: stm32h7x.c:53
#define FLASH_SNECCERR
Definition: stm32h7x.c:59

Definition at line 62 of file stm32h7x.c.

◆ FLASH_FW

#define FLASH_FW   (1 << 6)

Definition at line 46 of file stm32h7x.c.

◆ FLASH_INCERR

#define FLASH_INCERR   (1 << 21) /* Inconsistency error */

Definition at line 55 of file stm32h7x.c.

◆ FLASH_KEYR

#define FLASH_KEYR   0x04

Definition at line 24 of file stm32h7x.c.

◆ FLASH_LOCK

#define FLASH_LOCK   (1 << 0)

Definition at line 38 of file stm32h7x.c.

◆ FLASH_OPERR

#define FLASH_OPERR   (1 << 22) /* Operation error */

Definition at line 56 of file stm32h7x.c.

◆ FLASH_OPTCCR

#define FLASH_OPTCCR   0x24

Definition at line 32 of file stm32h7x.c.

◆ FLASH_OPTCR

#define FLASH_OPTCR   0x18

Definition at line 29 of file stm32h7x.c.

◆ FLASH_OPTKEYR

#define FLASH_OPTKEYR   0x08

Definition at line 25 of file stm32h7x.c.

◆ FLASH_OPTSR_CUR

#define FLASH_OPTSR_CUR   0x1C

Definition at line 30 of file stm32h7x.c.

◆ FLASH_OPTSR_PRG

#define FLASH_OPTSR_PRG   0x20

Definition at line 31 of file stm32h7x.c.

◆ FLASH_PG

#define FLASH_PG   (1 << 1)

Definition at line 39 of file stm32h7x.c.

◆ FLASH_PGSERR

#define FLASH_PGSERR   (1 << 18) /* Programming sequence error */

Definition at line 53 of file stm32h7x.c.

◆ FLASH_PSIZE_16

#define FLASH_PSIZE_16   (1 << 4)

Definition at line 43 of file stm32h7x.c.

◆ FLASH_PSIZE_32

#define FLASH_PSIZE_32   (2 << 4)

Definition at line 44 of file stm32h7x.c.

◆ FLASH_PSIZE_64

#define FLASH_PSIZE_64   (3 << 4)

Definition at line 45 of file stm32h7x.c.

◆ FLASH_PSIZE_8

#define FLASH_PSIZE_8   (0 << 4)

Definition at line 42 of file stm32h7x.c.

◆ FLASH_QW

#define FLASH_QW   (1 << 2) /* Operation queue in progress */

Definition at line 51 of file stm32h7x.c.

◆ FLASH_RDPERR

#define FLASH_RDPERR   (1 << 23) /* Read Protection error */

Definition at line 57 of file stm32h7x.c.

◆ FLASH_RDSERR

#define FLASH_RDSERR   (1 << 24) /* Secure Protection error */

Definition at line 58 of file stm32h7x.c.

◆ FLASH_REG_BASE_B0

#define FLASH_REG_BASE_B0   0x52002000

Definition at line 89 of file stm32h7x.c.

◆ FLASH_REG_BASE_B1

#define FLASH_REG_BASE_B1   0x52002100

Definition at line 90 of file stm32h7x.c.

◆ FLASH_SER

#define FLASH_SER   (1 << 2)

Definition at line 40 of file stm32h7x.c.

◆ FLASH_SNECCERR

#define FLASH_SNECCERR   (1 << 25) /* Single ECC error */

Definition at line 59 of file stm32h7x.c.

◆ FLASH_SR

#define FLASH_SR   0x10

Definition at line 27 of file stm32h7x.c.

◆ FLASH_START

#define FLASH_START   (1 << 7)

Definition at line 47 of file stm32h7x.c.

◆ FLASH_STRBERR

#define FLASH_STRBERR   (1 << 19) /* Strobe error */

Definition at line 54 of file stm32h7x.c.

◆ FLASH_WPSN_CUR

#define FLASH_WPSN_CUR   0x38

Definition at line 33 of file stm32h7x.c.

◆ FLASH_WPSN_PRG

#define FLASH_WPSN_PRG   0x3C

Definition at line 34 of file stm32h7x.c.

◆ FLASH_WRITE_TIMEOUT

#define FLASH_WRITE_TIMEOUT   5

Definition at line 18 of file stm32h7x.c.

◆ FLASH_WRPERR

#define FLASH_WRPERR   (1 << 17) /* Write protection error */

Definition at line 52 of file stm32h7x.c.

◆ KEY1

#define KEY1   0x45670123

Definition at line 79 of file stm32h7x.c.

◆ KEY2

#define KEY2   0xCDEF89AB

Definition at line 80 of file stm32h7x.c.

◆ OPT_BSY

#define OPT_BSY   (1 << 0)

Definition at line 70 of file stm32h7x.c.

◆ OPT_CLR_OPTCHANGEERR

#define OPT_CLR_OPTCHANGEERR   (1 << 30)

Definition at line 76 of file stm32h7x.c.

◆ OPT_LOCK

#define OPT_LOCK   (1 << 0)

Definition at line 66 of file stm32h7x.c.

◆ OPT_OPTCHANGEERR

#define OPT_OPTCHANGEERR   (1 << 30)

Definition at line 73 of file stm32h7x.c.

◆ OPT_RDP_MASK

#define OPT_RDP_MASK   (0xff << OPT_RDP_POS)

Definition at line 72 of file stm32h7x.c.

◆ OPT_RDP_POS

#define OPT_RDP_POS   8

Definition at line 71 of file stm32h7x.c.

◆ OPT_START

#define OPT_START   (1 << 1)

Definition at line 67 of file stm32h7x.c.

◆ OPTKEY1

#define OPTKEY1   0x08192A3B

Definition at line 83 of file stm32h7x.c.

◆ OPTKEY2

#define OPTKEY2   0x4C5D6E7F

Definition at line 84 of file stm32h7x.c.

Enumeration Type Documentation

◆ stm32h7x_opt_rdp

Enumerator
OPT_RDP_L0 
OPT_RDP_L1 
OPT_RDP_L2 

Definition at line 130 of file stm32h7x.c.

Function Documentation

◆ COMMAND_HANDLER() [1/5]

COMMAND_HANDLER ( stm32x_handle_lock_command  )

◆ COMMAND_HANDLER() [2/5]

COMMAND_HANDLER ( stm32x_handle_mass_erase_command  )

◆ COMMAND_HANDLER() [3/5]

COMMAND_HANDLER ( stm32x_handle_option_read_command  )

◆ COMMAND_HANDLER() [4/5]

COMMAND_HANDLER ( stm32x_handle_option_write_command  )

◆ COMMAND_HANDLER() [5/5]

COMMAND_HANDLER ( stm32x_handle_unlock_command  )

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( stm32x_flash_bank_command  )

◆ stm32h74_h75xx_compute_flash_cr()

static uint32_t stm32h74_h75xx_compute_flash_cr ( uint32_t  cmd,
int  snb 
)
static

Definition at line 148 of file stm32h7x.c.

References cmd.

◆ stm32h7a_h7bxx_compute_flash_cr()

static uint32_t stm32h7a_h7bxx_compute_flash_cr ( uint32_t  cmd,
int  snb 
)
static

Definition at line 153 of file stm32h7x.c.

References cmd, FLASH_FW, FLASH_PSIZE_64, and FLASH_START.

◆ stm32x_auto_probe()

static int stm32x_auto_probe ( struct flash_bank bank)
static

Definition at line 912 of file stm32h7x.c.

References bank, ERROR_OK, stm32h7x_flash_bank::probed, and stm32x_probe().

◆ stm32x_erase()

◆ stm32x_get_flash_reg()

static uint32_t stm32x_get_flash_reg ( struct flash_bank bank,
uint32_t  reg_offset 
)
inlinestatic

◆ stm32x_get_flash_status()

static int stm32x_get_flash_status ( struct flash_bank bank,
uint32_t *  status 
)
inlinestatic

Definition at line 258 of file stm32h7x.c.

References bank, FLASH_SR, status, and stm32x_read_flash_reg().

Referenced by stm32x_wait_flash_op_queue().

◆ stm32x_get_info()

◆ stm32x_lock_option_reg()

static int stm32x_lock_option_reg ( struct flash_bank bank)
inlinestatic

Definition at line 370 of file stm32h7x.c.

References bank, FLASH_OPTCR, OPT_LOCK, and stm32x_write_flash_reg().

Referenced by stm32x_write_option().

◆ stm32x_lock_reg()

static int stm32x_lock_reg ( struct flash_bank bank)
inlinestatic

Definition at line 365 of file stm32h7x.c.

References bank, FLASH_CR, FLASH_LOCK, and stm32x_write_flash_reg().

Referenced by stm32x_erase(), stm32x_mass_erase(), and stm32x_write().

◆ stm32x_mass_erase()

◆ stm32x_modify_option()

static int stm32x_modify_option ( struct flash_bank bank,
uint32_t  reg_offset,
uint32_t  value,
uint32_t  mask 
)
static

Definition at line 433 of file stm32h7x.c.

References bank, ERROR_OK, mask, stm32x_read_flash_reg(), and stm32x_write_option().

Referenced by COMMAND_HANDLER().

◆ stm32x_probe()

◆ stm32x_protect()

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

◆ stm32x_protect_check()

static int stm32x_protect_check ( struct flash_bank bank)
static

Definition at line 446 of file stm32h7x.c.

References bank, ERROR_OK, FLASH_WPSN_CUR, LOG_DEBUG, and stm32x_read_flash_reg().

◆ stm32x_read_flash_reg()

static int stm32x_read_flash_reg ( struct flash_bank bank,
uint32_t  reg_offset,
uint32_t *  value 
)
inlinestatic

◆ stm32x_read_id_code()

static int stm32x_read_id_code ( struct flash_bank bank,
uint32_t *  id 
)
static

Definition at line 740 of file stm32h7x.c.

References bank, DBGMCU_IDCODE_REGISTER, ERROR_OK, and target_read_u32().

Referenced by stm32x_probe().

◆ stm32x_set_rdp()

◆ stm32x_unlock_option_reg()

static int stm32x_unlock_option_reg ( struct flash_bank bank)
static

◆ stm32x_unlock_reg()

static int stm32x_unlock_reg ( struct flash_bank bank)
static

◆ stm32x_wait_flash_op_queue()

static int stm32x_wait_flash_op_queue ( struct flash_bank bank,
int  timeout 
)
static

◆ stm32x_write()

◆ stm32x_write_block()

◆ stm32x_write_flash_reg()

static int stm32x_write_flash_reg ( struct flash_bank bank,
uint32_t  reg_offset,
uint32_t  value 
)
inlinestatic

◆ stm32x_write_option()

Variable Documentation

◆ stm32h72_h73xx_revs

const struct stm32h7x_rev stm32h72_h73xx_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x1001, "Z" },
}

Definition at line 1 of file stm32h7x.c.

◆ stm32h74_h75xx_revs

const struct stm32h7x_rev stm32h74_h75xx_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x1001, "Z" }, { 0x1003, "Y" }, { 0x2001, "X" }, { 0x2003, "V" },
}

Definition at line 1 of file stm32h7x.c.

◆ stm32h7a_h7bxx_revs

const struct stm32h7x_rev stm32h7a_h7bxx_revs[]
static
Initial value:
= {
{ 0x1000, "A"},
}

Definition at line 1 of file stm32h7x.c.

◆ stm32h7x_command_handlers

const struct command_registration stm32h7x_command_handlers[]
static
Initial value:
= {
{
.name = "stm32h7x",
.mode = COMMAND_ANY,
.help = "stm32h7x 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 stm32h7x_exec_command_handlers[]
Definition: stm32h7x.c:1149

Definition at line 1127 of file stm32h7x.c.

◆ stm32h7x_exec_command_handlers

const struct command_registration stm32h7x_exec_command_handlers[]
static

Definition at line 1127 of file stm32h7x.c.

◆ stm32h7x_flash

const struct flash_driver stm32h7x_flash
Initial value:
= {
.name = "stm32h7x",
.flash_bank_command = stm32x_flash_bank_command,
.erase = stm32x_erase,
.protect = stm32x_protect,
.write = stm32x_write,
.probe = stm32x_probe,
.auto_probe = stm32x_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = stm32x_protect_check,
.info = stm32x_get_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 int stm32x_auto_probe(struct flash_bank *bank)
Definition: stm32h7x.c:912
static int stm32x_probe(struct flash_bank *bank)
Definition: stm32h7x.c:749
static const struct command_registration stm32h7x_command_handlers[]
Definition: stm32h7x.c:1188
static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: stm32h7x.c:661
static int stm32x_get_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: stm32h7x.c:923
static int stm32x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: stm32h7x.c:463
static int stm32x_protect_check(struct flash_bank *bank)
Definition: stm32h7x.c:446
static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: stm32h7x.c:519

Definition at line 1127 of file stm32h7x.c.

◆ stm32h7x_parts

const struct stm32h7x_part_info stm32h7x_parts[]
static

Definition at line 153 of file stm32h7x.c.

Referenced by stm32x_probe().