gr55xx_dfu.h
Go to the documentation of this file.
1
48 #ifndef __GR55XX_DFU_H__
49 #define __GR55XX_DFU_H__
50
51 #include <stdbool.h>
52 #include <stdint.h>
53
56 #define DFU_ADV_MAX_LENGTH 18
57 #define RECEIVE_MAX_LEN 2048
61 #define DFU_WRITE_RAM_DISABLE 0x0001
62 #define DFU_READ_RAM_DISABLE 0x0002
63 #define DFU_DUMP_FLASH_DISABLE 0x0004
64 #define DFU_ERASE_FLASH_DISABLE 0x0008
65 #define DFU_UPDAE_FLASH_DISABLE 0x0010
66 #define DFU_OPERATE_SYSTEM_INFO_DISABLE 0x0020
67 #define DFU_OPERATE_NVDS_DISABLE 0x0040
68 #define DFU_OPERATE_EFUSE_DISABLE 0x0080
69 #define DFU_CONFIG_SPI_FLASH_DISABLE 0x0100
70 #define DFU_OPERATE_REG_DISABLE 0x0200
79 typedef enum
80 {
81 DFU_UART_BAUDRATE_9600 = 9600,
82 DFU_UART_BAUDRATE_19200 = 19200,
83 DFU_UART_BAUDRATE_38400 = 38400,
84 DFU_UART_BAUDRATE_57600 = 57600,
85 DFU_UART_BAUDRATE_115200 = 115200,
86 DFU_UART_BAUDRATE_230400 = 230400,
87 DFU_UART_BAUDRATE_921600 = 921600,
88 } dfu_uart_baudrate_t;
89
91 typedef enum
92 {
93 DFU_UART_DATA_BIT_5 = 0,
94 DFU_UART_DATA_BIT_6,
95 DFU_UART_DATA_BIT_7,
96 DFU_UART_DATA_BIT_8,
97 } dfu_uart_data_bit_t;
98
100 typedef enum
101 {
102 DFU_UART_STOP_BIT_1 = 0,
103 DFU_UART_STOP_BIT_1_5,
104 DFU_UART_STOP_BIT_2,
105 } dfu_uart_stop_bit_t;
106
108 typedef enum
109 {
110 DFU_UART_PARITY_NONE = 0,
111 DFU_UART_PARITY_ODD,
112 DFU_UART_PARITY_EVEN,
113 DFU_UART_PARITY_SP_0,
114 DFU_UART_PARITY_SP_1,
115 } dfu_uart_parity_bit_t;
116
118 typedef enum
119 {
120 DFU_UART_PIN_GROUP_0 = 0,
121 DFU_UART_PIN_GROUP_1,
122 DFU_UART_PIN_GROUP_2,
123 DFU_UART_PIN_GROUP_3,
124 DFU_UART_PIN_GROUP_4,
125 DFU_UART_PIN_GROUP_5,
126 } dfu_uart_pin_group_t;
127
129 typedef enum
130 {
131 DFU_INFO_DISABLE = 0x5775,
132 DFU_INFO_ENABLE = 0x7ff7,
133 DFU_INFO_DEFAULT = 0x4774,
134 } dfu_info_state;
141 typedef struct
142 {
143 uint32_t bin_size;
144 uint32_t check_sum;
145 uint32_t load_addr;
146 uint32_t run_addr ;
147 uint32_t xqspi_xip_cmd;
149 uint32_t xqspi_speed: 4;
150 uint32_t code_copy_mode: 1;
151 uint32_t system_clk: 3;
152 uint32_t check_image:1;
153 uint32_t boot_delay:1;
154 uint32_t is_dap_boot:1;
155 uint32_t reserved:21;
156 } boot_info_t;
157
158
160 typedef struct
161 {
162 dfu_info_state state;
163 dfu_uart_baudrate_t baud_rate;
164 dfu_uart_data_bit_t data_bit;
165 dfu_uart_stop_bit_t stop_bits;
166 dfu_uart_parity_bit_t parity;
167 dfu_uart_pin_group_t pin_group;
168 } dfu_uart_info_t;
169
171 typedef struct
172 {
173 dfu_info_state state;
174 uint8_t adv_name[DFU_ADV_MAX_LENGTH];
175 uint16_t adv_name_length;
176 } dfu_adv_name_info_t;
177
179 typedef struct
180 {
181 dfu_info_state state;
182 uint16_t page_size;
183 uint32_t start_address;
184 }dfu_nvds_info_t;
185
187 typedef struct
188 {
189 dfu_info_state state;
190 uint16_t cmd_bit_map;
191 }dfu_cmd_disable_t;
192
193
195 typedef struct
196 {
197 void (*dfu_ble_send_data)(uint8_t *p_data, uint16_t length);
198 void (*dfu_uart_send_data)(uint8_t *p_data, uint16_t length);
199 uint32_t (*dfu_flash_read)(const uint32_t addr, uint8_t *p_buf, const uint32_t size);
200 uint32_t (*dfu_flash_write)(const uint32_t addr, const uint8_t *p_buf, const uint32_t size);
201 bool (*dfu_flash_erase)(const uint32_t addr, const uint32_t size);
202 bool (*dfu_flash_erase_chip)(void);
203 void (*dfu_flash_set_security)(bool enable);
204 bool (*dfu_flash_get_security)(void);
205 void (*dfu_flash_get_info)(uint32_t *id, uint32_t *size);
206 } dfu_func_t;
207
209 typedef struct
210 {
211 void (*dfu_spi_flash_init)(uint8_t *p_data);
212 uint32_t (*dfu_spi_flash_read)(uint32_t addr, uint8_t *buf, uint32_t size);
213 uint32_t (*dfu_spi_flash_write)(uint32_t addr, uint8_t *buf, uint32_t size);
214 bool (*dfu_spi_flash_erase)(uint32_t addr, uint32_t size);
215 bool (*dfu_spi_flash_erase_chip)(void);
216 void (*dfu_spi_flash_get_info)(uint32_t *id, uint32_t *size);
217 }dfu_spi_flash_func_t;
218
219
221 typedef struct
222 {
223 void (*dfu_program_start_callback)(void);
224 void (*dfu_programing_callback)(uint8_t pro);
225 void (*dfu_program_end_callback)(uint8_t status);
226 } dfu_pro_callback_t;
227
246 void dfu_init(dfu_func_t *p_app_dfu_func, uint8_t* p_dfu_buffer, dfu_pro_callback_t *p_dfu_callback);
247
255 void dfu_cmd_parse_state_reset(void);
256
267 void dfu_ble_set_mtu_size(uint16_t mtu_size);
268
278 void dfu_ble_send_data_cmpl_process(void);
279
290 void dfu_ble_receive_data_process(uint8_t *p_data, uint16_t length);
291
302 void dfu_uart_receive_data_process(uint8_t *p_data, uint16_t length);
303
311 void dfu_schedule(void);
312
323 void dfu_start_jump(uint32_t start_addr);
324
335 void dfu_start_address(boot_info_t *p_boot_info);
336
350 void dfu_start_default(dfu_uart_info_t *p_dfu_uart_info, dfu_adv_name_info_t *p_dfu_adv_name_info, dfu_nvds_info_t *p_dfu_nvds_info);
351
365 void dfu_start_set(dfu_uart_info_t *p_dfu_uart_info, dfu_adv_name_info_t *p_dfu_adv_name_info, dfu_nvds_info_t *p_dfu_nvds_info);
366
367
378 void dfu_set_disable_cmd(uint16_t disable_cmd_bit_map);
379
389 void dfu_spi_flash_func_config(dfu_spi_flash_func_t *spi_flash_func);
390
392 #endif
393
dfu_uart_info_t::pin_group
dfu_uart_pin_group_t pin_group
Definition: gr55xx_dfu.h:167
dfu_init
void dfu_init(dfu_func_t *p_app_dfu_func, uint8_t *p_dfu_buffer, dfu_pro_callback_t *p_dfu_callback)
Function for initializing the DFU Used and Program State Callback.
DFU_ADV_MAX_LENGTH
#define DFU_ADV_MAX_LENGTH
Definition: gr55xx_dfu.h:56
dfu_set_disable_cmd
void dfu_set_disable_cmd(uint16_t disable_cmd_bit_map)
Function for set DFU disable cmd.
boot_info_t::load_addr
uint32_t load_addr
Definition: gr55xx_dfu.h:145
boot_info_t::code_copy_mode
uint32_t code_copy_mode
Definition: gr55xx_dfu.h:150
DFU_UART_PARITY_ODD
@ DFU_UART_PARITY_ODD
Definition: gr55xx_dfu.h:111
dfu_func_t
DFU used functions config definition.
Definition: gr55xx_dfu.h:196
dfu_ble_receive_data_process
void dfu_ble_receive_data_process(uint8_t *p_data, uint16_t length)
This function should be called when BLE receives data.
DFU_UART_STOP_BIT_1_5
@ DFU_UART_STOP_BIT_1_5
Definition: gr55xx_dfu.h:103
DFU_UART_PIN_GROUP_0
@ DFU_UART_PIN_GROUP_0
Definition: gr55xx_dfu.h:120
dfu_uart_info_t
DFU uart config definition.
Definition: gr55xx_dfu.h:161
DFU_UART_BAUDRATE_9600
@ DFU_UART_BAUDRATE_9600
Definition: gr55xx_dfu.h:81
DFU_UART_PIN_GROUP_3
@ DFU_UART_PIN_GROUP_3
Definition: gr55xx_dfu.h:123
dfu_uart_receive_data_process
void dfu_uart_receive_data_process(uint8_t *p_data, uint16_t length)
This function should be called when UART receives data.
dfu_start_jump
void dfu_start_jump(uint32_t start_addr)
Function for jumping to address to run.
DFU_UART_DATA_BIT_5
@ DFU_UART_DATA_BIT_5
Definition: gr55xx_dfu.h:93
dfu_nvds_info_t
DFU NVDS init info definition.
Definition: gr55xx_dfu.h:180
dfu_uart_info_t::parity
dfu_uart_parity_bit_t parity
Definition: gr55xx_dfu.h:166
DFU_UART_PARITY_SP_1
@ DFU_UART_PARITY_SP_1
Definition: gr55xx_dfu.h:114
dfu_uart_info_t::data_bit
dfu_uart_data_bit_t data_bit
Definition: gr55xx_dfu.h:164
boot_info_t::xqspi_speed
uint32_t xqspi_speed
Definition: gr55xx_dfu.h:149
boot_info_t::boot_delay
uint32_t boot_delay
Definition: gr55xx_dfu.h:153
dfu_ble_set_mtu_size
void dfu_ble_set_mtu_size(uint16_t mtu_size)
Function for setting the BLE MTU size.
DFU_UART_BAUDRATE_921600
@ DFU_UART_BAUDRATE_921600
Definition: gr55xx_dfu.h:87
dfu_ble_send_data_cmpl_process
void dfu_ble_send_data_cmpl_process(void)
This function should be called when BLE stack sends data completely.
boot_info_t::bin_size
uint32_t bin_size
Definition: gr55xx_dfu.h:143
DFU_UART_PARITY_SP_0
@ DFU_UART_PARITY_SP_0
Definition: gr55xx_dfu.h:113
dfu_uart_stop_bit_t
dfu_uart_stop_bit_t
UART stop bit definition.
Definition: gr55xx_dfu.h:101
dfu_uart_parity_bit_t
dfu_uart_parity_bit_t
UART parity definition.
Definition: gr55xx_dfu.h:109
dfu_start_set
void dfu_start_set(dfu_uart_info_t *p_dfu_uart_info, dfu_adv_name_info_t *p_dfu_adv_name_info, dfu_nvds_info_t *p_dfu_nvds_info)
Function for set the default DFU bootloader informatica(Only available for GR5515_D Chip).
DFU_UART_BAUDRATE_230400
@ DFU_UART_BAUDRATE_230400
Definition: gr55xx_dfu.h:86
DFU_UART_BAUDRATE_19200
@ DFU_UART_BAUDRATE_19200
Definition: gr55xx_dfu.h:82
dfu_cmd_disable_t::state
dfu_info_state state
Definition: gr55xx_dfu.h:189
dfu_uart_info_t::stop_bits
dfu_uart_stop_bit_t stop_bits
Definition: gr55xx_dfu.h:165
DFU_UART_STOP_BIT_1
@ DFU_UART_STOP_BIT_1
Definition: gr55xx_dfu.h:102
dfu_info_state
dfu_info_state
DFU informatica status.
Definition: gr55xx_dfu.h:130
DFU_INFO_DISABLE
@ DFU_INFO_DISABLE
Definition: gr55xx_dfu.h:131
dfu_schedule
void dfu_schedule(void)
Function for checking DFU cmd.
dfu_uart_info_t::state
dfu_info_state state
Definition: gr55xx_dfu.h:162
DFU_UART_BAUDRATE_115200
@ DFU_UART_BAUDRATE_115200
Definition: gr55xx_dfu.h:85
dfu_nvds_info_t::page_size
uint16_t page_size
Definition: gr55xx_dfu.h:182
dfu_start_default
void dfu_start_default(dfu_uart_info_t *p_dfu_uart_info, dfu_adv_name_info_t *p_dfu_adv_name_info, dfu_nvds_info_t *p_dfu_nvds_info)
Function for starting the default DFU bootloader(Only available for GR5515_D Chip).
DFU_UART_DATA_BIT_7
@ DFU_UART_DATA_BIT_7
Definition: gr55xx_dfu.h:95
DFU_UART_PIN_GROUP_2
@ DFU_UART_PIN_GROUP_2
Definition: gr55xx_dfu.h:122
boot_info_t::run_addr
uint32_t run_addr
Definition: gr55xx_dfu.h:146
DFU_INFO_DEFAULT
@ DFU_INFO_DEFAULT
Definition: gr55xx_dfu.h:133
DFU_UART_BAUDRATE_38400
@ DFU_UART_BAUDRATE_38400
Definition: gr55xx_dfu.h:83
dfu_start_address
void dfu_start_address(boot_info_t *p_boot_info)
Function for changing the boot info and reseting device.
dfu_uart_pin_group_t
dfu_uart_pin_group_t
UART pin group definition.
Definition: gr55xx_dfu.h:119
boot_info_t::check_sum
uint32_t check_sum
Definition: gr55xx_dfu.h:144
DFU_UART_PIN_GROUP_1
@ DFU_UART_PIN_GROUP_1
Definition: gr55xx_dfu.h:121
dfu_adv_name_info_t::adv_name_length
uint16_t adv_name_length
Definition: gr55xx_dfu.h:175
dfu_uart_data_bit_t
dfu_uart_data_bit_t
UART data bit definition.
Definition: gr55xx_dfu.h:92
dfu_adv_name_info_t::state
dfu_info_state state
Definition: gr55xx_dfu.h:173
DFU_UART_PARITY_EVEN
@ DFU_UART_PARITY_EVEN
Definition: gr55xx_dfu.h:112
dfu_uart_baudrate_t
dfu_uart_baudrate_t
UART baudrate definition.
Definition: gr55xx_dfu.h:80
dfu_spi_flash_func_config
void dfu_spi_flash_func_config(dfu_spi_flash_func_t *spi_flash_func)
Function for initializing the DFU SPI Flash Callback.
dfu_uart_info_t::baud_rate
dfu_uart_baudrate_t baud_rate
Definition: gr55xx_dfu.h:163
dfu_cmd_disable_t::cmd_bit_map
uint16_t cmd_bit_map
Definition: gr55xx_dfu.h:190
DFU_UART_DATA_BIT_6
@ DFU_UART_DATA_BIT_6
Definition: gr55xx_dfu.h:94
boot_info_t
BootLoader information definition.
Definition: gr55xx_dfu.h:142
DFU_UART_STOP_BIT_2
@ DFU_UART_STOP_BIT_2
Definition: gr55xx_dfu.h:104
boot_info_t::check_image
uint32_t check_image
Definition: gr55xx_dfu.h:152
dfu_nvds_info_t::start_address
uint32_t start_address
Definition: gr55xx_dfu.h:183
dfu_adv_name_info_t
DFU Advertisement name config definition.
Definition: gr55xx_dfu.h:172
boot_info_t::xqspi_xip_cmd
uint32_t xqspi_xip_cmd
Definition: gr55xx_dfu.h:147
dfu_spi_flash_func_t
SPI used functions config definition.
Definition: gr55xx_dfu.h:210
DFU_UART_BAUDRATE_57600
@ DFU_UART_BAUDRATE_57600
Definition: gr55xx_dfu.h:84
boot_info_t::is_dap_boot
uint32_t is_dap_boot
Definition: gr55xx_dfu.h:154
boot_info_t::system_clk
uint32_t system_clk
Definition: gr55xx_dfu.h:151
dfu_pro_callback_t
DFU program state callback definition.
Definition: gr55xx_dfu.h:222
dfu_nvds_info_t::state
dfu_info_state state
Definition: gr55xx_dfu.h:181
dfu_cmd_parse_state_reset
void dfu_cmd_parse_state_reset(void)
Function for reset the DFU cmd parse state.
DFU_UART_PARITY_NONE
@ DFU_UART_PARITY_NONE
Definition: gr55xx_dfu.h:110
DFU_UART_PIN_GROUP_5
@ DFU_UART_PIN_GROUP_5
Definition: gr55xx_dfu.h:125
DFU_INFO_ENABLE
@ DFU_INFO_ENABLE
Definition: gr55xx_dfu.h:132
dfu_cmd_disable_t
DFU cmd disable info definition.
Definition: gr55xx_dfu.h:188
DFU_UART_DATA_BIT_8
@ DFU_UART_DATA_BIT_8
Definition: gr55xx_dfu.h:96
boot_info_t::reserved
uint32_t reserved
Definition: gr55xx_dfu.h:155
DFU_UART_PIN_GROUP_4
@ DFU_UART_PIN_GROUP_4
Definition: gr55xx_dfu.h:124