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

STM32L4R5ZIT6软件跳转ISP运行Hardfault问题

[复制链接]
yklstudent 发布时间:2019-11-14 14:08
最近研究ST芯片的内容ISP升级方法,按照官方推荐方式,需要设置BOOT引脚电平进入内容System Bootloader升级,感觉这种方式麻烦,所以查找是否可以软件方式直接跳转ISP进行升级;经过百度和各论坛查找资料,终于找到解决办法,并且经过验证大部分是可行的,少部分不行(暂时还没有搞清楚原因); w) @- ^3 v; n
以下是软件跳转内容ISP的代码,可以直接调用即可:* o1 S0 G9 ^- w$ k% G
/**9 K1 Q2 O8 E' N3 U2 y. o8 Q
* Function to perform jump to system memory boot from user application
$ ]1 G. Y2 h  X' o2 ~ *
& G: I2 p$ B# U' |0 t * Call function when you want to jump to system memory
6 l* l+ K" J0 v7 Y */
" ^! U' M& {5 o! Qvoid JumpToBootloader(void) {
0 @) p* Y9 J) p) ~        void (*SysMemBootJump)(void);
9 S; v& y  ~4 l7 O. G" Y; e/ ]       
* a" T/ o$ o  L& l0 Z        /**
- ?2 b8 p8 r+ ^  H         * Step: Set system memory address.
; y. T3 }' d4 x# C8 a         *       1 l% g4 S' F  P1 h
         *       For STM32F429, system memory is on 0x1FFF 0000
6 p/ Y+ J7 ?  \( ?         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
5 A6 R/ d6 m5 ^: I& E) u! G" ?: V         */3 S0 ?4 ?- y8 o& ]1 q9 S
        //volatile uint32_t addr = 0x1FFF0000;
