Merge remote-tracking branch 'upstream/feature/bl808'

This commit is contained in:
Pavel Zakopaylo 2023-11-28 19:53:07 +11:00
commit d278063472
No known key found for this signature in database
GPG Key ID: 9D4130BD5891F5CB
5 changed files with 50 additions and 20 deletions

View File

@ -9,9 +9,10 @@ option(BLISP_USE_SYSTEM_LIBRARIES "Use system-installed libraries" "${CMAKE_USE_
option(COMPILE_TESTS "Compile the tests" OFF) option(COMPILE_TESTS "Compile the tests" OFF)
add_library(libblisp_obj OBJECT add_library(libblisp_obj OBJECT
lib/blisp.c lib/blisp.c lib/blisp_easy.c
lib/chip/blisp_chip_bl60x.c lib/chip/blisp_chip_bl60x.c
lib/chip/blisp_chip_bl70x.c lib/blisp_easy.c) lib/chip/blisp_chip_bl70x.c
lib/chip/blisp_chip_bl808.c)
target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/include/) target_include_directories(libblisp_obj PRIVATE ${CMAKE_SOURCE_DIR}/include/)

View File

@ -216,11 +216,38 @@ blisp_return_t blisp_device_handshake(struct blisp_device* device,
sp_flush(serial_port, SP_BUF_INPUT); // Flush garbage out of RX sp_flush(serial_port, SP_BUF_INPUT); // Flush garbage out of RX
} }
ret = sp_blocking_read(serial_port, device->rx_buffer, 2, 50); uint32_t bytes_count = device->chip->handshake_byte_multiplier * (float)device->current_baud_rate / 10.0f;
if (ret >= 2) { if (bytes_count > 600) bytes_count = 600;
if (device->rx_buffer[0] == 'O' && device->rx_buffer[1] == 'K') { memset(handshake_buffer, 'U', bytes_count);
return BLISP_OK;
} // sp_flush(serial_port, SP_BUF_BOTH);
for (uint8_t i = 0; i < 5; i++) {
if (!in_ef_loader) {
if (device->is_usb) {
sp_blocking_write(serial_port, "BOUFFALOLAB5555RESET\0\0", 22,
100); // TODO: Error handling
}
}
ret = sp_blocking_write(serial_port, handshake_buffer, bytes_count,
500);
if (ret < 0) {
return -1;
}
if (device->chip->type == BLISP_CHIP_BL808) {
sleep_ms(300);
const uint8_t second_handshake[] = { 0x50, 0x00, 0x08, 0x00, 0x38, 0xF0, 0x00, 0x20, 0x00, 0x00, 0x00, 0x18 };
sp_blocking_write(serial_port, second_handshake, sizeof(second_handshake), 300); // TODO: Error handling
}
ret = sp_blocking_read(serial_port, device->rx_buffer, 20, 50);
if (ret >= 2) {
for (uint8_t j = 0; j < (ret - 1); j++) {
if (device->rx_buffer[j] == 'O' && device->rx_buffer[j + 1] == 'K') {
return BLISP_OK;
}
}
}
} }
} }
blisp_dlog("Received no response from chip."); blisp_dlog("Received no response from chip.");
@ -239,14 +266,13 @@ blisp_return_t blisp_device_get_boot_info(struct blisp_device* device,
if (ret < 0) if (ret < 0)
return ret; return ret;
memcpy(boot_info->boot_rom_version, &device->rx_buffer[0], memcpy(boot_info->boot_rom_version, &device->rx_buffer[0],
4); // TODO: Endianess; this may break on big endian machines 4); // TODO: Endianess; this may break on big endian machines
if (device->chip->type == BLISP_CHIP_BL70X || device->chip->type == BLISP_CHIP_BL808) { // TODO: This is only 70X related
if (device->chip->type == BLISP_CHIP_BL70X) { memcpy(boot_info->chip_id, &device->rx_buffer[16], 8);
memcpy(boot_info->chip_id, &device->rx_buffer[16], 8); }
} // TODO: BL60X, BL808
// TODO: BL60X return BLISP_OK;
return BLISP_OK;
} }
// TODO: Use struct instead of uint8_t* // TODO: Use struct instead of uint8_t*

View File

@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include "blisp.h" #include "blisp.h"
#include <stddef.h>
struct blisp_chip blisp_chip_bl808 = { struct blisp_chip blisp_chip_bl808 = {
.type = BLISP_CHIP_BL808, .type = BLISP_CHIP_BL808,
.type_str = "bl808", .type_str = "bl808",
.usb_isp_available = true, // TODO: Only for BL808D :-( .usb_isp_available = true, // TODO: Only for BL808D :-(
.default_xtal = "-", // ? .default_xtal = "-", // XXX: bfl software marks this as "Auto (0x07)"
.handshake_byte_multiplier = 0.003f, .handshake_byte_multiplier = 0.006f,
.get_eflash_loader = NULL .load_eflash_loader = NULL
}; };

View File

@ -31,6 +31,8 @@ blisp_return_t blisp_common_init_device(struct blisp_device* device,
chip = &blisp_chip_bl70x; chip = &blisp_chip_bl70x;
} else if (strcmp(chip_type->sval[0], "bl60x") == 0) { } else if (strcmp(chip_type->sval[0], "bl60x") == 0) {
chip = &blisp_chip_bl60x; chip = &blisp_chip_bl60x;
} else if (strcmp(chip_type->sval[0], "bl808") == 0) {
chip = &blisp_chip_bl808;
} else { } else {
fprintf(stderr, "Chip type is invalid.\n"); fprintf(stderr, "Chip type is invalid.\n");
return BLISP_ERR_INVALID_CHIP_TYPE; return BLISP_ERR_INVALID_CHIP_TYPE;