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

Go to the source code of this file.

Data Structures

struct  stm32x_flash_bank
 
struct  stm32x_options
 
struct  stm32x_property_addr
 

Macros

#define FLASH_BSY   (1 << 0)
 
#define FLASH_EOP   (1 << 5)
 
#define FLASH_ERASE_TIMEOUT   100
 
#define FLASH_LOCK   (1 << 7)
 
#define FLASH_MER   (1 << 2)
 
#define FLASH_OBL_LAUNCH   (1 << 13) /* except stm32f1x series */
 
#define FLASH_OPTER   (1 << 5)
 
#define FLASH_OPTPG   (1 << 4)
 
#define FLASH_OPTWRE   (1 << 9)
 
#define FLASH_PER   (1 << 1)
 
#define FLASH_PG   (1 << 0)
 
#define FLASH_PGERR   (1 << 2)
 
#define FLASH_REG_BASE_B0   0x40022000
 
#define FLASH_REG_BASE_B1   0x40022040
 
#define FLASH_STRT   (1 << 6)
 
#define FLASH_WRITE_TIMEOUT   10
 
#define FLASH_WRPRTERR   (1 << 4)
 
#define KEY1   0x45670123
 
#define KEY2   0xCDEF89AB
 
#define OPT_BFB2   5 /* dual flash bank only */
 
#define OPT_ERROR   0
 
#define OPT_RDRSTSTDBY   4
 
#define OPT_RDRSTSTOP   3
 
#define OPT_RDWDGSW   2
 
#define OPT_READOUT   1
 
#define STM32_FLASH_ACR   0x00
 
#define STM32_FLASH_ACR_B0   0x40022000
 
#define STM32_FLASH_AR   0x14
 
#define STM32_FLASH_AR_B0   0x40022014
 
#define STM32_FLASH_CR   0x10
 
#define STM32_FLASH_CR_B0   0x40022010
 
#define STM32_FLASH_KEYR   0x04
 
#define STM32_FLASH_KEYR_B0   0x40022004
 
#define STM32_FLASH_OBR   0x1C
 
#define STM32_FLASH_OBR_B0   0x4002201C
 
#define STM32_FLASH_OPTKEYR   0x08
 
#define STM32_FLASH_OPTKEYR_B0   0x40022008
 
#define STM32_FLASH_SR   0x0C
 
#define STM32_FLASH_SR_B0   0x4002200C
 
#define STM32_FLASH_WRPR   0x20
 
#define STM32_FLASH_WRPR_B0   0x40022020
 
#define STM32_OB_DATA0   0x1FFFF804
 
#define STM32_OB_DATA1   0x1FFFF806
 
#define STM32_OB_RDP   0x1FFFF800
 
#define STM32_OB_USER   0x1FFFF802
 
#define STM32_OB_WRP0   0x1FFFF808
 
#define STM32_OB_WRP1   0x1FFFF80A
 
#define STM32_OB_WRP2   0x1FFFF80C
 
#define STM32_OB_WRP3   0x1FFFF80E
 

Functions

 COMMAND_HANDLER (stm32x_handle_lock_command)
 
 COMMAND_HANDLER (stm32x_handle_mass_erase_command)
 
 COMMAND_HANDLER (stm32x_handle_options_load_command)
 
 COMMAND_HANDLER (stm32x_handle_options_read_command)
 
 COMMAND_HANDLER (stm32x_handle_options_write_command)
 
 COMMAND_HANDLER (stm32x_handle_unlock_command)
 
 FLASH_BANK_COMMAND_HANDLER (stm32x_flash_bank_command)
 
static const char * get_stm32f0_revision (uint16_t rev_id)
 
static int get_stm32x_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int stm32x_auto_probe (struct flash_bank *bank)
 
static int stm32x_check_operation_supported (struct flash_bank *bank)
 
static int stm32x_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int stm32x_erase_options (struct flash_bank *bank)
 
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_size (struct flash_bank *bank, uint16_t *flash_size_in_kb)
 
static int stm32x_get_flash_status (struct flash_bank *bank, uint32_t *status)
 
static int stm32x_get_property_addr (struct target *target, struct stm32x_property_addr *addr)
 
static int stm32x_mass_erase (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_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 address, uint32_t hwords_count)
 Writes a block to flash either using target algorithm or use fallback, host controlled halfword-by-halfword access. More...
 
static int stm32x_write_block_async (struct flash_bank *bank, const uint8_t *buffer, uint32_t address, uint32_t hwords_count)
 
static int stm32x_write_block_riscv (struct flash_bank *bank, const uint8_t *buffer, uint32_t address, uint32_t hwords_count)
 
static int stm32x_write_options (struct flash_bank *bank)
 

Variables

static const struct command_registration stm32f1x_command_handlers []
 
static const struct command_registration stm32f1x_exec_command_handlers []
 
const struct flash_driver stm32f1x_flash
 

Macro Definition Documentation

◆ FLASH_BSY

#define FLASH_BSY   (1 << 0)

Definition at line 76 of file stm32f1x.c.

◆ FLASH_EOP

#define FLASH_EOP   (1 << 5)

Definition at line 79 of file stm32f1x.c.

◆ FLASH_ERASE_TIMEOUT

#define FLASH_ERASE_TIMEOUT   100

Definition at line 98 of file stm32f1x.c.

◆ FLASH_LOCK

#define FLASH_LOCK   (1 << 7)

Definition at line 70 of file stm32f1x.c.

◆ FLASH_MER

#define FLASH_MER   (1 << 2)

Definition at line 66 of file stm32f1x.c.

◆ FLASH_OBL_LAUNCH

#define FLASH_OBL_LAUNCH   (1 << 13) /* except stm32f1x series */

Definition at line 72 of file stm32f1x.c.

◆ FLASH_OPTER

#define FLASH_OPTER   (1 << 5)

Definition at line 68 of file stm32f1x.c.

◆ FLASH_OPTPG

#define FLASH_OPTPG   (1 << 4)

Definition at line 67 of file stm32f1x.c.

◆ FLASH_OPTWRE

#define FLASH_OPTWRE   (1 << 9)

Definition at line 71 of file stm32f1x.c.

◆ FLASH_PER

#define FLASH_PER   (1 << 1)

Definition at line 65 of file stm32f1x.c.

◆ FLASH_PG

#define FLASH_PG   (1 << 0)

Definition at line 64 of file stm32f1x.c.

◆ FLASH_PGERR

#define FLASH_PGERR   (1 << 2)

Definition at line 77 of file stm32f1x.c.

◆ FLASH_REG_BASE_B0

#define FLASH_REG_BASE_B0   0x40022000

Definition at line 27 of file stm32f1x.c.

◆ FLASH_REG_BASE_B1

#define FLASH_REG_BASE_B1   0x40022040

Definition at line 28 of file stm32f1x.c.

◆ FLASH_STRT

#define FLASH_STRT   (1 << 6)

Definition at line 69 of file stm32f1x.c.

◆ FLASH_WRITE_TIMEOUT

#define FLASH_WRITE_TIMEOUT   10

Definition at line 97 of file stm32f1x.c.

◆ FLASH_WRPRTERR

#define FLASH_WRPRTERR   (1 << 4)

Definition at line 78 of file stm32f1x.c.

◆ KEY1

#define KEY1   0x45670123

Definition at line 92 of file stm32f1x.c.

◆ KEY2

#define KEY2   0xCDEF89AB

Definition at line 93 of file stm32f1x.c.

◆ OPT_BFB2

#define OPT_BFB2   5 /* dual flash bank only */

Definition at line 88 of file stm32f1x.c.

◆ OPT_ERROR

#define OPT_ERROR   0

Definition at line 83 of file stm32f1x.c.

◆ OPT_RDRSTSTDBY

#define OPT_RDRSTSTDBY   4

Definition at line 87 of file stm32f1x.c.

◆ OPT_RDRSTSTOP

#define OPT_RDRSTSTOP   3

Definition at line 86 of file stm32f1x.c.

◆ OPT_RDWDGSW

#define OPT_RDWDGSW   2

Definition at line 85 of file stm32f1x.c.

◆ OPT_READOUT

#define OPT_READOUT   1

Definition at line 84 of file stm32f1x.c.

◆ STM32_FLASH_ACR

#define STM32_FLASH_ACR   0x00

Definition at line 30 of file stm32f1x.c.

◆ STM32_FLASH_ACR_B0

#define STM32_FLASH_ACR_B0   0x40022000

Definition at line 42 of file stm32f1x.c.

◆ STM32_FLASH_AR

#define STM32_FLASH_AR   0x14

Definition at line 35 of file stm32f1x.c.

◆ STM32_FLASH_AR_B0

#define STM32_FLASH_AR_B0   0x40022014

Definition at line 47 of file stm32f1x.c.

◆ STM32_FLASH_CR

#define STM32_FLASH_CR   0x10

Definition at line 34 of file stm32f1x.c.

◆ STM32_FLASH_CR_B0

#define STM32_FLASH_CR_B0   0x40022010

Definition at line 46 of file stm32f1x.c.

◆ STM32_FLASH_KEYR

#define STM32_FLASH_KEYR   0x04

Definition at line 31 of file stm32f1x.c.

◆ STM32_FLASH_KEYR_B0

#define STM32_FLASH_KEYR_B0   0x40022004

Definition at line 43 of file stm32f1x.c.

◆ STM32_FLASH_OBR

#define STM32_FLASH_OBR   0x1C

Definition at line 36 of file stm32f1x.c.

◆ STM32_FLASH_OBR_B0

#define STM32_FLASH_OBR_B0   0x4002201C

Definition at line 48 of file stm32f1x.c.

◆ STM32_FLASH_OPTKEYR

#define STM32_FLASH_OPTKEYR   0x08

Definition at line 32 of file stm32f1x.c.

◆ STM32_FLASH_OPTKEYR_B0

#define STM32_FLASH_OPTKEYR_B0   0x40022008

Definition at line 44 of file stm32f1x.c.

◆ STM32_FLASH_SR

#define STM32_FLASH_SR   0x0C

Definition at line 33 of file stm32f1x.c.

◆ STM32_FLASH_SR_B0

#define STM32_FLASH_SR_B0   0x4002200C

Definition at line 45 of file stm32f1x.c.

◆ STM32_FLASH_WRPR

#define STM32_FLASH_WRPR   0x20

Definition at line 37 of file stm32f1x.c.

◆ STM32_FLASH_WRPR_B0

#define STM32_FLASH_WRPR_B0   0x40022020

Definition at line 49 of file stm32f1x.c.

◆ STM32_OB_DATA0

#define STM32_OB_DATA0   0x1FFFF804

Definition at line 55 of file stm32f1x.c.

◆ STM32_OB_DATA1

#define STM32_OB_DATA1   0x1FFFF806

Definition at line 56 of file stm32f1x.c.

◆ STM32_OB_RDP

#define STM32_OB_RDP   0x1FFFF800

Definition at line 53 of file stm32f1x.c.

◆ STM32_OB_USER

#define STM32_OB_USER   0x1FFFF802

Definition at line 54 of file stm32f1x.c.

◆ STM32_OB_WRP0

#define STM32_OB_WRP0   0x1FFFF808

Definition at line 57 of file stm32f1x.c.

◆ STM32_OB_WRP1

#define STM32_OB_WRP1   0x1FFFF80A

Definition at line 58 of file stm32f1x.c.

◆ STM32_OB_WRP2

#define STM32_OB_WRP2   0x1FFFF80C

Definition at line 59 of file stm32f1x.c.

◆ STM32_OB_WRP3

#define STM32_OB_WRP3   0x1FFFF80E

Definition at line 60 of file stm32f1x.c.

Function Documentation

◆ COMMAND_HANDLER() [1/6]

◆ COMMAND_HANDLER() [2/6]

COMMAND_HANDLER ( stm32x_handle_mass_erase_command  )

◆ COMMAND_HANDLER() [3/6]

◆ COMMAND_HANDLER() [4/6]

◆ COMMAND_HANDLER() [5/6]

◆ COMMAND_HANDLER() [6/6]

◆ FLASH_BANK_COMMAND_HANDLER()

◆ get_stm32f0_revision()

static const char* get_stm32f0_revision ( uint16_t  rev_id)
static

Definition at line 1068 of file stm32f1x.c.

References NULL.

Referenced by get_stm32x_info().

◆ get_stm32x_info()

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

◆ stm32x_auto_probe()

static int stm32x_auto_probe ( struct flash_bank bank)
static

Definition at line 1053 of file stm32f1x.c.

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

◆ stm32x_check_operation_supported()

static int stm32x_check_operation_supported ( struct flash_bank bank)
static

◆ stm32x_erase()

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

◆ stm32x_erase_options()

◆ 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_size()

static int stm32x_get_flash_size ( struct flash_bank bank,
uint16_t *  flash_size_in_kb 
)
static

Definition at line 794 of file stm32f1x.c.

References addr, bank, ERROR_OK, stm32x_get_property_addr(), and target_read_u16().

Referenced by stm32x_probe().

◆ stm32x_get_flash_status()

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

Definition at line 156 of file stm32f1x.c.

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

Referenced by stm32x_wait_status_busy().

◆ stm32x_get_property_addr()

◆ stm32x_mass_erase()

◆ 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

◆ stm32x_read_options()

◆ stm32x_wait_status_busy()

◆ stm32x_write()

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

◆ stm32x_write_block()

static int stm32x_write_block ( struct flash_bank bank,
const uint8_t *  buffer,
uint32_t  address,
uint32_t  hwords_count 
)
static

Writes a block to flash either using target algorithm or use fallback, host controlled halfword-by-halfword access.

Flash controller must be unlocked before this call.

Definition at line 650 of file stm32f1x.c.

References bank, buffer, ERROR_OK, ERROR_TARGET_RESOURCE_NOT_AVAILABLE, is_arm(), LOG_WARNING, stm32x_wait_status_busy(), stm32x_write_block_async(), stm32x_write_block_riscv(), target_to_arm(), and target_write_memory().

Referenced by stm32x_write(), and stm32x_write_options().

◆ stm32x_write_block_async()

◆ stm32x_write_block_riscv()

◆ stm32x_write_options()

Variable Documentation

◆ stm32f1x_command_handlers

const struct command_registration stm32f1x_command_handlers[]
static
Initial value:
= {
{
.name = "stm32f1x",
.mode = COMMAND_ANY,
.help = "stm32f1x 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 stm32f1x_exec_command_handlers[]
Definition: stm32f1x.c:1670

Definition at line 1651 of file stm32f1x.c.

◆ stm32f1x_exec_command_handlers

const struct command_registration stm32f1x_exec_command_handlers[]
static

Definition at line 1651 of file stm32f1x.c.

◆ stm32f1x_flash

const struct flash_driver stm32f1x_flash
Initial value:
= {
.name = "stm32f1x",
.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: stm32f1x.c:1053
static int stm32x_probe(struct flash_bank *bank)
Definition: stm32f1x.c:806
static const struct command_registration stm32f1x_command_handlers[]
Definition: stm32f1x.c:1718
static int get_stm32x_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: stm32f1x.c:1083
static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: stm32f1x.c:692
static int stm32x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: stm32f1x.c:366
static int stm32x_protect_check(struct flash_bank *bank)
Definition: stm32f1x.c:344
static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: stm32f1x.c:414

Definition at line 1651 of file stm32f1x.c.