From 14cf8505f703283fd5996ee8d776c15f61a651e7 Mon Sep 17 00:00:00 2001 From: Doug Brown Date: Sun, 28 May 2023 11:07:24 -0700 Subject: [PATCH] Break out bootloader entry into HAL For some reason, I didn't have this as part of the HAL, so the main program still had AVR dependencies. --- hal/at90usb646/board_hw.h | 24 ++++++++++++++++++++++++ hal/board.h | 1 + simm_programmer.c | 18 ++---------------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/hal/at90usb646/board_hw.h b/hal/at90usb646/board_hw.h index e392177..8050bb2 100644 --- a/hal/at90usb646/board_hw.h +++ b/hal/at90usb646/board_hw.h @@ -27,6 +27,8 @@ #include "gpio_hw.h" #include "../gpio.h" +#include "hardware.h" +#include "../usbcdc.h" /** Gets the GPIO pin on the board that controls the status LED * @@ -37,4 +39,26 @@ static inline GPIOPin Board_LEDPin(void) return GPIO_PIN(GPIOD, 7); } +/** Jumps to the bootloader + * + */ +static inline void Board_EnterBootloader(void) +{ + // Insert a small delay to ensure that it arrives before rebooting. + DelayMS(1000); + + // Done with the USB interface -- the bootloader will re-initialize it. + USBCDC_Disable(); + + // Disable interrupts so nothing weird happens... + DisableInterrupts(); + + // Wait a little bit to let everything settle and let the program + // close the port after the USB disconnect + DelayMS(2000); + + // And, of course, go into the bootloader. + __asm__ __volatile__ ( "jmp 0xE000" ); +} + #endif /* HAL_AT90USB646_BOARD_HW_H_ */ diff --git a/hal/board.h b/hal/board.h index 6d77f82..103a4be 100644 --- a/hal/board.h +++ b/hal/board.h @@ -30,6 +30,7 @@ // Commented-out functions should be static inline in each board-specific header file. //GPIOPin Board_LEDPin(void); +//void Board_EnterBootloader(void); #include "board_hw.h" void Board_Init(void); diff --git a/simm_programmer.c b/simm_programmer.c index 06600af..f8cf2aa 100644 --- a/simm_programmer.c +++ b/simm_programmer.c @@ -229,22 +229,8 @@ static void SIMMProgrammer_HandleWaitingForCommandByte(uint8_t byte) USBCDC_SendByte(CommandReplyOK); // Force this to be sent immediately so the programmer software knows. USBCDC_Flush(); - - // Insert a small delay to ensure that it arrives before rebooting. - DelayMS(1000); - - // Done with the USB interface -- the bootloader will re-initialize it. - USBCDC_Disable(); - - // Disable interrupts so nothing weird happens... - cli(); - - // Wait a little bit to let everything settle and let the program - // close the port after the USB disconnect - DelayMS(2000); - - // And, of course, go into the bootloader. - __asm__ __volatile__ ( "jmp 0xE000" ); + // Now enter the bootloader + Board_EnterBootloader(); break; // Enter the programmer. We're already there, so reply OK. case EnterProgrammer: