File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,44 @@ static uint8_t i2c_buffer[128];
4949
5050static uint8_t ADDRESS ;
5151
52+ void JumpToBootloader (void )
53+ {
54+ uint32_t i = 0 ;
55+ void (* SysMemBootJump )(void );
56+
57+ uint32_t BootAddr = 0x1FFF0000 ;
58+
59+ /* Disable all interrupts */
60+ __disable_irq ();
61+ /* Disable Systick timer */
62+ SysTick -> CTRL = 0 ;
63+ /* Set the clock to the default state */
64+ HAL_RCC_DeInit ();
65+
66+ /* Clear Interrupt Enable Register & Interrupt Pending Register */
67+ for (i = 0 ;i < 5 ;i ++ )
68+ {
69+ NVIC -> ICER [i ]= 0xFFFFFFFF ;
70+ NVIC -> ICPR [i ]= 0xFFFFFFFF ;
71+ }
72+
73+ /* Re-enable all interrupts */
74+ __enable_irq ();
75+ /* Set up the jump to boot loader address + 4 */
76+ SysMemBootJump = (void (* )(void )) (* ((uint32_t * ) ((BootAddr + 4 ))));
77+
78+ /* Set the main stack pointer to the boot loader stack */
79+ __set_MSP (* (uint32_t * )BootAddr );
80+ /* Call the function to jump to boot loader location */
81+ SysMemBootJump ();
82+
83+ /* Jump is done successfully */
84+ while (1 )
85+ {
86+ /* Code should never reach this loop */
87+ }
88+ }
89+
5290/**
5391 * @brief The application entry point.
5492 * @retval int
@@ -83,6 +121,11 @@ int main(void)
83121 }
84122
85123 if (dataReceived ) {
124+
125+ if (i2c_buffer [0 ] == 'D' && i2c_buffer [1 ] == 'I' && i2c_buffer [2 ] == 'E' ) {
126+ JumpToBootloader ();
127+ }
128+
86129 switch (ADDRESS ) {
87130 case NODE_BUTTONS :
88131 HAL_GPIO_WritePin (GPIOA , GPIO_PIN_0 , i2c_buffer [0 ] == 0 ? GPIO_PIN_RESET : GPIO_PIN_SET );
You can’t perform that action at this time.
0 commit comments