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
 
@@ -56,25 +56,28 @@ uint16_t windup_guard = 1;
 
uint16_t k_p = 1;
 
uint16_t k_i = 1;
 
uint16_t k_d = 1;
 
uint8_t ignore_tc_error  = 0;
 
int16_t setpoint_brew = 0;
 
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. */
 
    HAL_Init();
 
 
    /* Configure the system clock */
 
    SystemClock_Config();
 
 
    /* Initialize all configured peripherals */
 
@@ -510,26 +513,35 @@ void machine()
 
            }
 
 
            // Button handler
 
            if(SW_BTN_PRESSED) {
 
                switch(goto_mode) {
 
                    case 2:
 
                        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++;
 
            }
 
            else if(SW_DOWN_PRESSED && goto_mode > 0) {
 
                goto_mode--;
 
            }
 
 
startup_stm32f042x6.s
Show inline comments
 
@@ -55,31 +55,55 @@ defined in linker script */
 
.word _sdata
 
/* end address for the .data section. defined in linker script */
 
.word _edata
 
/* start address for the .bss section. defined in linker script */
 
.word _sbss
 
/* end address for the .bss section. 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
 
 
LoopCopyDataInit:
 
  ldr r0, =_sdata
 
  ldr r3, =_edata
 
  adds r2, r0, r1
 
  cmp r2, r3
 
  bcc CopyDataInit
0 comments (0 inline, 0 general)