stm32: stm32g0/h7 usb_dfu_bootloader support (#5596)
Signed-off-by: Alan.Ma from BigTreeTech <tech@biqu3d.com>
This commit is contained in:
parent
167736ad1c
commit
1636a9759b
|
@ -339,7 +339,8 @@ MCUTYPES = {
|
||||||
'sam3': flash_atsam3, 'sam4': flash_atsam4, 'samd': flash_atsamd,
|
'sam3': flash_atsam3, 'sam4': flash_atsam4, 'samd': flash_atsamd,
|
||||||
'same70': flash_atsam4, 'lpc176': flash_lpc176x, 'stm32f103': flash_stm32f1,
|
'same70': flash_atsam4, 'lpc176': flash_lpc176x, 'stm32f103': flash_stm32f1,
|
||||||
'stm32f4': flash_stm32f4, 'stm32f042': flash_stm32f4,
|
'stm32f4': flash_stm32f4, 'stm32f042': flash_stm32f4,
|
||||||
'stm32f072': flash_stm32f4, 'rp2040': flash_rp2040
|
'stm32f072': flash_stm32f4, 'stm32g0b1': flash_stm32f4,
|
||||||
|
'stm32h7': flash_stm32f4, 'rp2040': flash_rp2040
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,6 @@ usb_request_bootloader(void)
|
||||||
void
|
void
|
||||||
armcm_main(void)
|
armcm_main(void)
|
||||||
{
|
{
|
||||||
check_usb_dfu_bootloader();
|
|
||||||
SCB->VTOR = (uint32_t)VectorTable;
|
SCB->VTOR = (uint32_t)VectorTable;
|
||||||
|
|
||||||
// Reset clock registers (in case bootloader has changed them)
|
// Reset clock registers (in case bootloader has changed them)
|
||||||
|
@ -164,6 +163,8 @@ armcm_main(void)
|
||||||
RCC->APBENR1 = 0x00000000;
|
RCC->APBENR1 = 0x00000000;
|
||||||
RCC->APBENR2 = 0x00000000;
|
RCC->APBENR2 = 0x00000000;
|
||||||
|
|
||||||
|
check_usb_dfu_bootloader();
|
||||||
|
|
||||||
// Set flash latency
|
// Set flash latency
|
||||||
FLASH->ACR = (2<<FLASH_ACR_LATENCY_Pos) | FLASH_ACR_ICEN | FLASH_ACR_PRFTEN;
|
FLASH->ACR = (2<<FLASH_ACR_LATENCY_Pos) | FLASH_ACR_ICEN | FLASH_ACR_PRFTEN;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "autoconf.h" // CONFIG_CLOCK_REF_FREQ
|
#include "autoconf.h" // CONFIG_CLOCK_REF_FREQ
|
||||||
#include "board/armcm_boot.h" // VectorTable
|
#include "board/armcm_boot.h" // VectorTable
|
||||||
|
#include "board/irq.h" // irq_disable
|
||||||
#include "board/armcm_reset.h" // try_request_canboot
|
#include "board/armcm_reset.h" // try_request_canboot
|
||||||
#include "command.h" // DECL_CONSTANT_STR
|
#include "command.h" // DECL_CONSTANT_STR
|
||||||
#include "internal.h" // get_pclock_frequency
|
#include "internal.h" // get_pclock_frequency
|
||||||
|
@ -187,11 +188,36 @@ clock_setup(void)
|
||||||
* USB bootloader
|
* USB bootloader
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
|
#define USB_BOOT_FLAG_ADDR (CONFIG_RAM_START + CONFIG_RAM_SIZE - 1024)
|
||||||
|
#define USB_BOOT_FLAG 0x55534220424f4f54 // "USB BOOT"
|
||||||
|
|
||||||
|
// Flag that bootloader is desired and reboot
|
||||||
|
static void
|
||||||
|
usb_reboot_for_dfu_bootloader(void)
|
||||||
|
{
|
||||||
|
irq_disable();
|
||||||
|
*(uint64_t*)USB_BOOT_FLAG_ADDR = USB_BOOT_FLAG;
|
||||||
|
NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if rebooting into system DFU Bootloader
|
||||||
|
static void
|
||||||
|
check_usb_dfu_bootloader(void)
|
||||||
|
{
|
||||||
|
if (!CONFIG_USBSERIAL || *(uint64_t*)USB_BOOT_FLAG_ADDR != USB_BOOT_FLAG)
|
||||||
|
return;
|
||||||
|
*(uint64_t*)USB_BOOT_FLAG_ADDR = 0;
|
||||||
|
uint32_t *sysbase = (uint32_t*)0x1FF09800;
|
||||||
|
asm volatile("mov sp, %0\n bx %1"
|
||||||
|
: : "r"(sysbase[0]), "r"(sysbase[1]));
|
||||||
|
}
|
||||||
|
|
||||||
// Handle USB reboot requests
|
// Handle USB reboot requests
|
||||||
void
|
void
|
||||||
usb_request_bootloader(void)
|
usb_request_bootloader(void)
|
||||||
{
|
{
|
||||||
try_request_canboot();
|
try_request_canboot();
|
||||||
|
usb_reboot_for_dfu_bootloader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,8 +231,14 @@ armcm_main(void)
|
||||||
{
|
{
|
||||||
// Run SystemInit() and then restore VTOR
|
// Run SystemInit() and then restore VTOR
|
||||||
SystemInit();
|
SystemInit();
|
||||||
|
RCC->D1CCIPR = 0x00000000;
|
||||||
|
RCC->D2CCIP1R = 0x00000000;
|
||||||
|
RCC->D2CCIP2R = 0x00000000;
|
||||||
|
RCC->D3CCIPR = 0x00000000;
|
||||||
SCB->VTOR = (uint32_t)VectorTable;
|
SCB->VTOR = (uint32_t)VectorTable;
|
||||||
|
|
||||||
|
check_usb_dfu_bootloader();
|
||||||
|
|
||||||
clock_setup();
|
clock_setup();
|
||||||
|
|
||||||
sched_main();
|
sched_main();
|
||||||
|
|
Loading…
Reference in New Issue