HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
tmc9660_bootloader.hpp
Go to the documentation of this file.
1
6#pragma once
10#include <cstdint>
11#include <type_traits>
12
13namespace tmc9660 {
14
52template <typename CommType>
54public:
55 explicit TMC9660Bootloader(CommType& comm) noexcept;
56
57 //==================================================
58 // BASIC MEMORY OPERATIONS
59 //==================================================
60
72 bool setBank(uint8_t bank) noexcept;
73
83 bool setBank(MemoryBank bank) noexcept {
84 return setBank(static_cast<uint8_t>(bank));
85 }
86
96 bool setAddress(uint32_t addr) noexcept;
97
107 bool write8(uint8_t v) noexcept;
108
118 bool write16(uint16_t v) noexcept;
119
129 bool write32(uint32_t v) noexcept;
130
140 bool write8Inc(uint8_t v) noexcept;
141
151 bool write16Inc(uint16_t v) noexcept;
152
162 bool write32Inc(uint32_t v) noexcept;
163
174 bool write32IncMultiple(const uint32_t* values, size_t count) noexcept;
175
176 //==================================================
177 // READ OPERATIONS
178 //==================================================
179
189 bool read8(uint8_t* value) noexcept;
190
200 bool read16(uint16_t* value) noexcept;
201
211 bool read32(uint32_t* value) noexcept;
212
222 bool read8Inc(uint8_t* value) noexcept;
223
233 bool read16Inc(uint16_t* value) noexcept;
234
244 bool read32Inc(uint32_t* value) noexcept;
245
255 bool getBank(uint8_t* bank) noexcept;
256
266 bool getAddress(uint32_t* address) noexcept;
267
279 bool noOp(uint32_t* reply = nullptr) noexcept;
280
281 //==================================================
282 // VERIFICATION OPERATIONS
283 //==================================================
284
296 bool readAndVerify8(uint8_t expected, const char* config_name) noexcept;
297
309 bool readAndVerify16(uint16_t expected, const char* config_name) noexcept;
310
322 bool readAndVerify32(uint32_t expected, const char* config_name) noexcept;
323
324 //==================================================
325 // OTP OPERATIONS
326 //==================================================
327
339 bool otpLoad(uint8_t page, OtpLoadResult* result) noexcept;
340
352 bool otpLoad(uint8_t page, uint8_t* error_count = nullptr, uint8_t* page_tag = nullptr) noexcept;
353
367 bool otpBurn(uint8_t page, uint8_t page_addr, OtpBurnResult* result) noexcept;
368
380 bool otpBurn(uint8_t page, uint8_t page_addr = 0) noexcept;
381
397 bool otpBurnWithWorkaround(uint8_t page, uint8_t page_addr, OtpBurnResult* result,
398 uint32_t vdrv_wait_ms = 1000) noexcept;
399
410 bool checkOtpBurnStatus(bool* result) noexcept;
411
412 //==================================================
413 // EXTERNAL MEMORY OPERATIONS
414 //==================================================
415
427 bool memIsConfigured(MemoryBank bank, bool* is_configured) noexcept;
428
439 bool memIsConnected(MemoryBank bank, bool* is_connected) noexcept;
440
451 bool memIsBusy(MemoryBank bank, bool* is_busy) noexcept;
452
453 //==================================================
454 // SPI FLASH OPERATIONS
455 //==================================================
456
468 bool flashLoadBuffer(uint8_t offset, uint32_t data) noexcept;
469
480 bool flashReadBuffer(uint8_t offset, uint32_t* data) noexcept;
481
491 bool flashSendDatagram(uint8_t num_bytes) noexcept;
492
502 bool flashEraseSector(uint32_t address) noexcept;
503
513 bool flashReadJedecId(uint8_t* manufacturer_id) noexcept;
514
515 //==================================================
516 // RS485 CONFIGURATION
517 //==================================================
518
532 bool bootstrapRS485(uint8_t tx_en_pin, uint8_t pre_delay, uint8_t host_addr,
533 uint8_t device_addr) noexcept;
534
535 //==================================================
536 // INFORMATION QUERIES
537 //==================================================
538
550 bool getInfo(InfoQuery query, uint32_t* value) noexcept;
551
552 //==================================================
553 // CONVENIENCE INFO METHODS
554 //==================================================
555
565 bool getChipType(uint32_t* chip_type) noexcept {
566 return getInfo(InfoQuery::CHIP_TYPE, chip_type);
567 }
568
578 bool getBootloaderVersion(BootloaderVersion* version) noexcept;
579
589 bool getFeatures(BootloaderFeatures* features) noexcept;
590
600 bool getGitInfo(GitInfo* git_info) noexcept;
601
611 bool getChipVersion(uint32_t* version) noexcept {
612 return getInfo(InfoQuery::CHIP_VERSION, version);
613 }
614
624 bool getChipFrequency(uint32_t* frequency) noexcept {
625 return getInfo(InfoQuery::CHIP_FREQUENCY, frequency);
626 }
627
637 bool getConfigMemStart(uint32_t* address) noexcept {
638 return getInfo(InfoQuery::CONFIG_MEM_START, address);
639 }
640
650 bool getConfigMemSize(uint32_t* size) noexcept {
652 }
653
663 bool getOtpMemSize(uint32_t* size) noexcept {
664 return getInfo(InfoQuery::OTP_MEM_SIZE, size);
665 }
666
676 bool getI2cMemSize(uint32_t* size) noexcept {
677 return getInfo(InfoQuery::I2C_MEM_SIZE, size);
678 }
679
689 bool getSpiMemSize(uint32_t* size) noexcept {
690 return getInfo(InfoQuery::SPI_MEM_SIZE, size);
691 }
692
702 bool getPartitionVersion(PartitionVersion* version) noexcept;
703
713 bool getSpiMemPartitions(uint32_t* count) noexcept {
715 }
716
726 bool getI2cMemPartitions(uint32_t* count) noexcept {
728 }
729
739 bool getChipVariant(uint32_t* variant) noexcept {
740 return getInfo(InfoQuery::CHIP_VARIANT, variant);
741 }
742
759 bool getAllBootloaderInfo() noexcept;
760
761 //==================================================
762 // HIGH-LEVEL CONFIGURATION
763 //==================================================
764
779 bool applyConfiguration(const BootloaderConfig& cfg, bool fail_on_verify_error = true) noexcept;
780
781 //==================================================
782 // MOTOR CONTROL STARTUP
783 //==================================================
784
815 bool startMotorControl(bootcfg::BootMode boot_mode = bootcfg::BootMode::Parameter) noexcept;
816
817private:
818 bool sendCommand(uint8_t cmd, uint32_t value, uint32_t* reply = nullptr) noexcept;
819 bool sendCommandSPI(uint8_t cmd, uint32_t value, uint32_t* reply) noexcept;
820 bool sendCommandUART(uint8_t cmd, uint32_t value, uint32_t* reply) noexcept;
821
822 CommType& comm_;
823 uint8_t deviceAddr_;
824 uint8_t hostAddr_;
825};
826
827} // namespace tmc9660
828
829// Include template implementation
830#define TMC9660_BOOTLOADER_HEADER_INCLUDED
832#undef TMC9660_BOOTLOADER_HEADER_INCLUDED
TMC9660 bootloader configuration structures and enumerations.
TMC9660 bootloader communication protocol structures and enumerations.
Main TMC9660 bootloader interface class.
Definition tmc9660_bootloader.hpp:53
bool setAddress(uint32_t addr) noexcept
Set the address within the current memory bank.
Definition tmc9660_bootloader.cpp:278
bool getChipFrequency(uint32_t *frequency) noexcept
Get system frequency in MHz.
Definition tmc9660_bootloader.hpp:624
bool flashReadBuffer(uint8_t offset, uint32_t *data) noexcept
Read data from internal 6-byte flash command buffer.
Definition tmc9660_bootloader.cpp:732
bool getInfo(InfoQuery query, uint32_t *value) noexcept
Get bootloader information.
Definition tmc9660_bootloader.cpp:822
bool getAddress(uint32_t *address) noexcept
Get the currently selected memory address.
Definition tmc9660_bootloader.cpp:2343
bool readAndVerify8(uint8_t expected, const char *config_name) noexcept
Read back and verify an 8-bit value matches the expected value.
Definition tmc9660_bootloader.cpp:2283
bool readAndVerify32(uint32_t expected, const char *config_name) noexcept
Read back and verify a 32-bit value matches the expected value.
Definition tmc9660_bootloader.cpp:2323
bool memIsBusy(MemoryBank bank, bool *is_busy) noexcept
Check if external memory is busy.
Definition tmc9660_bootloader.cpp:706
bool sendCommandSPI(uint8_t cmd, uint32_t value, uint32_t *reply) noexcept
Send a bootloader command via SPI interface.
Definition tmc9660_bootloader.cpp:101
bool sendCommand(uint8_t cmd, uint32_t value, uint32_t *reply=nullptr) noexcept
Send a bootloader command and optionally receive a reply.
Definition tmc9660_bootloader.cpp:69
bool flashEraseSector(uint32_t address) noexcept
Erase a sector on external SPI flash.
Definition tmc9660_bootloader.cpp:755
bool read16Inc(uint16_t *value) noexcept
Read a 16-bit word and increment address by 2.
Definition tmc9660_bootloader.cpp:2238
bool bootstrapRS485(uint8_t tx_en_pin, uint8_t pre_delay, uint8_t host_addr, uint8_t device_addr) noexcept
Configure RS485 communication (must be first command for RS485).
Definition tmc9660_bootloader.cpp:788
bool noOp(uint32_t *reply=nullptr) noexcept
No operation - retrieve reply from previous command (SPI only).
Definition tmc9660_bootloader.cpp:364
bool sendCommandUART(uint8_t cmd, uint32_t value, uint32_t *reply) noexcept
Send a bootloader command via UART interface.
Definition tmc9660_bootloader.cpp:191
bool startMotorControl(bootcfg::BootMode boot_mode=bootcfg::BootMode::Parameter) noexcept
Start the motor control system and exit bootloader mode.
Definition tmc9660_bootloader.cpp:2094
bool otpBurnWithWorkaround(uint8_t page, uint8_t page_addr, OtpBurnResult *result, uint32_t vdrv_wait_ms=1000) noexcept
Burn OTP page with Erratum 1 workaround for reliable operation.
Definition tmc9660_bootloader.cpp:498
bool getSpiMemSize(uint32_t *size) noexcept
Get SPI memory size.
Definition tmc9660_bootloader.hpp:689
bool read32Inc(uint32_t *value) noexcept
Read a 32-bit word and increment address by 4.
Definition tmc9660_bootloader.cpp:2255
bool readAndVerify16(uint16_t expected, const char *config_name) noexcept
Read back and verify a 16-bit value matches the expected value.
Definition tmc9660_bootloader.cpp:2303
bool getBank(uint8_t *bank) noexcept
Get the currently selected memory bank.
Definition tmc9660_bootloader.cpp:2266
uint8_t hostAddr_
Host address for UART protocol.
Definition tmc9660_bootloader.hpp:824
bool write8Inc(uint8_t v) noexcept
Write a single byte and increment address by 1.
Definition tmc9660_bootloader.cpp:326
bool applyConfiguration(const BootloaderConfig &cfg, bool fail_on_verify_error=true) noexcept
Apply all fields of a ::BootloaderConfig.
Definition tmc9660_bootloader.cpp:956
bool memIsConfigured(MemoryBank bank, bool *is_configured) noexcept
Check if external memory is configured.
Definition tmc9660_bootloader.cpp:678
bool memIsConnected(MemoryBank bank, bool *is_connected) noexcept
Check if external memory is connected.
Definition tmc9660_bootloader.cpp:692
bool getChipVersion(uint32_t *version) noexcept
Get chip version (silicon revision).
Definition tmc9660_bootloader.hpp:611
bool getGitInfo(GitInfo *git_info) noexcept
Get Git version control information.
Definition tmc9660_bootloader.cpp:871
bool write32(uint32_t v) noexcept
Write a 32-bit word to the previously selected address.
Definition tmc9660_bootloader.cpp:320
bool write16(uint16_t v) noexcept
Write a 16-bit word to the previously selected address.
Definition tmc9660_bootloader.cpp:306
bool getChipVariant(uint32_t *variant) noexcept
Get chip variant (TMC9660 reports value 2).
Definition tmc9660_bootloader.hpp:739
bool checkOtpBurnStatus(bool *result) noexcept
Check OTP burn status using Erratum 1 workaround verification.
Definition tmc9660_bootloader.cpp:580
bool read8(uint8_t *value) noexcept
Read a single byte from the previously selected address.
Definition tmc9660_bootloader.cpp:2160
uint8_t deviceAddr_
Device address for UART protocol.
Definition tmc9660_bootloader.hpp:823
bool getFeatures(BootloaderFeatures *features) noexcept
Get available feature flags.
Definition tmc9660_bootloader.cpp:854
bool read32(uint32_t *value) noexcept
Read a 32-bit word from the previously selected address.
Definition tmc9660_bootloader.cpp:2210
TMC9660Bootloader(CommType &comm) noexcept
Construct a TMC9660Bootloader instance.
Definition tmc9660_bootloader.cpp:51
bool otpLoad(uint8_t page, OtpLoadResult *result) noexcept
Load an OTP (One-Time Programmable) page into the OTP memory bank.
Definition tmc9660_bootloader.cpp:385
bool getConfigMemSize(uint32_t *size) noexcept
Get CONFIG memory bank size.
Definition tmc9660_bootloader.hpp:650
bool flashLoadBuffer(uint8_t offset, uint32_t data) noexcept
Load data into internal 6-byte flash command buffer.
Definition tmc9660_bootloader.cpp:724
bool getI2cMemPartitions(uint32_t *count) noexcept
Get number of I2C memory partitions.
Definition tmc9660_bootloader.hpp:726
bool flashReadJedecId(uint8_t *manufacturer_id) noexcept
Read JEDEC manufacturer ID from SPI flash.
Definition tmc9660_bootloader.cpp:762
bool setBank(uint8_t bank) noexcept
Select the target memory bank for subsequent operations.
Definition tmc9660_bootloader.cpp:264
bool write32Inc(uint32_t v) noexcept
Write a 32-bit word and increment address by 4.
Definition tmc9660_bootloader.cpp:338
bool getChipType(uint32_t *chip_type) noexcept
Get chip type (should return 0x544D0001 for TMC9660).
Definition tmc9660_bootloader.hpp:565
bool getConfigMemStart(uint32_t *address) noexcept
Get CONFIG memory bank start address.
Definition tmc9660_bootloader.hpp:637
bool read16(uint16_t *value) noexcept
Read a 16-bit word from the previously selected address.
Definition tmc9660_bootloader.cpp:2185
bool getOtpMemSize(uint32_t *size) noexcept
Get OTP memory page size.
Definition tmc9660_bootloader.hpp:663
bool setBank(MemoryBank bank) noexcept
Select the target register bank using enum (overloaded).
Definition tmc9660_bootloader.hpp:83
bool write32IncMultiple(const uint32_t *values, size_t count) noexcept
Write multiple 32-bit words starting at the current address.
Definition tmc9660_bootloader.cpp:354
bool write8(uint8_t v) noexcept
Write a single byte to the previously selected address.
Definition tmc9660_bootloader.cpp:292
CommType & comm_
Definition tmc9660_bootloader.hpp:822
bool getSpiMemPartitions(uint32_t *count) noexcept
Get number of SPI memory partitions.
Definition tmc9660_bootloader.hpp:713
bool getI2cMemSize(uint32_t *size) noexcept
Get I2C memory size.
Definition tmc9660_bootloader.hpp:676
bool flashSendDatagram(uint8_t num_bytes) noexcept
Send datagram to SPI flash and receive reply.
Definition tmc9660_bootloader.cpp:747
bool read8Inc(uint8_t *value) noexcept
Read a single byte and increment address by 1.
Definition tmc9660_bootloader.cpp:2221
bool getAllBootloaderInfo() noexcept
Retrieve and log all available bootloader information.
Definition tmc9660_bootloader.cpp:2354
bool write16Inc(uint16_t v) noexcept
Write a 16-bit word and increment address by 2.
Definition tmc9660_bootloader.cpp:332
bool getBootloaderVersion(BootloaderVersion *version) noexcept
Get bootloader version information.
Definition tmc9660_bootloader.cpp:837
bool otpBurn(uint8_t page, uint8_t page_addr, OtpBurnResult *result) noexcept
Permanently burn data to OTP (One-Time Programmable) memory.
Definition tmc9660_bootloader.cpp:431
bool getPartitionVersion(PartitionVersion *version) noexcept
Get partition version information.
Definition tmc9660_bootloader.cpp:888
Definition bootloader_config.hpp:9
MemoryBank
Memory bank identifiers for bootloader operations.
Definition bootloader_protocol.hpp:86
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.
@ SPI_MEM_PARTITIONS
Get number of SPI memory partitions.
@ 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)
Complete bootloader configuration structure.
Definition bootloader_config.hpp:998
Feature flags indicating available bootloader capabilities.
Definition bootloader_protocol.hpp:151
Bootloader version information structure.
Definition bootloader_protocol.hpp:132
Git version control information from bootloader firmware.
Definition bootloader_protocol.hpp:177
OTP burn operation result information.
Definition bootloader_protocol.hpp:255
OTP load operation result information.
Definition bootloader_protocol.hpp:217
External memory partition version information.
Definition bootloader_protocol.hpp:197
Tmc9660 Bootloader definitions.
Communication interfaces for TMC9660 Parameter Mode devices using TMCL protocol over SPI.