mirror of
https://github.com/pine64/blisp.git
synced 2024-12-22 14:30:28 +00:00
Implemented setting clock parameters for BL808
This commit is contained in:
parent
87174b7682
commit
f55975fe9b
16
data/bl808_clock_para.h
Normal file
16
data/bl808_clock_para.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef BLISP_BL808_CLOCK_PARA_H
|
||||
#define BLISP_BL808_CLOCK_PARA_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Extracted from the bflb-iot-tool PIP package:
|
||||
* original location: chips/bl808/efuse_bootheader/clock_para.bin
|
||||
* SHA256 SUM: 14e57dfae793a41cf8a61c31a2c93b73b09126d8315230ede29898634a8dad3c
|
||||
* Copyright Bouffalo Lab, License: MIT
|
||||
*/
|
||||
static uint8_t bl808_clock_para_bin[] = { 0x50, 0x43, 0x46, 0x47, 0x07, 0x04, 0x00, 0x00, 0x03, 0x01, 0x03, 0x00,
|
||||
0x01, 0x02, 0x00, 0x02, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
|
||||
0x0a, 0x89, 0x4b, 0x86 };
|
||||
|
||||
#endif // BLISP_BL808_CLOCK_PARA_H
|
34
lib/blisp.c
34
lib/blisp.c
@ -11,6 +11,8 @@
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#include "../data/bl808_clock_para.h"
|
||||
|
||||
#define DEBUG
|
||||
|
||||
static void drain(struct sp_port* port) {
|
||||
@ -177,6 +179,7 @@ blisp_return_t blisp_receive_response(struct blisp_device* device,
|
||||
blisp_return_t blisp_device_handshake(struct blisp_device* device,
|
||||
bool in_ef_loader) {
|
||||
int ret;
|
||||
bool ok = false;
|
||||
uint8_t handshake_buffer[600];
|
||||
struct sp_port* serial_port = device->serial_port;
|
||||
|
||||
@ -230,15 +233,19 @@ blisp_return_t blisp_device_handshake(struct blisp_device* device,
|
||||
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;
|
||||
}
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
blisp_dlog("Received no response from chip.");
|
||||
return BLISP_ERR_NO_RESPONSE;
|
||||
}
|
||||
|
||||
return BLISP_OK;
|
||||
}
|
||||
}
|
||||
|
||||
blisp_return_t blisp_device_get_boot_info(struct blisp_device* device,
|
||||
struct blisp_boot_info* boot_info) {
|
||||
blisp_return_t ret;
|
||||
@ -426,3 +433,26 @@ void blisp_device_close(struct blisp_device* device) {
|
||||
struct sp_port* serial_port = device->serial_port;
|
||||
sp_close(serial_port);
|
||||
}
|
||||
|
||||
blisp_return_t bl808_load_clock_para(struct blisp_device* device,
|
||||
bool irq_en, uint32_t baudrate) {
|
||||
// XXX: this may be a good place to increase the baudrate for subsequent comms
|
||||
// XXX: for the write command, we may wish to use this data to update the boot header
|
||||
const uint32_t clock_para_size = sizeof(bl808_clock_para_bin);
|
||||
const uint32_t payload_size = 8 + clock_para_size;
|
||||
uint8_t payload[payload_size] = {};
|
||||
|
||||
uint32_t irq_enable = irq_en ? 1 : 0;
|
||||
memcpy(&payload[0], &irq_enable, 4);
|
||||
memcpy(&payload[4], &baudrate, 4);
|
||||
memcpy(&payload[8], bl808_clock_para_bin, clock_para_size);
|
||||
|
||||
blisp_return_t ret = blisp_send_command(device, 0x22, payload, payload_size, true);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
ret = blisp_receive_response(device, false);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return BLISP_OK;
|
||||
}
|
||||
|
@ -86,6 +86,15 @@ blisp_return_t blisp_common_prepare_flash(struct blisp_device* device) {
|
||||
boot_info.chip_id[3], boot_info.chip_id[4], boot_info.chip_id[5],
|
||||
boot_info.chip_id[6], boot_info.chip_id[7]);
|
||||
|
||||
if (device->chip->type == BLISP_CHIP_BL808) {
|
||||
printf("Setting clock parameters ...\n");
|
||||
ret = bl808_load_clock_para(device, true, device->current_baud_rate);
|
||||
if (ret != BLISP_OK) {
|
||||
fprintf(stderr, "Failed to set clock parameters.\n");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (device->chip->load_eflash_loader == NULL) {
|
||||
return BLISP_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user