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

Go to the source code of this file.

Data Structures

struct  stm32x_flash_bank
 
struct  stm32x_options
 

Macros

#define FLASH_BANK_BASE   0x80000000
 
#define FLASH_BSY   (1 << 16)
 
#define FLASH_ERASE_TIMEOUT   10000
 
#define FLASH_ERROR   (FLASH_PGSERR | FLASH_PGPERR | FLASH_PGAERR | FLASH_WRPERR | FLASH_OPERR)
 
#define FLASH_LOCK   (1 << 31)
 
#define FLASH_MASS_ERASE_TIMEOUT   33000
 
#define FLASH_MER   (1 << 2) /* MER/MER1 for f76x/77x */
 
#define FLASH_MER1   (1 << 15) /* MER2 for f76x/77x, confusing ... */
 
#define FLASH_OPERR   (1 << 1) /* Operation error */
 
#define FLASH_PG   (1 << 0)
 
#define FLASH_PGAERR   (1 << 5) /* Programming alignment error */
 
#define FLASH_PGPERR   (1 << 6) /* Programming parallelism error */
 
#define FLASH_PGSERR   (1 << 7) /* Programming sequence error */
 
#define FLASH_PSIZE_16   (1 << 8)
 
#define FLASH_PSIZE_32   (2 << 8)
 
#define FLASH_PSIZE_64   (3 << 8)
 
#define FLASH_PSIZE_8   (0 << 8)
 
#define FLASH_SER   (1 << 1)
 
#define FLASH_SNB(a)   ((a) << 3)
 
#define FLASH_STRT   (1 << 16)
 
#define FLASH_WRITE_TIMEOUT   5
 
#define FLASH_WRPERR   (1 << 4) /* Write protection error */
 
#define KEY1   0x45670123
 
#define KEY2   0xCDEF89AB
 
#define OPTCR2_PCROP_RDP   (1 << 31) /* erase PCROP zone when decreasing RDP */
 
#define OPTCR_DB1M   (1 << 30) /* 1 MiB devices dual flash bank option */
 
#define OPTCR_LOCK   (1 << 0)
 
#define OPTCR_NDBANK   (1 << 29) /* not dual bank mode */
 
#define OPTCR_SPRMOD   (1 << 31) /* switches PCROPi/nWPRi interpretation */
 
#define OPTCR_START   (1 << 1)
 
#define OPTKEY1   0x08192A3B
 
#define OPTKEY2   0x4C5D6E7F
 
#define STM32_FLASH_ACR   0x40023c00
 
#define STM32_FLASH_BASE   0x40023c00
 
#define STM32_FLASH_CR   0x40023c10
 
#define STM32_FLASH_KEYR   0x40023c04
 
#define STM32_FLASH_OPTCR   0x40023c14
 
#define STM32_FLASH_OPTCR1   0x40023c18
 
#define STM32_FLASH_OPTCR2   0x40023c1c
 
#define STM32_FLASH_OPTKEYR   0x40023c08
 
#define STM32_FLASH_SR   0x40023c0C
 
#define STM32F2_OTP_BANK_BASE   0x1fff7800
 
#define STM32F2_OTP_LOCK_BASE   ((STM32F2_OTP_BANK_BASE) + (STM32F2_OTP_SIZE))
 
#define STM32F2_OTP_SECTOR_SIZE   32
 
#define STM32F2_OTP_SIZE   512
 
#define STM32F7_OTP_BANK_BASE   0x1ff0f000
 
#define STM32F7_OTP_LOCK_BASE   ((STM32F7_OTP_BANK_BASE) + (STM32F7_OTP_SIZE))
 
#define STM32F7_OTP_SECTOR_SIZE   64
 
#define STM32F7_OTP_SIZE   1024
 

Functions

