Skip to content

Commit e011f5a

Browse files
committed
Use backup API for HID bootloader
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 7c84014 commit e011f5a

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

cores/arduino/stm32/backup.h

+12
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ extern "C" {
4646
#define RTC_BKP_VALUE 0x32F2
4747
#endif
4848

49+
#if defined (HIDBL_F1) || defined (HIDBL_F4)
50+
#if !defined(HID_MAGIC_NUMBER_BKP_INDEX)
51+
#if defined (HIDBL_F1)
52+
#define HID_MAGIC_NUMBER_BKP_INDEX LL_RTC_BKP_DR10
53+
#elif defined (HIDBL_F4)
54+
#define HID_MAGIC_NUMBER_BKP_INDEX 0
55+
#endif
56+
#endif /* HID_MAGIC_NUMBER_BKP_INDEX */
57+
#ifndef HID_MAGIC_NUMBER_BKP_VALUE
58+
#define HID_MAGIC_NUMBER_BKP_VALUE 0x424C
59+
#endif
60+
#endif /* HIDBL_F1 || HIDBL_F4 */
4961

5062
/* Exported functions ------------------------------------------------------- */
5163
static inline void resetBackupDomain(void)

cores/arduino/stm32/usb/cdc/usbd_cdc_if.c

+10-12
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,16 @@ 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')) {
233+
#if defined (HIDBL_F1) || defined (HIDBL_F4)
234+
enableBackupDomain();
232235
#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-
236+
setBackupRegister(HID_MAGIC_NUMBER_BKP_INDEX, HID_MAGIC_NUMBER_BKP_VALUE);
237+
#endif
238+
#if defined (HIDBL_F4)
239+
writeBackupSRAM(HID_MAGIC_NUMBER_BKP_INDEX, &(uint32_t) {
240+
HID_MAGIC_NUMBER_BKP_VALUE
241+
}, 1);
242+
#endif
245243
#endif
246244
HAL_NVIC_SystemReset();
247245
}

0 commit comments

Comments
 (0)