9 s  A7 Q$ i- c; D" A0 k6 x    /**
) o* h  f6 ]( B6 k         * Step: Set system memory address.
3 a6 A2 p- q7 u: x' U         *      
+ @8 Q5 C2 [; Y& a         *       For STM32F103, system memory is on 0x1FFF F000/ j( L* [8 N+ }* t5 U
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses 4 ?* t0 `# z# i7 t( ]- I& v0 a
         */
; |6 M# \) r9 g+ B        //volatile uint32_t addr = 0x1FFFF000;
3 n- \$ D" ^/ w# G) t9 J" `2 @! H    /**  |+ o) |% b6 F2 ~0 L
         * Step: Set system memory address.
( T: h, M1 _' y5 y3 p0 k. V( m         *       1 X% z( [" q8 u
         *       For STM32F107, system memory is on 0x1FFF B000- F! M/ [  o6 R$ v7 c
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses : ^7 u9 P  `. t) f2 z, {
         *// B& H% [' |# z1 U/ W
        //volatile uint32_t addr = 0x1FFFB000;, y2 B$ n3 [# Y% M! ?9 ]7 p
    /**- d/ }3 Q  i7 P
         * Step: Set system memory address. 5 ^6 v# I5 @) V0 a5 }  f/ N
         *       & M1 m. f2 i4 L$ p
         *       For STM32F303, system memory is on 0x1FFF D800
# t6 }' p4 p- O9 o         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
# j1 Q" D* l9 e         */9 Z& D0 n' _* O- M, v2 d
        //volatile uint32_t addr = 0x1FFFD800;2 W! n% k7 B- O$ l7 ]4 O
        /**
% k3 t+ u9 ?* f! z& i- _6 K$ g         * Step: Set system memory address.
1 k! R  ^' k: h5 a2 m' \         *       ) }. |- N8 A3 {) P/ P3 u
         *       For STM32L073, system memory is on 0x1FF0 0000( i( {$ S" l" Z* X
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
6 b" Z$ T! h" ~4 `: S! T         */
( l5 i/ G) m; o6 X0 p        volatile uint32_t addr = 0x1FF00000;' k0 e: j0 [* q5 n
        # c( w8 L3 B: C2 ]' Z; V0 x
        /**9 L, U% d7 Z6 ~3 }, f: g  Q+ q1 O
         * Step: Disable RCC, set it to default (after reset) settings
9 _4 e0 o: a3 M2 J0 D& q1 g& \( h         *       Internal clock, no PLL, etc.3 W3 d; K2 w8 ]& r- q/ n
         */
" Q. J/ [' d5 u3 j" z" Q#if defined(USE_HAL_DRIVER)/ v/ M, I8 J9 K. Z! M
        HAL_RCC_DeInit();* W+ @  z4 G: S+ p4 A8 m# C
#endif /* defined(USE_HAL_DRIVER) */
- G$ c8 V- v2 h1 C) u, e; S#if defined(USE_FULL_LL_DRIVER)
8 Q! l( U$ d/ y: o; o! `0 B: h4 o        LL_RCC_DeInit();( ^, z4 B" x! h/ |& n9 g: v( \
#endif
4 G# R) ?- d- o#if defined(USE_STDPERIPH_DRIVER)
: S; k+ [4 f$ i  ^4 d; |        RCC_DeInit();
. ?9 `) X% q! `: M* y#endif /* defined(USE_STDPERIPH_DRIVER) */- o. O; p! B0 S1 I0 ?
        9 ~6 R# I& E" q. b
        /**
- m- w4 u6 a+ ^0 n         * Step: Disable systick timer and reset it to default values/ z% l- k8 V# i
         */
& f$ h; [" e9 B/ i6 B* L9 V" ]        SysTick->CTRL = 0;
2 e5 n% b( O: u6 r. n) w        SysTick->LOAD = 0;
/ @( Z3 A. u# a8 o) Z        SysTick->VAL = 0;
3 \; O0 ]! Z* ]! }$ j/ c( B8 i% g2 v6 L
+ F# g3 i2 _+ o! M: Z        /**
/ L* |% h3 D& u: H5 K+ Z, d         * Step: Disable all interrupts
1 w: m9 j# a0 @7 O         */3 f" I$ @+ q: N1 @6 P9 \) {
        __disable_irq();, G, k7 u# s0 [
        - m. _; g6 ~6 {6 l# x
        /**
! |: V9 C; a& ]" E% R* H5 f         * Step: Remap system memory to address 0x0000 0000 in address space+ L1 i" W7 I2 I. z& ]* n
         *       For each family registers may be different.
& D, l. i* O2 H7 f' |5 D         *       Check reference manual for each family.8 @3 \. b9 y0 B& @3 h" {5 X5 v
         *0 H3 n; t! [; `" p9 ]
         *       For STM32F4xx, MEMRMP register in SYSCFG is used (bits[1:0])
0 p) N3 k, N% m! m( u( ^         *       For STM32F0xx, CFGR1 register in SYSCFG is used (bits[1:0])+ X0 w! @, m$ g, _% O' ^, ]6 k2 O
         *       For others, check family reference manual' p: Q+ A, I- Q
         */" J/ Q; m% ?1 P* `6 k# ]2 k& L
        //Remap by hand... {& W: y. u2 f  i$ C6 {: L- B$ e0 Z
#if defined(STM32F4)% r9 M) ]/ N& U- [% g" W4 g
        SYSCFG->MEMRMP = 0x01;- ]; b7 r, p# a0 y& z
#endif! o+ I2 l3 D! \9 @
#if defined(STM32L0)
6 b. L" M6 x7 `- e  I, U! s& d        SYSCFG->CFGR1 = 0x01;- e4 g) {2 E1 h) Z
#endif
% i0 _4 g& G* k) ^) L+ }1 T1 u- [#if defined(STM32F0)  x- ]! b8 i0 M6 x9 k) c9 j0 b, d
        SYSCFG->CFGR1 = 0x01;
. j6 f# y; a! `' ~/ ~6 v# N( M#endif
% h6 C4 _/ H0 D' ~( p. h        //} ...or if you use HAL drivers
- q% }$ q' f+ W. h1 k1 H# q. V. u$ s        //__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();        //Call HAL macro to do this for you# O- f* c4 k5 @6 l
       
