你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32L4R5ZIT6软件跳转ISP运行Hardfault问题

[复制链接]
yklstudent 发布时间:2019-11-14 14:08
最近研究ST芯片的内容ISP升级方法,按照官方推荐方式,需要设置BOOT引脚电平进入内容System Bootloader升级,感觉这种方式麻烦,所以查找是否可以软件方式直接跳转ISP进行升级;经过百度和各论坛查找资料,终于找到解决办法,并且经过验证大部分是可行的,少部分不行(暂时还没有搞清楚原因)
. I! U  S* ~. F  H9 Z4 K4 M0 x; d  ^7 B以下是软件跳转内容ISP的代码,可以直接调用即可:5 o* E5 n8 g" R6 x9 g+ J
/**( H  v/ Z5 B$ {* W6 J
* Function to perform jump to system memory boot from user application; [" U! |7 @- F+ d7 M- l8 q
*& g6 H4 F$ u; J1 X+ P
* Call function when you want to jump to system memory& J. i3 b3 O0 Y9 L* B0 N
*/
1 X" E5 M! j% g- kvoid JumpToBootloader(void) {2 k& @! C: E& y0 ]3 t& P
        void (*SysMemBootJump)(void);
9 j! r* x) L# ^: h       
; S- s# d; h: {$ A7 a8 w        /**- s2 ?  i* q2 [: @7 R) a; o
         * Step: Set system memory address.
8 _1 _$ {4 h% V$ ^4 E( J, S         *       % N0 d* V6 c6 U) h6 h0 N
         *       For STM32F429, system memory is on 0x1FFF 0000
& z5 y2 [* w5 ~. p; p# F/ m         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
3 C8 O; p. j6 D& O- K! p3 z         */* s0 ?# A0 L! M( X% l0 S2 w
        //volatile uint32_t addr = 0x1FFF0000;( m3 W% O1 E/ P. k; g
    /**: ?7 q& @! m9 E# @6 @0 }
         * Step: Set system memory address. ) g$ u8 S, @# a" l, g& B0 I
         *       , n( h# G: d# T  `$ t, I( g
         *       For STM32F103, system memory is on 0x1FFF F000; n$ U9 g/ f7 l; P
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses 4 c1 {, u( h% a% |' f
         */
2 V3 D3 B5 U) H        //volatile uint32_t addr = 0x1FFFF000;
, ]* e' O: l: y3 P. C& P; v    /**9 A; y/ u( ^! v& k
         * Step: Set system memory address.
* n- r& j- k& b1 Y' H# I  ?         *      
  a$ Z' z2 @3 y* S         *       For STM32F107, system memory is on 0x1FFF B000
6 F/ E* q0 Z" V7 s2 i3 B' d         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
( ^  i3 |0 I* A/ h6 m         */# P. {6 y+ L$ v: U
        //volatile uint32_t addr = 0x1FFFB000;
) F5 [5 b- D0 z, T: W, v    /**
: R7 {8 P; N' w         * Step: Set system memory address.
1 X6 }  ?4 L4 L2 P         *       5 e7 c  e, L/ a' a
         *       For STM32F303, system memory is on 0x1FFF D800
, ~2 G' k+ n& S! D5 R         *       For other families, check AN2606 document table 110 with descriptions of memory addresses 6 {: s4 D# D( b# @* F  k
         */9 T& ~0 d! f. g9 t# ~
        //volatile uint32_t addr = 0x1FFFD800;
$ A0 V% O) f2 m  W3 D  ?        /**2 {! k+ _: e% C% G
         * Step: Set system memory address. & R9 a. |. ^3 n$ v
         *      
5 f0 j% L& x. x% k         *       For STM32L073, system memory is on 0x1FF0 0000" E1 {: R3 B1 I
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses * J( ?; @- T% }5 O( g: b* l6 H
         */7 m8 O8 [4 W, }
        volatile uint32_t addr = 0x1FF00000;
