mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 23:05:19 +03:00
G4 system files update
This commit is contained in:
parent
e4d7c4e152
commit
65e8a0dce7
3 changed files with 7 additions and 88 deletions
|
@ -69,10 +69,6 @@ uint32_t getCycleCounter(void);
|
||||||
#if defined(STM32H7) || defined(STM32G4)
|
#if defined(STM32H7) || defined(STM32G4)
|
||||||
void systemCheckResetReason(void);
|
void systemCheckResetReason(void);
|
||||||
#endif
|
#endif
|
||||||
#if defined(STM32G4)
|
|
||||||
void systemBOOT0PinBootLoaderEnable(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void initialiseMemorySections(void);
|
void initialiseMemorySections(void);
|
||||||
|
|
||||||
|
|
|
@ -84,29 +84,11 @@ void systemReset(void)
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void forcedSystemResetWithoutDisablingCaches(void)
|
|
||||||
{
|
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_FORCED);
|
|
||||||
|
|
||||||
__disable_irq();
|
|
||||||
NVIC_SystemReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void systemResetToBootloader(bootloaderRequestType_e requestType)
|
void systemResetToBootloader(bootloaderRequestType_e requestType)
|
||||||
{
|
{
|
||||||
switch (requestType) {
|
UNUSED(requestType);
|
||||||
#if defined(USE_FLASH_BOOT_LOADER)
|
|
||||||
case BOATLOADER_REQUEST_FLASH:
|
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_FLASH_BOOTLOADER_REQUEST);
|
|
||||||
|
|
||||||
break;
|
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_REQUEST_ROM);
|
||||||
#endif
|
|
||||||
case BOOTLOADER_REQUEST_ROM:
|
|
||||||
default:
|
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_REQUEST_ROM);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
|
@ -131,77 +113,21 @@ void systemJumpToBootloader(void)
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t bootloaderRequest;
|
|
||||||
|
|
||||||
void systemCheckResetReason(void)
|
void systemCheckResetReason(void)
|
||||||
{
|
{
|
||||||
bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON);
|
uint32_t bootloaderRequest = persistentObjectRead(PERSISTENT_OBJECT_RESET_REASON);
|
||||||
|
|
||||||
switch (bootloaderRequest) {
|
switch (bootloaderRequest) {
|
||||||
#if defined(USE_FLASH_BOOT_LOADER)
|
|
||||||
case BOATLOADER_REQUEST_FLASH:
|
|
||||||
#endif
|
|
||||||
case RESET_BOOTLOADER_REQUEST_ROM:
|
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_BOOTLOADER_POST);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RESET_MSC_REQUEST:
|
case RESET_MSC_REQUEST:
|
||||||
// RESET_REASON will be reset by MSC
|
// RESET_REASON will be reset by MSC
|
||||||
return;
|
|
||||||
|
|
||||||
case RESET_FORCED:
|
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
|
|
||||||
return;
|
|
||||||
|
|
||||||
case RESET_NONE:
|
case RESET_NONE:
|
||||||
if (!(RCC->CSR & RCC_CSR_SFTRSTF)) {
|
return;
|
||||||
// Direct hard reset case
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Soft reset; boot loader may have been active with BOOT pin pulled high.
|
|
||||||
FALLTHROUGH;
|
|
||||||
|
|
||||||
case RESET_BOOTLOADER_POST:
|
case RESET_BOOTLOADER_REQUEST_ROM:
|
||||||
// Boot loader activity magically prevents SysTick from interrupting.
|
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
|
||||||
// Issue a soft reset to prevent the condition.
|
break;;
|
||||||
forcedSystemResetWithoutDisablingCaches(); // observed that disabling dcache after cold boot with BOOT pin high causes segfault.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*SysMemBootJump)(void);
|
|
||||||
__SYSCFG_CLK_ENABLE();
|
|
||||||
|
|
||||||
systemJumpToBootloader();
|
systemJumpToBootloader();
|
||||||
|
|
||||||
#define SYSTEM_BOOTLOADER_VEC 0x1fff0000
|
|
||||||
|
|
||||||
uint32_t p = (*((uint32_t *)SYSTEM_BOOTLOADER_VEC));
|
|
||||||
__set_MSP(p); //Set the main stack pointer to its defualt values
|
|
||||||
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(SYSTEM_BOOTLOADER_VEC + 4))); // Point the PC to the System Memory reset vector (+4)
|
|
||||||
SysMemBootJump();
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nucleo-G474RE board seems to come with software BOOT0 enabled.
|
|
||||||
// Call this function once from init() to honor PB8-BOOT0 pin status for boot loader invocation.
|
|
||||||
void systemBOOT0PinBootLoaderEnable(void)
|
|
||||||
{
|
|
||||||
FLASH_OBProgramInitTypeDef OBInit;
|
|
||||||
|
|
||||||
HAL_FLASH_Unlock();
|
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
|
||||||
HAL_FLASH_OB_Unlock();
|
|
||||||
|
|
||||||
HAL_FLASHEx_OBGetConfig(&OBInit);
|
|
||||||
|
|
||||||
if ((OBInit.USERConfig & (OB_BOOT0_FROM_PIN|OB_BOOT1_SYSTEM)) != (OB_BOOT0_FROM_PIN|OB_BOOT1_SYSTEM)) {
|
|
||||||
OBInit.OptionType = OPTIONBYTE_USER;
|
|
||||||
OBInit.USERType = OB_USER_nSWBOOT0|OB_USER_nBOOT1;
|
|
||||||
OBInit.USERConfig = OB_BOOT0_FROM_PIN|OB_BOOT1_SYSTEM;
|
|
||||||
HAL_FLASHEx_OBProgram(&OBInit);
|
|
||||||
|
|
||||||
HAL_FLASH_OB_Launch();
|
|
||||||
}
|
|
||||||
|
|
||||||
HAL_FLASH_OB_Lock();
|
|
||||||
HAL_FLASH_Lock();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,9 +77,6 @@ void SystemInit(void)
|
||||||
|
|
||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
SystemCoreClockUpdate();
|
SystemCoreClockUpdate();
|
||||||
|
|
||||||
// Enable BOOT0 pin, which some STM32G4 board, notably Nucleo-G474RE, comes disabled.
|
|
||||||
systemBOOT0PinBootLoaderEnable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue