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
 

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_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_unlock_command)
 
 COMMAND_HANDLER (stm32x_handle_options_read_command)
 
 COMMAND_HANDLER (stm32x_handle_options_write_command)
 
 COMMAND_HANDLER (stm32x_handle_mass_erase_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, char *buf, int buf_size)
 
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, int first, 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_mass_erase (struct flash_bank *bank)
 
static int stm32x_probe (struct flash_bank *bank)
 
static int stm32x_protect (struct flash_bank *bank, int set, int first, 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 offset, uint32_t count)
 
static int stm32x_write_options (struct flash_bank *bank)
 

Variables

struct flash_driver stm32f1x_flash
 
static const struct
command_registration 
stm32x_command_handlers []
 
static const struct
command_registration 
stm32x_exec_command_handlers []
 

Macro Definition Documentation

#define FLASH_BSY   (1 << 0)

Definition at line 84 of file stm32f1x.c.

Referenced by stm32x_wait_status_busy().

#define FLASH_EOP   (1 << 5)

Definition at line 87 of file stm32f1x.c.

#define FLASH_ERASE_TIMEOUT   100

Definition at line 106 of file stm32f1x.c.

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

#define FLASH_LOCK   (1 << 7)

Definition at line 79 of file stm32f1x.c.

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

#define FLASH_MER   (1 << 2)

Definition at line 75 of file stm32f1x.c.

Referenced by stm32x_mass_erase().

#define FLASH_OPTER   (1 << 5)

Definition at line 77 of file stm32f1x.c.

Referenced by stm32x_erase_options().

#define FLASH_OPTPG   (1 << 4)

Definition at line 76 of file stm32f1x.c.

Referenced by stm32x_write_options().

#define FLASH_OPTWRE   (1 << 9)

Definition at line 80 of file stm32f1x.c.

Referenced by stm32x_erase_options(), and stm32x_write_options().

#define FLASH_PER   (1 << 1)

Definition at line 74 of file stm32f1x.c.

Referenced by stm32x_erase().

#define FLASH_PG   (1 << 0)

Definition at line 73 of file stm32f1x.c.

Referenced by stm32x_write().

#define FLASH_PGERR   (1 << 2)

Definition at line 85 of file stm32f1x.c.

Referenced by stm32x_wait_status_busy(), and stm32x_write_block().

#define FLASH_REG_BASE_B0   0x40022000
#define FLASH_REG_BASE_B1   0x40022040

Definition at line 37 of file stm32f1x.c.

Referenced by stm32x_probe().

#define FLASH_STRT   (1 << 6)

Definition at line 78 of file stm32f1x.c.

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

#define FLASH_WRITE_TIMEOUT   10

Definition at line 105 of file stm32f1x.c.

#define FLASH_WRPRTERR   (1 << 4)

Definition at line 86 of file stm32f1x.c.

Referenced by stm32x_wait_status_busy(), and stm32x_write_block().

#define KEY1   0x45670123
#define KEY2   0xCDEF89AB
#define OPT_BFB2   5 /* dual flash bank only */

Definition at line 96 of file stm32f1x.c.

Referenced by COMMAND_HANDLER().

#define OPT_ERROR   0

Definition at line 91 of file stm32f1x.c.

Referenced by COMMAND_HANDLER().

#define OPT_RDRSTSTDBY   4

Definition at line 95 of file stm32f1x.c.

Referenced by COMMAND_HANDLER().

#define OPT_RDRSTSTOP   3

Definition at line 94 of file stm32f1x.c.

Referenced by COMMAND_HANDLER().

#define OPT_RDWDGSW   2

Definition at line 93 of file stm32f1x.c.

Referenced by COMMAND_HANDLER().

#define OPT_READOUT   1

Definition at line 92 of file stm32f1x.c.

Referenced by COMMAND_HANDLER(), and stm32x_read_options().

#define STM32_FLASH_ACR   0x00

Definition at line 39 of file stm32f1x.c.

#define STM32_FLASH_ACR_B0   0x40022000

Definition at line 51 of file stm32f1x.c.

#define STM32_FLASH_AR   0x14

Definition at line 44 of file stm32f1x.c.

Referenced by stm32x_erase().

#define STM32_FLASH_AR_B0   0x40022014

Definition at line 56 of file stm32f1x.c.

#define STM32_FLASH_CR   0x10

Definition at line 43 of file stm32f1x.c.

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

#define STM32_FLASH_CR_B0   0x40022010

Definition at line 55 of file stm32f1x.c.

Referenced by stm32x_erase_options(), and stm32x_write_options().

#define STM32_FLASH_KEYR   0x04

Definition at line 40 of file stm32f1x.c.

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

#define STM32_FLASH_KEYR_B0   0x40022004

Definition at line 52 of file stm32f1x.c.

Referenced by stm32x_erase_options(), and stm32x_write_options().

#define STM32_FLASH_OBR   0x1C

Definition at line 45 of file stm32f1x.c.

#define STM32_FLASH_OBR_B0   0x4002201C

Definition at line 57 of file stm32f1x.c.

Referenced by COMMAND_HANDLER(), and stm32x_read_options().

#define STM32_FLASH_OPTKEYR   0x08

Definition at line 41 of file stm32f1x.c.

#define STM32_FLASH_OPTKEYR_B0   0x40022008

Definition at line 53 of file stm32f1x.c.

Referenced by stm32x_erase_options(), and stm32x_write_options().

#define STM32_FLASH_SR   0x0C

Definition at line 42 of file stm32f1x.c.

Referenced by stm32x_get_flash_status(), stm32x_wait_status_busy(), and stm32x_write_block().

#define STM32_FLASH_SR_B0   0x4002200C

Definition at line 54 of file stm32f1x.c.

#define STM32_FLASH_WRPR   0x20

Definition at line 46 of file stm32f1x.c.

#define STM32_FLASH_WRPR_B0   0x40022020

Definition at line 58 of file stm32f1x.c.

Referenced by stm32x_protect(), stm32x_protect_check(), and stm32x_read_options().

#define STM32_OB_DATA0   0x1FFFF804

Definition at line 64 of file stm32f1x.c.

#define STM32_OB_DATA1   0x1FFFF806

Definition at line 65 of file stm32f1x.c.

#define STM32_OB_RDP   0x1FFFF800

Definition at line 62 of file stm32f1x.c.

Referenced by stm32x_write_options().

#define STM32_OB_USER   0x1FFFF802

Definition at line 63 of file stm32f1x.c.

#define STM32_OB_WRP0   0x1FFFF808

Definition at line 66 of file stm32f1x.c.

#define STM32_OB_WRP1   0x1FFFF80A

Definition at line 67 of file stm32f1x.c.

#define STM32_OB_WRP2   0x1FFFF80C

Definition at line 68 of file stm32f1x.c.

#define STM32_OB_WRP3   0x1FFFF80E

Definition at line 69 of file stm32f1x.c.

Function Documentation

static const char* get_stm32f0_revision ( uint16_t  rev_id)
static

Definition at line 1042 of file stm32f1x.c.

References NULL.

Referenced by get_stm32x_info().

static int get_stm32x_info ( struct flash_bank bank,
char *  buf,
int  buf_size 
)
static

Definition at line 1057 of file stm32f1x.c.

References ERROR_FAIL, ERROR_OK, get_stm32f0_revision(), NULL, and stm32x_get_device_id().

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

Definition at line 777 of file stm32f1x.c.

References ERROR_FAIL, ERROR_OK, LOG_ERROR, flash_bank::target, and target_read_u32().

Referenced by get_stm32x_info(), and stm32x_probe().

static int stm32x_get_flash_reg ( struct flash_bank bank,
uint32_t  reg 
)
inlinestatic
static int stm32x_get_flash_size ( struct flash_bank bank,
uint16_t *  flash_size_in_kb 
)
static

Definition at line 813 of file stm32f1x.c.

References ERROR_FAIL, ERROR_OK, LOG_ERROR, flash_bank::target, target_read_u16(), and target_read_u32().

Referenced by stm32x_probe().

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

Variable Documentation

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,
}
static int stm32x_probe(struct flash_bank *bank)
Definition: stm32f1x.c:843
static int get_stm32x_info(struct flash_bank *bank, char *buf, int buf_size)
Definition: stm32f1x.c:1057
static int stm32x_auto_probe(struct flash_bank *bank)
Definition: stm32f1x.c:1027
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
static int stm32x_erase(struct flash_bank *bank, int first, int last)
Definition: stm32f1x.c:420
static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: stm32f1x.c:693
static const struct command_registration stm32x_command_handlers[]
Definition: stm32f1x.c:1626
static int stm32x_protect_check(struct flash_bank *bank)
Definition: stm32f1x.c:355
static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
Definition: stm32f1x.c:468

Definition at line 1637 of file stm32f1x.c.

const struct command_registration stm32x_command_handlers[]
static
Initial value:
= {
{
.name = "stm32f1x",
.mode = COMMAND_ANY,
.help = "stm32f1x flash command group",
.usage = "",
},
}
static const struct command_registration stm32x_exec_command_handlers[]
Definition: stm32f1x.c:1585
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:222

Definition at line 1626 of file stm32f1x.c.

const struct command_registration stm32x_exec_command_handlers[]
static

Definition at line 1585 of file stm32f1x.c.