-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodigo_testing.txt
More file actions
88 lines (65 loc) · 1.72 KB
/
codigo_testing.txt
File metadata and controls
88 lines (65 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "main.h"
#include "ST-LIB.hpp"
void enter_bootloader(void) {
const uint32_t MAIN_APP_ADDRESS = 0x080E0000;
// 1. Stop ST-LIB Timers
HAL_TIM_Base_Stop_IT(&htim2);
HAL_TIM_Base_Stop_IT(&htim5);
HAL_TIM_Base_Stop_IT(&htim24);
HAL_TIM_Base_Stop_IT(&htim7);
// 2. Disable Interrupts
__disable_irq();
// 3. Disable SysTick
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
// 4. Clear all interrupts in NVIC
for (int i = 0; i < 8; i++) {
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
// 5. Disable MPU and Caches
HAL_MPU_Disable();
// SCB_DisableICache();
// SCB_DisableDCache();
// 6. De-init HAL
HAL_DeInit();
// 7. Force Reset Ethernet to ensure DMA stops
#if defined(ETH)
__HAL_RCC_ETH1MAC_FORCE_RESET();
__HAL_RCC_ETH1MAC_RELEASE_RESET();
#endif
// 8. Barrier
__DSB();
__ISB();
// 9. Set VTOR
SCB->VTOR = MAIN_APP_ADDRESS;
// 10. Set MSP
uint32_t main_stack_pointer = *(__IO uint32_t*)MAIN_APP_ADDRESS;
__set_MSP(main_stack_pointer);
// 11. Jump
uint32_t jump_address = *(__IO uint32_t*)(MAIN_APP_ADDRESS + 4);
void (*reset_handler)(void) = (void (*)(void))jump_address;
reset_handler();
}
int main(void) {
#ifdef SIM_ON
SharedMemory::start();
#endif
DigitalOutput coño(PB0);
STLIB::start("00:80:e1:00:00:E0","192.168.1.4");
Time::register_low_precision_alarm(1000, [&](){
coño.toggle();
});
Time::set_timeout(5000, [](){
enter_bootloader();
});
while (1) {
STLIB::update();
}
}
void Error_Handler(void) {
ErrorHandler("HAL error handler triggered");
while (1) {
}
}