static unsigned int calculate_number_of_sectors (struct flash_bank *bank, uint16_t flash_size_in_kb, uint16_t max_sector_size_in_kb)
 
 COMMAND_HANDLER (stm32f2x_handle_optcr2_write_command)
 
 COMMAND_HANDLER (stm32f2x_handle_options_read_command)
 
 COMMAND_HANDLER (stm32f2x_handle_options_write_command)
 
 COMMAND_HANDLER (stm32x_handle_lock_command)
 
 COMMAND_HANDLER (stm32x_handle_mass_erase_command)
 
 COMMAND_HANDLER (stm32x_handle_otp_command)
 
 COMMAND_HANDLER (stm32x_handle_unlock_command)
 
 FLASH_BANK_COMMAND_HANDLER (stm32x_flash_bank_command)
 
static int get_stm32x_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static uint16_t sector_size_in_kb (unsigned int i, uint16_t max_sector_size_in_kb)
 
static void setup_bank (struct flash_bank *bank, unsigned int start, uint16_t flash_size_in_kb, uint16_t max_sector_size_in_kb)
 
static void setup_sector (struct flash_bank *bank, unsigned int i, unsigned int size)
 
static int stm32x_auto_probe (struct flash_bank *bank)
 
static int stm32x_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int stm32x_get_device_id (struct flash_bank *bank, uint32_t *device_id)
 
static int stm32x_get_flash_reg (struct flash_bank *bank, uint32_t reg)
 
static int stm32x_get_flash_status (struct flash_bank *bank, uint32_t *status)
 
static bool stm32x_is_otp (struct flash_bank *bank)
 
static int stm32x_is_otp_unlocked (struct flash_bank *bank)
 
static int stm32x_mass_erase (struct flash_bank *bank)
 
static int stm32x_otp_disable (struct flash_bank *bank)
 
static int stm32x_otp_enable (struct flash_bank *bank)
 
static bool stm32x_otp_is_f7 (struct flash_bank *bank)
 
