20 #define BLUENRG2_JTAG_REG (flash_priv_data_2.jtag_idcode_reg)
21 #define BLUENRGLP_JTAG_REG (flash_priv_data_lp.jtag_idcode_reg)
22 #define BLUENRGLPF_JTAG_REG (flash_priv_data_lpf.jtag_idcode_reg)
24 #define DIE_ID_REG(bluenrgx_info) (bluenrgx_info->flash_ptr->die_id_reg)
25 #define JTAG_IDCODE_REG(bluenrgx_info) (bluenrgx_info->flash_ptr->jtag_idcode_reg)
26 #define FLASH_PAGE_SIZE(bluenrgx_info) (bluenrgx_info->flash_ptr->flash_page_size)
28 #define FLASH_SIZE_REG_MASK (0xFFFF)
42 .jtag_idcode_reg = 0x40900028,
43 .flash_base = 0x10040000,
44 .flash_regs_base = 0x40100000,
45 .flash_page_size = 2048,
46 .jtag_idcode = 0x00000000,
47 .part_name =
"BLUENRG-1",
52 .jtag_idcode_reg = 0x40900028,
53 .flash_base = 0x10040000,
54 .flash_regs_base = 0x40100000,
55 .flash_page_size = 2048,
56 .jtag_idcode = 0x0200A041,
57 .part_name =
"BLUENRG-2",
62 .jtag_idcode_reg = 0x40000004,
63 .flash_base = 0x10040000,
64 .flash_regs_base = 0x40001000,
65 .flash_page_size = 2048,
66 .jtag_idcode = 0x0201E041,
67 .part_name =
"STM32WB07 (BLUENRG-LP)",
72 .jtag_idcode_reg = 0x40000004,
73 .flash_base = 0x10040000,
74 .flash_regs_base = 0x40001000,
75 .flash_page_size = 2048,
76 .jtag_idcode = 0x02028041,
77 .part_name =
"STM32WB05 (BLUENRG-LPS)",
82 .jtag_idcode_reg = 0x40000004,
83 .flash_base = 0x10040000,
84 .flash_regs_base = 0x40001000,
85 .flash_page_size = 2048,
86 .jtag_idcode = 0x02032041,
87 .part_name =
"STM32WB09 (BLUENRG-LPF)",
109 bluenrgx_info = calloc(1,
sizeof(*bluenrgx_info));
112 if (!bluenrgx_info) {
113 LOG_ERROR(
"failed to allocate bank structure");
117 bank->write_start_alignment = 16;
118 bank->write_end_alignment = 16;
120 bank->driver_priv = bluenrgx_info;
122 bluenrgx_info->
probed =
false;
148 bool flag_raised =
false;
149 for (
unsigned int j = 0; j < 100; j++) {
156 if (value & interrupt_flag) {
165 LOG_ERROR(
"Cannot clear interrupt flag");
172 LOG_ERROR(
"Erase command failed (timeout)");
188 unsigned int num_sectors = (last - first + 1);
194 if (!bluenrgx_info->
probed)
231 for (
unsigned int i = first; i <= last; i++) {
278 static const uint8_t bluenrgx_flash_write_code[] = {
279 #include "../../../contrib/loaders/flash/bluenrg-x/bluenrg-x_write.inc"
284 LOG_WARNING(
"no working area available, can't do block memory writes");
289 sizeof(bluenrgx_flash_write_code),
290 bluenrgx_flash_write_code);
296 LOG_WARNING(
"no large enough working area available");
302 &write_algorithm_stack) !=
ERROR_OK) {
303 LOG_DEBUG(
"no working area for target algorithm stack");
361 LOG_ERROR(
"error executing bluenrg-x flash write algorithm");
363 uint32_t error =
buf_get_u32(reg_params[0].value, 0, 32);
366 LOG_ERROR(
"flash write failed = %08" PRIx32, error);
375 LOG_ERROR(
"flash write failed = %08" PRIx32, rp);
401 while (data_count--) {
442 if (!bluenrgx_info->
probed)
446 LOG_ERROR(
"Requested write past beyond of flash size: (offset+count) = %" PRIu32
", size=%" PRIu32,
463 LOG_WARNING(
"falling back to programming without a flash loader (slower)");
472 uint32_t idcode, size_info,
die_id;
509 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
512 bank->sectors[i].is_erased = -1;
513 bank->sectors[i].is_protected = 0;
516 bluenrgx_info->
probed =
true;
526 if (bluenrgx_info->
probed)
536 int mask_number, cut_number;
538 if (!bluenrgx_info->
probed) {
546 mask_number = (bluenrgx_info->
die_id >> 4) & 0xF;
547 cut_number = bluenrgx_info->
die_id & 0xF;
556 .flash_bank_command = bluenrgx_flash_bank_command,
563 .protect_check =
NULL,
void destroy_mem_param(struct mem_param *param)
void init_reg_param(struct reg_param *param, const char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
void init_mem_param(struct mem_param *param, uint32_t address, uint32_t size, enum param_direction direction)
#define ARMV7M_COMMON_MAGIC
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static const struct flash_ctrl_priv_data * flash_ctrl[]
static const struct flash_ctrl_priv_data flash_priv_data_lp
static int bluenrgx_write_with_loader(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
#define DIE_ID_REG(bluenrgx_info)
#define FLASH_PAGE_SIZE(bluenrgx_info)
static int bluenrgx_wait_for_interrupt(struct flash_bank *bank, uint32_t interrupt_flag)
static uint32_t bluenrgx_get_flash_reg(struct flash_bank *bank, uint32_t reg_offset)
const struct flash_driver bluenrgx_flash
static int bluenrgx_wait_for_command(struct flash_bank *bank)
static int bluenrgx_write_without_loader(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
#define BLUENRG2_JTAG_REG
static const struct flash_ctrl_priv_data flash_priv_data_2
static int bluenrgx_write_flash_reg(struct flash_bank *bank, uint32_t reg_offset, uint32_t value)
static int bluenrgx_probe(struct flash_bank *bank)
static int bluenrgx_get_info(struct flash_bank *bank, struct command_invocation *cmd)
static int bluenrgx_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
FLASH_BANK_COMMAND_HANDLER(bluenrgx_flash_bank_command)
#define FLASH_SIZE_REG_MASK
static int bluenrgx_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static const struct flash_ctrl_priv_data flash_priv_data_lps
static int bluenrgx_read_flash_reg(struct flash_bank *bank, uint32_t reg_offset, uint32_t *value)
static const struct flash_ctrl_priv_data flash_priv_data_lpf
#define BLUENRGLP_JTAG_REG
static int bluenrgx_auto_probe(struct flash_bank *bank)
static const struct flash_ctrl_priv_data flash_priv_data_1
#define FLASH_INT_CMDSTART
#define FLASH_INT_CMDDONE
#define FLASH_CMD_ERASE_PAGE
#define FLASH_REG_COMMAND
#define FLASH_DATA_WIDTH_W
#define FLASH_REG_ADDRESS
#define FLASH_CMD_MASSERASE
#define FLASH_CMD_BURSTWRITE
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
static int mass_erase(struct target *target, uint16_t *hfm_ustat)
Executes the FM mass erase command.
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t buffer_size
Size of dw_spi_program::buffer.
uint32_t address
Starting address. Sector aligned.
#define ERROR_FLASH_BANK_NOT_PROBED
#define ERROR_FLASH_OPERATION_FAILED
#define ERROR_FLASH_DST_OUT_OF_BANK
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.
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define ERROR_TIMEOUT_REACHED
#define LOG_DEBUG(expr ...)
unsigned int common_magic
const struct flash_ctrl_priv_data * flash_ptr
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
Describes the geometry and status of a single flash sector within a flash bank.
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_run_flash_async_algorithm(struct target *target, const uint8_t *buffer, uint32_t count, int block_size, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t buffer_start, uint32_t buffer_size, uint32_t entry_point, uint32_t exit_point, void *arch_info)
Streams data to a circular buffer on target intended for consumption by code running asynchronously o...
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.