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

Go to the source code of this file.

Data Structures

struct  qn908x_flash_bank
 
struct  qn908x_flash_page_lock
 

Macros

#define CLOCK_16MHZ   16000000u
 
#define CLOCK_32KHZ   32000u
 
#define CLOCK_32MHZ   32000000u
 
#define QN908X_DEFAULT_TIMEOUT_MS   500
 
#define QN908X_FLASH_BASE   0x01000000
 
#define QN908X_FLASH_BLOCK_SIZE    (QN908X_FLASH_PAGES_PER_BLOCK * QN908X_FLASH_PAGE_SIZE)
 
#define QN908X_FLASH_IRQ_VECTOR_CHECKSUM_END    (QN908X_FLASH_IRQ_VECTOR_CHECKSUM_POS + QN908X_FLASH_IRQ_VECTOR_CHECKSUM_SIZE)
 
#define QN908X_FLASH_IRQ_VECTOR_CHECKSUM_POS   0x1c
 
#define QN908X_FLASH_IRQ_VECTOR_CHECKSUM_SIZE   4
 
#define QN908X_FLASH_LOCK_ADDR   (QN908X_FLASH_BASE + 0x7f820)
 
#define QN908X_FLASH_LOCK_ENABLE_FLASH_PROTECTION   BIT(1)
 
#define QN908X_FLASH_LOCK_ENABLE_MASS_ERASE   BIT(0)
 
#define QN908X_FLASH_LOCK_ENABLE_MEMORY_PROTECTION   BIT(2)
 
#define QN908X_FLASH_MAX_BLOCKS   2
 
#define QN908X_FLASH_PAGE_SIZE   2048
 
#define QN908X_FLASH_PAGES_PER_BLOCK   128
 
#define QN908X_FMC_BASE   0x40081000u
 
#define QN908X_FMC_DEBUG_PASSWORD   (QN908X_FMC_BASE + 0xa8)
 
#define QN908X_FMC_ERASE_CTRL   (QN908X_FMC_BASE + 0x04)
 
#define QN908X_FMC_ERASE_CTRL_HALF_ERASEH_EN_SHIFT   29
 
#define QN908X_FMC_ERASE_CTRL_HALF_ERASEL_EN_SHIFT   28
 
#define QN908X_FMC_ERASE_CTRL_PAGE_ERASEH_EN_SHIFT   31
 
#define QN908X_FMC_ERASE_CTRL_PAGE_ERASEL_EN_SHIFT   30
 
#define QN908X_FMC_ERASE_CTRL_PAGE_IDXH_SHIFT   8
 
#define QN908X_FMC_ERASE_CTRL_PAGE_IDXL_SHIFT   0
 
#define QN908X_FMC_ERASE_PASSWORD   (QN908X_FMC_BASE + 0xac)
 
#define QN908X_FMC_ERASE_TIME   (QN908X_FMC_BASE + 0x08)
 
#define QN908X_FMC_INI_RD_EN   (QN908X_FMC_BASE + 0x00)
 
#define QN908X_FMC_INI_RD_EN_INI_RD_EN_MASK   BIT(0)
 
#define QN908X_FMC_INT_STAT   (QN908X_FMC_BASE + 0x18)
 
#define QN908X_FMC_INT_STAT_AHBH_INT_MASK   BIT(8)
 
#define QN908X_FMC_INT_STAT_AHBL_INT_MASK   BIT(0)
 
#define QN908X_FMC_INT_STAT_ERASE_FAIL_H_INT_MASK   BIT(14)
 
#define QN908X_FMC_INT_STAT_ERASE_FAIL_L_INT_MASK   BIT(6)
 
#define QN908X_FMC_INT_STAT_ERASEH_INT_MASK   BIT(10)
 
#define QN908X_FMC_INT_STAT_ERASEL_INT_MASK   BIT(2)
 
#define QN908X_FMC_INT_STAT_LOCKH_INT_MASK   BIT(9)
 
#define QN908X_FMC_INT_STAT_LOCKL_INT_MASK   BIT(1)
 
#define QN908X_FMC_INT_STAT_WR_BUFH_INT_MASK   BIT(12)
 
#define QN908X_FMC_INT_STAT_WR_BUFL_INT_MASK   BIT(4)
 
#define QN908X_FMC_INT_STAT_WRITE_FAIL_H_INT_MASK   BIT(13)
 
#define QN908X_FMC_INT_STAT_WRITE_FAIL_L_INT_MASK   BIT(5)
 
#define QN908X_FMC_INT_STAT_WRITEH_INT_MASK   BIT(11)
 
#define QN908X_FMC_INT_STAT_WRITEL_INT_MASK   BIT(3)
 
#define QN908X_FMC_LOCK_STAT_0   (QN908X_FMC_BASE + 0x20)
 
#define QN908X_FMC_LOCK_STAT_1   (QN908X_FMC_BASE + 0x24)
 
#define QN908X_FMC_LOCK_STAT_2   (QN908X_FMC_BASE + 0x28)
 
#define QN908X_FMC_LOCK_STAT_3   (QN908X_FMC_BASE + 0x2c)
 