$ E( U) l" X0 {, ?  i! C4 [: W& i& C        3 r7 n1 f3 }$ Y) I
        /**
% l5 I. K$ c, D6 O         * Step: Disable RCC, set it to default (after reset) settings+ j, Y4 H1 l9 w7 l
         *       Internal clock, no PLL, etc.7 o) Q0 u9 |) `. S  O2 a
         */% y7 l3 [8 |4 v4 T! w
#if defined(USE_HAL_DRIVER)8 b$ Y' q4 l  C# {! ^
        HAL_RCC_DeInit();( c' X1 ]7 _" E+ J& g
#endif /* defined(USE_HAL_DRIVER) */' }3 [) G/ k* V1 {+ B2 s5 R5 u+ Z
#if defined(USE_FULL_LL_DRIVER)0 j- q; B2 C) H1 f& m
        LL_RCC_DeInit();% x1 f8 {* ]' c0 P. A; N& v
#endif1 V4 V' c' z! k! }' M
#if defined(USE_STDPERIPH_DRIVER)
; W& |% Z9 o0 D4 J* E5 u; V' c; _        RCC_DeInit();5 ?  K) U4 D1 Q; w, f% h% o: S& }
#endif /* defined(USE_STDPERIPH_DRIVER) */
* c6 P0 u7 k/ l* c/ o3 U* g        ( f5 Q; Y" O  t+ a
        /**
+ x6 e8 s3 a% g) f" H' Z         * Step: Disable systick timer and reset it to default values0 _/ P" k7 g' }! n( @/ }. }& Y. V0 h/ `
         */
. Q) c7 N) x: R2 S2 b6 R1 U        SysTick->CTRL = 0;
* k1 g3 c) o" m6 G        SysTick->LOAD = 0;- V9 z0 J4 N. A6 e, u9 `3 {4 K
        SysTick->VAL = 0;8 D" O7 C( K4 J4 R* Z  q2 r% |
! U; s; U( p- c& S8 x
        /**0 ~. i: H) n, y
         * Step: Disable all interrupts9 y- J' b. C* t
         */: o3 c4 I, D& h) Y' t& ]1 U
        __disable_irq();5 f# z# j9 J/ }+ \+ O
       
/ X& k6 a3 n5 V3 A8 j! F9 D        /**4 f! @5 m; X* F! R- ?% N& _1 B
         * Step: Remap system memory to address 0x0000 0000 in address space
, d& s' K. {/ u5 ~/ x0 h) Q         *       For each family registers may be different. 6 L; R1 K! g6 U8 S# q8 B
         *       Check reference manual for each family.) Q) q( \& x/ E
         *7 q. x, n* V' X, l
         *       For STM32F4xx, MEMRMP register in SYSCFG is used (bits[1:0]), ^  c5 }& ?+ f! b' u1 c; ~
         *       For STM32F0xx, CFGR1 register in SYSCFG is used (bits[1:0])- C8 j( x! W( M  K9 Q, @
         *       For others, check family reference manual$ m$ o+ _, R' X$ z, o
         */
  |4 y8 u: `% u0 }+ f% R( T        //Remap by hand... {
( P# _* B+ b. ]' e( D6 w#if defined(STM32F4)
2 X: E" K9 p) \/ e3 c( k2 V. }        SYSCFG->MEMRMP = 0x01;# i9 \# ^: }4 ]
#endif( V8 k3 A# `1 f  i
#if defined(STM32L0)
" I$ y! j. s2 P- Q+ p; S7 F6 D+ `3 P        SYSCFG->CFGR1 = 0x01;) Y0 v% p  d$ v! x* o% y& ?
#endif
3 R2 L- s+ K; y/ p- z* d7 z4 q#if defined(STM32F0)
; j0 s+ o4 w( f. R$ H! s) W        SYSCFG->CFGR1 = 0x01;
. u1 X: c5 j  X: O" I#endif6 j% B& _. r4 T9 e3 C; D) A5 }% ?; z
        //} ...or if you use HAL drivers( `0 x8 P& ?+ z1 `2 H$ N
        //__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();        //Call HAL macro to do this for you
