139 v.
major =
static_cast<uint16_t
>(value >> 16);
140 v.
minor =
static_cast<uint16_t
>(value & 0xFFFF);
162 f.
rom = (value & (1u << 1)) != 0;
163 f.
otp = (value & (1u << 2)) != 0;
184 g.
dirty = (value & (1u << 28)) != 0;
204 v.
major =
static_cast<uint8_t
>((value >> 8) & 0xFF);
205 v.
minor =
static_cast<uint8_t
>(value & 0xFF);
224 result.
errorCount =
static_cast<uint8_t
>((value >> 8) & 0xFF);
225 result.
pageTag =
static_cast<uint8_t
>(value & 0xFF);
292 result.
errorDescription =
"Restoring original clock setup after OTP operation failed";
317 void toBuffer(std::array<uint8_t, 5>& out)
const noexcept {
319 out[1] =
static_cast<uint8_t
>(
value >> 24);
320 out[2] =
static_cast<uint8_t
>(
value >> 16);
321 out[3] =
static_cast<uint8_t
>(
value >> 8);
322 out[4] =
static_cast<uint8_t
>(
value);
341 void toBuffer(std::array<uint8_t, 8>& out)
const noexcept {
345 out[3] =
static_cast<uint8_t
>(
value >> 24);
346 out[4] =
static_cast<uint8_t
>(
value >> 16);
347 out[5] =
static_cast<uint8_t
>(
value >> 8);
348 out[6] =
static_cast<uint8_t
>(
value);
370 r.
value = (
static_cast<uint32_t
>(in[1]) << 24) | (
static_cast<uint32_t
>(in[2]) << 16) |
371 (
static_cast<uint32_t
>(in[3]) << 8) |
static_cast<uint32_t
>(in[4]);
411 r.
value = (
static_cast<uint32_t
>(in[3]) << 24) |
412 (
static_cast<uint32_t
>(in[4]) << 16) | (
static_cast<uint32_t
>(in[5]) << 8) |
413 static_cast<uint32_t
>(in[6]);
419 bool verifyCRC(
const std::array<uint8_t, 8>& in)
const noexcept {
421 return calculatedCRC == in[7];
TMC9660 bootloader utility functions and helpers.
Definition bootloader_config.hpp:9
OtpBurnError
OTP burn operation error codes.
Definition bootloader_protocol.hpp:239
@ CHARGE_PUMP_FAILED
Setting up internal OTP charge pump failed.
@ BURN_PROCEDURE_FAILED
The burn procedure failed.
@ CLOCK_RESTORE_FAILED
Restoring original clock setup after OTP operation failed.
@ INVALID_PAGE
The OTP page number is invalid.
@ CLOCK_SETUP_FAILED
Internal clock setup for OTP operation failed.
@ NO_MORE_BURNS
Last OTP page burnt, no more burns possible.
static constexpr uint8_t crc8Bootloader(const uint8_t *data, size_t len) noexcept
CRC-8 calculation for UART protocol (TMC9660 datasheet method).
Definition bootloader_utils.hpp:54
MemoryBank
Memory bank identifiers for bootloader operations.
Definition bootloader_protocol.hpp:86
@ SPI_FLASH
External SPI Flash.
@ CONFIG
Configuration memory (runtime reconfiguration)
@ I2C_EEPROM
External I2C EEPROM.
BootloaderCommand
Bootloader command codes for memory and configuration operations.
Definition bootloader_protocol.hpp:49
@ READ_32_INC
Read 32-bit data and increment address.
@ BOOTSTRAP_RS485
Set up RS485 settings.
@ NO_OP
No operation (for retrieving previous reply in SPI)
@ WRITE_8
Write 8-bit data to selected memory bank/address.
@ OTP_BURN
Burn an OTP page.
@ READ_16
Read 16-bit data from selected memory bank/address.
@ GET_ADDRESS
Get the current memory address.
@ READ_16_INC
Read 16-bit data and increment address.
@ MEM_IS_BUSY
Check whether an external memory is busy.
@ WRITE_16_INC
Write 16-bit data and increment address.
@ SET_ADDRESS
Set the memory address.
@ MEM_IS_CONNECTED
Check whether an external memory is connected.
@ FLASH_SEND_CMD
Send arbitrary commands to an external flash.
@ READ_32
Read 32-bit data from selected memory bank/address.
@ MEM_IS_CONFIGURED
Check whether an external memory bank is configured.
@ GET_BANK
Get the currently selected memory bank.
@ WRITE_32
Write 32-bit data to selected memory bank/address.
@ FLASH_ERASE_SECTOR
Send a sector erase command to an external flash.
@ WRITE_16
Write 16-bit data to selected memory bank/address.
@ OTP_LOAD
Read a programmed OTP page.
@ WRITE_32_INC
Write 32-bit data and increment address.
@ GET_INFO
Get various basic information about the connected TMC9660.
@ SET_BANK
Set the memory bank.
@ WRITE_8_INC
Write 8-bit data and increment address.
@ READ_8
Read 8-bit data from selected memory bank/address.
@ READ_8_INC
Read 8-bit data and increment address.
BootloaderStatus
Bootloader status codes returned by command replies.
Definition bootloader_protocol.hpp:24
@ BOOTLOADER_RESUMED
First SPI datagram after returning to bootloader from motor control (SPI only)
@ SESSION_START
First SPI datagram after power-on (SPI only)
@ MEM_UNCONFIGURED
The external memory is not configured.
@ INVALID_BANK
The memory bank is not valid for the requested command.
@ INVALID_ADDR
The memory address is not valid for the requested command.
@ CMD_NOT_FOUND
The request has an invalid command number.
@ BUSY
Bootloader has not yet finished processing the last command (SPI only)
@ INVALID_VALUE
The request has an invalid value.
@ CMD_NOT_AVAILABLE
The command is currently not available.
@ OTP_ERROR
The OTP command has failed.
@ OK
Command executed successfully.
InfoQuery
GET_INFO query types for retrieving system information.
Definition bootloader_protocol.hpp:105
@ CHIP_TYPE
Get the Chip type (returns 0x544D0001)
@ CONFIG_MEM_SIZE
Get size of CONFIG memory.
@ CONFIG_MEM_START
Get starting address of CONFIG memory.
@ SPI_MEM_SIZE
Get memory size of connected SPI memory.
@ OTP_MEM_SIZE
Get size of one OTP memory page.
@ PARTITION_VERSION
Get version of external memory partition format.
@ GIT_INFO
Get Git version control information.
@ SPI_MEM_PARTITIONS
Get number of SPI memory partitions.
@ BL_VERSION
Get bootloader version (major in upper 16 bits, minor in lower 16 bits)
@ FEATURES
Get available feature groups (bit flags)
@ CHIP_VARIANT
Get chip variant (TMC9660 reports value 2)
@ I2C_MEM_SIZE
Get memory size of connected I2C memory.
@ I2C_MEM_PARTITIONS
Get number of I2C memory partitions.
@ CHIP_FREQUENCY
Get system frequency in MHz.
@ CHIP_VERSION
Get silicon revision (TMC9660 reports revision 1)
Bootloader command structure for SPI (40-bit / 5-byte protocol).
Definition bootloader_protocol.hpp:312
void toBuffer(std::array< uint8_t, 5 > &out) const noexcept
Serialize to 5-byte buffer for SPI transmission.
Definition bootloader_protocol.hpp:317
uint8_t command
Command byte.
Definition bootloader_protocol.hpp:313
uint32_t value
32-bit data value
Definition bootloader_protocol.hpp:314
Bootloader command structure for UART (64-bit / 8-byte protocol).
Definition bootloader_protocol.hpp:335
void toBuffer(std::array< uint8_t, 8 > &out) const noexcept
Serialize to 8-byte buffer for UART transmission.
Definition bootloader_protocol.hpp:341
uint8_t command
Command byte.
Definition bootloader_protocol.hpp:337
uint8_t deviceAddr
Device address.
Definition bootloader_protocol.hpp:336
uint32_t value
32-bit data value
Definition bootloader_protocol.hpp:338
Feature flags indicating available bootloader capabilities.
Definition bootloader_protocol.hpp:151
static BootloaderFeatures fromValue(uint32_t value) noexcept
Parse from 32-bit value.
Definition bootloader_protocol.hpp:159
bool rom
Bit 1: ROM.
Definition bootloader_protocol.hpp:153
bool sram_support
Bit 0: SRAM support.
Definition bootloader_protocol.hpp:152
bool otp
Bit 2: OTP.
Definition bootloader_protocol.hpp:154
bool spi_flash
Bit 3: SPI flash external memory.
Definition bootloader_protocol.hpp:155
bool i2c_eeprom
Bit 4: I2C EEPROM external memory.
Definition bootloader_protocol.hpp:156
Bootloader reply structure for SPI (40-bit / 5-byte protocol).
Definition bootloader_protocol.hpp:362
bool isOK() const noexcept
Check if reply indicates success.
Definition bootloader_protocol.hpp:376
static BootloaderReplySPI fromBuffer(const std::array< uint8_t, 5 > &in) noexcept
Deserialize from 5-byte SPI buffer.
Definition bootloader_protocol.hpp:367
BootloaderStatus getStatus() const noexcept
Get status as enum.
Definition bootloader_protocol.hpp:383
uint8_t status
Status byte.
Definition bootloader_protocol.hpp:363
uint32_t value
32-bit data value
Definition bootloader_protocol.hpp:364
Bootloader reply structure for UART (64-bit / 8-byte protocol).
Definition bootloader_protocol.hpp:397
uint8_t hostAddr
Host address.
Definition bootloader_protocol.hpp:398
static BootloaderReplyUART fromBuffer(const std::array< uint8_t, 8 > &in) noexcept
Deserialize from 8-byte UART buffer.
Definition bootloader_protocol.hpp:404
uint32_t value
32-bit data value
Definition bootloader_protocol.hpp:401
bool verifyCRC(const std::array< uint8_t, 8 > &in) const noexcept
Verify CRC8 checksum.
Definition bootloader_protocol.hpp:419
BootloaderStatus getStatus() const noexcept
Get status as enum.
Definition bootloader_protocol.hpp:430
uint8_t deviceAddr
Device address.
Definition bootloader_protocol.hpp:399
bool isOK() const noexcept
Check if reply indicates success.
Definition bootloader_protocol.hpp:425
uint8_t status
Status byte.
Definition bootloader_protocol.hpp:400
Bootloader version information structure.
Definition bootloader_protocol.hpp:132
uint16_t major
Major version number.
Definition bootloader_protocol.hpp:133
uint16_t minor
Minor version number.
Definition bootloader_protocol.hpp:134
static BootloaderVersion fromValue(uint32_t value) noexcept
Parse from 32-bit value (major in upper 16 bits, minor in lower 16 bits)
Definition bootloader_protocol.hpp:137
Git version control information from bootloader firmware.
Definition bootloader_protocol.hpp:177
uint32_t commit_hash
Bits 27-0: 7-digit hex commit hash.
Definition bootloader_protocol.hpp:179
static GitInfo fromValue(uint32_t value) noexcept
Parse from 32-bit value.
Definition bootloader_protocol.hpp:182
bool dirty
Bit 28: Dirty bit - uncommitted changes.
Definition bootloader_protocol.hpp:178
OTP burn operation result information.
Definition bootloader_protocol.hpp:255
static OtpBurnResult createSuccess() noexcept
Create success result.
Definition bootloader_protocol.hpp:261
const char * errorDescription
Human-readable error description.
Definition bootloader_protocol.hpp:258
bool isSuccess
Whether the burn operation succeeded.
Definition bootloader_protocol.hpp:256
OtpBurnError errorCode
Error code if operation failed.
Definition bootloader_protocol.hpp:257
static OtpBurnResult createError(OtpBurnError code) noexcept
Create error result.
Definition bootloader_protocol.hpp:270
OTP load operation result information.
Definition bootloader_protocol.hpp:217
uint8_t pageTag
OTP page tag (bits 7-0)
Definition bootloader_protocol.hpp:219
uint8_t errorCount
OTP bit error count (bits 15-8)
Definition bootloader_protocol.hpp:218
static OtpLoadResult fromValue(uint32_t value) noexcept
Parse from 32-bit value.
Definition bootloader_protocol.hpp:222
External memory partition version information.
Definition bootloader_protocol.hpp:197
uint8_t minor
Bits 7-0: Minor version.
Definition bootloader_protocol.hpp:199
uint8_t major
Bits 15-8: Major version.
Definition bootloader_protocol.hpp:198
static PartitionVersion fromValue(uint32_t value) noexcept
Parse from 32-bit value.
Definition bootloader_protocol.hpp:202