Skip to content

Commit 0add3a3

Browse files
committed
Use backup API for HID bootloader
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 857ff65 commit 0add3a3

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

Diff for: cores/arduino/stm32/usb/cdc/usbd_cdc_if.c

+4-13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/* Includes ------------------------------------------------------------------*/
2424
#include "usbd_desc.h"
2525
#include "usbd_cdc_if.h"
26+
#include "backup.h"
2627

2728
#ifdef USE_USB_HS
2829
#define CDC_MAX_PACKET_SIZE USB_OTG_HS_MAX_PACKET_SIZE
@@ -229,19 +230,9 @@ static int8_t USBD_CDC_Receive(uint8_t *Buf, uint32_t *Len)
229230
*/
230231
if (dtr_toggling > 3) {
231232
if ((Buf[0] == '1') && (Buf[1] == 'E') && (Buf[2] == 'A') && (Buf[3] == 'F')) {
232-
#if defined (HIDBL_F1)
233-
RTC_HandleTypeDef hrtc;
234-
__HAL_RCC_PWR_CLK_ENABLE();
235-
__HAL_RCC_BKP_CLK_ENABLE();
236-
HAL_PWR_EnableBkUpAccess();
237-
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR10, 0x424C); //Write the magic number 0x424C
238-
239-
#elif defined (HIDBL_F4)
240-
__HAL_RCC_PWR_CLK_ENABLE();
241-
HAL_PWR_EnableBkUpAccess();
242-
__BKPSRAM_CLK_ENABLE();
243-
*(__IO uint32_t *)(BKPSRAM_BASE) = 0x424C; //Write the magic number 0x424C at Backup SRAM address 0x40024000
244-
233+
#if defined (HIDBL_F1) || defined (HIDBL_F4)
234+
enableBackupRegister();
235+
setBackupRegister(LL_RTC_BKP_DR10, 0x424C);
245236
#endif
246237
HAL_NVIC_SystemReset();
247238
}

0 commit comments

Comments
 (0)