Skip to content

Commit

Permalink
implement generic jump to bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm committed Feb 1, 2024
1 parent 3a65027 commit a53ec5b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,44 @@ static uint8_t i2c_buffer[128];

static uint8_t ADDRESS;

void JumpToBootloader (void)
{
uint32_t i=0;
void (*SysMemBootJump)(void);

uint32_t BootAddr = 0x1FFF0000;

/* Disable all interrupts */
__disable_irq();
/* Disable Systick timer */
SysTick->CTRL = 0;
/* Set the clock to the default state */
HAL_RCC_DeInit();

/* Clear Interrupt Enable Register & Interrupt Pending Register */
for (i=0;i<5;i++)
{
NVIC->ICER[i]=0xFFFFFFFF;
NVIC->ICPR[i]=0xFFFFFFFF;
}

/* Re-enable all interrupts */
__enable_irq();
/* Set up the jump to boot loader address + 4 */
SysMemBootJump = (void (*)(void)) (*((uint32_t *) ((BootAddr + 4))));

/* Set the main stack pointer to the boot loader stack */
__set_MSP(*(uint32_t *)BootAddr);
/* Call the function to jump to boot loader location */
SysMemBootJump();

/* Jump is done successfully */
while (1)
{
/* Code should never reach this loop */
}
}

/**
* @brief The application entry point.
* @retval int
Expand Down Expand Up @@ -83,6 +121,11 @@ int main(void)
}

if (dataReceived) {

if (i2c_buffer[0] == 'D' && i2c_buffer[1] == 'I' && i2c_buffer[2] == 'E') {
JumpToBootloader();
}

switch (ADDRESS) {
case NODE_BUTTONS:
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, i2c_buffer[0] == 0 ? GPIO_PIN_RESET: GPIO_PIN_SET);
Expand Down

0 comments on commit a53ec5b

Please sign in to comment.