Compare commits

..

2 Commits

Author SHA1 Message Date
Thomas Klaehn
637ff7ea68 Bootloader: add bootloader version read out 2021-11-18 10:32:07 +01:00
Thomas Klaehn
b55a05e7a0 wip 2021-11-18 10:07:09 +01:00
4 changed files with 43 additions and 1 deletions

7
.vscode/launch.json vendored
View File

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

View File

@ -7,8 +7,10 @@ Bootloader::Bootloader(Uart &uart) : uart(uart)
{ {
syn(); syn();
get(); get();
get_version();
get_chip_id(); get_chip_id();
get_flash_memory_size(); get_flash_memory_size();
get_bl_version();
} }
void Bootloader::syn() void Bootloader::syn()
@ -46,6 +48,21 @@ 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;
chip.option_byte_1 = buffer[2];
chip.option_byte_2 = buffer[3];
}
}
void Bootloader::get_chip_id() void Bootloader::get_chip_id()
{ {
unsigned char buffer[0xff]; unsigned char buffer[0xff];
@ -62,6 +79,14 @@ void Bootloader::get_chip_id()
} }
} }
void Bootloader::get_bl_version()
{
unsigned char buffer[1];
read_memory(BL_VERSION_REGISTER_ADDRESS, buffer, sizeof(buffer));
chip.bootloader_version_major = (buffer[0] & 0xf0) >> 4;
chip.bootloader_version_minor = buffer[0] & 0x0f;
}
void Bootloader::get_flash_memory_size() void Bootloader::get_flash_memory_size()
{ {
unsigned char buffer[2]; unsigned char buffer[2];

View File

@ -25,8 +25,12 @@ public:
struct ChipData struct ChipData
{ {
uint16_t id; uint16_t id;
uint8_t bootloader_version_major;
uint8_t bootloader_version_minor;
uint8_t protocol_version_major; uint8_t protocol_version_major;
uint8_t protocol_version_minor; uint8_t protocol_version_minor;
uint8_t option_byte_1;
uint8_t option_byte_2;
uint32_t flash_size; uint32_t flash_size;
}; };
@ -48,14 +52,17 @@ public:
private: private:
void syn(); void syn();
void get(); void get();
void get_version();
void get_chip_id(); void get_chip_id();
void get_flash_memory_size(); void get_flash_memory_size();
void get_bl_version();
void send_command(uint8_t command); void send_command(uint8_t command);
void send_address(uint32_t address); void send_address(uint32_t address);
bool wait_for_ack(); bool wait_for_ack();
const uint32_t FLASH_MEMORY_SIZE_DATA_REGISTER_ADDRESS = 0x1fff75e0; 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 uint16_t SUPPORTED_DEVICE_ID = 0x466;
const uint8_t ACK = 0x79; const uint8_t ACK = 0x79;
const uint8_t NAK = 0x1f; const uint8_t NAK = 0x1f;
@ -76,8 +83,12 @@ private:
ChipData chip = { ChipData chip = {
.id = 0, .id = 0,
.bootloader_version_major = 0,
.bootloader_version_minor = 0,
.protocol_version_major = 0, .protocol_version_major = 0,
.protocol_version_minor = 0, .protocol_version_minor = 0,
.option_byte_1 = 0,
.option_byte_2 = 0,
.flash_size = 0, .flash_size = 0,
}; };

View File

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