From: snickersun Date: Tue, 29 Dec 2020 17:23:18 +0000 (+0800) Subject: 完成AG3335M_download 程序 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.js?a=commitdiff_plain;h=HEAD;p=ag3335m_download_demo.git 完成AG3335M_download 程序 --- diff --git a/app/src/main/jni/libag3335m/inc/hdl_api.h b/app/src/main/jni/libag3335m/inc/hdl_api.h index 59c6615..87849e4 100644 --- a/app/src/main/jni/libag3335m/inc/hdl_api.h +++ b/app/src/main/jni/libag3335m/inc/hdl_api.h @@ -42,7 +42,7 @@ extern "C" { #endif -#ifndef PSRAM_DOWNLOAD + typedef enum { DISCONNECT_NONE = 0, DISCONNECT_POWER_OFF, @@ -54,9 +54,7 @@ bool hdl_connect(const hdl_image_t *da_info, const hdl_connect_arg_t *connect_ar bool hdl_format(const hdl_format_arg_t *format_arg); bool hdl_readback(const hdl_readback_arg_t *readback_arg); bool hdl_disconnect(HDL_DISCONNECT_TYPE disconnect_type); -#else -bool hdl_connect(const hdl_da_info_t *da_info, const hdl_connect_arg_t *connect_arg); -#endif + bool hdl_download(const hdl_download_arg_t *download_arg); diff --git a/app/src/main/jni/libag3335m/inc/hdl_config.h b/app/src/main/jni/libag3335m/inc/hdl_config.h index 9452e40..ac1f464 100644 --- a/app/src/main/jni/libag3335m/inc/hdl_config.h +++ b/app/src/main/jni/libag3335m/inc/hdl_config.h @@ -113,7 +113,7 @@ typedef int BOOL; #define FALSE 0 typedef int hal_uart_baudrate_t ; // Turn on HDL Debug Log -#define HDL_DEBUG +//#define HDL_DEBUG // Choose PSRAM download //#define PSRAM_DOWNLOAD diff --git a/app/src/main/jni/libag3335m/inc/hdl_debug.h b/app/src/main/jni/libag3335m/inc/hdl_debug.h index 42d6d47..da6b351 100644 --- a/app/src/main/jni/libag3335m/inc/hdl_debug.h +++ b/app/src/main/jni/libag3335m/inc/hdl_debug.h @@ -54,10 +54,10 @@ extern "C" { #define HDL_LOGW(...) __android_log_print(ANDROID_LOG_WARN,DEV_LOG_TAG,__VA_ARGS__) #define HDL_LOGE(...) __android_log_print(ANDROID_LOG_ERROR,DEV_LOG_TAG,__VA_ARGS__) #else -#define HDL_LOGI(...) -#define HDL_LOGD(...) -#define HDL_LOGW(...) -#define HDL_LOGE(...) +#define HDL_LOGI(format, ...) printf(format"\n", ##__VA_ARGS__) +#define HDL_LOGD(format, ...) printf(format"\n", ##__VA_ARGS__) +#define HDL_LOGW(format, ...) printf(format"\n", ##__VA_ARGS__) +#define HDL_LOGE(format, ...) printf(format"\n", ##__VA_ARGS__) #endif #define HDL_SUCCESS_LOG(X) HDL_LOGI("%s %s", X, ((success) ? "success" : "fail")) diff --git a/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/ag3335_bootloader.bin b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/ag3335_bootloader.bin new file mode 100644 index 0000000..d0a8b24 Binary files /dev/null and b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/ag3335_bootloader.bin differ diff --git a/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/cm4_log_str.bin b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/cm4_log_str.bin new file mode 100644 index 0000000..654bf7e Binary files /dev/null and b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/cm4_log_str.bin differ diff --git a/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/flash_download.cfg b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/flash_download.cfg new file mode 100644 index 0000000..fadce54 --- /dev/null +++ b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/flash_download.cfg @@ -0,0 +1,35 @@ +############################################################################################################ +# +# General Setting +# +############################################################################################################ + +general: + config_version : v2.0 + platform: AG3335 + +############################################################################################################ +# +# Main Region Setting +# +############################################################################################################ + +main_region: + address_type: physical + rom_list: + - rom: + file: partition_table.bin + name: PartitionTable + begin_address: 0x08000000 + - rom: + file: ag3335_bootloader.bin + name: BootLoader + begin_address: 0x08003000 + - rom: + file: gnss_demo.bin + name: CM4 + begin_address: 0x08013000 + - rom: + file: gnss_config.bin + name: GNSSConfiguration + begin_address: 0x083FF000 diff --git a/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/gnss_config.bin b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/gnss_config.bin new file mode 100644 index 0000000..1d3a7fa Binary files /dev/null and b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/gnss_config.bin differ diff --git a/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/gnss_demo.bin b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/gnss_demo.bin new file mode 100644 index 0000000..b50c488 Binary files /dev/null and b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/gnss_demo.bin differ diff --git a/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/partition_table.bin b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/partition_table.bin new file mode 100644 index 0000000..ffce4e1 Binary files /dev/null and b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/partition_table.bin differ diff --git a/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/slave_da_UART.bin b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/slave_da_UART.bin new file mode 100644 index 0000000..f7d1288 Binary files /dev/null and b/app/src/main/jni/libag3335m/roms/data/ag3335m_rom/slave_da_UART.bin differ diff --git a/app/src/main/jni/libag3335m/src/hdl_api.c b/app/src/main/jni/libag3335m/src/hdl_api.c index ad830e6..8270fda 100644 --- a/app/src/main/jni/libag3335m/src/hdl_api.c +++ b/app/src/main/jni/libag3335m/src/hdl_api.c @@ -37,45 +37,7 @@ #define HDL_HW_CODE_REG 0x80000008 #define HDL_HW_SUBCODE_REG 0x8000000C -#ifdef PSRAM_DOWNLOAD -bool hdl_connect(const hdl_da_info_t *da_info, const hdl_connect_arg_t *connect_arg) -{ - if (da_info == NULL || connect_arg == NULL) { - HDL_LOGE("hdl_connect fail, invalid parameter"); - return FALSE; - } - - // Init Channel & HandShake with Chip BROM via Brom_StartCMD - bool success = hdl_channel_init(); - HDL_Require_Noerr_Action(success, exit, "hdl_channel_init"); - hdl_brom_start(); - - // Read Chip HW_Code/SubCode - uint16_t hw_code = 0; - uint16_t hw_subcode = 0; - hdl_brom_read16(HDL_HW_CODE_REG, &hw_code); - hdl_brom_read16(HDL_HW_SUBCODE_REG, &hw_subcode); - HDL_LOGI("hdl_connect, hw_code 0x%04X 0x%04X", hw_code, hw_subcode); - - // Brom Disable WDT - success = hdl_brom_disable_wdt(); - HDL_Require_Noerr_Action(success, exit, "hdl_brom_disable_wdt"); - // Brom Send DA - success = hdl_brom_send_da(connect_arg, da_info->da_flash_addr, da_info->da_run_addr, da_info->da_len); - HDL_Require_Noerr_Action(success, exit, "hdl_brom_send_da"); - - // Brom Jump to DA - success = hdl_brom_jump_da(da_info->da_run_addr); - HDL_Require_Noerr_Action(success, exit, "hdl_brom_jump_da"); - - // DA Sync - success = hdl_sync_with_da(connect_arg->conn_enable_log); - -exit: - return success; -} -#else bool hdl_connect(const hdl_image_t *da_info, const hdl_connect_arg_t *connect_arg, hdl_da_report_t *da_report) { if (da_info == NULL || connect_arg == NULL || da_report == NULL) { @@ -93,7 +55,7 @@ bool hdl_connect(const hdl_image_t *da_info, const hdl_connect_arg_t *connect_ar uint16_t hw_subcode = 0; hdl_brom_read16(HDL_HW_CODE_REG, &hw_code); hdl_brom_read16(HDL_HW_SUBCODE_REG, &hw_subcode); - HDL_LOGI("hdl_connect, hw_code 0x%04X 0x%04X", hw_code, hw_subcode); + HDL_LOGI("======hdl_connect, hw_code 0x%04X 0x%04X", hw_code, hw_subcode); da_report->hw_code = hw_code; da_report->hw_subcode = hw_subcode; @@ -119,7 +81,7 @@ bool hdl_connect(const hdl_image_t *da_info, const hdl_connect_arg_t *connect_ar exit: return success; } -#endif + #ifndef PSRAM_DOWNLOAD bool hdl_format(const hdl_format_arg_t *format_arg) @@ -187,16 +149,6 @@ exit: } #ifndef PSRAM_DOWNLOAD -bool hdl_readback(const hdl_readback_arg_t *readback_arg) -{ - // Check Empty Parameter - if (readback_arg == NULL || readback_arg->readback_flash_addr < 0x08000000 - || readback_arg->readback_total_len == 0) { - HDL_LOGE("hdl_readback fail, invalid parameter"); - return FALSE; - } - return hdl_da_readback(readback_arg); -} bool hdl_disconnect(HDL_DISCONNECT_TYPE disconnect_type) { diff --git a/app/src/main/jni/libag3335m/src/hdl_brom_base.c b/app/src/main/jni/libag3335m/src/hdl_brom_base.c index ffabb94..6ac7236 100644 --- a/app/src/main/jni/libag3335m/src/hdl_brom_base.c +++ b/app/src/main/jni/libag3335m/src/hdl_brom_base.c @@ -55,7 +55,7 @@ static void brom_start_task(void *pvParameters) HDL_LOGI("brom_start_task put_char 0xA0"); hdl_delay(50); } - HDL_LOGD("brom task end!"); + // HDL_LOGD("brom task end!"); } void hdl_create_brom_start_task(){ int rc; @@ -99,7 +99,6 @@ bool hdl_brom_start() char rx_data = 0; brom_start_retry: -#if defined (HDL_VIA_UART) // ToDo Note: For our UART, need to create asnyc_task to send START_CMD[0]=0xA0 // continuously in UART Polling mode. // For your UART, you could try to use UART DMA mode, or create task like us. @@ -115,26 +114,7 @@ brom_start_retry: break; } } -#elif defined (HDL_VIA_SPI) || defined (HDL_VIA_I2C) - HDL_COM_PutByte(HDL_START_CMD[0]); - rx_data = HDL_COM_GetByte(); - if (rx_data == HDL_BROM_RSP_CMD[0]) { - HDL_LOGI("hdl_brom_start 0xA0<->0x5F"); - } else { - HDL_LOGE("hdl_brom_start 0x0A ->(error) 0x%02X, retry", rx_data); - #if defined (HDL_VIA_SPI) - hdl_delay(2000); - #else - hdl_delay(50); - #endif - goto brom_start_retry; - } -#endif - - #if defined (HDL_VIA_I2C) - hdl_i2c_enable_check_data_valid(); - #endif - + HDL_LOGI("hdl_brom_start 23"); HDL_COM_PutByte(HDL_START_CMD[1]); rx_data = HDL_COM_GetByte(); if (rx_data == HDL_BROM_RSP_CMD[1]) { @@ -252,7 +232,7 @@ bool hdl_brom_send_da(const hdl_connect_arg_t *connect_arg, bool success = FALSE; bool ret = hdl_flash_init(); HDL_Require_Noerr_Action(ret, exit, "hdl_flash_init"); - HDL_LOGI("hdl_brom_send_da fd 0x%08X ,start addr 0x%08X ,len %d", img_info->fd, da_start_addr, da_len); + HDL_LOGI("hdl_brom_send_da %s fd 0x%08X ,start addr 0x%08X ,len %d",img_info->image_file_path, img_info->fd, da_start_addr, da_len); // DA Init Callback if (connect_arg != NULL && connect_arg->conn_da_init_cb != NULL) { diff --git a/app/src/main/jni/libag3335m/src/hdl_channel.c b/app/src/main/jni/libag3335m/src/hdl_channel.c index b62ac4c..b537602 100644 --- a/app/src/main/jni/libag3335m/src/hdl_channel.c +++ b/app/src/main/jni/libag3335m/src/hdl_channel.c @@ -43,7 +43,7 @@ HDL_CHANNEL_TYPE g_hdl_channel_type = CHANNEL_TYPE_UART; bool hdl_channel_init(void) { bool success = TRUE; -#ifdef HDL_VIA_UART + g_hdl_channel_type = CHANNEL_TYPE_UART; g_hdl_channel.m_com_init = hdl_uart_init; g_hdl_channel.m_com_get_byte = hdl_uart_get_byte; @@ -60,44 +60,6 @@ bool hdl_channel_init(void) g_hdl_channel.m_com_set_baudrate = hdl_uart_set_baudrate; g_hdl_channel.m_com_deinit = hdl_uart_deinit; -#elif defined(HDL_VIA_SPI) - g_hdl_channel_type = CHANNEL_TYPE_SPI; - g_hdl_channel.m_com_init = hdl_spi_master_init; - g_hdl_channel.m_com_get_byte = hdl_spi_master_get_byte; - g_hdl_channel.m_com_get_byte_status = hdl_spi_master_get_byte_status; - g_hdl_channel.m_com_get_byte_buffer = hdl_spi_master_get_byte_buffer; - g_hdl_channel.m_com_put_byte = hdl_spi_master_put_byte; - g_hdl_channel.m_com_put_byte_buffer = hdl_spi_master_put_byte_buffer; - g_hdl_channel.m_com_put_byte_complete = hdl_spi_master_put_byte_complete; - g_hdl_channel.m_com_get_data16 = hdl_spi_master_get_data16; - g_hdl_channel.m_com_put_data16 = hdl_spi_master_put_data16; - g_hdl_channel.m_com_get_data32 = hdl_spi_master_get_data32; - g_hdl_channel.m_com_put_data32 = hdl_spi_master_put_data32; - g_hdl_channel.m_com_purge_fifo = hdl_spi_master_purge_fifo; - g_hdl_channel.m_com_set_baudrate = hdl_spi_master_set_baudrate; - g_hdl_channel.m_com_deinit = hdl_spi_master_deinit; - -#elif defined(HDL_VIA_I2C) - g_hdl_channel_type = CHANNEL_TYPE_I2C; - g_hdl_channel.m_com_init = hdl_i2c_master_init; - g_hdl_channel.m_com_get_byte = hdl_i2c_master_get_byte; - g_hdl_channel.m_com_get_byte_status = hdl_i2c_master_get_byte_status; - g_hdl_channel.m_com_get_byte_buffer = hdl_i2c_master_get_byte_buffer; - g_hdl_channel.m_com_put_byte = hdl_i2c_master_put_byte; - g_hdl_channel.m_com_put_byte_buffer = hdl_i2c_master_put_byte_buffer; - g_hdl_channel.m_com_put_byte_complete = hdl_i2c_master_put_byte_complete; - g_hdl_channel.m_com_get_data16 = hdl_i2c_master_get_data16; - g_hdl_channel.m_com_put_data16 = hdl_i2c_master_put_data16; - g_hdl_channel.m_com_get_data32 = hdl_i2c_master_get_data32; - g_hdl_channel.m_com_put_data32 = hdl_i2c_master_put_data32; - g_hdl_channel.m_com_purge_fifo = hdl_i2c_master_purge_fifo; - g_hdl_channel.m_com_set_baudrate = hdl_i2c_master_set_baudrate; - g_hdl_channel.m_com_deinit = hdl_i2c_master_deinit; - -#else -#error "No Define HDL_VIA_UART/SPI/I2C" -#endif - HDL_LOGI("hdl_channel_type=%d", g_hdl_channel_type); success = HDL_COM_Init(); return success; diff --git a/app/src/main/jni/libag3335m/src/hdl_da_cmd.c b/app/src/main/jni/libag3335m/src/hdl_da_cmd.c index d74e2df..69ebf83 100644 --- a/app/src/main/jni/libag3335m/src/hdl_da_cmd.c +++ b/app/src/main/jni/libag3335m/src/hdl_da_cmd.c @@ -80,6 +80,7 @@ static bool hdl_wirte_packet(uint8_t *packet_buf, uint32_t packet_len, uint32_t HDL_LOGE("hdl_wirte_packet fail, invalid parameter"); return FALSE; } + uint8_t retry_count = 0; while (retry_count < 3) { uint8_t response = 0; @@ -137,70 +138,7 @@ static bool hdl_wirte_packet(uint8_t *packet_buf, uint32_t packet_len, uint32_t return FALSE; } -#ifdef PSRAM_DOWNLOAD -bool hdl_sync_with_da(bool enable_log) -{ - // DA HandShake - bool success = FALSE; - bool da_handshake = hdl_da_handshake(); - HDL_Require_Noerr_Action(da_handshake, exit, "hdl_da_handshake"); - - // DA Init_logging - HDL_COM_PutByte((enable_log ? 1 : 0)); - uint8_t da_rx_data = HDL_COM_GetByte(); - HDL_Require_Noerr_Action(da_rx_data == DA_CONT_CHAR, exit, "Init_logging"); - - // EPP Function - PMU Latch Power - da_rx_data = HDL_COM_GetByte(); - HDL_Require_Noerr_Action(da_rx_data == DA_CONT_CHAR, exit, "DA Latch Power"); - HDL_COM_PutByte(DA_ACK); - - // EPP Function - Disable long press power key - HDL_COM_PutByte(0); - da_rx_data = HDL_COM_GetByte(); - HDL_Require_Noerr_Action(da_rx_data == DA_CONT_CHAR, exit, "DA Disable Long Press Power Key"); - HDL_COM_PutByte(DA_ACK); - - // EPP Function - Raise MCU Speed - da_rx_data = HDL_COM_GetByte(); - HDL_Require_Noerr_Action(da_rx_data == DA_CONT_CHAR, exit, "DA Raise MCU Speed"); - HDL_COM_PutByte(DA_ACK); - -#if defined (HDL_VIA_UART) - // EPP Function - Setup Uart HighBaud - hdl_delay(100); // Wait previous DA_ACK to sent (115200) - - //HDL_COM_SetBaudRate(HAL_UART_BAUDRATE_921600); - HDL_COM_SetBaudRate(HAL_UART_BAUDRATE_3000000); - - hdl_delay(100); // Wait Device DA Update BaudRate 921600 or 3000000 - - for (int i = 0; i < 20; i++) { - HDL_COM_PutByte(DA_SYNC_CHAR); - da_rx_data = HDL_COM_GetByte(); - if (da_rx_data == DA_SYNC_CHAR) { - HDL_LOGE("DA Setup Uart HighBaud 1 pass"); - break; - } else { - hdl_delay(100); - HDL_LOGE("DA Setup Uart HighBaud 1 fail, 0x%02X", da_rx_data); - } - } - - HDL_COM_PutByte(DA_ACK); - da_rx_data = HDL_COM_GetByte(); - HDL_Require_Noerr_Action(da_rx_data == DA_ACK, exit, "DA Setup Uart HighBaud 2"); - - da_rx_data = HDL_COM_GetByte(); - HDL_Require_Noerr_Action(da_rx_data == DA_CONT_CHAR, exit, "DA Setup Uart HighBaud 3"); - HDL_COM_PutByte(DA_ACK); -#endif - success = TRUE; -exit: - return success; -} -#else bool hdl_sync_with_da(bool enable_log, hdl_da_report_t *da_report) { // DA HandShake @@ -229,7 +167,7 @@ bool hdl_sync_with_da(bool enable_log, hdl_da_report_t *da_report) HDL_Require_Noerr_Action(da_rx_data == DA_CONT_CHAR, exit, "DA Raise MCU Speed"); HDL_COM_PutByte(DA_ACK); -#if defined (HDL_VIA_UART) + // EPP Function - Setup Uart HighBaud hdl_delay(100); // Wait previous DA_ACK to sent (115200) HDL_COM_SetBaudRate(HAL_UART_BAUDRATE_921600); @@ -253,7 +191,7 @@ bool hdl_sync_with_da(bool enable_log, hdl_da_report_t *da_report) da_rx_data = HDL_COM_GetByte(); HDL_Require_Noerr_Action(da_rx_data == DA_CONT_CHAR, exit, "DA Setup Uart HighBaud 3"); HDL_COM_PutByte(DA_ACK); -#endif + // DA Mount Flash uint16_t manufacturer_id = HDL_COM_GetData16(); @@ -281,7 +219,7 @@ bool hdl_sync_with_da(bool enable_log, hdl_da_report_t *da_report) exit: return success; } -#endif + bool hdl_da_format(const hdl_format_arg_t *format_arg) { @@ -357,10 +295,10 @@ bool hdl_da_download(hdl_image_t *image, hdl_download_cb download_cb, void *down bool da_check_success = hdl_da_check_cmd_arg(&error_status); HDL_Require_Noerr_Action(da_check_success, exit, "DA Download CMD, Check Range"); -#ifndef PSRAM_DOWNLOAD + da_check_success = hdl_da_check_cmd_arg(&error_status); HDL_Require_Noerr_Action(da_check_success, exit, "DA Download CMD, first block erase"); -#endif + // Compute & Send Packet uint32_t packet_sent_num = 0; @@ -380,16 +318,17 @@ bool hdl_da_download(hdl_image_t *image, hdl_download_cb download_cb, void *down if (is_last_packet && cur_packet_len < DA_SEND_PACKET_LEN) { // DA Must received whole DA_SEND_PACKET_LEN, so Fill 0xFF to packet_buf uint32_t fill_num = DA_SEND_PACKET_LEN - cur_packet_len; + if(packet_buf!=NULL) memset(packet_buf + cur_packet_len, 0xFF, fill_num); } packet_buf = g_hdl_data_buf; packet_checksum = hdl_compute_simple_checksum(packet_buf, DA_SEND_PACKET_LEN); image_checksum += packet_checksum; - bool wirte_packet_success = hdl_wirte_packet(packet_buf, DA_SEND_PACKET_LEN, packet_checksum); HDL_Require_Noerr_Action(wirte_packet_success, exit, "hdl_wirte_packet"); // Download Progress callback if (download_cb != NULL) { + HDL_LOGE("DA Download Imgaes done %d",__LINE__ ); download_cb(download_cb_arg, image->image_name, start_offset + cur_packet_len, image_len); } @@ -398,10 +337,8 @@ bool hdl_da_download(hdl_image_t *image, hdl_download_cb download_cb, void *down image->fd , cur_packet_len); continue; } - packet_sent_num++; } - // Read ACK & Image CheckSum da_check_success = hdl_da_check_cmd_arg(&error_status); HDL_Require_Noerr_Action(da_check_success, exit, "DA Write Image Packets"); @@ -415,12 +352,12 @@ bool hdl_da_download(hdl_image_t *image, hdl_download_cb download_cb, void *down return FALSE; } -#ifndef PSRAM_DOWNLOAD + // For Bootloader(ACC) HDL_COM_PutByte((image->image_is_bootloader ? DA_ACK : DA_NACK)); da_check_success = hdl_da_check_cmd_arg(&error_status); HDL_Require_Noerr_Action(da_check_success, exit, "DA Download End"); -#endif + if (packet_sent_num == packet_num && error_status == 0) { success = TRUE; } @@ -432,74 +369,6 @@ exit: } #ifndef PSRAM_DOWNLOAD -bool hdl_da_readback(const hdl_readback_arg_t *readback_arg) -{ - bool success = FALSE; - uint32_t error_status = 0; - const uint32_t readback_flash_addr = readback_arg->readback_flash_addr; - const uint32_t readback_total_len = readback_arg->readback_total_len; - HDL_COM_PutByte(DA_READ_CMD); - HDL_COM_PutData32(readback_flash_addr); - HDL_COM_PutData32(readback_total_len); - HDL_COM_PutData32(DA_RECV_PACKET_LEN); - - // DA Check Readback Arg - bool da_check_success = hdl_da_check_cmd_arg(&error_status); - HDL_Require_Noerr_Action(da_check_success, exit, "DA Readback CMD, Check Range"); - - // Readback init callback - if (readback_arg->readback_init_cb != NULL) { - readback_arg->readback_init_cb(readback_arg->readback_init_cb_arg); - } - - // Readback Packet(4K) & Callback - const uint32_t packet_num = ((readback_total_len - 1) / DA_RECV_PACKET_LEN) + 1; - uint32_t packet_read_num = 0; - uint32_t read_total_bytes = 0; - while (packet_read_num < packet_num) { - const bool is_last_packet = (packet_read_num == (packet_num - 1)); - const uint32_t start_offset = packet_read_num * DA_RECV_PACKET_LEN; - const uint32_t cur_packet_len = is_last_packet ? (readback_total_len - start_offset) : DA_RECV_PACKET_LEN; - HDL_LOGI("hdl_da_readback packet %d/%d %d", packet_read_num + 1, packet_num, cur_packet_len); - - uint32_t packet_read_bytes = 0; - uint8_t *packet_read_buf = g_hdl_data_buf; - while (packet_read_bytes < cur_packet_len) { - // Even if last_packet, should also read DA_RECV_PACKET_LEN - packet_read_bytes += HDL_COM_GetByte_Buffer(packet_read_buf + packet_read_bytes, - DA_RECV_PACKET_LEN - packet_read_bytes); - } - read_total_bytes += cur_packet_len; - #if defined (HDL_VIA_I2C) - // ToDo Note: Wait DA to compute checksum - // hdl_delay(50); - #endif - uint32_t packet_checksum_from_local = hdl_compute_simple_checksum(packet_read_buf, cur_packet_len); - uint32_t packet_checksum_from_device = HDL_COM_GetData32(); - HDL_Require_Noerr_Action(packet_checksum_from_device == packet_checksum_from_local, exit, - "hdl_readback packet checksum"); - // Readback Callback - if (readback_arg->readback_cb != NULL) { - readback_arg->readback_cb(readback_arg->readback_cb_arg, readback_flash_addr + start_offset, - packet_read_buf, cur_packet_len, - read_total_bytes, readback_total_len); - } - - // Next - HDL_COM_PutByte(DA_ACK); - - packet_read_num++; - } - if (read_total_bytes == readback_total_len) { - success = TRUE; - } - -exit: - if (error_status != 0) { - HDL_LOGE("hdl_da_readback error_status=%d", error_status); - } - return success; -} bool hdl_da_enable_wdt(uint16_t wdt_sec) { diff --git a/app/src/main/jni/libag3335m/src/hdl_demo.c b/app/src/main/jni/libag3335m/src/hdl_demo.c index f5d1083..bd693ca 100644 --- a/app/src/main/jni/libag3335m/src/hdl_demo.c +++ b/app/src/main/jni/libag3335m/src/hdl_demo.c @@ -69,6 +69,7 @@ void hdl_host_dl_demo() da_info.image_file_path = HDL_DA_FILE_PATH; da_info.image_slave_flash_addr = HDL_DA_RUN_ADDR; da_info.image_len = HDL_DA_SIZE; + da_info.fd=-1; hdl_connect_arg_t connect_arg; connect_arg.conn_da_init_cb = init_cb_demo; connect_arg.conn_da_init_cb_arg = "Download DA now..."; @@ -102,24 +103,28 @@ void hdl_host_dl_demo() partition_image.image_is_bootloader = false; partition_image.image_slave_flash_addr = HDL_PARTITION_IMAGE_SLAVE_FLASH_POS; partition_image.image_name = HDL_PARTITION_IMAGE_NAME; + partition_image.fd=-1; partition_image.next = &bl_image; bl_image.image_file_path = HDL_BL_IMAGE_HOST_IMAGE_NAME; bl_image.image_slave_flash_addr = HDL_BL_IMAGE_SLAVE_FLASH_POS; bl_image.image_len = HDL_BL_IMAGE_SIZE; bl_image.image_name = HDL_BL_IMAGE_NAME; bl_image.image_is_bootloader = TRUE; + bl_image.fd=-1; bl_image.next = &cm4_image; cm4_image.image_file_path = HDL_CM4_IMAGE_HOST_IMAGE_NAME; cm4_image.image_slave_flash_addr = HDL_CM4_IMAGE_SLAVE_FLASH_POS; cm4_image.image_len = HDL_CM4_IMAGE_SIZE; cm4_image.image_name = HDL_CM4_IMAGE_NAME; cm4_image.image_is_bootloader = FALSE; + cm4_image.fd=-1; cm4_image.next = &config_image; config_image.image_file_path = HDL_OTHER_IMAGE_HOST_IMAGE_NAME; config_image.image_slave_flash_addr = HDL_OTHER_IMAGE_SLAVE_FLASH_POS; config_image.image_len = HDL_OTHER_IMAGE_SIZE; config_image.image_name = HDL_OTHER_IMAGE_NAME; config_image.image_is_bootloader = FALSE; + config_image.fd=-1; config_image.next = NULL; hdl_download_arg_t download_arg; diff --git a/app/src/main/jni/libag3335m/src/hdl_ports/hdl_flash_api.c b/app/src/main/jni/libag3335m/src/hdl_ports/hdl_flash_api.c index dff3bd7..33b9f0a 100644 --- a/app/src/main/jni/libag3335m/src/hdl_ports/hdl_flash_api.c +++ b/app/src/main/jni/libag3335m/src/hdl_ports/hdl_flash_api.c @@ -51,16 +51,18 @@ bool hdl_flash_read(hdl_image_t *hdlimg, uint8_t *buffer, uint32_t length) if( hdlimg->fd ==-1){ char path[1024]={0}; sprintf(path,"%s/%s",ROMPATH,hdlimg->image_file_path); - hdlimg->fd=open(hdlimg->image_file_path,O_RDWR); + hdlimg->fd=open(path,O_RDWR); + HDL_LOGD("open %s fd = %d ",path,hdlimg->fd); } if(hdlimg->fd >0){ int ret=read(hdlimg->fd,buffer,length); if(ret==length){ + HDL_LOGE(" hdl_flash_read %s read %d ", hdlimg->image_file_path,ret); return true; }else{ HDL_LOGE(" read failed! read %d != %d", ret,length); - close(hdlimg->fd); - hdlimg->fd=-1; + // close(hdlimg->fd); + // hdlimg->fd=-1; return false; } }else{ diff --git a/app/src/main/jni/libag3335m/src/hdl_ports/hdl_uart.c b/app/src/main/jni/libag3335m/src/hdl_ports/hdl_uart.c index aa644bf..78f9f81 100644 --- a/app/src/main/jni/libag3335m/src/hdl_ports/hdl_uart.c +++ b/app/src/main/jni/libag3335m/src/hdl_ports/hdl_uart.c @@ -54,6 +54,10 @@ static void set_fdattr(int fd , int baud ) // termios.c_cflag &= ~(CSIZE | PARENB |CRTSCTS);//CRTSCTS termios.c_cflag |= (CS8 |CRTSCTS );//CRTSCTS //termios.c_cflag |= (CS8 );//CRTSCTS + + termios.c_cc[VMIN] = 1;//DATA_LEN; + termios.c_cc[VTIME] = 3;//每个单位是0.1秒 20就是2秒 + /* set input/output baudrate */ cfsetospeed(&termios, baud); cfsetispeed(&termios, baud); @@ -180,14 +184,14 @@ uint8_t hdl_uart_get_byte() { uint8_t data = 0; int ret=read(gps_fd,&data,1); - HDL_LOGI("hdl_uart_get_byte 0x%02X ret=%d", data,ret); + // HDL_LOGI("hdl_uart_get_byte 0x%02X ret=%d", data,ret); return data; } bool hdl_uart_get_byte_status(uint8_t *data) { int ret=read(gps_fd,data,1); - HDL_LOGI("hdl_uart_get_byte 0x%02X ret=%d", *data,ret); + HDL_LOGI("hdl_uart_get_byte_status 0x%02X ret=%d", *data,ret); return TRUE; } @@ -202,12 +206,16 @@ uint32_t hdl_uart_get_byte_buffer(uint8_t *buf, uint32_t length) void hdl_uart_put_byte(uint8_t data) { write(gps_fd,&data,1); - HDL_LOGI("hdl_uart_put_byte 0x%02X", data); + // HDL_LOGI("hdl_uart_put_byte 0x%02X", data); } uint32_t hdl_uart_put_byte_buffer(uint8_t *buf, uint32_t length) { - write(gps_fd,buf,length); + // uint32_t sent_len = hal_uart_send_polling(g_hdl_uart_port, buf, length); + for (int i = 0; i < length; i++) { + hdl_uart_put_byte( *buf++); +// hal_gpt_delay_us(100); + } HDL_LOGI("hdl_uart_put_byte_buffer length=%d", length); return length; } @@ -221,29 +229,45 @@ void hdl_uart_put_byte_complete(uint8_t data) uint16_t hdl_uart_get_data16() { uint16_t result = 0; - int ret=read(gps_fd,(char*)result,2); - HDL_LOGI("hdl_uart_get_data16 0x%04X", result); + uint8_t tmp1 = (uint8_t)hdl_uart_get_byte(); + uint8_t tmp2 = (uint8_t)hdl_uart_get_byte(); + result = (tmp1 << 8) | tmp2; + HDL_LOGI("hdl_uart_get_data16 0x%02X 0x%02X -> 0x%04X", tmp1, tmp2, result); return result; } void hdl_uart_put_data16(uint16_t data) { - write(gps_fd,(char*)data,2); - HDL_LOGI("hdl_uart_put_data16 0x%04X ", data); + uint8_t tmp1 = (uint8_t)(data >> 8); + uint8_t tmp2 = (uint8_t)(data & 0x00FF); + hdl_uart_put_byte( tmp1); + hdl_uart_put_byte( tmp2); + HDL_LOGI("hdl_uart_put_data16 0x%04X -> 0x%02X 0x%02X", data, tmp1, tmp2); } uint32_t hdl_uart_get_data32() { + uint8_t tmp = 0; uint32_t result = 0; - int ret=read(gps_fd,(char*)result,4); + for (int i = 0; i < 4; i++) { + tmp = (uint8_t)hdl_uart_get_byte(); + result |= (tmp << (24 - 8 * i)); + } HDL_LOGI("hdl_uart_get_data32 0x%08X", result); return result; + } void hdl_uart_put_data32(uint32_t data) { - write(gps_fd,(char*)data,4); + + uint32_t tmp32 = 0; + for (int i = 0; i < 4; i++) { + tmp32 = (data >> (24 - 8 * i)); + hdl_uart_put_byte( (char)tmp32); + } HDL_LOGI("hdl_uart_put_data32 0x%08X", data); + } void hdl_uart_purge_fifo() @@ -261,8 +285,8 @@ void hdl_uart_purge_fifo() void hdl_uart_set_baudrate(hal_uart_baudrate_t baud_rate) { // hal_uart_status_t status = hal_uart_set_baudrate(g_hdl_uart_port, baud_rate); - set_fdattr(gps_fd,baud_rate); - HDL_LOGI("hdl_uart_set_baudrate baud_rate=%d", baud_rate); + set_fdattr(gps_fd,B921600); + HDL_LOGI("hdl_uart_set_baudrate baud_rate=%d", B921600); } #endif diff --git a/app/src/main/libs/armeabi-v7a/libag3335m_dl.so b/app/src/main/libs/armeabi-v7a/libag3335m_dl.so index 34a17c9..0a97529 100644 Binary files a/app/src/main/libs/armeabi-v7a/libag3335m_dl.so and b/app/src/main/libs/armeabi-v7a/libag3335m_dl.so differ diff --git a/app/src/main/libs/armeabi-v7a/libag3335m_jni.so b/app/src/main/libs/armeabi-v7a/libag3335m_jni.so index 34fa820..6047b80 100644 Binary files a/app/src/main/libs/armeabi-v7a/libag3335m_jni.so and b/app/src/main/libs/armeabi-v7a/libag3335m_jni.so differ