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

Go to the source code of this file.

Data Structures

struct  stm32lx_flash_bank
 
struct  stm32lx_part_info
 
struct  stm32lx_rev
 

Macros

#define DBGMCU_IDCODE   0xE0042000
 
#define DBGMCU_IDCODE_L0   0x40015800
 
#define FLASH_ACR   0x00
 
#define FLASH_ACR__ACC64   (1<<2)
 
#define FLASH_ACR__LATENCY   (1<<0)
 
#define FLASH_ACR__PRFTEN   (1<<1)
 
#define FLASH_ACR__RUN_PD   (1<<4)
 
#define FLASH_ACR__SLEEP_PD   (1<<3)
 
#define FLASH_BANK0_ADDRESS   0x08000000
 
#define FLASH_OBR   0x1C
 
#define FLASH_OPTKEYR   0x14
 
#define FLASH_PDKEYR   0x08
 
#define FLASH_PECR   0x04
 
#define FLASH_PECR__DATA   (1<<4)
 
#define FLASH_PECR__EOPIE   (1<<16)
 
#define FLASH_PECR__ERASE   (1<<9)
 
#define FLASH_PECR__ERRIE   (1<<17)
 
#define FLASH_PECR__FPRG   (1<<10)
 
#define FLASH_PECR__FTDW   (1<<8)
 
#define FLASH_PECR__OBL_LAUNCH   (1<<18)
 
#define FLASH_PECR__OPTLOCK   (1<<2)
 
#define FLASH_PECR__PELOCK   (1<<0)
 
#define FLASH_PECR__PRGLOCK   (1<<1)
 
#define FLASH_PECR__PROG   (1<<3)
 
#define FLASH_PEKEYR   0x0C
 
#define FLASH_PRGKEYR   0x10
 
#define FLASH_SECTOR_SIZE   4096
 
#define FLASH_SR   0x18
 
#define FLASH_SR__BSY   (1<<0)
 
#define FLASH_SR__ENDHV   (1<<2)
 
#define FLASH_SR__EOP   (1<<1)
 
#define FLASH_SR__OPTVERR   (1<<11)
 
#define FLASH_SR__PGAERR   (1<<9)
 
#define FLASH_SR__READY   (1<<3)
 
#define FLASH_SR__SIZERR   (1<<10)
 
#define FLASH_SR__WRPERR   (1<<8)
 
#define FLASH_WRPR   0x20
 
#define OPTION_BYTE_0_PR0   0xFF5500AA
 
#define OPTION_BYTE_0_PR1   0xFFFF0000
 
#define OPTION_BYTES_ADDRESS   0x1FF80000
 
#define OPTKEY1   0xFBEAD9C8
 
#define OPTKEY2   0x24252627
 
#define PEKEY1   0x89ABCDEF
 
#define PEKEY2   0x02030405
 
#define PRGKEY1   0x8C9DAEBF
 
#define PRGKEY2   0x13141516
 

Functions

 COMMAND_HANDLER (stm32lx_handle_lock_command)
 
 COMMAND_HANDLER (stm32lx_handle_mass_erase_command)
 
 COMMAND_HANDLER (stm32lx_handle_unlock_command)
 
 FLASH_BANK_COMMAND_HANDLER (stm32lx_flash_bank_command)
 
static int stm32lx_auto_probe (struct flash_bank *bank)
 
static int stm32lx_enable_write_half_page (struct flash_bank *bank)
 
static int stm32lx_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int stm32lx_erase_sector (struct flash_bank *bank, int sector)
 
static int stm32lx_get_flash_status (struct flash_bank *bank, uint32_t *status)
 
static int stm32lx_get_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int stm32lx_lock (struct flash_bank *bank)
 
static int stm32lx_lock_program_memory (struct flash_bank *bank)
 
static int stm32lx_mass_erase (struct flash_bank *bank)
 
static int stm32lx_obl_launch (struct flash_bank *bank)
 
static int stm32lx_probe (struct flash_bank *bank)
 
static int stm32lx_protect_check (struct flash_bank *bank)
 
static int stm32lx_read_id_code (struct target *target, uint32_t *id)
 
static int stm32lx_unlock (struct flash_bank *bank)
 
static int stm32lx_unlock_options_bytes (struct flash_bank *bank)
 
static int stm32lx_unlock_program_memory (struct flash_bank *bank)
 
static int stm32lx_update_part_info (struct flash_bank *bank, uint16_t flash_size_in_kb)
 
static int stm32lx_wait_until_bsy_clear (struct flash_bank *bank)
 
static int stm32lx_wait_until_bsy_clear_timeout (struct flash_bank *bank, int timeout)
 