! C, z7 a9 r0 p        /**4 ?& n2 y, Y( D. X) ]8 @* ]
         * Step: Set jump memory location for system memory
2 t+ @( w' B% C+ d( g         *       Use address with 4 bytes offset which specifies jump location where program starts
/ [$ O: _# x9 z6 q. M3 t         */
, Z( W' C& u  c+ i% W        SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
' b6 R  S- L2 i/ X" ~$ h# \1 |9 ]       
7 Q2 ^$ S  Y5 W; D        /**: U6 I& l( w& [! @9 F8 ^$ o- k; [9 F! K
         * Step: Set main stack pointer./ n+ q, u/ p# V/ N  R& Z6 H, P
         *       This step must be done last otherwise local variables in this function# p% b- m: c$ v1 @3 l
         *       don't have proper value since stack pointer is located on different position
: L; X+ C6 L+ \( h8 y         *
% h- S: Z8 l# v' z* G- _         *       Set direct address location which specifies stack pointer in SRAM location! n$ W' p2 d) A& {  |1 u
         */
5 C# \7 x9 F; l2 s1 b        __set_MSP(*(uint32_t *)addr);
7 v9 W2 N, u3 v& z! X6 u/ K       
8 J( J3 k# t0 ?8 u        /**
$ ^: R9 m% J! \  Z9 C. A+ M         * Step: Actually call our function to jump to set location3 @* R! J# M1 u* B  y* m  f8 @
         *       This will start system memory execution- ~- a( _3 b2 R1 q
         */
' M6 I$ _/ X2 h3 s/ k& Y        SysMemBootJump();
0 i8 k, m) E" M- b0 a& Z        5 k4 e% u+ ]$ k4 V8 |/ J! W% w' z
        /**
$ e: W: G, S8 S( ?( }/ ^         * Step: Connect USB<->UART converter to dedicated USART pins and test9 B% n+ W$ D5 x" U  R- h
         *       and test with bootloader works with STM32 Flash Loader Demonstrator software4 h1 p& |0 l$ p4 y0 P. @  T
         */
1 n4 u& h7 o) b& {' r}2 r% X) T% J# I6 I
然后介绍下测试结果:
. f: V9 S( L% @5 Z; \1、F0系列:STM32F030、STM32F051、STM32F070、STM32F071和STM32F072芯片,其中除STM32F070跳转运行ISP运行错误(发现内部ISP代码好像有问题,具体也不确定)外,均可以支持软件跳转ISP后串口方式升级;, U! g5 E# V$ u) O/ O( H% d1 Z0 n8 w
2、F1系列:STM32F103和STM32F107芯片,均可以支持软件跳转ISP后串口方式升级;
7 T  J; p" H3 K: F3、F2系列:无芯片平台验证;
1 M$ m) R  [+ I( M4 a6 c4、F4系列:STM32F407芯片,支持软件跳转ISP后串口方式升级;
% T) p( ^& l1 O. r2 a3 {- g$ \- E0 y5、L0系列:STM32L073芯片,支持软件跳转ISP后串口方式升级;
4 q7 O( {* \% s. q4 a& r- q6、L4系列:STM32L4R5芯片,软件跳转ISP后运行直接跳转Hardfault(后续查找原因);& ?- ]3 s- J& @
7、其它系列均无平台验证;" R+ }0 W1 `; J9 p) s2 I
* y/ P, M4 U0 m+ Q+ T/ |+ {" M
. |0 g3 x' K% U. ~* U3 [( X- H
收藏 评论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工具,也不能进行升级呢。9 D. C: y' Z1 u5 y7 `9 q- m4 p: x
我用的开发板是官方的nucleo开发板,连接串口用的是lpuart1
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版