Skip to content

Commit 61d98b5

Browse files
committed
Add support for calling bootloader without BOOT pins
1 parent 0c80e90 commit 61d98b5

File tree

5 files changed

+140
-11
lines changed

5 files changed

+140
-11
lines changed

Diff for: cores/arduino/Reset.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Copyright (c) 2012 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include "stm32_def.h"
20+
#include "Reset.h"
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
#define RESET_TO_BOOTLOADER_MAGIC_CODE 0xDEADBEEF
27+
28+
uint32_t reset_to_bootloader_magic __attribute__ ((section (".noinit")));
29+
30+
void checkBoot()
31+
{
32+
if (reset_to_bootloader_magic == RESET_TO_BOOTLOADER_MAGIC_CODE) {
33+
reset_to_bootloader_magic = 0;
34+
#if defined(MCU_SERIES_F7)
35+
// arm-none-eabi-gcc 4.9.0 does not correctly inline this
36+
// MSP function, so we write it out explicitly here.
37+
//__set_MSP(*((uint32_t*) 0x1FF00000));
38+
__ASM volatile ("movw r3, #0x0000\nmovt r3, #0x1FF0\nldr r3, [r3, #0]\nMSR msp, r3\n" : : : "r3", "sp");
39+
40+
((void (*)(void)) *((uint32_t*) 0x1FF00004))();
41+
#else
42+
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
43+
44+
// arm-none-eabi-gcc 4.9.0 does not correctly inline this
45+
// MSP function, so we write it out explicitly here.
46+
//__set_MSP(*((uint32_t*) 0x00000000));
47+
__ASM volatile ("movs r3, #0\nldr r3, [r3, #0]\nMSR msp, r3\n" : : : "r3", "sp");
48+
49+
((void (*)(void)) *((uint32_t*) 0x00000004))();
50+
#endif
51+
}
52+
}
53+
54+
// Activate the bootloader without BOOT* pins.
55+
void banzai() {
56+
reset_to_bootloader_magic = RESET_TO_BOOTLOADER_MAGIC_CODE;
57+
NVIC_SystemReset();
58+
}
59+
60+
static int ticks = -1;
61+
62+
void initiateReset(int _ticks) {
63+
ticks = _ticks;
64+
}
65+
66+
void cancelReset() {
67+
ticks = -1;
68+
}
69+
70+
void tickReset() {
71+
if (ticks == -1)
72+
return;
73+
ticks--;
74+
if (ticks == 0)
75+
banzai();
76+
}
77+
78+
#ifdef __cplusplus
79+
}
80+
#endif

Diff for: cores/arduino/Reset.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright (c) 2012 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef RESET_H
20+
#define RESET_H
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
void initiateReset(int ms);
27+
void tickReset();
28+
void cancelReset();
29+
30+
void checkBoot();
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
36+
#endif

Diff for: cores/arduino/stm32/clock.c

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
******************************************************************************
3737
*/
3838
#include "stm32_def.h"
39+
#include "Reset.h"
3940

4041
#ifdef __cplusplus
4142
extern "C" {
@@ -84,6 +85,7 @@ void SysTick_Handler(void)
8485
HAL_IncTick();
8586
HAL_SYSTICK_IRQHandler();
8687
osSystickHandler();
88+
tickReset();
8789
}
8890

8991
/**

Diff for: cores/arduino/stm32/hw_config.c

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
#include "stm32_def.h"
3939
#include "hw_config.h"
40+
#include "Reset.h"
4041

4142
#ifdef __cplusplus
4243
extern "C" {
@@ -49,6 +50,8 @@
4950
*/
5051
void hw_config_init(void)
5152
{
53+
checkBoot();
54+
5255
//Initialize the HAL
5356
HAL_Init();
5457

Diff for: variants/OPENTRACKER_V3/ldscript.ld

+19-11
Original file line numberDiff line numberDiff line change
@@ -89,39 +89,40 @@ SECTIONS
8989
. = ALIGN(8);
9090
} >FLASH
9191
.ARM : {
92-
. = ALIGN(8);
92+
. = ALIGN(8);
9393
__exidx_start = .;
9494
*(.ARM.exidx*)
9595
__exidx_end = .;
96-
. = ALIGN(8);
96+
. = ALIGN(8);
9797
} >FLASH
9898

9999
.preinit_array :
100100
{
101-
. = ALIGN(8);
101+
. = ALIGN(8);
102102
PROVIDE_HIDDEN (__preinit_array_start = .);
103103
KEEP (*(.preinit_array*))
104104
PROVIDE_HIDDEN (__preinit_array_end = .);
105-
. = ALIGN(8);
105+
. = ALIGN(8);
106106
} >FLASH
107107

108108
.init_array :
109109
{
110-
. = ALIGN(8);
110+
. = ALIGN(8);
111111
PROVIDE_HIDDEN (__init_array_start = .);
112112
KEEP (*(SORT(.init_array.*)))
113113
KEEP (*(.init_array*))
114114
PROVIDE_HIDDEN (__init_array_end = .);
115-
. = ALIGN(8);
115+
. = ALIGN(8);
116116
} >FLASH
117+
117118
.fini_array :
118119
{
119-
. = ALIGN(8);
120+
. = ALIGN(8);
120121
PROVIDE_HIDDEN (__fini_array_start = .);
121122
KEEP (*(SORT(.fini_array.*)))
122123
KEEP (*(.fini_array*))
123124
PROVIDE_HIDDEN (__fini_array_end = .);
124-
. = ALIGN(8);
125+
. = ALIGN(8);
125126
} >FLASH
126127

127128
/* used by the startup to initialize data */
@@ -141,9 +142,9 @@ SECTIONS
141142

142143

143144
/* Uninitialized data section */
144-
. = ALIGN(4);
145145
.bss :
146146
{
147+
. = ALIGN(4);
147148
/* This is used by the startup in order to initialize the .bss secion */
148149
_sbss = .; /* define a global symbol at bss start */
149150
__bss_start__ = _sbss;
@@ -156,6 +157,15 @@ SECTIONS
156157
__bss_end__ = _ebss;
157158
} >RAM
158159

160+
.noinit (NOLOAD) : ALIGN(4)
161+
{
162+
_noinit = .;
163+
*(.noinit)
164+
*(.noinit.*)
165+
. = ALIGN(4) ;
166+
_end_noinit = .;
167+
} > RAM
168+
159169
/* User_heap_stack section, used to check that there is enough RAM left */
160170
._user_heap_stack :
161171
{
@@ -167,8 +177,6 @@ SECTIONS
167177
. = ALIGN(8);
168178
} >RAM
169179

170-
171-
172180
/* Remove information from the standard libraries */
173181
/DISCARD/ :
174182
{

0 commit comments

Comments
 (0)