static int stm32lx_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
static int stm32lx_write_half_pages (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 

Variables

static const struct stm32lx_rev stm32_416_revs []
 
static const struct stm32lx_rev stm32_417_revs []
 
static const struct stm32lx_rev stm32_425_revs []
 
static const struct stm32lx_rev stm32_427_revs []
 
static const struct stm32lx_rev stm32_429_revs []
 
static const struct stm32lx_rev stm32_436_revs []
 
static const struct stm32lx_rev stm32_437_revs []
 
static const struct stm32lx_rev stm32_447_revs []
 
static const struct stm32lx_rev stm32_457_revs []
 
static const struct command_registration stm32lx_command_handlers []
 
static const struct command_registration stm32lx_exec_command_handlers []
 
const struct flash_driver stm32lx_flash
 
static const struct stm32lx_part_info stm32lx_parts []
 

Macro Definition Documentation

◆ DBGMCU_IDCODE

#define DBGMCU_IDCODE   0xE0042000

Definition at line 75 of file stm32lx.c.

◆ DBGMCU_IDCODE_L0

#define DBGMCU_IDCODE_L0   0x40015800

Definition at line 76 of file stm32lx.c.

◆ FLASH_ACR

#define FLASH_ACR   0x00

Definition at line 26 of file stm32lx.c.

◆ FLASH_ACR__ACC64

#define FLASH_ACR__ACC64   (1<<2)

Definition at line 39 of file stm32lx.c.

◆ FLASH_ACR__LATENCY

#define FLASH_ACR__LATENCY   (1<<0)

Definition at line 37 of file stm32lx.c.

◆ FLASH_ACR__PRFTEN

#define FLASH_ACR__PRFTEN   (1<<1)

Definition at line 38 of file stm32lx.c.

◆ FLASH_ACR__RUN_PD

#define FLASH_ACR__RUN_PD   (1<<4)

Definition at line 41 of file stm32lx.c.

◆ FLASH_ACR__SLEEP_PD

#define FLASH_ACR__SLEEP_PD   (1<<3)

Definition at line 40 of file stm32lx.c.

◆ FLASH_BANK0_ADDRESS

#define FLASH_BANK0_ADDRESS   0x08000000

Definition at line 80 of file stm32lx.c.

◆ FLASH_OBR

#define FLASH_OBR   0x1C

Definition at line 33 of file stm32lx.c.

◆ FLASH_OPTKEYR

#define FLASH_OPTKEYR   0x14

Definition at line 31 of file stm32lx.c.

◆ FLASH_PDKEYR

#define FLASH_PDKEYR   0x08

Definition at line 28 of file stm32lx.c.

◆ FLASH_PECR

#define FLASH_PECR   0x04

Definition at line 27 of file stm32lx.c.

◆ FLASH_PECR__DATA

#define FLASH_PECR__DATA   (1<<4)

Definition at line 48 of file stm32lx.c.

◆ FLASH_PECR__EOPIE

#define FLASH_PECR__EOPIE   (1<<16)

Definition at line 52 of file stm32lx.c.

◆ FLASH_PECR__ERASE

#define FLASH_PECR__ERASE   (1<<9)

Definition at line 50 of file stm32lx.c.

◆ FLASH_PECR__ERRIE

#define FLASH_PECR__ERRIE   (1<<17)

Definition at line 53 of file stm32lx.c.

◆ FLASH_PECR__FPRG

#define FLASH_PECR__FPRG   (1<<10)

Definition at line 51 of file stm32lx.c.

◆ FLASH_PECR__FTDW

#define FLASH_PECR__FTDW   (1<<8)

Definition at line 49 of file stm32lx.c.

◆ FLASH_PECR__OBL_LAUNCH

#define FLASH_PECR__OBL_LAUNCH   (1<<18)

Definition at line 54 of file stm32lx.c.

◆ FLASH_PECR__OPTLOCK

#define FLASH_PECR__OPTLOCK   (1<<2)

Definition at line 46 of file stm32lx.c.

◆ FLASH_PECR__PELOCK

#define FLASH_PECR__PELOCK   (1<<0)

Definition at line 44 of file stm32lx.c.

◆ FLASH_PECR__PRGLOCK

#define FLASH_PECR__PRGLOCK   (1<<1)

Definition at line 45 of file stm32lx.c.

◆ FLASH_PECR__PROG

#define FLASH_PECR__PROG   (1<<3)

Definition at line 47 of file stm32lx.c.

◆ FLASH_PEKEYR

#define FLASH_PEKEYR   0x0C

Definition at line 29 of file stm32lx.c.

◆ FLASH_PRGKEYR

#define FLASH_PRGKEYR   0x10

Definition at line 30 of file stm32lx.c.

◆ FLASH_SECTOR_SIZE

#define FLASH_SECTOR_SIZE   4096

Definition at line 79 of file stm32lx.c.

◆ FLASH_SR

#define FLASH_SR   0x18

Definition at line 32 of file stm32lx.c.

◆ FLASH_SR__BSY

#define FLASH_SR__BSY   (1<<0)

Definition at line 57 of file stm32lx.c.

◆ FLASH_SR__ENDHV

#define FLASH_SR__ENDHV   (1<<2)

Definition at line 59 of file stm32lx.c.

◆ FLASH_SR__EOP

#define FLASH_SR__EOP   (1<<1)

Definition at line 58 of file stm32lx.c.

◆ FLASH_SR__OPTVERR

#define FLASH_SR__OPTVERR   (1<<11)

Definition at line 64 of file stm32lx.c.

◆ FLASH_SR__PGAERR

#define FLASH_SR__PGAERR   (1<<9)

Definition at line 62 of file stm32lx.c.

◆ FLASH_SR__READY

#define FLASH_SR__READY   (1<<3)

Definition at line 60 of file stm32lx.c.

◆ FLASH_SR__SIZERR

#define FLASH_SR__SIZERR   (1<<10)

Definition at line 63 of file stm32lx.c.

◆ FLASH_SR__WRPERR

#define FLASH_SR__WRPERR   (1<<8)

Definition at line 61 of file stm32lx.c.

◆ FLASH_WRPR

#define FLASH_WRPR   0x20

Definition at line 34 of file stm32lx.c.

◆ OPTION_BYTE_0_PR0

#define OPTION_BYTE_0_PR0   0xFF5500AA

Definition at line 86 of file stm32lx.c.

◆ OPTION_BYTE_0_PR1

#define OPTION_BYTE_0_PR1   0xFFFF0000

Definition at line 85 of file stm32lx.c.

◆ OPTION_BYTES_ADDRESS

#define OPTION_BYTES_ADDRESS   0x1FF80000

Definition at line 83 of file stm32lx.c.

◆ OPTKEY1

#define OPTKEY1   0xFBEAD9C8

Definition at line 71 of file stm32lx.c.

◆ OPTKEY2

#define OPTKEY2   0x24252627

Definition at line 72 of file stm32lx.c.

◆ PEKEY1

#define PEKEY1   0x89ABCDEF

Definition at line 67 of file stm32lx.c.

◆ PEKEY2

#define PEKEY2   0x02030405

Definition at line 68 of file stm32lx.c.

◆ PRGKEY1

#define PRGKEY1   0x8C9DAEBF

Definition at line 69 of file stm32lx.c.

◆ PRGKEY2

#define PRGKEY2   0x13141516

Definition at line 70 of file stm32lx.c.

Function Documentation

◆ COMMAND_HANDLER() [1/3]

COMMAND_HANDLER ( stm32lx_handle_lock_command  )

◆ COMMAND_HANDLER() [2/3]

COMMAND_HANDLER ( stm32lx_handle_mass_erase_command  )

◆ COMMAND_HANDLER() [3/3]

COMMAND_HANDLER ( stm32lx_handle_unlock_command  )

◆ FLASH_BANK_COMMAND_HANDLER()

FLASH_BANK_COMMAND_HANDLER ( stm32lx_flash_bank_command  )

◆ stm32lx_auto_probe()

static int stm32lx_auto_probe ( struct flash_bank bank)
static

Definition at line 863 of file stm32lx.c.

References bank, ERROR_OK, stm32lx_flash_bank::probed, and stm32lx_probe().

◆ stm32lx_enable_write_half_page()

static int stm32lx_enable_write_half_page ( struct flash_bank bank)
static

Unlock the program memory, then set the FPRG bit in the PECR register.

Definition at line 1020 of file stm32lx.c.

References bank, ERROR_OK, stm32lx_flash_bank::flash_base, FLASH_PECR, FLASH_PECR__FPRG, FLASH_PECR__PROG, stm32lx_unlock_program_memory(), target_read_u32(), and target_write_u32().

Referenced by stm32lx_write_half_pages().

◆ stm32lx_erase()

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

◆ stm32lx_erase_sector()

◆ stm32lx_get_flash_status()

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

◆ stm32lx_get_info()

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

Definition at line 874 of file stm32lx.c.

◆ stm32lx_lock()

◆ stm32lx_lock_program_memory()

static int stm32lx_lock_program_memory ( struct flash_bank bank)
static

◆ stm32lx_mass_erase()

◆ stm32lx_obl_launch()

static int stm32lx_obl_launch ( struct flash_bank bank)
static

◆ stm32lx_probe()

◆ stm32lx_protect_check()

static int stm32lx_protect_check ( struct flash_bank bank)
static

Definition at line 357 of file stm32lx.c.

References bank, ERROR_OK, stm32lx_flash_bank::flash_base, FLASH_WRPR, and target_read_u32().

◆ stm32lx_read_id_code()

static int stm32lx_read_id_code ( struct target target,
uint32_t *  id 
)
static

◆ stm32lx_unlock()

◆ stm32lx_unlock_options_bytes()

static int stm32lx_unlock_options_bytes ( struct flash_bank bank)
static

◆ stm32lx_unlock_program_memory()

◆ stm32lx_update_part_info()

static int stm32lx_update_part_info ( struct flash_bank bank,
uint16_t  flash_size_in_kb 
)
static

◆ stm32lx_wait_until_bsy_clear()

static int stm32lx_wait_until_bsy_clear ( struct flash_bank bank)
static

◆ stm32lx_wait_until_bsy_clear_timeout()

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

◆ stm32lx_write()

◆ stm32lx_write_half_pages()

Variable Documentation

◆ stm32_416_revs

const struct stm32lx_rev stm32_416_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x1008, "Y" }, { 0x1038, "W" }, { 0x1078, "V" },
}

