Created
August 6, 2023 17:32
-
-
Save M0nteCarl0/4d8609e37edf668354f243cb6db89309 to your computer and use it in GitHub Desktop.
STM32F4 simple bootloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "bootloader.h" | |
BootloaderInfo Info; | |
/** | |
****************************************************************************** | |
* @file bootloader.c | |
* @author Molotaliev A.O | |
* @version V 0.5.1 | |
* @date 16-february-2016/17-february-2016/9-March-2016 | |
* @brief This file provides bootloader f(x) for stm32f405 dual stage start | |
* | |
*/ | |
/****************************************************************************/ | |
pFunction FirmwareStart; | |
#define MAIN_PROGRAM_ADRESS 0x08040000 | |
/****************************************************************************/ | |
void InitBootloader(void) | |
{ | |
Info.Major = 0; | |
Info.Minor = 1; | |
Info.Ext = 1; | |
}; | |
/****************************************************************************/ | |
void MainLoop(void) | |
{ | |
uint32_t JumpAddress = 0x08040000; | |
FirmwareStart = (pFunction) *(__IO uint32_t*) (JumpAddress + 4); | |
__set_MSP(*(__IO uint32_t*)0x08040000); | |
FirmwareStart(); | |
} | |
/****************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include "stm32f4xx.h" | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
typedef void (*pFunction)(void); | |
typedef enum BootloaderState | |
{ | |
BootloaderState_UPDATE, | |
BootloaderState_RESTORE, | |
BootloaderState_BACKUP, | |
BootloaderState_COMPLETE, | |
}BootloaderState; | |
typedef struct BootloaderInfo | |
{ | |
uint32_t Major; | |
uint32_t Minor; | |
uint32_t Ext; | |
uint32_t BootCount; | |
BootloaderState State; | |
bool AvalibleNewFimwaware; | |
}BootloaderInfo; | |
void InitBootloader(void); | |
void MainLoop(void); | |
#ifdef __cplusplus | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*###ICF### Section handled by ICF editor, don't touch! ****/ | |
/*-Editor annotation file-*/ | |
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ | |
/*-Specials-*/ | |
define symbol __ICFEDIT_intvec_start__ = 0x08000000; | |
/*-Memory Regions-*/ | |
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000; | |
define symbol __ICFEDIT_region_ROM_end__ = 0x0802000; | |
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; | |
define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF; | |
/*-Sizes-*/ | |
define symbol __ICFEDIT_size_cstack__ = 0x2000; | |
define symbol __ICFEDIT_size_heap__ = 0x2000; | |
/**** End of ICF editor section. ###ICF###*/ | |
define symbol __region_RAM1_start__ = 0x10000000; | |
define symbol __region_RAM1_end__ = 0x1000FFFF; | |
define memory mem with size = 4G; | |
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; | |
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; | |
define region RAM1_region = mem:[from __region_RAM1_start__ to __region_RAM1_end__]; | |
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; | |
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; | |
initialize by copy { readwrite }; | |
do not initialize { section .noinit }; | |
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; | |
place in ROM_region { readonly }; | |
place in RAM_region { readwrite, | |
block CSTACK, block HEAP }; | |
place in RAM1_region { section .sram }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment