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.
This commit is contained in:
Doug Brown 2023-05-28 11:07:24 -07:00 committed by Doug Brown
parent 8aec8807c9
commit 14cf8505f7
3 changed files with 27 additions and 16 deletions

View File

@ -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_ */

View File

@ -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);

View File

@ -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: