BootLoader:
) F" x) N- u! @6 Y$ V' H/ o! E5 ?2 A _+ J. C
main里调用函数跳转到APP地址0x8003000% P1 | i9 M# g( M
+ m: s) X, X: T7 @1 m# j% c& S3 L- typedef void (*pFunction)(void);
复制代码- #define ApplicationAddress 0x8003000
复制代码- void UserAppStart(void)$ |$ F# s* Y2 o7 u& b$ D. R
- { q- p. H9 S4 y% @1 E
- if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000). X3 Y/ a0 F1 d5 L/ c+ F7 r/ @; y1 T; `
- { , h( V& n. O" [8 o* i) }
- /* Jump to user application */
, t1 Z9 J5 F' O( a8 H4 s" Z% m* P# V - JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
+ z1 p* G! N1 F( e4 ` A - Jump_To_Application = (pFunction) JumpAddress;: s8 W( A% v$ q+ Q* H
- /* Initialize user application's Stack Pointer */, j g2 W& {% Y' A1 |
- __set_MSP(*(__IO uint32_t*) ApplicationAddress);: \* s1 a/ v, x, @* b2 ]
- Jump_To_Application();
, D( k2 {9 l( g: e! Z - }
1 w$ ?: o$ R$ P$ ~; e - }
复制代码 4 b9 C( {- ]! }+ j8 q
APP:/ j2 g9 I' J, l/ \# g% L& C
9 S+ s7 v, v4 o' U3 |main 函数添加& B) R' @' N _# y: x" Z5 S
: g2 N1 b, q" }9 ?0 L, R- #define APPLICATION_ADDRESS ((uint32_t)0x08003000), L6 C. E j, F; L2 T
- #if (defined ( __CC_ARM ))
2 M& R& X; A% Q7 V5 l - __IO uint32_t VectorTable[48] __attribute__((at(0x20000000)));
' {0 I, V+ Z5 _2 e; J, b" x - #elif (defined (__ICCARM__))
% m, ^( \4 W- Q* v( t - #pragma location = 0x200000002 T& W! _, M/ S) j, |5 g
- __no_init __IO uint32_t VectorTable[48];
6 r1 {, Z& v7 C) W- U4 E5 p - #elif defined ( __GNUC__ )# ^, O- F+ X" a8 Q" m6 \$ R: S
- __IO uint32_t VectorTable[48] __attribute__((section(".RAMVectorTable")));
) ^9 x2 e% T5 d( Z, ^ - #elif defined ( __TASKING__ )
# U! O9 P; P' R4 L% ]* V4 q" X - __IO uint32_t VectorTable[48] __at(0x20000000);
8 j7 M# n) Y7 d' X; r X" v9 _2 { - #endif
复制代码- /* USER CODE BEGIN 1 */
# q) R& n$ ~: C$ w4 _5 s - uint32_t i = 0;
复制代码- /* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/
8 U- Z8 `( H6 J. i% T+ c - * K7 `1 Z U- L! b8 e
- /* Copy the vector table from the Flash (mapped at the base of the application
{/ i6 w' [& s8 ^" L5 s' E - load address 0x08003000) to the base address of the SRAM at 0x20000000. */9 A: G. q4 \% |4 w+ W& P- ] B
- 2 e8 k1 Q2 Z+ A6 B
- for(i = 0; i < 48; i++)
- y' Z& }9 B# i* n - {
4 z: U3 b- }, V/ l- U, w4 K. d0 Q3 H - VectorTable<i> = *(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));</i>8 t! {, z9 h, P9 h0 G
- }' Z1 q+ U F+ K) _' A
- // Enable the SYSCFG peripheral clock4 n3 `+ W m+ K; U! [
- __HAL_RCC_SYSCFG_CLK_ENABLE();
: G; ~3 X6 y4 o - // Remap SRAM at 0x00000000
复制代码- __HAL_SYSCFG_REMAPMEMORY_SRAM();
复制代码
. c" C( k0 a, B4 d6 h) x: Q$ T8 e5 n& A) x' R6 z
在Keil下设置IROM1:start 0x8003000 IRAM1:Start 0x200000C0. H, P; V# c2 ? N1 r: {
b* c# T& |- cstm32f0 没有中断偏移寄存器,所以将中断向量表读取到RAM中,然后重映射到RAM地址.0 b% V/ }8 @4 e* g2 q
; d$ ^6 b7 F) V8 o( O, `
+ @3 D- h) c( Q ~+ v* N |