TURAG-Feldbus
bmax_protocol.h
1
10#ifndef TURAG_FELDBUS_FUER_BOOTLOADER_H_
11#define TURAG_FELDBUS_FUER_BOOTLOADER_H_
12
13
14#include "base_protocol.h"
15
20#define TURAG_FELDBUS_BOOTLOADER_GENERIC 0x01
21#define TURAG_FELDBUS_BOOTLOADER_ATMEGA 0x02
22#define TURAG_FELDBUS_BOOTLOADER_XMEGA 0x03
23#define TURAG_FELDBUS_BOOTLOADER_STM32 0x04
24#define TURAG_FELDBUS_BOOTLOADER_STM32V2 0x05
25
27
28
29/*
30 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 *
32 * NEVER EVER CHANGE ANY
33 * OF THOSE DEFINITIONS!!!!!!
34 * (Adding new ones is ok.)
35 *
36 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37 */
38
39
44#define TURAG_FELDBUS_BOOTLOADER_COMMAND_GET_MCUID 0x01
45#define TURAG_FELDBUS_BOOTLOADER_COMMAND_UNLOCK_BOOTLOADER 0x02
46
47// only supported if the device returns 0xFFFF as mcu id
48#define TURAG_FELDBUS_BOOTLOADER_COMMAND_RECEIVE_MCU_STRING 0x03
49#define TURAG_FELDBUS_BOOTLOADER_COMMAND_RECEIVE_MCU_STRING_LENGTH 0x04
50
51#define TURAG_FELDBUS_BOOTLOADER_COMMAND_ENTER_BOOTLOADER 0xA1
52#define TURAG_FELDBUS_BOOTLOADER_COMMAND_START_PROGRAMM 0xAF
53
54#define TURAG_FELDBUS_BOOTLOADER_UNLOCK_CODE 0x4266
55#define TURAG_FELDBUS_BOOTLOADER_RESPONSE_UNLOCKED 0x00
56#define TURAG_FELDBUS_BOOTLOADER_RESPONSE_UNLOCK_REJECTED 0x01
57
59
60
65#define TURAG_FELDBUS_BOOTLOADER_AVR_GET_PAGE_SIZE 0x11
66#define TURAG_FELDBUS_BOOTLOADER_AVR_GET_FLASH_SIZE 0x13
67#define TURAG_FELDBUS_BOOTLOADER_AVR_PAGE_WRITE 0xAA
68#define TURAG_FELDBUS_BOOTLOADER_AVR_DATA_READ 0xAB
69
70
71#define TURAG_FELDBUS_BOOTLOADER_AVR_RESPONSE_SUCCESS 0x00
72#define TURAG_FELDBUS_BOOTLOADER_AVR_RESPONSE_FAIL_SIZE 0xFA
73#define TURAG_FELDBUS_BOOTLOADER_AVR_RESPONSE_FAIL_ADDRESS 0xFB
74#define TURAG_FELDBUS_BOOTLOADER_AVR_RESPONSE_FAIL_NOT_SUPPORTED 0xFC
75#define TURAG_FELDBUS_BOOTLOADER_AVR_RESPONSE_FAIL_CONTENT 0xFD
77
82#define TURAG_FELDBUS_BOOTLOADER_ATMEGA_GET_FUSES 0x12
84
89#define TURAG_FELDBUS_BOOTLOADER_XMEGA_GET_FUSES 0x12
90#define TURAG_FELDBUS_BOOTLOADER_XMEGA_GET_REVISION 0x14
92
93
98#define TURAG_FELDBUS_BOOTLOADER_STM32V2_GET_PAGE_SIZE 0x11
99#define TURAG_FELDBUS_BOOTLOADER_STM32V2_GET_FLASH_SIZE 0x13
100
101#define TURAG_FELDBUS_BOOTLOADER_STM32V2_GET_APP_ADDRESS_MODE 0x15
102
103// In this mode the stack address and the address of the reset handler are stored
104// at a specific address in the flash in addition to the program itself by using a
105// special command. When the bootloader
106// needs to start the program it reads these addresses from this flash position.
107// This approach is easy to implement but requires an additional erasable flash segment which
108// may be wasteful on some F4 devices whose flash sectors are very large at the end of the flash.
109#define TURAG_FELDBUS_BOOTLOADER_STM32V2_APP_ADDRESS_MODE_DEDICATED_PAGE 0x00
110
111// This method makes use of reserved positions within the vector table itself. This is the
112// preferred option for any device which has suitable unused space within its vector table.
113#define TURAG_FELDBUS_BOOTLOADER_STM32V2_APP_ADDRESS_MODE_HIDDEN_IN_VECTOR_TABLE 0x01
114
115
116//#define TURAG_FELDBUS_BOOTLOADER_STM32V2_GET_BOOTLOADER_RESET_VECTOR 0x16
117//#define TURAG_FELDBUS_BOOTLOADER_STM32V2_STORE_APP_RESET_VECTORS 0x17 // only defined in APP_ADDRESS_MODE_DEDICATED_PAGE
118//#define TURAG_FELDBUS_BOOTLOADER_STM32V2_GET_APP_RESET_VECTOR_STORAGE_ADDRESS 0x18 // only defined in APP_ADDRESS_MODE_HIDDEN_IN_VECTOR_TABLE
119
120// Transmits the content of the reset vector of the user application to the bootloader.
121// This command must be called before transmitting any of the user application code if the address mode
122// is hidden vector.
123#define TURAG_FELDBUS_BOOTLOADER_STM32V2_TRANSMIT_APP_RESET_VECTOR 0x16
124
125// This function schould be called after the whole user application has been
126// transmitted. Depending on the used address mode this function either
127// - writes the user application reset vector to the dedicated flash page
128// - checks whether the supplied reset vector can be found at the expected
129// position in the vector table.
130//
131// Returns an error code.
132#define TURAG_FELDBUS_BOOTLOADER_STM32V2_COMMIT_APP_RESET_VECTOR 0x17
133
134// Returns the location of the user app reset vector. This can be used
135// by the host when verifying the flash contents by reading it and comparing it
136// with the written data. If the reset vector is stored in the vector table, the first
137// flash page will be modified at this position and the read data will be different than the written data.
138#define TURAG_FELDBUS_BOOTLOADER_STM32V2_GET_APP_RESET_VECTOR_STORAGE_ADDRESS 0x18
139
140// and APP_ADDRESS_MODE_AFTER_USERAPP
141#define TURAG_FELDBUS_BOOTLOADER_STM32V2_PAGE_WRITE 0xAA
142#define TURAG_FELDBUS_BOOTLOADER_STM32V2_DATA_READ 0xAB
143
144
145
146
147#define TURAG_FELDBUS_BOOTLOADER_STM32V2_RESPONSE_SUCCESS 0x00
148#define TURAG_FELDBUS_BOOTLOADER_STM32V2_RESPONSE_FAIL_SIZE 0xFA
149#define TURAG_FELDBUS_BOOTLOADER_STM32V2_RESPONSE_FAIL_ADDRESS 0xFB
150#define TURAG_FELDBUS_BOOTLOADER_STM32V2_RESPONSE_FAIL_NOT_SUPPORTED 0xFC
151#define TURAG_FELDBUS_BOOTLOADER_STM32V2_RESPONSE_FAIL_FLASH 0xFD
152#define TURAG_FELDBUS_BOOTLOADER_STM32V2_RESPONSE_FAIL_MISMATCH 0xFE
153
154
155
156
158
159
160
165#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_INVALID 0x0000
166#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_STRING 0xFFFF
167
168#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_ATMEGA8 0x0793
169#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_ATMEGA16 0x0394
170#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_ATMEGA32 0x0295
171#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_ATMEGA128 0x0297
172#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_ATMEGA88 0x0A93
173#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_ATMEGA168 0x0694
174#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_ATMEGA644 0x0996
175
176#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_XMEGA16D4 0x9442
177#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_XMEGA32D4 0x9542
178#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_XMEGA64D4 0x9647
179#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_XMEGA128D4 0x9747
180
181#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_XMEGA16E5 0x9445
182#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_XMEGA32E5 0x944C
183
184// note: the values above are legacy. From here on values are manually
185// chosen (mainly because for STM32 there seems to be no unique
186// model nuber).
187#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_STM32F051x8 0x1001
188#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_STM32F030x4 0x1002
189#define TURAG_FELDBUS_BOOTLOADER_MCU_ID_STM32F031x6 0x1003
190
191
192
194
195#endif