lenz-flashtool 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lenz_flashtool/__init__.py +68 -0
- lenz_flashtool/biss/__init__.py +42 -0
- lenz_flashtool/biss/cli.py +391 -0
- lenz_flashtool/biss/commands.py +157 -0
- lenz_flashtool/biss/crc.py +54 -0
- lenz_flashtool/biss/registers.py +185 -0
- lenz_flashtool/encproc/__init__.py +48 -0
- lenz_flashtool/encproc/processing.py +464 -0
- lenz_flashtool/flashtool/__init__.py +37 -0
- lenz_flashtool/flashtool/core.py +1680 -0
- lenz_flashtool/flashtool/errors.py +7 -0
- lenz_flashtool/flashtool/hex_utils.py +842 -0
- lenz_flashtool/flashtool/logging.py +161 -0
- lenz_flashtool/flashtool/operations.py +140 -0
- lenz_flashtool/flashtool/uart.py +254 -0
- lenz_flashtool/testing/__init__.py +6 -0
- lenz_flashtool/testing/mock_flashtool.py +426 -0
- lenz_flashtool/utils/__init__.py +28 -0
- lenz_flashtool/utils/plot.py +115 -0
- lenz_flashtool/utils/progress.py +125 -0
- lenz_flashtool/utils/termcolors.py +76 -0
- lenz_flashtool-0.1.0.dist-info/METADATA +148 -0
- lenz_flashtool-0.1.0.dist-info/RECORD +26 -0
- lenz_flashtool-0.1.0.dist-info/WHEEL +4 -0
- lenz_flashtool-0.1.0.dist-info/entry_points.txt +2 -0
- lenz_flashtool-0.1.0.dist-info/licenses/LICENSE +22 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
r'''
|
|
2
|
+
_ _____ _ _ _____ _____ _ _ ____ ___ ____ _____ ____ ____
|
|
3
|
+
| | | ____| \ | |__ / | ____| \ | |/ ___/ _ \| _ \| ____| _ \/ ___|
|
|
4
|
+
| | | _| | \| | / / | _| | \| | | | | | | | | | _| | |_) \___ \
|
|
5
|
+
| |___| |___| |\ |/ /_ | |___| |\ | |__| |_| | |_| | |___| _ < ___) |
|
|
6
|
+
|_____|_____|_| \_/____| |_____|_| \_|\____\___/|____/|_____|_| \_|____/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Calculate the BiSS C CRC6 checksum for a 32-bit data word using a precomputed lookup table.
|
|
10
|
+
|
|
11
|
+
This implementation uses the standard BiSS CRC6 polynomial (x⁶ + x + 1) with an initial value
|
|
12
|
+
of 0x3F and final XOR of 0x00. The calculation is optimized using a 256-byte lookup table
|
|
13
|
+
for efficient processing of 32-bit data words.
|
|
14
|
+
|
|
15
|
+
Author:
|
|
16
|
+
LENZ ENCODERS, 2020-2025
|
|
17
|
+
'''
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def biss_crc6_calc(data: int) -> int:
|
|
21
|
+
"""
|
|
22
|
+
Calculate the BiSS C CRC6 checksum for a 32-bit data word.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
data (int): A 32-bit integer representing the data for which to calculate the CRC6 checksum.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
int: The calculated 6-bit CRC checksum.
|
|
29
|
+
"""
|
|
30
|
+
crc6_table = [
|
|
31
|
+
0x00, 0x0C, 0x18, 0x14, 0x30, 0x3C, 0x28, 0x24, 0x60, 0x6C, 0x78, 0x74, 0x50, 0x5C, 0x48, 0x44,
|
|
32
|
+
0xC0, 0xCC, 0xD8, 0xD4, 0xF0, 0xFC, 0xE8, 0xE4, 0xA0, 0xAC, 0xB8, 0xB4, 0x90, 0x9C, 0x88, 0x84,
|
|
33
|
+
0x8C, 0x80, 0x94, 0x98, 0xBC, 0xB0, 0xA4, 0xA8, 0xEC, 0xE0, 0xF4, 0xF8, 0xDC, 0xD0, 0xC4, 0xC8,
|
|
34
|
+
0x4C, 0x40, 0x54, 0x58, 0x7C, 0x70, 0x64, 0x68, 0x2C, 0x20, 0x34, 0x38, 0x1C, 0x10, 0x04, 0x08,
|
|
35
|
+
0x14, 0x18, 0x0C, 0x00, 0x24, 0x28, 0x3C, 0x30, 0x74, 0x78, 0x6C, 0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
|
+
0x70, 0x7C, 0x68, 0x64, 0x40, 0x4C, 0x58, 0x54, 0x10, 0x1C, 0x08, 0x04, 0x20, 0x2C, 0x38, 0x34
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
crc = crc6_table[(data >> 24) & 0x3]
|
|
50
|
+
crc = crc6_table[((data >> 16) & 0xFF) ^ crc]
|
|
51
|
+
crc = crc6_table[((data >> 8) & 0xFF) ^ crc]
|
|
52
|
+
crc = crc6_table[(data & 0xFF) ^ crc]
|
|
53
|
+
crc = ((crc ^ 0xFF) >> 2) & 0x3F
|
|
54
|
+
return crc
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
r'''
|
|
2
|
+
_ _____ _ _ _____ _____ _ _ ____ ___ ____ _____ ____ ____
|
|
3
|
+
| | | ____| \ | |__ / | ____| \ | |/ ___/ _ \| _ \| ____| _ \/ ___|
|
|
4
|
+
| | | _| | \| | / / | _| | \| | | | | | | | | | _| | |_) \___ \
|
|
5
|
+
| |___| |___| |\ |/ /_ | |___| |\ | |__| |_| | |_| | |___| _ < ___) |
|
|
6
|
+
|_____|_____|_| \_/____| |_____|_| \_|\____\___/|____/|_____|_| \_|____/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
BiSS Encoder Register Definitions Module
|
|
10
|
+
|
|
11
|
+
This module defines the register mappings and banking system for BiSS C encoder devices used
|
|
12
|
+
with the LENZ FlashTool. It provides an enumeration (`BiSSBank`) of register indices and constants
|
|
13
|
+
for accessing programmable and fixed-address registers, as well as managing the paged banking system for extended configuration.
|
|
14
|
+
|
|
15
|
+
Register Organization:
|
|
16
|
+
- Programmable Registers (Indices 0-63): Used for device configuration, including nonce, CRC, serial number,
|
|
17
|
+
production date, and security keys.
|
|
18
|
+
- Fixed-Address Registers (Indices 64-127): Contain device information (e.g., serial number, device ID)
|
|
19
|
+
and runtime data (e.g., encoder data, status flags).
|
|
20
|
+
|
|
21
|
+
Banking System:
|
|
22
|
+
- Supports a paged banking system with a service bank (index 2) and user banks (indices 5-37).
|
|
23
|
+
- Each bank contains 64 bytes of data, with a bank select register (`BSEL_REG_INDEX`) to switch banks.
|
|
24
|
+
- Fixed-address registers (64-127) are accessible regardless of the selected bank.
|
|
25
|
+
|
|
26
|
+
Usage Notes:
|
|
27
|
+
- Registers are 32-bit unless otherwise specified and stored in big-endian format (highest-value byte at the lowest address).
|
|
28
|
+
- Some registers (e.g., configuration registers) require unlock sequences before writing.
|
|
29
|
+
- The `BiSSBank` enum provides indices for accessing registers and constants for bank management.
|
|
30
|
+
|
|
31
|
+
Key Constants:
|
|
32
|
+
- Programmable Registers: Nonce, CRC32, serial number, production date, device ID, and key registers.
|
|
33
|
+
- Fixed-Address Registers: Command, encoder data, harmonic measurements, status flags, version information,
|
|
34
|
+
and device/manufacturer IDs.
|
|
35
|
+
- Banking: Service bank, user banks, and bank/page sizes for firmware updates and data transfers.
|
|
36
|
+
|
|
37
|
+
Author:
|
|
38
|
+
LENZ ENCODERS, 2020-2025
|
|
39
|
+
'''
|
|
40
|
+
from enum import IntEnum
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class BiSSBank(IntEnum):
|
|
44
|
+
"""
|
|
45
|
+
Enumeration of BiSS C encoder register indices and banking constants.
|
|
46
|
+
|
|
47
|
+
Defines indices for programmable registers (0-63), fixed-address registers (64-127),
|
|
48
|
+
and constants for the banking system. Each constant represents either a register index
|
|
49
|
+
or a size/bank definition used for device configuration, operation, and data access.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
NONCE_REG_INDEX = 0
|
|
53
|
+
"""int: Index for the nonce register while programming."""
|
|
54
|
+
|
|
55
|
+
CRC32_REG_INDEX = 12
|
|
56
|
+
"""int: Index for the CRC32 register for data integrity checks while programming."""
|
|
57
|
+
|
|
58
|
+
SERIALNUM_REG_INDEX = 16
|
|
59
|
+
"""int: Index for the serial number programming register."""
|
|
60
|
+
|
|
61
|
+
PRODDATE_REG_INDEX = 20
|
|
62
|
+
"""int: Index for the production date programming register."""
|
|
63
|
+
|
|
64
|
+
CRC_ARRAY_REG_INDEX = 24
|
|
65
|
+
"""int: CRC array programming register index."""
|
|
66
|
+
|
|
67
|
+
PAGENUM_REG_INDEX = 24
|
|
68
|
+
"""int: Page number programming register index."""
|
|
69
|
+
|
|
70
|
+
SERIALNUM_CRC_REG_INDEX = 25 # Serial number CRC programming register index
|
|
71
|
+
"""int: Serial number CRC programming register index."""
|
|
72
|
+
|
|
73
|
+
KEY_CRC_REG_INDEX = 26 # Key CRC programming register index
|
|
74
|
+
"""int: Key CRC programming register index."""
|
|
75
|
+
|
|
76
|
+
DEVID_CRC_REG_INDEX = 27 # Device ID CRC programming register index
|
|
77
|
+
"""int: Device ID CRC programming register index."""
|
|
78
|
+
|
|
79
|
+
KEY_REG_INDEX = 28 # Key programming register index
|
|
80
|
+
"""int: Key programming register index."""
|
|
81
|
+
|
|
82
|
+
DEVID_L_REG_INDEX = 54 # Lower part of device ID programming register index
|
|
83
|
+
"""int: Lower part of device ID programming register index."""
|
|
84
|
+
|
|
85
|
+
DEVID_H_REG_INDEX = 58 # Higher part of device ID programming register index
|
|
86
|
+
"""int: Higher part of device ID programming register index."""
|
|
87
|
+
|
|
88
|
+
# ==== Fixed addresses registers indexes
|
|
89
|
+
|
|
90
|
+
FIXED_ADDRESSES_START_INDEX = 64
|
|
91
|
+
"""int: Start index of fixed address registers."""
|
|
92
|
+
|
|
93
|
+
BSEL_REG_INDEX = 64 # Bank select register index
|
|
94
|
+
"""int: Bank select register index."""
|
|
95
|
+
|
|
96
|
+
DEV_SN_REG_INDEX = 68 # Device serial number index
|
|
97
|
+
"""int: Device serial number index."""
|
|
98
|
+
|
|
99
|
+
DEV_SN_SIZE = 4 # Device serial number size in bytes
|
|
100
|
+
"""int: Device serial number size in bytes."""
|
|
101
|
+
|
|
102
|
+
# ==== Free Registers start:
|
|
103
|
+
CMD_REG_INDEX = 72 # Command register index - 2 bytes
|
|
104
|
+
"""int: Command register index - 2 bytes."""
|
|
105
|
+
|
|
106
|
+
ENC_DATA_REG_INDEX = 74 # Encoder data: Calibration state, temperature, Vcc, Signal Mod,
|
|
107
|
+
"""int: Encoder data register index (calibration state, temperature, Vcc, Signal Mod)."""
|
|
108
|
+
|
|
109
|
+
FIRSTHARMAMP_REG_INDEX = 80 # First harmonic amplitude register index
|
|
110
|
+
"""int: First harmonic amplitude register index."""
|
|
111
|
+
|
|
112
|
+
FIRSTHARMANGLE_REG_INDEX = 82 # First harmonic angle register index
|
|
113
|
+
"""int: First harmonic angle register index."""
|
|
114
|
+
|
|
115
|
+
REV_RES_REG_INDEX = 84 # 0x54 # rev and resolution
|
|
116
|
+
"""int: Revolution and resolution register index."""
|
|
117
|
+
|
|
118
|
+
SHIFT_REG_INDEX = 85 # 0x55 # 3 bytes 0x55 0x56 0x57 # shift (0x80 to 0x55 for 180°)
|
|
119
|
+
"""int: Shift register index (3 bytes for 180° shift)."""
|
|
120
|
+
|
|
121
|
+
CMD_STATE_FLAG_REG_INDEX = 97 # Command state flag register index
|
|
122
|
+
"""int: Command state flag register index."""
|
|
123
|
+
|
|
124
|
+
STATE_FLAG_REG_INDEX = 98 # State flag register index
|
|
125
|
+
"""int: State flag register index."""
|
|
126
|
+
|
|
127
|
+
BOOTLOADER_VER_REG_INDEX = 108
|
|
128
|
+
"""int: Bootloader version register index."""
|
|
129
|
+
|
|
130
|
+
BOOTLOADER_VER_SIZE = 4
|
|
131
|
+
"""int: Bootloader version size in bytes."""
|
|
132
|
+
|
|
133
|
+
PROGVER_REG_INDEX = 112 # Program version register index
|
|
134
|
+
"""int: Program version register index."""
|
|
135
|
+
|
|
136
|
+
PROGVER_REG_SIZE = 4
|
|
137
|
+
"""int: Program version size in bytes."""
|
|
138
|
+
|
|
139
|
+
MFG_REG_INDEX = 116
|
|
140
|
+
"""int: Manufacturing date register index."""
|
|
141
|
+
|
|
142
|
+
MFG_REG_SIZE = 4
|
|
143
|
+
"""int: Manufacturer date register size in bytes."""
|
|
144
|
+
|
|
145
|
+
# ==== Free Registers end.
|
|
146
|
+
|
|
147
|
+
DEV_ID_H_REG_INDEX = 120 # Device ID
|
|
148
|
+
"""int: Device ID (high part) register index."""
|
|
149
|
+
|
|
150
|
+
DEV_ID_H_SIZE = 4
|
|
151
|
+
"""int: Device ID (high part) size in bytes."""
|
|
152
|
+
|
|
153
|
+
DEV_ID_L_REG_INDEX = 124
|
|
154
|
+
"""int: Device ID (low part) register index."""
|
|
155
|
+
|
|
156
|
+
DEV_ID_L_SIZE = 2
|
|
157
|
+
"""int: Device ID (low part) size in bytes."""
|
|
158
|
+
|
|
159
|
+
MFR_ID_REG_INDEX = 126 # Manufacturer ID
|
|
160
|
+
"""int: Manufacturer ID register index."""
|
|
161
|
+
|
|
162
|
+
MFG_ID_SIZE = 2
|
|
163
|
+
"""int: Manufacturer ID size in bytes."""
|
|
164
|
+
|
|
165
|
+
# BiSS banking definitions
|
|
166
|
+
BISS_BANK_SERV = 2 # Service bank index
|
|
167
|
+
"""int: Service bank index."""
|
|
168
|
+
|
|
169
|
+
BISS_USERBANK_START = 5 # Start index of user banks
|
|
170
|
+
"""int: Start index of user banks."""
|
|
171
|
+
|
|
172
|
+
BISS_USERBANK_END = 37 # End index of user banks
|
|
173
|
+
"""int: End index of user banks."""
|
|
174
|
+
|
|
175
|
+
BANKS_PER_PAGE = 32 # Number of banks per page
|
|
176
|
+
"""int: Number of banks per page."""
|
|
177
|
+
|
|
178
|
+
REGISTER_PLUS_BSEL_SIZE = 65 # Size of each bank in bytes (64) plus BSEL reg size (1) (data + bank number)
|
|
179
|
+
"""int: Size of each bank in bytes (64) plus BSEL reg size (1) (data + bank number)."""
|
|
180
|
+
|
|
181
|
+
REGISTER_PLUS_FIXED_BANK_SIZE = 128 # Register bank (64) and Fixed Addresses (64) size
|
|
182
|
+
"""int: Register bank (64) and Fixed Addresses (64) size."""
|
|
183
|
+
|
|
184
|
+
FIXED_BANK_SIZE = 64
|
|
185
|
+
"""int: Fixed bank size in bytes."""
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""
|
|
2
|
+
|
|
3
|
+
LENZ Encoder Signal Processing Library
|
|
4
|
+
|
|
5
|
+
This library provides a comprehensive suite of signal processing functions for high-precision
|
|
6
|
+
LENZ encoder systems, designed to enhance the accuracy of position measurements in applications
|
|
7
|
+
such as motor control, robotics, and industrial automation. It includes advanced algorithms for
|
|
8
|
+
differential signal computation, harmonic analysis, noise filtering, and calibration table
|
|
9
|
+
generation, with specialized support for motor-driven systems to suppress harmonic errors.
|
|
10
|
+
|
|
11
|
+
Key Features:
|
|
12
|
+
|
|
13
|
+
- Differential signal computation between paired encoder signals for error analysis.
|
|
14
|
+
- Advanced filtering techniques, including bidirectional moving average and custom smoothing filters.
|
|
15
|
+
- Harmonic analysis using Fast Fourier Transform (FFT) to identify and quantify periodic errors.
|
|
16
|
+
- Generation of difference compensation tables for systematic error correction.
|
|
17
|
+
- Motor harmonic suppression for enhanced accuracy in motor-driven encoder systems.
|
|
18
|
+
- Support for 24-bit encoder data with proper handling of wrap-around effects.
|
|
19
|
+
|
|
20
|
+
Notes:
|
|
21
|
+
|
|
22
|
+
- The library assumes 24-bit encoder data (0 to 2^24 - 1) but can be adapted for other resolutions.
|
|
23
|
+
- Functions are designed for static use, requiring no instantiation of `LenzEncoderProcessor`.
|
|
24
|
+
- Calibration routines (`lenz_cal`, `lenz_cal_motor_harm`) are optimized for high-precision
|
|
25
|
+
applications but may require tuning of parameters like `coarse_red` and `motor_harm` for
|
|
26
|
+
specific use cases.
|
|
27
|
+
- The `diff_table_gen_motor_harm` function includes motor harmonic suppression, which is critical
|
|
28
|
+
for motor-driven systems but requires a valid `motor_harm` value.
|
|
29
|
+
|
|
30
|
+
Author:
|
|
31
|
+
LENZ ENCODERS, 2020-2025
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# r'''
|
|
36
|
+
# _ _____ _ _ _____ _____ _ _ ____ ___ ____ _____ ____ ____
|
|
37
|
+
# | | | ____| \ | |__ / | ____| \ | |/ ___/ _ \| _ \| ____| _ \/ ___|
|
|
38
|
+
# | | | _| | \| | / / | _| | \| | | | | | | | | | _| | |_) \___ \
|
|
39
|
+
# | |___| |___| |\ |/ /_ | |___| |\ | |__| |_| | |_| | |___| _ < ___) |
|
|
40
|
+
# |_____|_____|_| \_/____| |_____|_| \_|\____\___/|____/|_____|_| \_|____/
|
|
41
|
+
# '''
|
|
42
|
+
|
|
43
|
+
# Core functions
|
|
44
|
+
from .processing import LenzEncoderProcessor
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
'LenzEncoderProcessor'
|
|
48
|
+
]
|