; A, ^3 z! f$ H+ ?  U        / ~+ L' c, ?( k( N4 C
        /**
7 y3 u8 P2 f' [* v- L3 i         * Step: Set jump memory location for system memory
! ?* _, z3 R+ L  ?         *       Use address with 4 bytes offset which specifies jump location where program starts
6 }6 z$ m3 M: U# m0 I         */# U5 d4 |% u2 W) ]: Q8 ^, |7 s
        SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
& S) ], ~6 }/ a+ k" j) [5 M        , o* R: H9 D( s
        /**0 _, G4 ^6 [" a
         * Step: Set main stack pointer.
" ^8 E, ?& ~' _+ i; a         *       This step must be done last otherwise local variables in this function
. R/ _2 D3 Z, z         *       don't have proper value since stack pointer is located on different position" `# U9 Y8 _7 @5 H4 H! n
         *. i6 t2 S5 Y; ~5 I
         *       Set direct address location which specifies stack pointer in SRAM location
. w6 C  D3 C- s; L: t4 r3 L         */4 J3 n) ?7 @+ p; r2 c/ Z% s; f* p
        __set_MSP(*(uint32_t *)addr);
' Q" t) {2 y9 V8 ]. ?; f        + c9 a1 f/ B0 r! H1 _/ r! R
        /**
/ ?  l5 f* R* P         * Step: Actually call our function to jump to set location5 o' }, h& j1 i) G" G+ D7 U$ p
         *       This will start system memory execution
6 b) N7 @3 n; `: l         */; T/ c% Q# N* d0 Q- d# U
        SysMemBootJump();+ O1 H$ p/ \" Q; P; M7 z$ N  q
        1 w! j. x  L, f
        /**
$ b# o- s( X3 C# h, s& ]         * Step: Connect USB<->UART converter to dedicated USART pins and test: i1 Y* U7 B" p& Q
         *       and test with bootloader works with STM32 Flash Loader Demonstrator software  Y6 z. q; M) d/ K
         */9 o2 s: l1 f! X7 R& m" U
}  A( [. a& s# a: z
然后介绍下测试结果:
% B2 e1 {1 @' [! N( z" o1、F0系列:STM32F030、STM32F051、STM32F070、STM32F071和STM32F072芯片,其中除STM32F070跳转运行ISP运行错误(发现内部ISP代码好像有问题,具体也不确定)外,均可以支持软件跳转ISP后串口方式升级;
2 `4 C! z0 i1 c  I: _  f/ j2 H5 a9 Y2、F1系列:STM32F103和STM32F107芯片,均可以支持软件跳转ISP后串口方式升级;& ~8 z5 x! D7 b( s/ |) X, c
3、F2系列:无芯片平台验证;' w; j+ m/ j2 t# Q' K7 j
4、F4系列:STM32F407芯片,支持软件跳转ISP后串口方式升级;  m1 V) W6 T0 I* Q$ j% U
5、L0系列:STM32L073芯片,支持软件跳转ISP后串口方式升级;" G, H/ _/ U# b' Z; \
6、L4系列:STM32L4R5芯片,软件跳转ISP后运行直接跳转Hardfault(后续查找原因);, [6 ^! e. S/ F
7、其它系列均无平台验证;
8 I  Z# K4 T" }: t% C" Z$ c% [$ V6 f7 r
/ V2 _, n* }4 J* J. C. a6 q. w
赞 收藏 评论2 发布时间:2019-11-14 14:08

举报

2个回答
jimmy20080105 回答时间:2019-11-19 08:51:33
签到
a117185178 回答时间:2020-7-11 12:17:31
请问你一下,SMT32L4R5ZIT6如何进入system bootloader?这个芯片只有BOOT0,在官网提供的开发板上,无论是置高还是置低,用那个demonstrator工具,也不能进行升级呢。$ q$ W' a% w2 Q: i' e! Q* B0 E) `
我用的开发板是官方的nucleo开发板,连接串口用的是lpuart1

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版