2
2
3
3
#include "stm32_def.h"
4
4
#include "backup.h"
5
+ #include "usbd_if.h"
5
6
6
7
#ifdef BL_LEGACY_LEAF
7
8
void dtr_togglingHook (uint8_t * buf , uint32_t * len )
@@ -37,3 +38,60 @@ void dtr_togglingHook(uint8_t *buf, uint32_t *len)
37
38
}
38
39
}
39
40
#endif /* BL_HID */
41
+
42
+ /* Request to jump to system memory boot */
43
+ void jumpToBootloaderRequested (void )
44
+ {
45
+ enableBackupDomain ();
46
+ setBackupRegister (SYSBL_MAGIC_NUMBER_BKP_INDEX , SYSBL_MAGIC_NUMBER_BKP_VALUE );
47
+ NVIC_SystemReset ();
48
+ }
49
+
50
+ /* Jump to system memory boot from user application */
51
+ void jumpToBootloader (void )
52
+ {
53
+ enableBackupDomain ();
54
+ if (getBackupRegister (SYSBL_MAGIC_NUMBER_BKP_INDEX ) == SYSBL_MAGIC_NUMBER_BKP_VALUE ) {
55
+ setBackupRegister (SYSBL_MAGIC_NUMBER_BKP_INDEX , 0 );
56
+
57
+ #ifdef USBCON
58
+ USBD_reenumerate ();
59
+ #endif
60
+ void (* sysMemBootJump )(void );
61
+
62
+ /**
63
+ * Get system memory address
64
+ *
65
+ * Available in AN2606 document:
66
+ * Table 116. Bootloader device-dependent parameters
67
+ */
68
+ volatile uint32_t sysMem_addr = 0x1FFF0000 ;
69
+
70
+ /* Remap system Flash memory at address 0x00000000 */
71
+ __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH ();
72
+
73
+ /**
74
+ * Set jump memory location for system memory
75
+ * Use address with 4 bytes offset which specifies jump location
76
+ * where program starts
77
+ */
78
+ sysMemBootJump = (void (* )(void ))(* ((uint32_t * )(sysMem_addr + 4 )));
79
+
80
+ /**
81
+ * Set main stack pointer.
82
+ * This step must be done last otherwise local variables in this function
83
+ * don't have proper value since stack pointer is located on different position
84
+ *
85
+ * Set direct address location which specifies stack pointer in SRAM location
86
+ */
87
+ __set_MSP (* (uint32_t * )sysMem_addr );
88
+
89
+ /**
90
+ * Jump to set location
91
+ * This will start system memory execution
92
+ */
93
+ sysMemBootJump ();
94
+
95
+ while (1 );
96
+ }
97
+ }
0 commit comments