static int stm32x_otp_protect (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int stm32x_otp_read_protect (struct flash_bank *bank)
 
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_options (struct flash_bank *bank)
 
static int stm32x_unlock_option_reg (struct target *target)
 
static int stm32x_unlock_reg (struct target *target)
 
static int stm32x_wait_status_busy (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_options (struct flash_bank *bank)
 

Variables

static const struct command_registration stm32f2x_command_handlers []
 
static const struct command_registration stm32f2x_exec_command_handlers []
 
const struct flash_driver stm32f2x_flash
 

Macro Definition Documentation

◆ FLASH_BANK_BASE

#define FLASH_BANK_BASE   0x80000000

Definition at line 115 of file stm32f2x.c.

◆ FLASH_BSY

#define FLASH_BSY   (1 << 16)

Definition at line 153 of file stm32f2x.c.

◆ FLASH_ERASE_TIMEOUT

#define FLASH_ERASE_TIMEOUT   10000

Definition at line 109 of file stm32f2x.c.

◆ FLASH_ERROR

#define FLASH_ERROR   (FLASH_PGSERR | FLASH_PGPERR | FLASH_PGAERR | FLASH_WRPERR | FLASH_OPERR)

Definition at line 160 of file stm32f2x.c.

◆ FLASH_LOCK

#define FLASH_LOCK   (1 << 31)

Definition at line 150 of file stm32f2x.c.

◆ FLASH_MASS_ERASE_TIMEOUT

#define FLASH_MASS_ERASE_TIMEOUT   33000

Definition at line 113 of file stm32f2x.c.

◆ FLASH_MER

#define FLASH_MER   (1 << 2) /* MER/MER1 for f76x/77x */

Definition at line 141 of file stm32f2x.c.

◆ FLASH_MER1

#define FLASH_MER1   (1 << 15) /* MER2 for f76x/77x, confusing ... */

Definition at line 142 of file stm32f2x.c.

◆ FLASH_OPERR

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

Definition at line 158 of file stm32f2x.c.

◆ FLASH_PG

#define FLASH_PG   (1 << 0)

Definition at line 139 of file stm32f2x.c.

◆ FLASH_PGAERR

#define FLASH_PGAERR   (1 << 5) /* Programming alignment error */

Definition at line 156 of file stm32f2x.c.

◆ FLASH_PGPERR

#define FLASH_PGPERR   (1 << 6) /* Programming parallelism error */

Definition at line 155 of file stm32f2x.c.

◆ FLASH_PGSERR

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

Definition at line 154 of file stm32f2x.c.

◆ FLASH_PSIZE_16

#define FLASH_PSIZE_16   (1 << 8)

Definition at line 145 of file stm32f2x.c.

◆ FLASH_PSIZE_32

#define FLASH_PSIZE_32   (2 << 8)

Definition at line 146 of file stm32f2x.c.

◆ FLASH_PSIZE_64

#define FLASH_PSIZE_64   (3 << 8)

Definition at line 147 of file stm32f2x.c.

◆ FLASH_PSIZE_8

#define FLASH_PSIZE_8   (0 << 8)

Definition at line 144 of file stm32f2x.c.

◆ FLASH_SER

#define FLASH_SER   (1 << 1)

Definition at line 140 of file stm32f2x.c.

◆ FLASH_SNB

#define FLASH_SNB (   a)    ((a) << 3)

Definition at line 149 of file stm32f2x.c.

◆ FLASH_STRT

#define FLASH_STRT   (1 << 16)

Definition at line 143 of file stm32f2x.c.

◆ FLASH_WRITE_TIMEOUT

#define FLASH_WRITE_TIMEOUT   5

Definition at line 110 of file stm32f2x.c.

◆ FLASH_WRPERR

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

Definition at line 157 of file stm32f2x.c.

◆ KEY1

#define KEY1   0x45670123

Definition at line 173 of file stm32f2x.c.

◆ KEY2

#define KEY2   0xCDEF89AB

Definition at line 174 of file stm32f2x.c.

◆ OPTCR2_PCROP_RDP

#define OPTCR2_PCROP_RDP   (1 << 31) /* erase PCROP zone when decreasing RDP */

Definition at line 170 of file stm32f2x.c.

◆ OPTCR_DB1M

#define OPTCR_DB1M   (1 << 30) /* 1 MiB devices dual flash bank option */

Definition at line 166 of file stm32f2x.c.

◆ OPTCR_LOCK

#define OPTCR_LOCK   (1 << 0)

Definition at line 163 of file stm32f2x.c.

◆ OPTCR_NDBANK

#define OPTCR_NDBANK   (1 << 29) /* not dual bank mode */

Definition at line 165 of file stm32f2x.c.

◆ OPTCR_SPRMOD

#define OPTCR_SPRMOD   (1 << 31) /* switches PCROPi/nWPRi interpretation */

Definition at line 167 of file stm32f2x.c.

◆ OPTCR_START

#define OPTCR_START   (1 << 1)

Definition at line 164 of file stm32f2x.c.

◆ OPTKEY1

#define OPTKEY1   0x08192A3B

Definition at line 177 of file stm32f2x.c.

◆ OPTKEY2

#define OPTKEY2   0x4C5D6E7F

Definition at line 178 of file stm32f2x.c.

◆ STM32_FLASH_ACR

#define STM32_FLASH_ACR   0x40023c00

Definition at line 129 of file stm32f2x.c.

◆ STM32_FLASH_BASE

#define STM32_FLASH_BASE   0x40023c00

Definition at line 128 of file stm32f2x.c.

◆ STM32_FLASH_CR

#define STM32_FLASH_CR   0x40023c10

Definition at line 133 of file stm32f2x.c.

◆ STM32_FLASH_KEYR

#define STM32_FLASH_KEYR   0x40023c04

Definition at line 130 of file stm32f2x.c.

◆ STM32_FLASH_OPTCR

#define STM32_FLASH_OPTCR   0x40023c14

Definition at line 134 of file stm32f2x.c.

◆ STM32_FLASH_OPTCR1

#define STM32_FLASH_OPTCR1   0x40023c18

Definition at line 135 of file stm32f2x.c.

◆ STM32_FLASH_OPTCR2

#define STM32_FLASH_OPTCR2   0x40023c1c

Definition at line 136 of file stm32f2x.c.

◆ STM32_FLASH_OPTKEYR

#define STM32_FLASH_OPTKEYR   0x40023c08

Definition at line 131 of file stm32f2x.c.

◆ STM32_FLASH_SR

#define STM32_FLASH_SR   0x40023c0C

Definition at line 132 of file stm32f2x.c.

◆ STM32F2_OTP_BANK_BASE

#define STM32F2_OTP_BANK_BASE   0x1fff7800

Definition at line 119 of file stm32f2x.c.

◆ STM32F2_OTP_LOCK_BASE

#define STM32F2_OTP_LOCK_BASE   ((STM32F2_OTP_BANK_BASE) + (STM32F2_OTP_SIZE))

Definition at line 120 of file stm32f2x.c.

◆ STM32F2_OTP_SECTOR_SIZE

#define STM32F2_OTP_SECTOR_SIZE   32

Definition at line 118 of file stm32f2x.c.

◆ STM32F2_OTP_SIZE

#define STM32F2_OTP_SIZE   512

Definition at line 117 of file stm32f2x.c.

◆ STM32F7_OTP_BANK_BASE

#define STM32F7_OTP_BANK_BASE   0x1ff0f000

Definition at line 125 of file stm32f2x.c.

◆ STM32F7_OTP_LOCK_BASE

#define STM32F7_OTP_LOCK_BASE   ((STM32F7_OTP_BANK_BASE) + (STM32F7_OTP_SIZE))

Definition at line 126 of file stm32f2x.c.

◆ STM32F7_OTP_SECTOR_SIZE

#define STM32F7_OTP_SECTOR_SIZE   64

Definition at line 123 of file stm32f2x.c.

◆ STM32F7_OTP_SIZE

#define STM32F7_OTP_SIZE   1024

Definition at line 124 of file stm32f2x.c.

Function Documentation

◆ calculate_number_of_sectors()

static unsigned int calculate_number_of_sectors ( struct flash_bank bank,
uint16_t  flash_size_in_kb,
uint16_t  max_sector_size_in_kb 
)
static

Definition at line 904 of file stm32f2x.c.

References bank, stm32x_flash_bank::has_large_mem, LOG_INFO, and sector_size_in_kb().

Referenced by stm32x_probe().

◆ COMMAND_HANDLER() [1/7]

◆ COMMAND_HANDLER() [2/7]

◆ COMMAND_HANDLER() [3/7]

◆ COMMAND_HANDLER() [4/7]

◆ COMMAND_HANDLER() [5/7]

COMMAND_HANDLER ( stm32x_handle_mass_erase_command  )

◆ COMMAND_HANDLER() [6/7]

◆ COMMAND_HANDLER() [7/7]

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( stm32x_flash_bank_command  )

◆ get_stm32x_info()

static int get_stm32x_info ( struct flash_bank bank,
struct command_invocation cmd 
)
static

Definition at line 1237 of file stm32f2x.c.

References bank, cmd, command_print_sameline(), ERROR_FAIL, ERROR_OK, NULL, and stm32x_get_device_id().

◆ sector_size_in_kb()

static uint16_t sector_size_in_kb ( unsigned int  i,
uint16_t  max_sector_size_in_kb 
)
static

Definition at line 895 of file stm32f2x.c.

Referenced by calculate_number_of_sectors(), and setup_bank().

◆ setup_bank()

static void setup_bank ( struct flash_bank bank,
unsigned int  start,
uint16_t  flash_size_in_kb,
uint16_t  max_sector_size_in_kb 
)
static

Definition at line 931 of file stm32f2x.c.

References bank, sector_size_in_kb(), setup_sector(), and start.

Referenced by stm32x_probe().

◆ setup_sector()

static void setup_sector ( struct flash_bank bank,
unsigned int  i,
unsigned int  size 
)
static

Definition at line 885 of file stm32f2x.c.

References bank, LOG_DEBUG, and size.

Referenced by setup_bank().

◆ stm32x_auto_probe()

static int stm32x_auto_probe ( struct flash_bank bank)
static

Definition at line 1229 of file stm32f2x.c.

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

◆ stm32x_erase()

◆ stm32x_get_device_id()

static int stm32x_get_device_id ( struct flash_bank bank,
uint32_t *  device_id 
)
static

◆ stm32x_get_flash_reg()

static int stm32x_get_flash_reg ( struct flash_bank bank,
uint32_t  reg 
)
inlinestatic

◆ stm32x_get_flash_status()

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

Definition at line 267 of file stm32f2x.c.

References bank, status, STM32_FLASH_SR, stm32x_get_flash_reg(), and target_read_u32().

Referenced by stm32x_wait_status_busy().

◆ stm32x_is_otp()

static bool stm32x_is_otp ( struct flash_bank bank)
static

◆ stm32x_is_otp_unlocked()

static int stm32x_is_otp_unlocked ( struct flash_bank bank)
static

Definition at line 211 of file stm32f2x.c.

References bank, and stm32x_flash_bank::otp_unlocked.

Referenced by COMMAND_HANDLER(), and stm32x_write_block().

◆ stm32x_mass_erase()

◆ stm32x_otp_disable()

static int stm32x_otp_disable ( struct flash_bank bank)
static

Definition at line 218 of file stm32f2x.c.

References bank, ERROR_OK, LOG_INFO, and stm32x_flash_bank::otp_unlocked.

Referenced by COMMAND_HANDLER().

◆ stm32x_otp_enable()

static int stm32x_otp_enable ( struct flash_bank bank)
static

Definition at line 228 of file stm32f2x.c.

References bank, ERROR_OK, LOG_INFO, LOG_WARNING, and stm32x_flash_bank::otp_unlocked.

Referenced by COMMAND_HANDLER().

◆ stm32x_otp_is_f7()

static bool stm32x_otp_is_f7 ( struct flash_bank bank)
static

Definition at line 206 of file stm32f2x.c.

References bank, and STM32F7_OTP_BANK_BASE.

Referenced by stm32x_otp_protect(), stm32x_otp_read_protect(), and stm32x_probe().

◆ stm32x_otp_protect()

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

◆ stm32x_otp_read_protect()

static int stm32x_otp_read_protect ( struct flash_bank bank)
static

◆ stm32x_probe()

◆ stm32x_protect()

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

◆ stm32x_protect_check()

◆ stm32x_read_options()

◆ stm32x_unlock_option_reg()

static int stm32x_unlock_option_reg ( struct target target)
static

◆ stm32x_unlock_reg()

static int stm32x_unlock_reg ( struct target target)
static

◆ stm32x_wait_status_busy()

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

◆ stm32x_write()

◆ stm32x_write_block()

◆ stm32x_write_options()

Variable Documentation

◆ stm32f2x_command_handlers

const struct command_registration stm32f2x_command_handlers[]
static
Initial value:
= {
{
.name = "stm32f2x",
.mode = COMMAND_ANY,
.help = "stm32f2x 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 stm32f2x_exec_command_handlers[]
Definition: stm32f2x.c:1728

Definition at line 1699 of file stm32f2x.c.

◆ stm32f2x_exec_command_handlers

const struct command_registration stm32f2x_exec_command_handlers[]
static

Definition at line 1699 of file stm32f2x.c.

◆ stm32f2x_flash

const struct flash_driver stm32f2x_flash
Initial value:
= {
.name = "stm32f2x",
.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 = get_stm32x_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: stm32f2x.c:1229
static int stm32x_probe(struct flash_bank *bank)
Definition: stm32f2x.c:972
static int get_stm32x_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: stm32f2x.c:1237
static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: stm32f2x.c:789
static int stm32x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: stm32f2x.c:592
static int stm32x_protect_check(struct flash_bank *bank)
Definition: stm32f2x.c:559
static const struct command_registration stm32f2x_command_handlers[]
Definition: stm32f2x.c:1781
static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: stm32f2x.c:650

Definition at line 1699 of file stm32f2x.c.