#define QN908X_FMC_LOCK_STAT_4   (QN908X_FMC_BASE + 0x30)
 
#define QN908X_FMC_LOCK_STAT_5   (QN908X_FMC_BASE + 0x34)
 
#define QN908X_FMC_LOCK_STAT_6   (QN908X_FMC_BASE + 0x38)
 
#define QN908X_FMC_LOCK_STAT_7   (QN908X_FMC_BASE + 0x3c)
 
#define QN908X_FMC_LOCK_STAT_8   (QN908X_FMC_BASE + 0x40)
 
#define QN908X_FMC_LOCK_STAT_8_FSH_PROTECT_EN   BIT(1)
 
#define QN908X_FMC_LOCK_STAT_8_MASS_ERASE_LOCK_EN   BIT(0)
 
#define QN908X_FMC_LOCK_STAT_8_MEM_PROTECT_EN   BIT(2)
 
#define QN908X_FMC_LOCK_STAT_8_PROTECT_ANY   (BIT(1) | BIT(2))
 
#define QN908X_FMC_SMART_CTRL   (QN908X_FMC_BASE + 0x10)
 
#define QN908X_FMC_SMART_CTRL_MAX_ERASE(x)
 
#define QN908X_FMC_SMART_CTRL_MAX_ERASE_MASK   0x3f000u
 
#define QN908X_FMC_SMART_CTRL_MAX_ERASE_RETRIES   9
 
#define QN908X_FMC_SMART_CTRL_MAX_ERASE_SHIFT   12u
 
#define QN908X_FMC_SMART_CTRL_MAX_WRITE(x)
 
#define QN908X_FMC_SMART_CTRL_MAX_WRITE_MASK   0xf00u
 
#define QN908X_FMC_SMART_CTRL_MAX_WRITE_RETRIES   9
 
#define QN908X_FMC_SMART_CTRL_MAX_WRITE_SHIFT   8u
 
#define QN908X_FMC_SMART_CTRL_PRGMH_EN_MASK   BIT(1)
 
#define QN908X_FMC_SMART_CTRL_PRGML_EN_MASK   BIT(0)
 
#define QN908X_FMC_SMART_CTRL_SMART_ERASEH_EN_MASK   BIT(5)
 
#define QN908X_FMC_SMART_CTRL_SMART_ERASEL_EN_MASK   BIT(4)
 
#define QN908X_FMC_SMART_CTRL_SMART_WRITEH_EN_MASK   BIT(3)
 
#define QN908X_FMC_SMART_CTRL_SMART_WRITEL_EN_MASK   BIT(2)
 
#define QN908X_FMC_STATUS1   (QN908X_FMC_BASE + 0x48)
 
#define QN908X_FMC_STATUS1_FSH_ERA_BUSY_H_MASK   BIT(12)
 
#define QN908X_FMC_STATUS1_FSH_ERA_BUSY_L_MASK   BIT(9)
 
#define QN908X_FMC_STATUS1_FSH_STA_MASK   BIT(26)
 
#define QN908X_FMC_STATUS1_FSH_WR_BUSY_H_MASK   BIT(13)
 
#define QN908X_FMC_STATUS1_FSH_WR_BUSY_L_MASK   BIT(10)
 
#define QN908X_FMC_STATUS1_INI_RD_DONE_MASK   BIT(15)
 
#define QN908X_FMC_TIME_CTRL   (QN908X_FMC_BASE + 0x0c)
 
#define QN908X_FMC_TIME_CTRL_PRGM_CYCLE(x)
 
#define QN908X_FMC_TIME_CTRL_PRGM_CYCLE_MASK   0xfffu
 
#define QN908X_FMC_TIME_CTRL_PRGM_CYCLE_SHIFT   0u
 
#define QN908X_FMC_TIME_CTRL_TIME_BASE(x)
 
#define QN908X_FMC_TIME_CTRL_TIME_BASE_MASK   0xff000u
 
#define QN908X_FMC_TIME_CTRL_TIME_BASE_SHIFT   12u
 
#define QN908X_INFO_PAGE_BASE   0x210b0000u
 
#define QN908X_INFO_PAGE_BLUETOOTH_ADDR   (QN908X_INFO_PAGE_BASE + 0x7fa)
 
#define QN908X_INFO_PAGE_BOOTLOADER_VER   (QN908X_INFO_PAGE_BASE + 0x704)
 
#define QN908X_INFO_PAGE_CRC32   (QN908X_INFO_PAGE_BASE + 0x700)
 
#define QN908X_INFO_PAGE_CRC_END   (QN908X_INFO_PAGE_BASE + 0x800)
 
#define QN908X_INFO_PAGE_CRC_START   (QN908X_INFO_PAGE_BASE + 0x704)
 
#define QN908X_INFO_PAGE_FLASH_SIZE   (QN908X_INFO_PAGE_BASE + 0x708)
 
#define QN908X_SYSCON_BASE   0x40000000u
 
#define QN908X_SYSCON_CHIP_ID   (QN908X_SYSCON_BASE + 0x108u)
 
#define QN908X_SYSCON_CLK_CTRL   (QN908X_SYSCON_BASE + 0x010u)
 