Definition at line 97 of file stm32lx.c.

◆ stm32_417_revs

const struct stm32lx_rev stm32_417_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x1008, "Z" }, { 0x1018, "Y" }, { 0x1038, "X" }
}

Definition at line 97 of file stm32lx.c.

◆ stm32_425_revs

const struct stm32lx_rev stm32_425_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x2000, "B" }, { 0x2008, "Y" }, { 0x2018, "1, X" },
}

Definition at line 97 of file stm32lx.c.

◆ stm32_427_revs

const struct stm32lx_rev stm32_427_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x1018, "Y" }, { 0x1038, "X" }, { 0x10f8, "V" },
}

Definition at line 97 of file stm32lx.c.

◆ stm32_429_revs

const struct stm32lx_rev stm32_429_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x1018, "Z" },
}

Definition at line 97 of file stm32lx.c.

◆ stm32_436_revs

const struct stm32lx_rev stm32_436_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x1008, "Z" }, { 0x1018, "Y" }, { 0x1038, "X" },
}

Definition at line 97 of file stm32lx.c.

◆ stm32_437_revs

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

Definition at line 97 of file stm32lx.c.

◆ stm32_447_revs

const struct stm32lx_rev stm32_447_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x2000, "B" }, { 0x2008, "Z" },
}

Definition at line 97 of file stm32lx.c.

◆ stm32_457_revs

const struct stm32lx_rev stm32_457_revs[]
static
Initial value:
= {
{ 0x1000, "A" }, { 0x1008, "Z" },
}

Definition at line 97 of file stm32lx.c.

◆ stm32lx_command_handlers

const struct command_registration stm32lx_command_handlers[]
static
Initial value:
= {
{
.name = "stm32lx",
.mode = COMMAND_ANY,
.help = "stm32lx 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 stm32lx_exec_command_handlers[]
Definition: stm32lx.c:902

Definition at line 874 of file stm32lx.c.

◆ stm32lx_exec_command_handlers

const struct command_registration stm32lx_exec_command_handlers[]
static
Initial value:
= {
{
.name = "mass_erase",
.handler = stm32lx_handle_mass_erase_command,
.mode = COMMAND_EXEC,
.usage = "bank_id",
.help = "Erase entire flash device. including available EEPROM",
},
{
.name = "lock",
.handler = stm32lx_handle_lock_command,
.mode = COMMAND_EXEC,
.usage = "bank_id",
.help = "Increase the readout protection to Level 1.",
},
{
.name = "unlock",
.handler = stm32lx_handle_unlock_command,
.mode = COMMAND_EXEC,
.usage = "bank_id",
.help = "Lower the readout protection from Level 1 to 0.",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 874 of file stm32lx.c.

◆ stm32lx_flash

const struct flash_driver stm32lx_flash
Initial value:
= {
.name = "stm32lx",
.flash_bank_command = stm32lx_flash_bank_command,
.erase = stm32lx_erase,
.write = stm32lx_write,
.probe = stm32lx_probe,
.auto_probe = stm32lx_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = stm32lx_protect_check,
.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 stm32lx_protect_check(struct flash_bank *bank)
Definition: stm32lx.c:357
static int stm32lx_auto_probe(struct flash_bank *bank)
Definition: stm32lx.c:863
static int stm32lx_probe(struct flash_bank *bank)
Definition: stm32lx.c:730
static const struct command_registration stm32lx_command_handlers[]
Definition: stm32lx.c:927
static int stm32lx_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: stm32lx.c:383
static int stm32lx_get_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: stm32lx.c:874
static int stm32lx_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: stm32lx.c:606

Definition at line 874 of file stm32lx.c.

◆ stm32lx_parts

const struct stm32lx_part_info stm32lx_parts[]
static

Definition at line 97 of file stm32lx.c.

Referenced by stm32lx_probe().