/* This file was generated by the Hex-Rays decompiler version 9.3.0.260213. Copyright (c) 2007-2025 Hex-Rays Detected compiler: GNU C++ */ #include //------------------------------------------------------------------------- // Function declarations void __noreturn Reset_Handler(); void __noreturn loop0(); void __noreturn loop1(); void *_user_initial_stackheap(); void ReadChipID(); // idb void EraseSector(); // idb void EraseAll(); // idb void Program(); // idb void NVIC_Configuration(); // idb void RCC_Configuration(); // idb void Flash_Init(); // idb void Main(); // idb int __fastcall BlankCheck(unsigned int targetAddr, unsigned int targetSize); int __fastcall Verification(unsigned int targetAddr, unsigned int limit, unsigned int srcAddr); void __fastcall FLASH_SetLatency(u32 FLASH_Latency); void __fastcall FLASH_HalfCycleAccessCmd(u32 FLASH_HalfCycleAccess); void __fastcall FLASH_PrefetchBufferCmd(u32 FLASH_PrefetchBuffer); void FLASH_Unlock(); // idb void FLASH_Lock(); // idb int FLASH_GetStatus(); void delay(); // idb FLASH_Status __fastcall FLASH_WaitForLastOperation(u32 Timeout); FLASH_Status __fastcall FLASH_ErasePage(u32 Page_Address); int FLASH_EraseAllPages(); FLASH_Status __fastcall FLASH_ProgramHalfWord(u32 targetP, u16 *srcP); void FLASH_GetReadOutProtectionStatus(); // idb void __fastcall FLASH_GetFlagStatus(u16 FLASH_FLAG); void __fastcall FLASH_ClearFlag(u16 FLASH_FLAG); void RCC_DeInit(); // idb void __fastcall RCC_HSEConfig(u32 RCC_HSE); void __fastcall RCC_GetFlagStatus(u8 RCC_FLAG); bool RCC_WaitForHSEStartUp(); void __fastcall RCC_AdjustHSICalibrationValue(u8 HSICalibrationValue); void __fastcall RCC_HSICmd(FunctionalState NewState); void __fastcall RCC_PLLConfig(u32 RCC_PLLSource, u32 RCC_PLLMul); void __fastcall RCC_PLLCmd(FunctionalState NewState); void __fastcall RCC_SYSCLKConfig(u32 RCC_SYSCLKSource); int RCC_GetSYSCLKSource(); void __fastcall RCC_HCLKConfig(u32 RCC_HCLK); void __fastcall RCC_PCLK1Config(u32 RCC_PCLK1); void __fastcall RCC_PCLK2Config(u32 RCC_PCLK2); void __fastcall RCC_ITConfig(u8 RCC_IT, FunctionalState NewState); void __fastcall RCC_USBCLKConfig(u32 RCC_USBCLKSource); void __fastcall RCC_ADCCLKConfig(u32 RCC_ADCCLK); void __fastcall RCC_LSEConfig(u32 RCC_LSE); void __fastcall RCC_LSICmd(FunctionalState NewState); void __fastcall RCC_RTCCLKConfig(u32 RCC_RTCCLKSource); void __fastcall RCC_RTCCLKCmd(FunctionalState NewState); void __fastcall RCC_GetClocksFreq(RCC_ClocksTypeDef *RCC_Clocks); void __fastcall RCC_AHBPeriphClockCmd(u32 RCC_AHBPeriph, FunctionalState NewState); void __fastcall RCC_APB2PeriphClockCmd(u32 RCC_APB2Periph, FunctionalState NewState); void __fastcall RCC_APB1PeriphClockCmd(u32 RCC_APB1Periph, FunctionalState NewState); void __fastcall RCC_APB2PeriphResetCmd(u32 RCC_APB2Periph, FunctionalState NewState); void __fastcall RCC_APB1PeriphResetCmd(u32 RCC_APB1Periph, FunctionalState NewState); void __fastcall RCC_BackupResetCmd(FunctionalState NewState); void __fastcall RCC_ClockSecuritySystemCmd(FunctionalState NewState); void __fastcall RCC_MCOConfig(u8 RCC_MCO); void RCC_ClearFlag(); // idb ITStatus __fastcall RCC_GetITStatus(u8 RCC_IT); void __fastcall RCC_ClearITPendingBit(u8 RCC_IT); void NVIC_DeInit(); // idb void NVIC_SCBDeInit(); // idb void __fastcall NVIC_PriorityGroupConfig(u32 NVIC_PriorityGroup); void __fastcall NVIC_Init(NVIC_InitTypeDef *NVIC_InitStruct); void __fastcall NVIC_StructInit(NVIC_InitTypeDef *NVIC_InitStruct); void NVIC_SETPRIMASK(); // idb void NVIC_RESETPRIMASK(); // idb void NVIC_SETFAULTMASK(); // idb void NVIC_RESETFAULTMASK(); // idb void __fastcall NVIC_BASEPRICONFIG(u32 NewPriority); u32 NVIC_GetBASEPRI(); // idb int NVIC_GetCurrentPendingIRQChannel(); ITStatus __fastcall NVIC_GetIRQChannelPendingBitStatus(u8 NVIC_IRQChannel); void __fastcall NVIC_SetIRQChannelPendingBit(u8 NVIC_IRQChannel); void __fastcall NVIC_ClearIRQChannelPendingBit(u8 NVIC_IRQChannel); int NVIC_GetCurrentActiveHandler(); ITStatus __fastcall NVIC_GetIRQChannelActiveBitStatus(u8 NVIC_IRQChannel); u32 NVIC_GetCPUID(); // idb void __fastcall NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset); void NVIC_GenerateSystemReset(); // idb void NVIC_GenerateCoreReset(); // idb void __fastcall NVIC_SystemLPConfig(u8 LowPowerMode, FunctionalState NewState); void __fastcall NVIC_SystemHandlerConfig(u32 SystemHandler, FunctionalState NewState); void __fastcall NVIC_SystemHandlerPriorityConfig(u32 SystemHandler, u8 SystemHandlerPreemptionPriority, u8 SystemHandlerSubPriority); ITStatus __fastcall NVIC_GetSystemHandlerPendingBitStatus(u32 SystemHandler); void __fastcall NVIC_SetSystemHandlerPendingBit(u32 SystemHandler); void __fastcall NVIC_ClearSystemHandlerPendingBit(u32 SystemHandler); ITStatus __fastcall NVIC_GetSystemHandlerActiveBitStatus(u32 SystemHandler); u32 __fastcall NVIC_GetFaultHandlerSources(u32 SystemHandler); u32 __fastcall NVIC_GetFaultAddress(u32 SystemHandler); void _WFI(); void _WFE(); void _SEV(); void _ISB(); void _DSB(); void _DMB(); void _SVC(); unsigned int _MRS_CONTROL(); int __fastcall _MSR_CONTROL(int result); unsigned int _MRS_PSP(); int __fastcall _MSR_PSP(int result); unsigned int _MRS_MSP(); int __fastcall _MSR_MSP(int result); void _SETPRIMASK(); void _RESETPRIMASK(); void _SETFAULTMASK(); void _RESETFAULTMASK(); int __fastcall _BASEPRICONFIG(int result); unsigned int _GetBASEPRI(); unsigned int __fastcall _REV_HalfWord(unsigned int a1); unsigned int __fastcall _REV_Word(unsigned int a1); void _use_two_region_memory(); __int64 _rt_stackheap_init_2region(); int _rt_heap_extend_2region(); int _user_setup_stackheap(); void *_rt_stackheap_storage(); void *_user_libspace(); //------------------------------------------------------------------------- // Data declarations uc8 APBAHBPrescTable[16] = { 0u, 0u, 0u, 0u, 1u, 2u, 3u, 4u, 1u, 2u, 3u, 4u, 6u, 7u, 8u, 9u }; // idb uc8 ADCPrescTable[4] = { 2u, 4u, 6u, 8u }; // idb u32 EraseCounter = 0u; // idb vu32 NbrOfPage = 0u; // idb volatile FLASH_Status FLASHStatus = 0; // idb volatile TestStatus MemoryProgramStatus = FAILED; // idb ErrorStatus HSEStartUpStatus = ERROR; // idb volatile FLASH_INFO Flash_Info; // idb _UNKNOWN _libspace_start; // weak _UNKNOWN unk_20002F30; // weak _UNKNOWN Heap_Mem; // weak int RCC_CR; // weak int RCC_CFGR; // weak int RCC_CIR; // weak int RCC_APB2RSTR; // weak int RCC_APB1RSTR; // weak int RCC_AHBENR; // weak int RCC_APB2ENR; // weak int RCC_APB1ENR; // weak int RCC_BDCR; // weak int RCC_CSR; // weak int FLASH_ACR; // weak int FLASH_KEYR; // weak int FLASH_SR; // weak int FLASH_CR; // weak int FLASH_AR; // weak int NVIC_ICER0[]; // weak int NVIC_ICER1; // weak int NVIC_ISPR0[]; // weak int NVIC_ICPR0[]; // weak int NVIC_ICPR1; // weak int NVIC_IABR0[]; // weak _UNKNOWN unk_E000ED00; // weak _UNKNOWN unk_E000ED04; // weak _UNKNOWN unk_E000ED08; // weak _UNKNOWN unk_E000ED0C; // weak _UNKNOWN unk_E000ED10; // weak _UNKNOWN unk_E000ED14; // weak _DWORD dword_E000ED18[122]; // weak int NVIC_STIR; // weak //----- (20000000) -------------------------------------------------------- void __noreturn Reset_Handler() { Main(); __breakpoint(0); __breakpoint(0); __breakpoint(0); __breakpoint(0); loop0(); } //----- (20000014) -------------------------------------------------------- void __noreturn loop0() { while ( 1 ) ; } //----- (20000018) -------------------------------------------------------- void __noreturn loop1() { while ( 1 ) ; } //----- (2000001C) -------------------------------------------------------- void *_user_initial_stackheap() { return &Heap_Mem; } //----- (2000003C) -------------------------------------------------------- void ReadChipID() { Flash_Info.Result = 1; } //----- (20000044) -------------------------------------------------------- void EraseSector() { vu32 i; // r4 int v1; // r0 Flash_Info.Result = 0; for ( i = 0; NbrOfPage - 1 > i && ((i + 1) << 10) + 0x8000000 <= Flash_Info.TargetAddr; ++i ) ; while ( NbrOfPage - 1 > i && FLASHStatus == FLASH_COMPLETE && Flash_Info.TargetAddr + Flash_Info.Length > (i << 10) + 0x8000000 ) { v1 = FLASH_ErasePage((i << 10) + 0x8000000); FLASHStatus = (char)v1; if ( !v1 ) return; ++i; } Flash_Info.Result = 1; } //----- (200000BC) -------------------------------------------------------- void EraseAll() { for ( EraseCounter = 0; EraseCounter < NbrOfPage && FLASHStatus == FLASH_COMPLETE; ++EraseCounter ) FLASHStatus = FLASH_ErasePage((EraseCounter << 10) + 0x8000000); Flash_Info.Result = 1; } //----- (200000FE) -------------------------------------------------------- void Program() { u32 TargetAddr; // r4 u16 *Buf; // r5 u32 i; // r6 TargetAddr = Flash_Info.TargetAddr; Buf = (u16 *)Flash_Info.Buf; for ( i = 0; Flash_Info.Length > i; i += 2 ) { FLASHStatus = FLASH_ProgramHalfWord(TargetAddr, Buf); TargetAddr += 2; ++Buf; } Flash_Info.Result = 1; } //----- (2000012E) -------------------------------------------------------- void NVIC_Configuration() { NVIC_SetVectorTable(0x8000000u, 0); } //----- (2000013C) -------------------------------------------------------- void RCC_Configuration() { int v0; // r0 RCC_DeInit(); RCC_HSEConfig(0x10000u); HSEStartUpStatus = RCC_WaitForHSEStartUp(); if ( HSEStartUpStatus == SUCCESS ) { RCC_HCLKConfig(0); RCC_PCLK2Config(0); RCC_PCLK1Config(0x400u); FLASH_SetLatency(2u); FLASH_PrefetchBufferCmd(0x10u); RCC_PLLConfig(0x10000u, 0x1C0000u); RCC_PLLCmd(ENABLE); do RCC_GetFlagStatus(0x39u); while ( !v0 ); RCC_SYSCLKConfig(2u); while ( RCC_GetSYSCLKSource() != 8 ) ; } } // 20000196: variable 'v0' is possibly undefined //----- (200001AA) -------------------------------------------------------- void Flash_Init() { FLASHStatus = FLASH_COMPLETE; MemoryProgramStatus = PASSED; RCC_Configuration(); NVIC_Configuration(); FLASH_Unlock(); NbrOfPage = 128; FLASH_ClearFlag(0x35u); } //----- (200001D2) -------------------------------------------------------- void Main() { Flash_Init(); if ( Flash_Info.Command ) { switch ( Flash_Info.Command ) { case 1u: EraseAll(); break; case 2u: EraseSector(); break; case 3u: ReadChipID(); break; default: Flash_Info.Result = 0; break; } } else { Program(); } } //----- (2000020E) -------------------------------------------------------- int __fastcall BlankCheck(unsigned int targetAddr, unsigned int targetSize) { unsigned int i; // r3 int v4; // r0 for ( i = 0; i < targetSize; i += 4 ) { v4 = *(_DWORD *)targetAddr; targetAddr += 4; if ( v4 != -1 ) return 0; } return 1; } //----- (2000022E) -------------------------------------------------------- int __fastcall Verification(unsigned int targetAddr, unsigned int limit, unsigned int srcAddr) { unsigned int i; // r6 int v6; // r0 int v7; // r7 for ( i = 0; i < limit; i += 4 ) { v6 = *(_DWORD *)targetAddr; targetAddr += 4; v7 = *(_DWORD *)srcAddr; srcAddr += 4; if ( v6 != v7 ) return 0; } return 1; } //----- (2000026C) -------------------------------------------------------- void __fastcall FLASH_SetLatency(u32 FLASH_Latency) { char v1; // r1 v1 = FLASH_ACR; FLASH_ACR = v1 & 0x38; FLASH_ACR = v1 & 0x38 | FLASH_Latency; } // 40022000: using guessed type int FLASH_ACR; //----- (20000282) -------------------------------------------------------- void __fastcall FLASH_HalfCycleAccessCmd(u32 FLASH_HalfCycleAccess) { int v1; // r1 v1 = FLASH_ACR; FLASH_ACR = v1 & 0xFFFFFFF7; FLASH_ACR = v1 & 0xFFFFFFF7 | FLASH_HalfCycleAccess; } // 40022000: using guessed type int FLASH_ACR; //----- (20000298) -------------------------------------------------------- void __fastcall FLASH_PrefetchBufferCmd(u32 FLASH_PrefetchBuffer) { int v1; // r1 v1 = FLASH_ACR; FLASH_ACR = v1 & 0xFFFFFFEF; FLASH_ACR = v1 & 0xFFFFFFEF | FLASH_PrefetchBuffer; } // 40022000: using guessed type int FLASH_ACR; //----- (200002AE) -------------------------------------------------------- void FLASH_Unlock() { FLASH_KEYR = 1164378403; FLASH_KEYR = -839939669; } // 40022004: using guessed type int FLASH_KEYR; //----- (200002BA) -------------------------------------------------------- void FLASH_Lock() { int v0; // r0 v0 = FLASH_CR; FLASH_CR = v0 | 0x80; } // 40022010: using guessed type int FLASH_CR; //----- (200002C8) -------------------------------------------------------- int FLASH_GetStatus() { char v0; // r1 char v2; // r1 char v3; // r1 v0 = FLASH_SR; if ( (v0 & 1) == 1 ) return 1; v2 = FLASH_SR; if ( (v2 & 4) != 0 ) return 2; v3 = FLASH_SR; if ( (v3 & 0x10) != 0 ) return 3; else return 4; } // 4002200C: using guessed type int FLASH_SR; //----- (200002FA) -------------------------------------------------------- void delay() { int i; // r0 for ( i = 4095; i; --i ) ; } //----- (2000030A) -------------------------------------------------------- FLASH_Status __fastcall FLASH_WaitForLastOperation(u32 Timeout) { int v1; // r2 int Status; // r3 int v3; // r2 Status = FLASH_GetStatus(); while ( Status == 1 && v1 ) { delay(); Status = FLASH_GetStatus(); v1 = v3 - 1; } if ( !v1 ) LOBYTE(Status) = 5; return (char)Status; } // 20000322: variable 'v3' is possibly undefined // 2000032A: variable 'v1' is possibly undefined //----- (20000334) -------------------------------------------------------- FLASH_Status __fastcall FLASH_ErasePage(u32 Page_Address) { int Operation; // r5 int v3; // r0 __int16 v4; // r0 Operation = FLASH_WaitForLastOperation(0xFFFu); if ( Operation == 4 ) { v3 = FLASH_CR; FLASH_CR = v3 | 2; FLASH_AR = Page_Address; FLASH_CR = v3 | 0x42; Operation = FLASH_WaitForLastOperation(0xFFFu); if ( Operation != 1 ) { v4 = FLASH_CR; FLASH_CR = v4 & 0x1FFD; } } return (char)Operation; } // 40022010: using guessed type int FLASH_CR; // 40022014: using guessed type int FLASH_AR; //----- (20000380) -------------------------------------------------------- int FLASH_EraseAllPages() { int Operation; // r4 int v1; // r0 __int16 v2; // r0 Operation = FLASH_WaitForLastOperation(0xFFFu); if ( Operation == 4 ) { v1 = FLASH_CR; FLASH_CR = v1 | 4; FLASH_CR = v1 | 0x44; Operation = FLASH_WaitForLastOperation(0xFFFu); if ( Operation != 1 ) { v2 = FLASH_CR; FLASH_CR = v2 & 0x1FFB; } } return Operation; } // 40022010: using guessed type int FLASH_CR; //----- (200003C8) -------------------------------------------------------- FLASH_Status __fastcall FLASH_ProgramHalfWord(u32 targetP, u16 *srcP) { int Operation; // r6 int v5; // r0 __int16 v6; // r0 Operation = FLASH_WaitForLastOperation(0xFu); if ( Operation == 4 ) { v5 = FLASH_CR; FLASH_CR = v5 | 1; *(_WORD *)targetP = *srcP; Operation = FLASH_WaitForLastOperation(0xFu); if ( Operation != 1 ) { v6 = FLASH_CR; FLASH_CR = v6 & 0x1FFE; } } return (char)Operation; } // 40022010: using guessed type int FLASH_CR; //----- (2000040A) -------------------------------------------------------- void FLASH_GetReadOutProtectionStatus() { ; } //----- (2000041E) -------------------------------------------------------- void __fastcall FLASH_GetFlagStatus(u16 FLASH_FLAG) { ; } //----- (20000448) -------------------------------------------------------- void __fastcall FLASH_ClearFlag(u16 FLASH_FLAG) { FLASH_SR = FLASH_FLAG; } // 4002200C: using guessed type int FLASH_SR; //----- (2000045C) -------------------------------------------------------- void RCC_DeInit() { int v0; // r0 int v1; // r0 int v2; // r0 int v3; // r0 RCC_APB2RSTR = 0; RCC_APB1RSTR = 0; RCC_AHBENR = 20; RCC_APB2ENR = 0; RCC_APB1ENR = 0; v0 = RCC_CR; RCC_CR = v0 | 1; v1 = RCC_CFGR; RCC_CFGR = v1 & 0xF8FF0000; v2 = RCC_CR; RCC_CR = v2 & 0xFEF6FFFF; RCC_CR = v2 & 0xFEF2FFFF; v3 = RCC_CFGR; RCC_CFGR = v3 & 0xFF80FFFF; RCC_CIR = 0; } // 40021000: using guessed type int RCC_CR; // 40021004: using guessed type int RCC_CFGR; // 40021008: using guessed type int RCC_CIR; // 4002100C: using guessed type int RCC_APB2RSTR; // 40021010: using guessed type int RCC_APB1RSTR; // 40021014: using guessed type int RCC_AHBENR; // 40021018: using guessed type int RCC_APB2ENR; // 4002101C: using guessed type int RCC_APB1ENR; //----- (200004AA) -------------------------------------------------------- void __fastcall RCC_HSEConfig(u32 RCC_HSE) { int v1; // r1 int v2; // r1 int v3; // r1 v1 = RCC_CR; RCC_CR = v1 & 0xFFFEFFFF; RCC_CR = v1 & 0xFFFAFFFF; if ( RCC_HSE == 0x10000 ) { v2 = RCC_CR; RCC_CR = v2 | 0x10000; } else if ( RCC_HSE == 0x40000 ) { v3 = RCC_CR; RCC_CR = v3 | 0x50000; } } // 40021000: using guessed type int RCC_CR; //----- (200004EE) -------------------------------------------------------- void __fastcall RCC_GetFlagStatus(u8 RCC_FLAG) { ; } //----- (20000526) -------------------------------------------------------- bool RCC_WaitForHSEStartUp() { int i; // r4 int v1; // r0 int v2; // r0 for ( i = 0; ; ++i ) { RCC_GetFlagStatus(0x31u); if ( v1 || i == 128 ) break; } RCC_GetFlagStatus(0x31u); return v2 != 0; } // 20000534: variable 'v1' is possibly undefined // 20000540: variable 'v2' is possibly undefined //----- (2000054A) -------------------------------------------------------- void __fastcall RCC_AdjustHSICalibrationValue(u8 HSICalibrationValue) { int v1; // r1 v1 = RCC_CR; RCC_CR = v1 & 0xFFFFFF07 | (8 * HSICalibrationValue); } // 40021000: using guessed type int RCC_CR; //----- (2000055C) -------------------------------------------------------- void __fastcall RCC_HSICmd(FunctionalState NewState) { MEMORY[0x42420000] = NewState; } //----- (20000562) -------------------------------------------------------- void __fastcall RCC_PLLConfig(u32 RCC_PLLSource, u32 RCC_PLLMul) { int v2; // r2 v2 = RCC_CFGR; RCC_CFGR = v2 & 0xFFC0FFFF | RCC_PLLSource | RCC_PLLMul; } // 40021004: using guessed type int RCC_CFGR; //----- (20000578) -------------------------------------------------------- void __fastcall RCC_PLLCmd(FunctionalState NewState) { MEMORY[0x42420060] = NewState; } //----- (2000057E) -------------------------------------------------------- void __fastcall RCC_SYSCLKConfig(u32 RCC_SYSCLKSource) { int v1; // r1 v1 = RCC_CFGR; RCC_CFGR = v1 & 0xFFFFFFFC | RCC_SYSCLKSource; } // 40021004: using guessed type int RCC_CFGR; //----- (2000058E) -------------------------------------------------------- int RCC_GetSYSCLKSource() { char v0; // r0 v0 = RCC_CFGR; return v0 & 0xC; } // 40021004: using guessed type int RCC_CFGR; //----- (20000598) -------------------------------------------------------- void __fastcall RCC_HCLKConfig(u32 RCC_HCLK) { int v1; // r1 v1 = RCC_CFGR; RCC_CFGR = v1 & 0xFFFFFF0F | RCC_HCLK; } // 40021004: using guessed type int RCC_CFGR; //----- (200005A8) -------------------------------------------------------- void __fastcall RCC_PCLK1Config(u32 RCC_PCLK1) { int v1; // r1 v1 = RCC_CFGR; RCC_CFGR = v1 & 0xFFFFF8FF | RCC_PCLK1; } // 40021004: using guessed type int RCC_CFGR; //----- (200005B8) -------------------------------------------------------- void __fastcall RCC_PCLK2Config(u32 RCC_PCLK2) { int v1; // r1 v1 = RCC_CFGR; RCC_CFGR = v1 & 0xFFFFC7FF | (8 * RCC_PCLK2); } // 40021004: using guessed type int RCC_CFGR; //----- (200005CA) -------------------------------------------------------- void __fastcall RCC_ITConfig(u8 RCC_IT, FunctionalState NewState) { char v2; // r2 char v3; // r2 v2 = BYTE1(RCC_CIR); if ( NewState ) v3 = v2 | RCC_IT; else v3 = v2 & ~RCC_IT; BYTE1(RCC_CIR) = v3; } // 40021008: using guessed type int RCC_CIR; //----- (200005E4) -------------------------------------------------------- void __fastcall RCC_USBCLKConfig(u32 RCC_USBCLKSource) { MEMORY[0x424200D8] = RCC_USBCLKSource; } //----- (200005EC) -------------------------------------------------------- void __fastcall RCC_ADCCLKConfig(u32 RCC_ADCCLK) { int v1; // r1 v1 = RCC_CFGR; RCC_CFGR = v1 & 0xFFFF3FFF | RCC_ADCCLK; } // 40021004: using guessed type int RCC_CFGR; //----- (200005FC) -------------------------------------------------------- void __fastcall RCC_LSEConfig(u32 RCC_LSE) { LOBYTE(RCC_BDCR) = 0; LOBYTE(RCC_BDCR) = 0; if ( RCC_LSE == 1 ) { LOBYTE(RCC_BDCR) = 1; } else if ( RCC_LSE == 4 ) { LOBYTE(RCC_BDCR) = 5; } } // 40021020: using guessed type int RCC_BDCR; //----- (20000628) -------------------------------------------------------- void __fastcall RCC_LSICmd(FunctionalState NewState) { MEMORY[0x42420480] = NewState; } //----- (2000062E) -------------------------------------------------------- void __fastcall RCC_RTCCLKConfig(u32 RCC_RTCCLKSource) { int v1; // r1 v1 = RCC_BDCR; RCC_BDCR = v1 | RCC_RTCCLKSource; } // 40021020: using guessed type int RCC_BDCR; //----- (2000063A) -------------------------------------------------------- void __fastcall RCC_RTCCLKCmd(FunctionalState NewState) { MEMORY[0x4242043C] = NewState; } //----- (20000642) -------------------------------------------------------- void __fastcall RCC_GetClocksFreq(RCC_ClocksTypeDef *RCC_Clocks) { char v1; // r5 int v2; // r1 int v3; // r5 unsigned int v4; // r2 int v5; // r5 int v6; // r5 char v7; // r5 __int16 v8; // r5 __int16 v9; // r5 __int16 v10; // r5 v1 = RCC_CFGR; v2 = v1 & 0xC; if ( (v1 & 0xC) != 0 ) { if ( v2 == 4 ) { RCC_Clocks->SYSCLK_Frequency = 8000000; } else if ( v2 == 8 ) { v3 = RCC_CFGR; v4 = ((v3 & 0x3C0000u) >> 18) + 2; v5 = RCC_CFGR; if ( (v5 & 0x10000) != 0 ) { v6 = RCC_CFGR; if ( (v6 & 0x20000) != 0 ) RCC_Clocks->SYSCLK_Frequency = 4000000 * v4; else RCC_Clocks->SYSCLK_Frequency = 8000000 * v4; } else { RCC_Clocks->SYSCLK_Frequency = 4000000 * v4; } } else { RCC_Clocks->SYSCLK_Frequency = 8000000; } } else { RCC_Clocks->SYSCLK_Frequency = 8000000; } v7 = RCC_CFGR; RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> APBAHBPrescTable[(unsigned __int8)(v7 & 0xF0) >> 4]; v8 = RCC_CFGR; RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> APBAHBPrescTable[(unsigned __int16)(v8 & 0x700) >> 8]; v9 = RCC_CFGR; RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> APBAHBPrescTable[(unsigned __int16)(v9 & 0x3800) >> 11]; v10 = RCC_CFGR; RCC_Clocks->ADCCLK_Frequency = RCC_Clocks->PCLK2_Frequency / ADCPrescTable[(unsigned __int16)(v10 & 0xC000) >> 14]; } // 40021004: using guessed type int RCC_CFGR; //----- (20000704) -------------------------------------------------------- void __fastcall RCC_AHBPeriphClockCmd(u32 RCC_AHBPeriph, FunctionalState NewState) { int v2; // r2 v2 = RCC_AHBENR; if ( NewState ) RCC_AHBENR = v2 | RCC_AHBPeriph; else RCC_AHBENR = v2 & ~RCC_AHBPeriph; } // 40021014: using guessed type int RCC_AHBENR; //----- (2000071E) -------------------------------------------------------- void __fastcall RCC_APB2PeriphClockCmd(u32 RCC_APB2Periph, FunctionalState NewState) { int v2; // r2 v2 = RCC_APB2ENR; if ( NewState ) RCC_APB2ENR = v2 | RCC_APB2Periph; else RCC_APB2ENR = v2 & ~RCC_APB2Periph; } // 40021018: using guessed type int RCC_APB2ENR; //----- (20000738) -------------------------------------------------------- void __fastcall RCC_APB1PeriphClockCmd(u32 RCC_APB1Periph, FunctionalState NewState) { int v2; // r2 v2 = RCC_APB1ENR; if ( NewState ) RCC_APB1ENR = v2 | RCC_APB1Periph; else RCC_APB1ENR = v2 & ~RCC_APB1Periph; } // 4002101C: using guessed type int RCC_APB1ENR; //----- (20000752) -------------------------------------------------------- void __fastcall RCC_APB2PeriphResetCmd(u32 RCC_APB2Periph, FunctionalState NewState) { int v2; // r2 v2 = RCC_APB2RSTR; if ( NewState ) RCC_APB2RSTR = v2 | RCC_APB2Periph; else RCC_APB2RSTR = v2 & ~RCC_APB2Periph; } // 4002100C: using guessed type int RCC_APB2RSTR; //----- (2000076C) -------------------------------------------------------- void __fastcall RCC_APB1PeriphResetCmd(u32 RCC_APB1Periph, FunctionalState NewState) { int v2; // r2 v2 = RCC_APB1RSTR; if ( NewState ) RCC_APB1RSTR = v2 | RCC_APB1Periph; else RCC_APB1RSTR = v2 & ~RCC_APB1Periph; } // 40021010: using guessed type int RCC_APB1RSTR; //----- (20000786) -------------------------------------------------------- void __fastcall RCC_BackupResetCmd(FunctionalState NewState) { MEMORY[0x42420440] = NewState; } //----- (2000078E) -------------------------------------------------------- void __fastcall RCC_ClockSecuritySystemCmd(FunctionalState NewState) { MEMORY[0x4242004C] = NewState; } //----- (20000794) -------------------------------------------------------- void __fastcall RCC_MCOConfig(u8 RCC_MCO) { HIBYTE(RCC_CFGR) = RCC_MCO; } // 40021004: using guessed type int RCC_CFGR; //----- (2000079A) -------------------------------------------------------- void RCC_ClearFlag() { int v0; // r0 v0 = RCC_CSR; RCC_CSR = v0 | 0x1000000; } // 40021024: using guessed type int RCC_CSR; //----- (200007A8) -------------------------------------------------------- ITStatus __fastcall RCC_GetITStatus(u8 RCC_IT) { int v1; // r2 v1 = RCC_CIR; return (v1 & RCC_IT) != 0; } // 40021008: using guessed type int RCC_CIR; //----- (200007BC) -------------------------------------------------------- void __fastcall RCC_ClearITPendingBit(u8 RCC_IT) { BYTE2(RCC_CIR) = RCC_IT; } // 40021008: using guessed type int RCC_CIR; //----- (200007E4) -------------------------------------------------------- void NVIC_DeInit() { unsigned int v0; // r0 v0 = 0; NVIC_ICER0 = -1; NVIC_ICER1 = 2047; NVIC_ICPR0 = -1; NVIC_ICPR1 = 2047; while ( v0 < 0xB ) *(_DWORD *)(4 * v0++ - 536812544) = 0; } // E000E180: using guessed type int NVIC_ICER0; // E000E184: using guessed type int NVIC_ICER1; // E000E280: using guessed type int NVIC_ICPR0; // E000E284: using guessed type int NVIC_ICPR1; //----- (2000080E) -------------------------------------------------------- void NVIC_SCBDeInit() { unsigned int v0; // r0 v0 = 0; unk_E000ED04 = 167772160; unk_E000ED08 = 0; unk_E000ED0C = 100270080; unk_E000ED10 = 0; unk_E000ED14 = 0; while ( v0 < 3 ) dword_E000ED18[v0++] = 0; dword_E000ED18[3] = 0; dword_E000ED18[4] = -1; dword_E000ED18[5] = -1; dword_E000ED18[6] = -1; } // E000ED18: using guessed type _DWORD[122]; //----- (2000085A) -------------------------------------------------------- void __fastcall NVIC_PriorityGroupConfig(u32 NVIC_PriorityGroup) { unk_E000ED0C = NVIC_PriorityGroup | 0x5FA0000; } //----- (20000866) -------------------------------------------------------- void __fastcall NVIC_Init(NVIC_InitTypeDef *NVIC_InitStruct) { __int16 v1; // r6 if ( NVIC_InitStruct->NVIC_IRQChannelCmd ) { v1 = unk_E000ED0C; *(_DWORD *)(4 * ((int)NVIC_InitStruct->NVIC_IRQChannel >> 2) - 536812544) = *(_DWORD *)(4 * ((int)NVIC_InitStruct->NVIC_IRQChannel >> 2) - 536812544) & ~(255 << ((8 * NVIC_InitStruct->NVIC_IRQChannel) & 0x1F)) | ((16 * ((NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << (4 - ((unsigned __int16)(1792 - (v1 & 0x700)) >> 8))) | NVIC_InitStruct->NVIC_IRQChannelSubPriority & (0xFu >> ((unsigned __int16)(1792 - (v1 & 0x700)) >> 8)))) << ((8 * NVIC_InitStruct->NVIC_IRQChannel) & 0x1F)) & (255 << ((8 * NVIC_InitStruct->NVIC_IRQChannel) & 0x1F)); *(_DWORD *)(4 * ((int)NVIC_InitStruct->NVIC_IRQChannel >> 5) - 536813312) = 1 << (NVIC_InitStruct->NVIC_IRQChannel & 0x1F); } else { NVIC_ICER0[(int)NVIC_InitStruct->NVIC_IRQChannel >> 5] = 1 << (NVIC_InitStruct->NVIC_IRQChannel & 0x1F); } } // E000E180: using guessed type int NVIC_ICER0[]; //----- (20000906) -------------------------------------------------------- void __fastcall NVIC_StructInit(NVIC_InitTypeDef *NVIC_InitStruct) { NVIC_InitStruct->NVIC_IRQChannel = 0; NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStruct->NVIC_IRQChannelSubPriority = 0; NVIC_InitStruct->NVIC_IRQChannelCmd = DISABLE; } //----- (20000912) -------------------------------------------------------- void NVIC_SETPRIMASK() { _SETPRIMASK(); } //----- (2000091A) -------------------------------------------------------- void NVIC_RESETPRIMASK() { _RESETPRIMASK(); } //----- (20000922) -------------------------------------------------------- void NVIC_SETFAULTMASK() { _SETFAULTMASK(); } //----- (2000092A) -------------------------------------------------------- void NVIC_RESETFAULTMASK() { _RESETFAULTMASK(); } //----- (20000932) -------------------------------------------------------- void __fastcall NVIC_BASEPRICONFIG(u32 NewPriority) { _BASEPRICONFIG(16 * NewPriority); } //----- (2000093E) -------------------------------------------------------- u32 NVIC_GetBASEPRI() { return _GetBASEPRI(); } //----- (20000946) -------------------------------------------------------- int NVIC_GetCurrentPendingIRQChannel() { unsigned int v0; // r0 v0 = unk_E000ED04; return (v0 >> 12) & 0x3FF; } //----- (20000950) -------------------------------------------------------- ITStatus __fastcall NVIC_GetIRQChannelPendingBitStatus(u8 NVIC_IRQChannel) { return (NVIC_ISPR0[(int)NVIC_IRQChannel >> 5] & (1 << (NVIC_IRQChannel & 0x1F))) == 1 << (NVIC_IRQChannel & 0x1F); } // E000E200: using guessed type int NVIC_ISPR0[]; //----- (2000097A) -------------------------------------------------------- void __fastcall NVIC_SetIRQChannelPendingBit(u8 NVIC_IRQChannel) { NVIC_STIR = NVIC_IRQChannel; } // E000EF00: using guessed type int NVIC_STIR; //----- (20000980) -------------------------------------------------------- void __fastcall NVIC_ClearIRQChannelPendingBit(u8 NVIC_IRQChannel) { NVIC_ICPR0[(int)NVIC_IRQChannel >> 5] = 1 << (NVIC_IRQChannel & 0x1F); } // E000E280: using guessed type int NVIC_ICPR0[]; //----- (20000994) -------------------------------------------------------- int NVIC_GetCurrentActiveHandler() { __int16 v0; // r0 v0 = unk_E000ED04; return v0 & 0x3FF; } //----- (2000099E) -------------------------------------------------------- ITStatus __fastcall NVIC_GetIRQChannelActiveBitStatus(u8 NVIC_IRQChannel) { return (NVIC_IABR0[(int)NVIC_IRQChannel >> 5] & (1 << (NVIC_IRQChannel & 0x1F))) == 1 << (NVIC_IRQChannel & 0x1F); } // E000E300: using guessed type int NVIC_IABR0[]; //----- (200009C8) -------------------------------------------------------- u32 NVIC_GetCPUID() { return unk_E000ED00; } //----- (200009D0) -------------------------------------------------------- void __fastcall NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset) { unk_E000ED08 = Offset & 0x1FFFFF80 | NVIC_VectTab; } //----- (200009DE) -------------------------------------------------------- void NVIC_GenerateSystemReset() { unk_E000ED0C = 100270084; } //----- (200009EA) -------------------------------------------------------- void NVIC_GenerateCoreReset() { unk_E000ED0C = 100270081; } //----- (200009F6) -------------------------------------------------------- void __fastcall NVIC_SystemLPConfig(u8 LowPowerMode, FunctionalState NewState) { int v2; // r2 int v3; // r2 v2 = unk_E000ED10; if ( NewState ) v3 = v2 | LowPowerMode; else v3 = v2 & ~LowPowerMode; unk_E000ED10 = v3; } //----- (20000A18) -------------------------------------------------------- void __fastcall NVIC_SystemHandlerConfig(u32 SystemHandler, FunctionalState NewState) { int v2; // r2 int v3; // r3 int v4; // r3 v2 = 1 << (SystemHandler & 0x1F); v3 = dword_E000ED18[3]; if ( NewState ) v4 = v3 | v2; else v4 = v3 & ~v2; dword_E000ED18[3] = v4; } // E000ED18: using guessed type _DWORD dword_E000ED18[122]; // E000ED24: using guessed type _DWORD; //----- (20000A48) -------------------------------------------------------- void __fastcall NVIC_SystemHandlerPriorityConfig( u32 SystemHandler, u8 SystemHandlerPreemptionPriority, u8 SystemHandlerSubPriority) { __int16 v3; // r7 int v4; // r4 u32 v5; // r5 v3 = unk_E000ED0C; v4 = (unsigned __int8)(SystemHandler & 0xC0) >> 6; v5 = (SystemHandler >> 8) & 3; dword_E000ED18[v4] &= ~(255 << (8 * v5)); dword_E000ED18[v4] |= (16 * ((SystemHandlerPreemptionPriority << (4 - ((unsigned __int16)(1792 - (v3 & 0x700)) >> 8))) | SystemHandlerSubPriority & (0xFFu >> ((unsigned __int16)(1792 - (v3 & 0x700)) >> 8)))) << (8 * v5); } // E000ED18: using guessed type _DWORD dword_E000ED18[122]; //----- (20000AB0) -------------------------------------------------------- ITStatus __fastcall NVIC_GetSystemHandlerPendingBitStatus(u32 SystemHandler) { int v1; // r4 v1 = dword_E000ED18[3]; return (v1 & (1 << ((SystemHandler >> 10) & 0xF))) == 1 << ((SystemHandler >> 10) & 0xF); } // E000ED18: using guessed type _DWORD dword_E000ED18[122]; // E000ED24: using guessed type _DWORD; //----- (20000ADC) -------------------------------------------------------- void __fastcall NVIC_SetSystemHandlerPendingBit(u32 SystemHandler) { int v1; // r2 v1 = unk_E000ED04; unk_E000ED04 = v1 | (1 << (SystemHandler & 0x1F)); } //----- (20000AF2) -------------------------------------------------------- void __fastcall NVIC_ClearSystemHandlerPendingBit(u32 SystemHandler) { int v1; // r2 v1 = unk_E000ED04; unk_E000ED04 = v1 | (1 << ((SystemHandler & 0x1F) - 1)); } //----- (20000B0E) -------------------------------------------------------- ITStatus __fastcall NVIC_GetSystemHandlerActiveBitStatus(u32 SystemHandler) { int v1; // r4 v1 = dword_E000ED18[3]; return (v1 & (1 << ((SystemHandler >> 14) & 0xF))) == 1 << ((SystemHandler >> 14) & 0xF); } // E000ED18: using guessed type _DWORD dword_E000ED18[122]; // E000ED24: using guessed type _DWORD; //----- (20000B38) -------------------------------------------------------- u32 __fastcall NVIC_GetFaultHandlerSources(u32 SystemHandler) { u32 v1; // r2 u32 v2; // r3 u32 result; // r0 unsigned int v4; // r4 v1 = (SystemHandler >> 18) & 3; v2 = (SystemHandler >> 20) & 3; if ( !v1 ) return dword_E000ED18[5]; if ( v1 != 1 ) return dword_E000ED18[6]; v4 = dword_E000ED18[4]; result = v4 >> (8 * v2); if ( v2 == 2 ) return (unsigned __int8)result; else return (v4 >> (8 * v2)) & 0xF; } // E000ED18: using guessed type _DWORD dword_E000ED18[122]; // E000ED28: using guessed type _DWORD; // E000ED2C: using guessed type _DWORD; // E000ED30: using guessed type _DWORD; //----- (20000B7A) -------------------------------------------------------- u32 __fastcall NVIC_GetFaultAddress(u32 SystemHandler) { if ( ((SystemHandler >> 22) & 1) != 0 ) return dword_E000ED18[8]; else return dword_E000ED18[7]; } // E000ED18: using guessed type _DWORD dword_E000ED18[122]; // E000ED34: using guessed type _DWORD; // E000ED38: using guessed type _DWORD; //----- (20000BB4) -------------------------------------------------------- void _WFI() { __wfi(); } //----- (20000BB8) -------------------------------------------------------- void _WFE() { __wfe(); } //----- (20000BBC) -------------------------------------------------------- void _SEV() { __sev(); } //----- (20000BC0) -------------------------------------------------------- void _ISB() { __isb(0xFu); } //----- (20000BC6) -------------------------------------------------------- void _DSB() { __dsb(0xFu); } //----- (20000BCC) -------------------------------------------------------- void _DMB() { __dmb(0xFu); } //----- (20000BD2) -------------------------------------------------------- void _SVC() { __asm { SVC 1 } } //----- (20000BD6) -------------------------------------------------------- unsigned int _MRS_CONTROL() { return __get_CPSR(); } //----- (20000BDC) -------------------------------------------------------- int __fastcall _MSR_CONTROL(int result) { __asm { MSR.W CONTROL, R0 } __isb(0xFu); return result; } //----- (20000BE6) -------------------------------------------------------- unsigned int _MRS_PSP() { return __get_CPSR(); } //----- (20000BEC) -------------------------------------------------------- int __fastcall _MSR_PSP(int result) { __asm { MSR.W PSP, R0 } return result; } //----- (20000BF2) -------------------------------------------------------- unsigned int _MRS_MSP() { return __get_CPSR(); } //----- (20000BF8) -------------------------------------------------------- int __fastcall _MSR_MSP(int result) { __asm { MSR.W MSP, R0 } return result; } //----- (20000BFE) -------------------------------------------------------- void _SETPRIMASK() { __disable_irq(); } //----- (20000C02) -------------------------------------------------------- void _RESETPRIMASK() { __enable_irq(); } //----- (20000C06) -------------------------------------------------------- void _SETFAULTMASK() { __asm { CPSID F } } //----- (20000C0A) -------------------------------------------------------- void _RESETFAULTMASK() { __asm { CPSIE F } } //----- (20000C0E) -------------------------------------------------------- int __fastcall _BASEPRICONFIG(int result) { __asm { MSR.W BASEPRI, R0 } return result; } //----- (20000C14) -------------------------------------------------------- unsigned int _GetBASEPRI() { return __get_CPSR(); } //----- (20000C1A) -------------------------------------------------------- unsigned int __fastcall _REV_HalfWord(unsigned int a1) { return __rev16(a1); } //----- (20000C1E) -------------------------------------------------------- unsigned int __fastcall _REV_Word(unsigned int a1) { return bswap32(a1); } //----- (20000C28) -------------------------------------------------------- __int64 _rt_stackheap_init_2region() { int v0; // r2 int v1; // r0 __int64 v3; // [sp-10h] [bp-10h] LODWORD(v3) = _user_setup_stackheap(); HIDWORD(v3) = v0; v1 = _rt_stackheap_storage(); *(_DWORD *)(v1 + 8) = 1152; *(_DWORD *)(v1 + 4) = 1; return v3; } // 20000C30: variable 'v0' is possibly undefined // 20000C64: using guessed type int _user_setup_stackheap(void); // 20000CB0: using guessed type __int64 _rt_stackheap_storage(void); //----- (20000C54) -------------------------------------------------------- int _rt_heap_extend_2region() { return 0; } //----- (20000C64) -------------------------------------------------------- // positive sp value has been detected, the output may be wrong! int _user_setup_stackheap() { int result; // r0 _DWORD *v1; // [sp-8h] [bp-8h] v1 = (_DWORD *)_user_libspace(); result = _user_initial_stackheap(); *v1 = 0; v1[1] = 0; v1[2] = 0; v1[3] = 0; v1[4] = 0; v1[5] = 0; v1[6] = 0; v1[7] = 0; v1[8] = 0; v1[9] = 0; v1[10] = 0; v1[11] = 0; v1[12] = 0; v1[13] = 0; v1[14] = 0; v1[15] = 0; return result; } // 20000C78: positive sp value 60 has been found // 2000001C: using guessed type int _user_initial_stackheap(); // 20000CBC: using guessed type int _user_libspace(); //----- (20000CB0) -------------------------------------------------------- void *_rt_stackheap_storage() { return &unk_20002F30; } //----- (20000CBC) -------------------------------------------------------- // Alternative name is '__user_perproc_libspace' // Alternative name is '__user_perthread_libspace' void *_user_libspace() { return &_libspace_start; } // nfuncs=118 queued=116 decompiled=116 lumina nreq=0 worse=0 better=0 // ALL OK, 116 function(s) have been successfully decompiled