#define QN908X_SYSCON_CLK_EN   (QN908X_SYSCON_BASE + 0x00cu)
 
#define QN908X_SYSCON_CLK_EN_CLK_DP_EN_MASK   BIT(21)
 
#define QN908X_SYSCON_XTAL_CTRL   (QN908X_SYSCON_BASE + 0x180u)
 
#define QN908X_WDT_BASE   0x40001000u
 
#define QN908X_WDT_CTRL   (QN908X_WDT_BASE + 0x08u)
 
#define QN908X_WDT_LOCK   (QN908X_WDT_BASE + 0x20u)
 
#define SYSCON_CLK_CTRL_AHB_DIV_MASK   0x1FFF0u
 
#define SYSCON_CLK_CTRL_AHB_DIV_SHIFT   4u
 
#define SYSCON_CLK_CTRL_CLK_OSC32M_DIV_MASK   BIT(20)
 
#define SYSCON_CLK_CTRL_CLK_XTAL_SEL_MASK   BIT(19)
 
#define SYSCON_CLK_CTRL_SYS_CLK_SEL_MASK   0xC0000000u
 
#define SYSCON_CLK_CTRL_SYS_CLK_SEL_SHIFT   30u
 
#define SYSCON_XTAL_CTRL_XTAL_DIV_MASK   BIT(31)
 

Enumerations

enum  qn908x_info_page_flash_size { QN908X_FLASH_SIZE_512K = 0xfffff0ff , QN908X_FLASH_SIZE_256K = 0xffffe0ff }
 

Functions

struct qn908x_flash_page_lock __attribute__ ((packed))
 
 COMMAND_HANDLER (qn908x_handle_allow_brick_command)
 
 COMMAND_HANDLER (qn908x_handle_disable_wdog_command)
 
 COMMAND_HANDLER (qn908x_handle_mass_erase_command)
 
 FLASH_BANK_COMMAND_HANDLER (qn908x_flash_bank_command)
 
static int is_flash_protected (struct flash_bank *bank, bool *is_protected)
 
static int qn908x_auto_probe (struct flash_bank *bank)
 
static int qn908x_busy_check (struct target *target)
 
static int qn908x_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int qn908x_get_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int qn908x_init_flash (struct target *target)
 
static int qn908x_load_lock_stat (struct target *target)
 
static int qn908x_probe (struct flash_bank *bank)
 
static int qn908x_protect (struct flash_bank *bank, int set, unsigned int first, unsigned int last)
 
static int qn908x_protect_check (struct flash_bank *bank)
 
static int qn908x_read_page_lock (struct flash_bank *bank)
 
static int qn908x_setup_erase (struct target *target)
 
static int qn908x_status_check (struct target *target)
 
static int qn908x_update_reg (struct target *target, target_addr_t reg, uint32_t mask, uint32_t value)
 
static int qn908x_wait_for_idle (struct target *target, int64_t timeout_ms)
 
static int qn908x_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 

Variables

struct qn908x_flash_bank __attribute__
 
uint8_t _reserved [3]
 
uint8_t bits [QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
 
uint8_t nvds_size [4]
 
uint8_t protection
 
static const struct command_registration qn908x_command_handlers []
 
static const struct command_registration qn908x_exec_command_handlers []
 
const struct flash_driver qn908x_flash
 

Macro Definition Documentation

◆ CLOCK_16MHZ

#define CLOCK_16MHZ   16000000u

Definition at line 200 of file qn908x.c.

◆ CLOCK_32KHZ

#define CLOCK_32KHZ   32000u

Definition at line 202 of file qn908x.c.

◆ CLOCK_32MHZ

#define CLOCK_32MHZ   32000000u

Definition at line 201 of file qn908x.c.

◆ QN908X_DEFAULT_TIMEOUT_MS

#define QN908X_DEFAULT_TIMEOUT_MS   500

Definition at line 226 of file qn908x.c.

◆ QN908X_FLASH_BASE

#define QN908X_FLASH_BASE   0x01000000

Definition at line 42 of file qn908x.c.

◆ QN908X_FLASH_BLOCK_SIZE

#define QN908X_FLASH_BLOCK_SIZE    (QN908X_FLASH_PAGES_PER_BLOCK * QN908X_FLASH_PAGE_SIZE)

Definition at line 47 of file qn908x.c.

◆ QN908X_FLASH_IRQ_VECTOR_CHECKSUM_END

#define QN908X_FLASH_IRQ_VECTOR_CHECKSUM_END    (QN908X_FLASH_IRQ_VECTOR_CHECKSUM_POS + QN908X_FLASH_IRQ_VECTOR_CHECKSUM_SIZE)

Definition at line 51 of file qn908x.c.

◆ QN908X_FLASH_IRQ_VECTOR_CHECKSUM_POS

#define QN908X_FLASH_IRQ_VECTOR_CHECKSUM_POS   0x1c

Definition at line 49 of file qn908x.c.

◆ QN908X_FLASH_IRQ_VECTOR_CHECKSUM_SIZE

#define QN908X_FLASH_IRQ_VECTOR_CHECKSUM_SIZE   4

Definition at line 50 of file qn908x.c.

◆ QN908X_FLASH_LOCK_ADDR

#define QN908X_FLASH_LOCK_ADDR   (QN908X_FLASH_BASE + 0x7f820)

Definition at line 163 of file qn908x.c.

◆ QN908X_FLASH_LOCK_ENABLE_FLASH_PROTECTION

#define QN908X_FLASH_LOCK_ENABLE_FLASH_PROTECTION   BIT(1)

Definition at line 167 of file qn908x.c.

◆ QN908X_FLASH_LOCK_ENABLE_MASS_ERASE

#define QN908X_FLASH_LOCK_ENABLE_MASS_ERASE   BIT(0)

Definition at line 165 of file qn908x.c.

◆ QN908X_FLASH_LOCK_ENABLE_MEMORY_PROTECTION

#define QN908X_FLASH_LOCK_ENABLE_MEMORY_PROTECTION   BIT(2)

Definition at line 169 of file qn908x.c.

◆ QN908X_FLASH_MAX_BLOCKS

#define QN908X_FLASH_MAX_BLOCKS   2

Definition at line 46 of file qn908x.c.

◆ QN908X_FLASH_PAGE_SIZE

#define QN908X_FLASH_PAGE_SIZE   2048

Definition at line 44 of file qn908x.c.

◆ QN908X_FLASH_PAGES_PER_BLOCK

#define QN908X_FLASH_PAGES_PER_BLOCK   128

Definition at line 45 of file qn908x.c.

◆ QN908X_FMC_BASE

#define QN908X_FMC_BASE   0x40081000u

Definition at line 75 of file qn908x.c.

◆ QN908X_FMC_DEBUG_PASSWORD

#define QN908X_FMC_DEBUG_PASSWORD   (QN908X_FMC_BASE + 0xa8)

Definition at line 92 of file qn908x.c.

◆ QN908X_FMC_ERASE_CTRL

#define QN908X_FMC_ERASE_CTRL   (QN908X_FMC_BASE + 0x04)

Definition at line 77 of file qn908x.c.

◆ QN908X_FMC_ERASE_CTRL_HALF_ERASEH_EN_SHIFT

#define QN908X_FMC_ERASE_CTRL_HALF_ERASEH_EN_SHIFT   29

Definition at line 107 of file qn908x.c.

◆ QN908X_FMC_ERASE_CTRL_HALF_ERASEL_EN_SHIFT

#define QN908X_FMC_ERASE_CTRL_HALF_ERASEL_EN_SHIFT   28

Definition at line 106 of file qn908x.c.

◆ QN908X_FMC_ERASE_CTRL_PAGE_ERASEH_EN_SHIFT

#define QN908X_FMC_ERASE_CTRL_PAGE_ERASEH_EN_SHIFT   31

Definition at line 109 of file qn908x.c.

◆ QN908X_FMC_ERASE_CTRL_PAGE_ERASEL_EN_SHIFT

#define QN908X_FMC_ERASE_CTRL_PAGE_ERASEL_EN_SHIFT   30

Definition at line 108 of file qn908x.c.

◆ QN908X_FMC_ERASE_CTRL_PAGE_IDXH_SHIFT

#define QN908X_FMC_ERASE_CTRL_PAGE_IDXH_SHIFT   8

Definition at line 105 of file qn908x.c.

◆ QN908X_FMC_ERASE_CTRL_PAGE_IDXL_SHIFT

#define QN908X_FMC_ERASE_CTRL_PAGE_IDXL_SHIFT   0

Definition at line 104 of file qn908x.c.

◆ QN908X_FMC_ERASE_PASSWORD

#define QN908X_FMC_ERASE_PASSWORD   (QN908X_FMC_BASE + 0xac)

Definition at line 93 of file qn908x.c.

◆ QN908X_FMC_ERASE_TIME

#define QN908X_FMC_ERASE_TIME   (QN908X_FMC_BASE + 0x08)

Definition at line 78 of file qn908x.c.

◆ QN908X_FMC_INI_RD_EN

#define QN908X_FMC_INI_RD_EN   (QN908X_FMC_BASE + 0x00)

Definition at line 76 of file qn908x.c.

◆ QN908X_FMC_INI_RD_EN_INI_RD_EN_MASK

#define QN908X_FMC_INI_RD_EN_INI_RD_EN_MASK   BIT(0)

Definition at line 95 of file qn908x.c.

◆ QN908X_FMC_INT_STAT

#define QN908X_FMC_INT_STAT   (QN908X_FMC_BASE + 0x18)

Definition at line 81 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_AHBH_INT_MASK

#define QN908X_FMC_INT_STAT_AHBH_INT_MASK   BIT(8)

Definition at line 118 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_AHBL_INT_MASK

#define QN908X_FMC_INT_STAT_AHBL_INT_MASK   BIT(0)

Definition at line 111 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_ERASE_FAIL_H_INT_MASK

#define QN908X_FMC_INT_STAT_ERASE_FAIL_H_INT_MASK   BIT(14)

Definition at line 124 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_ERASE_FAIL_L_INT_MASK

#define QN908X_FMC_INT_STAT_ERASE_FAIL_L_INT_MASK   BIT(6)

Definition at line 117 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_ERASEH_INT_MASK

#define QN908X_FMC_INT_STAT_ERASEH_INT_MASK   BIT(10)

Definition at line 120 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_ERASEL_INT_MASK

#define QN908X_FMC_INT_STAT_ERASEL_INT_MASK   BIT(2)

Definition at line 113 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_LOCKH_INT_MASK

#define QN908X_FMC_INT_STAT_LOCKH_INT_MASK   BIT(9)

Definition at line 119 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_LOCKL_INT_MASK

#define QN908X_FMC_INT_STAT_LOCKL_INT_MASK   BIT(1)

Definition at line 112 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_WR_BUFH_INT_MASK

#define QN908X_FMC_INT_STAT_WR_BUFH_INT_MASK   BIT(12)

Definition at line 122 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_WR_BUFL_INT_MASK

#define QN908X_FMC_INT_STAT_WR_BUFL_INT_MASK   BIT(4)

Definition at line 115 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_WRITE_FAIL_H_INT_MASK

#define QN908X_FMC_INT_STAT_WRITE_FAIL_H_INT_MASK   BIT(13)

Definition at line 123 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_WRITE_FAIL_L_INT_MASK

#define QN908X_FMC_INT_STAT_WRITE_FAIL_L_INT_MASK   BIT(5)

Definition at line 116 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_WRITEH_INT_MASK

#define QN908X_FMC_INT_STAT_WRITEH_INT_MASK   BIT(11)

Definition at line 121 of file qn908x.c.

◆ QN908X_FMC_INT_STAT_WRITEL_INT_MASK

#define QN908X_FMC_INT_STAT_WRITEL_INT_MASK   BIT(3)

Definition at line 114 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_0

#define QN908X_FMC_LOCK_STAT_0   (QN908X_FMC_BASE + 0x20)

Definition at line 82 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_1

#define QN908X_FMC_LOCK_STAT_1   (QN908X_FMC_BASE + 0x24)

Definition at line 83 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_2

#define QN908X_FMC_LOCK_STAT_2   (QN908X_FMC_BASE + 0x28)

Definition at line 84 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_3

#define QN908X_FMC_LOCK_STAT_3   (QN908X_FMC_BASE + 0x2c)

Definition at line 85 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_4

#define QN908X_FMC_LOCK_STAT_4   (QN908X_FMC_BASE + 0x30)

Definition at line 86 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_5

#define QN908X_FMC_LOCK_STAT_5   (QN908X_FMC_BASE + 0x34)

Definition at line 87 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_6

#define QN908X_FMC_LOCK_STAT_6   (QN908X_FMC_BASE + 0x38)

Definition at line 88 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_7

#define QN908X_FMC_LOCK_STAT_7   (QN908X_FMC_BASE + 0x3c)

Definition at line 89 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_8

#define QN908X_FMC_LOCK_STAT_8   (QN908X_FMC_BASE + 0x40)

Definition at line 90 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_8_FSH_PROTECT_EN

#define QN908X_FMC_LOCK_STAT_8_FSH_PROTECT_EN   BIT(1)

Definition at line 158 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_8_MASS_ERASE_LOCK_EN

#define QN908X_FMC_LOCK_STAT_8_MASS_ERASE_LOCK_EN   BIT(0)

Definition at line 157 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_8_MEM_PROTECT_EN

#define QN908X_FMC_LOCK_STAT_8_MEM_PROTECT_EN   BIT(2)

Definition at line 159 of file qn908x.c.

◆ QN908X_FMC_LOCK_STAT_8_PROTECT_ANY

#define QN908X_FMC_LOCK_STAT_8_PROTECT_ANY   (BIT(1) | BIT(2))

Definition at line 160 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL

#define QN908X_FMC_SMART_CTRL   (QN908X_FMC_BASE + 0x10)

Definition at line 80 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_MAX_ERASE

#define QN908X_FMC_SMART_CTRL_MAX_ERASE (   x)
Value:
(((uint32_t)(((uint32_t)(x)) << QN908X_FMC_SMART_CTRL_MAX_ERASE_SHIFT)) \
#define QN908X_FMC_SMART_CTRL_MAX_ERASE_SHIFT
Definition: qn908x.c:138
#define QN908X_FMC_SMART_CTRL_MAX_ERASE_MASK
Definition: qn908x.c:137

Definition at line 139 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_MAX_ERASE_MASK

#define QN908X_FMC_SMART_CTRL_MAX_ERASE_MASK   0x3f000u

Definition at line 137 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_MAX_ERASE_RETRIES

#define QN908X_FMC_SMART_CTRL_MAX_ERASE_RETRIES   9

Definition at line 143 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_MAX_ERASE_SHIFT

#define QN908X_FMC_SMART_CTRL_MAX_ERASE_SHIFT   12u

Definition at line 138 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_MAX_WRITE

#define QN908X_FMC_SMART_CTRL_MAX_WRITE (   x)
Value:
(((uint32_t)(((uint32_t)(x)) << QN908X_FMC_SMART_CTRL_MAX_WRITE_SHIFT)) \
#define QN908X_FMC_SMART_CTRL_MAX_WRITE_MASK
Definition: qn908x.c:132
#define QN908X_FMC_SMART_CTRL_MAX_WRITE_SHIFT
Definition: qn908x.c:133

Definition at line 134 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_MAX_WRITE_MASK

#define QN908X_FMC_SMART_CTRL_MAX_WRITE_MASK   0xf00u

Definition at line 132 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_MAX_WRITE_RETRIES

#define QN908X_FMC_SMART_CTRL_MAX_WRITE_RETRIES   9

Definition at line 144 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_MAX_WRITE_SHIFT

#define QN908X_FMC_SMART_CTRL_MAX_WRITE_SHIFT   8u

Definition at line 133 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_PRGMH_EN_MASK

#define QN908X_FMC_SMART_CTRL_PRGMH_EN_MASK   BIT(1)

Definition at line 127 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_PRGML_EN_MASK

#define QN908X_FMC_SMART_CTRL_PRGML_EN_MASK   BIT(0)

Definition at line 126 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_SMART_ERASEH_EN_MASK

#define QN908X_FMC_SMART_CTRL_SMART_ERASEH_EN_MASK   BIT(5)

Definition at line 131 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_SMART_ERASEL_EN_MASK

#define QN908X_FMC_SMART_CTRL_SMART_ERASEL_EN_MASK   BIT(4)

Definition at line 130 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_SMART_WRITEH_EN_MASK

#define QN908X_FMC_SMART_CTRL_SMART_WRITEH_EN_MASK   BIT(3)

Definition at line 129 of file qn908x.c.

◆ QN908X_FMC_SMART_CTRL_SMART_WRITEL_EN_MASK

#define QN908X_FMC_SMART_CTRL_SMART_WRITEL_EN_MASK   BIT(2)

Definition at line 128 of file qn908x.c.

◆ QN908X_FMC_STATUS1

#define QN908X_FMC_STATUS1   (QN908X_FMC_BASE + 0x48)

Definition at line 91 of file qn908x.c.

◆ QN908X_FMC_STATUS1_FSH_ERA_BUSY_H_MASK

#define QN908X_FMC_STATUS1_FSH_ERA_BUSY_H_MASK   BIT(12)

Definition at line 99 of file qn908x.c.

◆ QN908X_FMC_STATUS1_FSH_ERA_BUSY_L_MASK

#define QN908X_FMC_STATUS1_FSH_ERA_BUSY_L_MASK   BIT(9)

Definition at line 97 of file qn908x.c.

◆ QN908X_FMC_STATUS1_FSH_STA_MASK

#define QN908X_FMC_STATUS1_FSH_STA_MASK   BIT(26)

Definition at line 102 of file qn908x.c.

◆ QN908X_FMC_STATUS1_FSH_WR_BUSY_H_MASK

#define QN908X_FMC_STATUS1_FSH_WR_BUSY_H_MASK   BIT(13)

Definition at line 100 of file qn908x.c.

◆ QN908X_FMC_STATUS1_FSH_WR_BUSY_L_MASK

#define QN908X_FMC_STATUS1_FSH_WR_BUSY_L_MASK   BIT(10)

Definition at line 98 of file qn908x.c.

◆ QN908X_FMC_STATUS1_INI_RD_DONE_MASK

#define QN908X_FMC_STATUS1_INI_RD_DONE_MASK   BIT(15)

Definition at line 101 of file qn908x.c.

◆ QN908X_FMC_TIME_CTRL

#define QN908X_FMC_TIME_CTRL   (QN908X_FMC_BASE + 0x0c)

Definition at line 79 of file qn908x.c.

◆ QN908X_FMC_TIME_CTRL_PRGM_CYCLE

#define QN908X_FMC_TIME_CTRL_PRGM_CYCLE (   x)
Value:
(((uint32_t)(((uint32_t)(x)) << QN908X_FMC_TIME_CTRL_PRGM_CYCLE_SHIFT)) \
#define QN908X_FMC_TIME_CTRL_PRGM_CYCLE_SHIFT
Definition: qn908x.c:147
#define QN908X_FMC_TIME_CTRL_PRGM_CYCLE_MASK
Definition: qn908x.c:146

Definition at line 148 of file qn908x.c.

◆ QN908X_FMC_TIME_CTRL_PRGM_CYCLE_MASK

#define QN908X_FMC_TIME_CTRL_PRGM_CYCLE_MASK   0xfffu

Definition at line 146 of file qn908x.c.

◆ QN908X_FMC_TIME_CTRL_PRGM_CYCLE_SHIFT

#define QN908X_FMC_TIME_CTRL_PRGM_CYCLE_SHIFT   0u

Definition at line 147 of file qn908x.c.

◆ QN908X_FMC_TIME_CTRL_TIME_BASE

#define QN908X_FMC_TIME_CTRL_TIME_BASE (   x)
Value:
(((uint32_t)(((uint32_t)(x)) << QN908X_FMC_TIME_CTRL_TIME_BASE_SHIFT)) \
#define QN908X_FMC_TIME_CTRL_TIME_BASE_MASK
Definition: qn908x.c:151
#define QN908X_FMC_TIME_CTRL_TIME_BASE_SHIFT
Definition: qn908x.c:152

Definition at line 153 of file qn908x.c.

◆ QN908X_FMC_TIME_CTRL_TIME_BASE_MASK

#define QN908X_FMC_TIME_CTRL_TIME_BASE_MASK   0xff000u

Definition at line 151 of file qn908x.c.

◆ QN908X_FMC_TIME_CTRL_TIME_BASE_SHIFT

#define QN908X_FMC_TIME_CTRL_TIME_BASE_SHIFT   12u

Definition at line 152 of file qn908x.c.

◆ QN908X_INFO_PAGE_BASE

#define QN908X_INFO_PAGE_BASE   0x210b0000u

Definition at line 56 of file qn908x.c.

◆ QN908X_INFO_PAGE_BLUETOOTH_ADDR

#define QN908X_INFO_PAGE_BLUETOOTH_ADDR   (QN908X_INFO_PAGE_BASE + 0x7fa)

Definition at line 61 of file qn908x.c.

◆ QN908X_INFO_PAGE_BOOTLOADER_VER

#define QN908X_INFO_PAGE_BOOTLOADER_VER   (QN908X_INFO_PAGE_BASE + 0x704)

Definition at line 59 of file qn908x.c.

◆ QN908X_INFO_PAGE_CRC32

#define QN908X_INFO_PAGE_CRC32   (QN908X_INFO_PAGE_BASE + 0x700)

Definition at line 57 of file qn908x.c.

◆ QN908X_INFO_PAGE_CRC_END

#define QN908X_INFO_PAGE_CRC_END   (QN908X_INFO_PAGE_BASE + 0x800)

Definition at line 62 of file qn908x.c.

◆ QN908X_INFO_PAGE_CRC_START

#define QN908X_INFO_PAGE_CRC_START   (QN908X_INFO_PAGE_BASE + 0x704)

Definition at line 58 of file qn908x.c.

◆ QN908X_INFO_PAGE_FLASH_SIZE

#define QN908X_INFO_PAGE_FLASH_SIZE   (QN908X_INFO_PAGE_BASE + 0x708)

Definition at line 60 of file qn908x.c.

◆ QN908X_SYSCON_BASE

#define QN908X_SYSCON_BASE   0x40000000u

Definition at line 182 of file qn908x.c.

◆ QN908X_SYSCON_CHIP_ID

#define QN908X_SYSCON_CHIP_ID   (QN908X_SYSCON_BASE + 0x108u)

Definition at line 185 of file qn908x.c.

◆ QN908X_SYSCON_CLK_CTRL

#define QN908X_SYSCON_CLK_CTRL   (QN908X_SYSCON_BASE + 0x010u)

Definition at line 184 of file qn908x.c.

◆ QN908X_SYSCON_CLK_EN

#define QN908X_SYSCON_CLK_EN   (QN908X_SYSCON_BASE + 0x00cu)

Definition at line 183 of file qn908x.c.

◆ QN908X_SYSCON_CLK_EN_CLK_DP_EN_MASK

#define QN908X_SYSCON_CLK_EN_CLK_DP_EN_MASK   BIT(21)

Definition at line 189 of file qn908x.c.

◆ QN908X_SYSCON_XTAL_CTRL

#define QN908X_SYSCON_XTAL_CTRL   (QN908X_SYSCON_BASE + 0x180u)

Definition at line 186 of file qn908x.c.

◆ QN908X_WDT_BASE

#define QN908X_WDT_BASE   0x40001000u

Definition at line 205 of file qn908x.c.

◆ QN908X_WDT_CTRL

#define QN908X_WDT_CTRL   (QN908X_WDT_BASE + 0x08u)

Definition at line 206 of file qn908x.c.

◆ QN908X_WDT_LOCK

#define QN908X_WDT_LOCK   (QN908X_WDT_BASE + 0x20u)

Definition at line 207 of file qn908x.c.

◆ SYSCON_CLK_CTRL_AHB_DIV_MASK

#define SYSCON_CLK_CTRL_AHB_DIV_MASK   0x1FFF0u

Definition at line 193 of file qn908x.c.

◆ SYSCON_CLK_CTRL_AHB_DIV_SHIFT

#define SYSCON_CLK_CTRL_AHB_DIV_SHIFT   4u

Definition at line 194 of file qn908x.c.

◆ SYSCON_CLK_CTRL_CLK_OSC32M_DIV_MASK

#define SYSCON_CLK_CTRL_CLK_OSC32M_DIV_MASK   BIT(20)

Definition at line 196 of file qn908x.c.

◆ SYSCON_CLK_CTRL_CLK_XTAL_SEL_MASK

#define SYSCON_CLK_CTRL_CLK_XTAL_SEL_MASK   BIT(19)

Definition at line 195 of file qn908x.c.

◆ SYSCON_CLK_CTRL_SYS_CLK_SEL_MASK

#define SYSCON_CLK_CTRL_SYS_CLK_SEL_MASK   0xC0000000u

Definition at line 197 of file qn908x.c.

◆ SYSCON_CLK_CTRL_SYS_CLK_SEL_SHIFT

#define SYSCON_CLK_CTRL_SYS_CLK_SEL_SHIFT   30u

Definition at line 198 of file qn908x.c.

◆ SYSCON_XTAL_CTRL_XTAL_DIV_MASK

#define SYSCON_XTAL_CTRL_XTAL_DIV_MASK   BIT(31)

Definition at line 191 of file qn908x.c.

Enumeration Type Documentation

◆ qn908x_info_page_flash_size

Enumerator
QN908X_FLASH_SIZE_512K 
QN908X_FLASH_SIZE_256K 

Definition at line 66 of file qn908x.c.

Function Documentation

◆ __attribute__()

struct qn908x_flash_page_lock __attribute__ ( (packed)  )

◆ COMMAND_HANDLER() [1/3]

COMMAND_HANDLER ( qn908x_handle_allow_brick_command  )

◆ COMMAND_HANDLER() [2/3]

◆ COMMAND_HANDLER() [3/3]

◆ FLASH_BANK_COMMAND_HANDLER()

◆ is_flash_protected()

static int is_flash_protected ( struct flash_bank bank,
bool *  is_protected 
)
static

◆ qn908x_auto_probe()

static int qn908x_auto_probe ( struct flash_bank bank)
static

Definition at line 915 of file qn908x.c.

References bank, ERROR_OK, LOG_DEBUG, qn908x_flash_bank::num_blocks, and qn908x_probe().

◆ qn908x_busy_check()

◆ qn908x_erase()

◆ qn908x_get_info()

◆ qn908x_init_flash()

◆ qn908x_load_lock_stat()

◆ qn908x_probe()

◆ qn908x_protect()

◆ qn908x_protect_check()

static int qn908x_protect_check ( struct flash_bank bank)
static

◆ qn908x_read_page_lock()

◆ qn908x_setup_erase()

◆ qn908x_status_check()

◆ qn908x_update_reg()

static int qn908x_update_reg ( struct target target,
target_addr_t  reg,
uint32_t  mask,
uint32_t  value 
)
static

Definition at line 236 of file qn908x.c.

References ERROR_OK, LOG_DEBUG, mask, TARGET_ADDR_FMT, target_read_u32(), and target_write_u32().

Referenced by qn908x_setup_erase().

◆ qn908x_wait_for_idle()

static int qn908x_wait_for_idle ( struct target target,
int64_t  timeout_ms 
)
static

◆ qn908x_write()

Variable Documentation

◆ __attribute__

static __attribute__

Definition at line 1016 of file armv8.c.

◆ _reserved

uint8_t _reserved[3]

Definition at line 2 of file qn908x.c.

◆ bits

◆ nvds_size

uint8_t nvds_size[4]

Definition at line 5 of file qn908x.c.

◆ protection

◆ qn908x_command_handlers

const struct command_registration qn908x_command_handlers[]
static
Initial value:
= {
{
.name = "qn908x",
.mode = COMMAND_ANY,
.help = "qn908x flash controller commands",
.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 qn908x_exec_command_handlers[]
Definition: qn908x.c:1145

Definition at line 1037 of file qn908x.c.

◆ qn908x_exec_command_handlers

const struct command_registration qn908x_exec_command_handlers[]
static
Initial value:
= {
{
.name = "allow_brick",
.handler = qn908x_handle_allow_brick_command,
.mode = COMMAND_EXEC,
.help = "Allow writing images that disable SWD access in their "
"Code Read Protection (CRP) word. Warning: This can make your "
"chip inaccessible from OpenOCD or any other SWD debugger.",
.usage = "",
},
{
.name = "disable_wdog",
.handler = qn908x_handle_disable_wdog_command,
.mode = COMMAND_EXEC,
.help = "Disabled the watchdog (WDT).",
.usage = "",
},
{
.name = "mass_erase",
.handler = qn908x_handle_mass_erase_command,
.mode = COMMAND_EXEC,
.help = "Erase the whole flash chip.",
.usage = "[keep_lock]",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 1037 of file qn908x.c.

◆ qn908x_flash

const struct flash_driver qn908x_flash
Initial value:
= {
.name = "qn908x",
.flash_bank_command = qn908x_flash_bank_command,
.info = qn908x_get_info,
.erase = qn908x_erase,
.protect = qn908x_protect,
.write = qn908x_write,
.probe = qn908x_probe,
.auto_probe = qn908x_auto_probe,
.erase_check = default_flash_blank_check,
.protect_check = qn908x_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 qn908x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
Definition: qn908x.c:671
static int qn908x_auto_probe(struct flash_bank *bank)
Definition: qn908x.c:915
static int qn908x_get_info(struct flash_bank *bank, struct command_invocation *cmd)
Definition: qn908x.c:942
static int qn908x_protect_check(struct flash_bank *bank)
Definition: qn908x.c:924
static int qn908x_probe(struct flash_bank *bank)
Definition: qn908x.c:822
static const struct command_registration qn908x_command_handlers[]
Definition: qn908x.c:1172
static int qn908x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
Definition: qn908x.c:576
static int qn908x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
Definition: qn908x.c:524

Definition at line 1037 of file qn908x.c.