mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-21 17:21:04 +03:00
Add starting sources to CANbus_stepper
This commit is contained in:
@@ -6,22 +6,32 @@
|
||||
#define SYSMEM09x 0x1FFFD800
|
||||
|
||||
#define SystemMem SYSMEM07x
|
||||
typedef void (*pF)(void);
|
||||
uint32_t JumpAddress = *(volatile uint32_t*) (SystemMem + 4);
|
||||
pF Jump_To_Boot = (pFunction) JumpAddress;
|
||||
|
||||
// first - deinit all peripherial!!!!
|
||||
/*
|
||||
// default timing settings
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
*/
|
||||
__disable_irq(); // - may not work
|
||||
|
||||
// remap memory to 0
|
||||
SYSCFG->CFGR1 = 0x01;
|
||||
|
||||
__set_MSP(*(volatile uint32_t*) SystemMem);
|
||||
Jump_To_Boot();
|
||||
|
||||
void Jump2Boot(){ // for STM32F072
|
||||
void (*SysMemBootJump)(void);
|
||||
volatile uint32_t addr = 0x1FFFC800;
|
||||
// reset systick
|
||||
SysTick->CTRL = 0;
|
||||
// reset clocks
|
||||
RCC->APB1RSTR = RCC_APB1RSTR_CECRST | RCC_APB1RSTR_DACRST | RCC_APB1RSTR_PWRRST | RCC_APB1RSTR_CRSRST |
|
||||
RCC_APB1RSTR_CANRST | RCC_APB1RSTR_USBRST | RCC_APB1RSTR_I2C2RST | RCC_APB1RSTR_I2C1RST |
|
||||
RCC_APB1RSTR_USART4RST | RCC_APB1RSTR_USART3RST | RCC_APB1RSTR_USART2RST | RCC_APB1RSTR_SPI2RST |
|
||||
RCC_APB1RSTR_WWDGRST | RCC_APB1RSTR_TIM14RST | RCC_APB1RSTR_TIM7RST | RCC_APB1RSTR_TIM6RST |
|
||||
RCC_APB1RSTR_TIM3RST | RCC_APB1RSTR_TIM2RST;
|
||||
RCC->APB2RSTR = RCC_APB2RSTR_DBGMCURST | RCC_APB2RSTR_TIM17RST | RCC_APB2RSTR_TIM16RST | RCC_APB2RSTR_TIM15RST |
|
||||
RCC_APB2RSTR_USART1RST | RCC_APB2RSTR_SPI1RST | RCC_APB2RSTR_TIM1RST | RCC_APB2RSTR_ADCRST | RCC_APB2RSTR_SYSCFGRST;
|
||||
RCC->AHBRSTR = 0;
|
||||
RCC->APB1RSTR = 0;
|
||||
RCC->APB2RSTR = 0;
|
||||
// Enable the SYSCFG peripheral.
|
||||
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
|
||||
// remap memory to 0 (only for STM32F0)
|
||||
SYSCFG->CFGR1 = 0x01; __DSB(); __ISB();
|
||||
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
|
||||
// set main stack pointer
|
||||
__set_MSP(*((uint32_t *)addr));
|
||||
// jump to bootloader
|
||||
SysMemBootJump();
|
||||
}
|
||||
Reference in New Issue
Block a user