/** ****************************************************************************** * * @file gr55xx_dfu.h * * @brief Device Firmware Update API * ****************************************************************************** * @attention #####Copyright (c) 2019 GOODIX All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of GOODIX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***************************************************************************************** */ /** * @addtogroup SYSTEM * @{ */ /** @addtogroup DFU Device Firmware Update @{ @brief Definitions and prototypes for the DFU interface. */ #ifndef __GR55XX_DFU_H__ #define __GR55XX_DFU_H__ #include #include /** @addtogroup DFU_DEFINES Defines * @{ */ #define DFU_ADV_MAX_LENGTH 18 /**< The max length of advertisement is 18 bytes. */ #define RECEIVE_MAX_LEN 2048 /**< The max length of received data is 2048 bytes. */ /** @defgroup DFU_CMD_DISABLE DFU cmd disable option (bitmask) * @{ */ #define DFU_WRITE_RAM_DISABLE 0x0001 /**< Disable DFU write ram. */ #define DFU_READ_RAM_DISABLE 0x0002 /**< Disable DFU read ram. */ #define DFU_DUMP_FLASH_DISABLE 0x0004 /**< Disable DFU dump flash. */ #define DFU_ERASE_FLASH_DISABLE 0x0008 /**< Disable DFU erase flash. */ #define DFU_UPDAE_FLASH_DISABLE 0x0010 /**< Disable DFU update flash. */ #define DFU_OPERATE_SYSTEM_INFO_DISABLE 0x0020 /**< Disable DFU operate system info area. */ #define DFU_OPERATE_NVDS_DISABLE 0x0040 /**< Disable DFU operate NVDS. */ #define DFU_OPERATE_EFUSE_DISABLE 0x0080 /**< Disable DFU operate EFUSE. */ #define DFU_CONFIG_SPI_FLASH_DISABLE 0x0100 /**< Disable DFU config spi flash. */ #define DFU_OPERATE_REG_DISABLE 0x0200 /**< Disable DFU operate register. */ /** @} */ /** @} */ /** @addtogroup DFU_ENUMERATIONS Enumerations * @{ */ /** @brief UART baudrate definition. */ typedef enum { DFU_UART_BAUDRATE_9600 = 9600, /**< Baudrate 9600. */ DFU_UART_BAUDRATE_19200 = 19200, /**< Baudrate 19200. */ DFU_UART_BAUDRATE_38400 = 38400, /**< Baudrate 38400. */ DFU_UART_BAUDRATE_57600 = 57600, /**< Baudrate 57600. */ DFU_UART_BAUDRATE_115200 = 115200, /**< Baudrate 115200. */ DFU_UART_BAUDRATE_230400 = 230400, /**< Baudrate 230400. */ DFU_UART_BAUDRATE_921600 = 921600, /**< Baudrate 921600. */ } dfu_uart_baudrate_t; /** @brief UART data bit definition. */ typedef enum { DFU_UART_DATA_BIT_5 = 0, /**< Data bit 5. */ DFU_UART_DATA_BIT_6, /**< Data bit 6. */ DFU_UART_DATA_BIT_7, /**< Data bit 7. */ DFU_UART_DATA_BIT_8, /**< Data bit 8. */ } dfu_uart_data_bit_t; /** @brief UART stop bit definition. */ typedef enum { DFU_UART_STOP_BIT_1 = 0, /**< Stop bit 1. Avaliable when data bit = 5,6,7,8. */ DFU_UART_STOP_BIT_1_5, /**< Stop bit 1.5. Avaliable when data bit = 5. */ DFU_UART_STOP_BIT_2, /**< Stop bit 2. Avaliable when data bit = 6,7,8. */ } dfu_uart_stop_bit_t; /** @brief UART parity definition. */ typedef enum { DFU_UART_PARITY_NONE = 0, /**< Parity none. */ DFU_UART_PARITY_ODD, /**< Parity odd. */ DFU_UART_PARITY_EVEN, /**< Parity even. */ DFU_UART_PARITY_SP_0, /**< Parity stick 0. */ DFU_UART_PARITY_SP_1, /**< Parity stick 1. */ } dfu_uart_parity_bit_t; /** @brief UART pin group definition. */ typedef enum { DFU_UART_PIN_GROUP_0 = 0, /**< GPIO0_PIN3 -> UART0_TXD(MUX0),GPIO0_PIN4 -> UART0_RXD(MUX0)*/ DFU_UART_PIN_GROUP_1, /**< GPIO0_PIN10 -> UART0_TXD(MUX2),GPIO0_PIN11 -> UART0_RXD(MUX2)*/ DFU_UART_PIN_GROUP_2, /**< GPIO0_PIN0 -> UART0_TXD(MUX4),GPIO0_PIN1 -> UART0_RXD(MUX4)*/ DFU_UART_PIN_GROUP_3, /**< GPIO1_PIN14 -> UART0_TXD(MUX5),GPIO1_PIN10 -> UART0_RXD(MUX5)*/ DFU_UART_PIN_GROUP_4, /**< GPIO0_PIN7 -> UART1_TXD(MUX3),GPIO0_PIN6 -> UART1_RXD(MUX3)*/ DFU_UART_PIN_GROUP_5, /**< GPIO0_PIN9 -> UART1_TXD(MUX3),GPIO0_PIN8 -> UART1_RXD(MUX3)*/ } dfu_uart_pin_group_t; /** @brief DFU informatica status. */ typedef enum { DFU_INFO_DISABLE = 0x5775, /**< DFU Config Info Disable. */ DFU_INFO_ENABLE = 0x7ff7, /**< DFU Config Info Enable. */ DFU_INFO_DEFAULT = 0x4774, /**< DFU Config Info DEFAULT */ } dfu_info_state; /** @} */ /** @addtogroup DFU_STRUCTURES Structures * @{ */ /** @brief BootLoader information definition. */ typedef struct { uint32_t bin_size; /**< Firmware Size. */ uint32_t check_sum; /**< Firmware Check Sum Value. */ uint32_t load_addr; /**< Firmware Load Address. */ uint32_t run_addr ; /**< Firmware Run Address. */ uint32_t xqspi_xip_cmd; /**< XIP Read Mode. 0x03: Read mode, 0x0B: Fast Read mode, 0x3B: DualOut Fast Read mode, 0xBB: DualIO Fast Read mode, 0x6B: QuadOut Fast Read mode, 0xEB: QuadIO Fast Read mode */ uint32_t xqspi_speed : 4; /**< Bit: 0-3 clock speed. 0 :64 MHz, 1:48 MHz, 2:32 MHz, 3:24 MHz, 4:16 MHz. */ uint32_t code_copy_mode : 1; /**< Bit: 4 code copy mode. 0:XIP,1:QSPI. */ uint32_t system_clk : 3; /**< Bit: 5-7 system clock. 0:64 MHz, 1:48 MHz, 2:32 MHz(xo), 3:24 MHz, 4:16 MHz, 5:32 MHz(cpll). */ uint32_t check_image : 1; /**< Bit: 8 check image. */ uint32_t boot_delay : 1; /**< Bit: Boot delay flag. */ uint32_t is_dap_boot : 1; /**< Bit: 11 check if boot dap mode. */ uint32_t reserved : 21; /**< Bit: 24 reserved. */ } boot_info_t; /** @brief DFU uart config definition. */ typedef struct { dfu_info_state state; /**< DFU UART Enable or Disable. This parameter can be a value of @ref dfu_info_state. */ dfu_uart_baudrate_t baud_rate; /**< UART communication baudrate. This parameter can be a value of @ref dfu_uart_baudrate_t. */ dfu_uart_data_bit_t data_bit; /**< The number of data bits transmitted or received in a frame. This parameter can be a value of @ref dfu_uart_data_bit_t. */ dfu_uart_stop_bit_t stop_bits; /**< The number of stop bits transmitted. This parameter can be a value of @ref dfu_uart_stop_bit_t. */ dfu_uart_parity_bit_t parity; /**< Specify the parity mode. This parameter can be a value of @ref dfu_uart_parity_bit_t. */ dfu_uart_pin_group_t pin_group; /**< Uart pin group. This parameter can be a value of @ref dfu_uart_pin_group_t. */ } dfu_uart_info_t; /** @brief DFU Advertisement name config definition. */ typedef struct { dfu_info_state state; /**< If a set name is used, this parameter can be a value of @ref dfu_info_state. */ uint8_t adv_name[DFU_ADV_MAX_LENGTH]; /**< Adv name data. */ uint16_t adv_name_length; /**< The length of the name. */ } dfu_adv_name_info_t; /** @brief DFU NVDS init info definition. */ typedef struct { dfu_info_state state; /**< If NVDS init is required, this parameter can be a value of @ref dfu_info_state. */ uint16_t page_size; /**< NVDS page size. */ uint32_t start_address; /**< NVDS start address. */ } dfu_nvds_info_t; /** @brief DFU cmd disable info definition. */ typedef struct { dfu_info_state state; /**< If DFU cmd disable config is required, this parameter can be a value of @ref dfu_info_state. */ uint16_t cmd_bit_map; /**< NVDS start address. */ } dfu_cmd_disable_t; /** @brief DFU used functions config definition. */ typedef struct { /**< The function is used to send data to master by BLE. */ void (*dfu_ble_send_data)(uint8_t *p_data, uint16_t length); /**< The function is used to send data to master by UART. */ void (*dfu_uart_send_data)(uint8_t *p_data, uint16_t length); /**< The function is used to read data from flash. */ uint32_t (*dfu_flash_read)(const uint32_t addr, uint8_t *p_buf, const uint32_t size); /**< The function is used to write data to flash. */ uint32_t (*dfu_flash_write)(const uint32_t addr, const uint8_t *p_buf, const uint32_t size); /**< The function is used to erase flash by address. */ bool (*dfu_flash_erase)(const uint32_t addr, const uint32_t size); /**< The function is used to erase flash chip. */ bool (*dfu_flash_erase_chip)(void); /**< The function is used to set the flash security mode as Enable or Disable. */ void (*dfu_flash_set_security)(bool enable); /**< The function is used to get the flash security mode (Enable or Disable). */ bool (*dfu_flash_get_security)(void); /**< The function is used to get the flash id and size. */ void (*dfu_flash_get_info)(uint32_t *id, uint32_t *size); } dfu_func_t; /** @brief SPI used functions config definition. */ typedef struct { /**< The function is used to config flash spi. */ void (*dfu_spi_flash_init)(uint8_t *p_data); /**< The function is used to read external flash . */ uint32_t (*dfu_spi_flash_read)(uint32_t addr, uint8_t *buf, uint32_t size); /**< The function is used to write external flash. */ uint32_t (*dfu_spi_flash_write)(uint32_t addr, uint8_t *buf, uint32_t size); /**< The function is used to erase external flash by address. */ bool (*dfu_spi_flash_erase)(uint32_t addr, uint32_t size); /**< The function is used to erase exteral flash chip. */ bool (*dfu_spi_flash_erase_chip)(void); /**< The function is used to get external flash id and size. */ void (*dfu_spi_flash_get_info)(uint32_t *id, uint32_t *size); } dfu_spi_flash_func_t; /** @brief DFU program state callback definition. */ typedef struct { void (*dfu_program_start_callback)(void); /**