This commit is contained in:
Thomas Klaehn 2021-11-18 10:07:09 +01:00
parent 147ee2469e
commit b55a05e7a0
4 changed files with 36 additions and 1 deletions

7
.vscode/launch.json vendored
View File

@ -6,7 +6,12 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/bootloader",
"args": [],
"args": [
"-p",
"/dev/ttyACM1",
"-f",
"nucleo.bin"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],

View File

@ -7,8 +7,10 @@ Bootloader::Bootloader(Uart &uart) : uart(uart)
{
syn();
get();
get_version();
get_chip_id();
get_flash_memory_size();
get_bl_version();
}
void Bootloader::syn()
@ -46,6 +48,19 @@ void Bootloader::get()
}
}
void Bootloader::get_version()
{
unsigned char buffer[0xff];
send_command(commands.get_version_and_read_protection_status);
usleep(10000);
int rec = uart.receive(buffer, sizeof(buffer));
if ((rec == 5) && ((buffer[0] == ACK) && (buffer[4] == ACK)))
{
chip.bootloader_version_major = (buffer[1] & 0xf0) >> 4;
chip.bootloader_version_minor = buffer[1] & 0x0f;
}
}
void Bootloader::get_chip_id()
{
unsigned char buffer[0xff];
@ -62,6 +77,13 @@ void Bootloader::get_chip_id()
}
}
void Bootloader::get_bl_version()
{
unsigned char buffer[2];
read_memory(BL_VERSION_REGISTER_ADDRESS, buffer, sizeof(buffer));
chip.flash_size = ((buffer[1] << 8) + buffer[0]) * 1024;
}
void Bootloader::get_flash_memory_size()
{
unsigned char buffer[2];

View File

@ -25,6 +25,8 @@ public:
struct ChipData
{
uint16_t id;
uint8_t bootloader_version_major;
uint8_t bootloader_version_minor;
uint8_t protocol_version_major;
uint8_t protocol_version_minor;
uint32_t flash_size;
@ -48,14 +50,17 @@ public:
private:
void syn();
void get();
void get_version();
void get_chip_id();
void get_flash_memory_size();
void get_bl_version();
void send_command(uint8_t command);
void send_address(uint32_t address);
bool wait_for_ack();
const uint32_t FLASH_MEMORY_SIZE_DATA_REGISTER_ADDRESS = 0x1fff75e0;
const uint32_t BL_VERSION_REGISTER_ADDRESS = 0x1fff1ffe;
const uint16_t SUPPORTED_DEVICE_ID = 0x466;
const uint8_t ACK = 0x79;
const uint8_t NAK = 0x1f;
@ -76,6 +81,8 @@ private:
ChipData chip = {
.id = 0,
.bootloader_version_major = 0,
.bootloader_version_minor = 0,
.protocol_version_major = 0,
.protocol_version_minor = 0,
.flash_size = 0,

View File

@ -11,6 +11,7 @@
int main()
{
Uart uart("/dev/ttyACM1");
// Uart uart("/dev/ttyUSB0");
Bootloader bootloader(uart);
if (bootloader.chip_is_supported())