|
33 | 33 | #define CDC_MAX_PACKET_SIZE USB_MAX_EP0_SIZE |
34 | 34 | #endif |
35 | 35 |
|
| 36 | +// TODO: Put this elsewhere |
| 37 | +#define BOOTLOADER_RESET_1200_BAUD |
| 38 | + |
36 | 39 | /* |
37 | 40 | * The value USB_CDC_TRANSMIT_TIMEOUT is defined in terms of HAL_GetTick() units. |
38 | 41 | * Typically it is 1ms value. The timeout determines when we would consider the |
@@ -169,9 +172,6 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length) |
169 | 172 | linecoding.format = pbuf[4]; |
170 | 173 | linecoding.paritytype = pbuf[5]; |
171 | 174 | linecoding.datatype = pbuf[6]; |
172 | | - if (linecoding.bitrate == 1200) { |
173 | | - jumpToBootloaderRequested(); |
174 | | - } |
175 | 175 | break; |
176 | 176 |
|
177 | 177 | case CDC_GET_LINE_CODING: |
@@ -203,6 +203,19 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length) |
203 | 203 | break; |
204 | 204 | } |
205 | 205 |
|
| 206 | +#ifdef BOOTLOADER_RESET_1200_BAUD |
| 207 | + if (cmd == CDC_SET_LINE_CODING || cmd == CDC_SET_CONTROL_LINE_STATE) { |
| 208 | + // Auto-reset into the bootloader is triggered when the port, already |
| 209 | + // open at 1200 bps, is closed. Cancel the reset when the port is |
| 210 | + // opened again. |
| 211 | + if (linecoding.bitrate == 1200 && !lineState) { |
| 212 | + scheduleBootloaderReset(); |
| 213 | + } else { |
| 214 | + cancelBootloaderReset(); |
| 215 | + } |
| 216 | + } |
| 217 | +#endif /* BOOTLOADER_RESET_1200_BAUD */ |
| 218 | + |
206 | 219 | return ((int8_t)USBD_OK); |
207 | 220 | } |
208 | 221 |
|
|
0 commit comments