Changeset - c14060ecae42
[Not reviewed]
cortex-f0
0 2 0
Ethan Zonca - 10 years ago 2015-01-24 16:19:18
ez@ethanzonca.com
Added initial prototype of jump-to-bootloader
2 files changed with 38 insertions and 2 deletions:
0 comments (0 inline, 0 general)
main.c
Show inline comments
 
@@ -62,13 +62,16 @@ int16_t setpoint_steam = 0;
 
 
SPI_HandleTypeDef hspi1;
 
 
static __IO uint32_t TimingDelay;
 
 
 
 
void deinit(void)
 
{
 
    HAL_DeInit();
 
}
 
 
volatile int i=0;
 
int main(void)
 
{
 
 
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 
@@ -516,14 +519,23 @@ void machine()
 
                        state = STATE_PREHEAT_BREW;
 
                        break;
 
                    case 1:
 
                        state = STATE_SETP;
 
                        break;
 
                    case 0:
 
                    {
 
                        ssd1306_clearscreen();
 
                        ssd1306_DrawString("Entering Bootloader", 1, 0);
 
                        ssd1306_DrawString("(hopefully)", 2, 0);
 
                        HAL_Delay(1000);
 
                        *((unsigned long *)0x200017F0) = 0xDEADBEEF; // 6KB STM32F042
 
                        NVIC_SystemReset();
 
 
                        state = STATE_IDLE;
 
                        break;
 
                    } break;
 
 
                    default:
 
                        state = STATE_PREHEAT_BREW;
 
                }
 
            }
 
            else if(SW_UP_PRESSED && goto_mode < 2) {
 
                goto_mode++;
startup_stm32f042x6.s
Show inline comments
 
@@ -61,19 +61,43 @@ defined in linker script */
 
.word _ebss
 
 
  .section .text.Reset_Handler
 
  .weak Reset_Handler
 
  .type Reset_Handler, %function
 
Reset_Handler:
 
 
  /* Bootloader jumping */
 
  ldr r0, =0x200017F0 /* address of magic token, is addr within memory range? */
 
  ldr r1, =0xDEADBEEF /* magical beef token */
 
  ldr r2, [r0, #0] /* load data from magic address */
 
  str r0, [r0, #0] /* zero data at magic address so we don't bootloop */ 
 
  cmp r2, r1 /* compare data at magic address to magic token */
 
  beq Reboot_Loader /* jump to bootloader if token match */
 
  /* End bootloader jumping */
 
 
 
  ldr   r0, =_estack
 
  mov   sp, r0          /* set stack pointer */
 
 
/* Copy the data segment initializers from flash to SRAM */
 
  movs r1, #0
 
  b LoopCopyDataInit
 
 
/* Boot into bootloader */
 
Reboot_Loader:
 
  ldr r0, =0x1FFFF6A6 /* Address of bootloader on f042 from CD00167594 pg 15 table 3 */
 
  /* This replaces ldr sp, [r0, #0] which doesn't work on m0 */
 
  // Set stack pointer
 
  ldr r1, [r0, #0]
 
  mov sp, r1
 
 
  // Branch to bootloader
 
  ldr r0, [r0, #4]
 
  bx r0
 
 
 
CopyDataInit:
 
  ldr r3, =_sidata
 
  ldr r3, [r3, r1]
 
  str r3, [r0, r1]
 
  adds r1, r1, #4
 
0 comments (0 inline, 0 general)