Compare commits
2 Commits
147ee2469e
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
637ff7ea68 | ||
|
b55a05e7a0 |
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@ -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": [],
|
||||||
|
@ -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];
|
||||||
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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())
|
||||||
|
Loading…
Reference in New Issue
Block a user