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

STM32L4R5ZIT6软件跳转ISP运行Hardfault问题

[复制链接]
yklstudent 发布时间:2019-11-14 14:08
最近研究ST芯片的内容ISP升级方法,按照官方推荐方式,需要设置BOOT引脚电平进入内容System Bootloader升级,感觉这种方式麻烦,所以查找是否可以软件方式直接跳转ISP进行升级;经过百度和各论坛查找资料,终于找到解决办法,并且经过验证大部分是可行的,少部分不行(暂时还没有搞清楚原因)- s6 {$ Z; z5 j- ~; S3 T" b
以下是软件跳转内容ISP的代码,可以直接调用即可:
1 T4 I& `/ i6 h2 v! _4 W2 S$ X/**5 P. ^; u  g% F2 _" [# J
* Function to perform jump to system memory boot from user application  q$ H8 ^# Z2 i# s7 _4 B
*8 Y; s, E# B: m! P$ E
* Call function when you want to jump to system memory
- ^5 _9 r2 o: Y4 w */
& A+ o" l! n) ?; C* }/ wvoid JumpToBootloader(void) {
9 Y* n/ u7 f5 U  i        void (*SysMemBootJump)(void);
' U; C# m3 _: I+ t/ J- T1 h- n       
/ [/ D7 ?4 \. P" r        /**
  ?; s/ K% c) C1 h6 r         * Step: Set system memory address.
) L# w! h) v" s4 V# _* e& y" t         *      
3 l, v. `  i. v) ^! x$ D         *       For STM32F429, system memory is on 0x1FFF 0000
1 ~. P, c, z2 o7 ~) h         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
' v# t0 h9 ?8 I) M/ d         */
" L/ k1 j+ w$ l. {# O        //volatile uint32_t addr = 0x1FFF0000;
! |% U5 }5 \' Q9 L6 q3 d7 Z) u    /**
4 S& K3 T4 e; Q+ l5 j3 b         * Step: Set system memory address. % i- [3 |' X5 s1 ^; f  `
         *      
4 @! r$ M1 n* B         *       For STM32F103, system memory is on 0x1FFF F0005 F% }; w, U6 b: S
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
  B1 n, E( H% t: \: @8 H( o; n4 f         */3 F! C5 |& f3 ], S3 {. f
        //volatile uint32_t addr = 0x1FFFF000;7 y" R3 e7 j' b; F( y2 ~/ K
    /**
: a9 D! e3 e, w% S& x/ o3 {         * Step: Set system memory address. % Q- ]8 M# {9 W. x
         *       , N: Z* o9 f9 R+ ^! Q
         *       For STM32F107, system memory is on 0x1FFF B0001 T1 V! x7 }" J
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
7 i; B! x. L8 }+ o# I& K2 v- g         */# z5 h+ ^+ _. S2 q+ i
        //volatile uint32_t addr = 0x1FFFB000;: L3 X" ^, F6 @) w. p
    /**8 b( T& ?; ~  c' h5 N. ~
         * Step: Set system memory address. ' V% v$ N4 f$ k" P* X  ]  b) W
         *       9 w- o6 n+ Y7 t  Y$ B& O% `5 i
         *       For STM32F303, system memory is on 0x1FFF D800
0 j; p# q5 D0 c, j         *       For other families, check AN2606 document table 110 with descriptions of memory addresses 3 h5 W) p/ ?! \% m9 f$ V) y$ [
         */
1 w6 ]6 E0 h1 `3 o( d        //volatile uint32_t addr = 0x1FFFD800;
( ~( P) i9 b1 M        /**
" Q" ], [# Q+ |4 `: _         * Step: Set system memory address. ' K# c( R' p# p
         *       : ]& i4 e  ^+ ]
         *       For STM32L073, system memory is on 0x1FF0 0000# K) s% B& ~4 q* t, K- j$ ^7 s
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses 5 l" g" h2 d0 l9 U  N# I
         */5 k, D2 t% R; _6 `$ K
        volatile uint32_t addr = 0x1FF00000;9 x) D/ S4 J* x  f& X" K0 h5 I  K
       
- e4 J. J+ B7 T0 [) W" j        /**" b9 u0 G# F4 ?3 R' i! q, S& N
         * Step: Disable RCC, set it to default (after reset) settings
  F8 v' e: E* F! M* M         *       Internal clock, no PLL, etc.
! }7 E% h: ]& s+ T1 ?; |         */6 f2 Z* N+ ?* ~1 r, K
#if defined(USE_HAL_DRIVER)! J0 O$ N, m& Q) u& I3 i
        HAL_RCC_DeInit();5 a2 u" C/ ^& v
#endif /* defined(USE_HAL_DRIVER) */# u  E' `; c, i. |
#if defined(USE_FULL_LL_DRIVER)8 d. ~* m/ d2 Z" p
        LL_RCC_DeInit();
1 h2 q1 x+ I  g#endif8 [; ]( o3 D' A0 |3 f: e+ Z# _
#if defined(USE_STDPERIPH_DRIVER)
3 S+ G4 K5 f" {0 B  f6 b7 m: e" V9 h        RCC_DeInit();
% d2 x# b8 n& @$ Z, R6 f4 ^#endif /* defined(USE_STDPERIPH_DRIVER) */
9 r4 X, A4 y) P7 f: C+ B       
' ]/ j7 F- g: R- p, L        /**
! y* F- H5 o8 e2 k7 Y         * Step: Disable systick timer and reset it to default values! L1 n, S/ E' [# h- [
         */  d4 Q0 W$ i1 J7 x$ n
        SysTick->CTRL = 0;$ O/ z1 c/ v1 W" {$ v. O& S/ R7 S; K  O
        SysTick->LOAD = 0;
: T$ {/ ]0 n5 }( ]" t        SysTick->VAL = 0;
2 n6 n( l  e# o8 t. c( c+ @
* }! D6 D  y7 x. o: J/ e& v) q; U        /**
( L0 v  H% x, O+ A5 [         * Step: Disable all interrupts
" c3 G! R% y5 U. A. p6 H         */2 R3 U, j" L$ U+ A6 o% [" g1 R1 `
        __disable_irq();0 L0 V8 V) [0 ^6 ~3 D: ~
       
6 ~/ X2 C7 Z, W. p! z$ C+ |. s        /**& X# s  {8 C. x  a
         * Step: Remap system memory to address 0x0000 0000 in address space+ s6 ]4 i. \  i" ^. }) }
         *       For each family registers may be different.
8 }4 e/ F7 Y' W7 C" C3 C% |  j* m         *       Check reference manual for each family.
# c1 v2 N7 Q2 S8 T         *; L0 V& h# i& p1 H- b% z/ H  h
         *       For STM32F4xx, MEMRMP register in SYSCFG is used (bits[1:0])
. F+ i9 h: V& ]         *       For STM32F0xx, CFGR1 register in SYSCFG is used (bits[1:0])
) Q. b5 R" R# Q2 E- @1 s& i) t" ?5 ]         *       For others, check family reference manual
/ l% ^  m; f. d/ X' _. o         */+ Y  \3 D) V. R# ]* ^5 F6 Y) k
        //Remap by hand... {9 ~4 q. P" k$ x# V# Y* |
#if defined(STM32F4)
3 l* a8 B$ t+ a+ w4 k        SYSCFG->MEMRMP = 0x01;! c2 j* L( L1 }3 S8 {: D2 Q5 d
#endif
- F! y+ Y! }- m5 g#if defined(STM32L0)
- R5 {  B4 H. |9 z7 {        SYSCFG->CFGR1 = 0x01;, \/ E" c/ v2 Z- G
#endif
: V& s! M& a3 A9 `. u#if defined(STM32F0)) l1 j9 X* R# L
        SYSCFG->CFGR1 = 0x01;% }, ]3 S* e6 R$ |
#endif5 Z: J7 Q2 T: y# x% S. H
        //} ...or if you use HAL drivers! E( F+ y6 _9 g# ?, J9 V& v8 W; c
        //__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();        //Call HAL macro to do this for you
. V0 C) d/ O, x3 g6 T: R        2 b% m+ \. b+ a9 l, V8 Q# j
        /**
8 b9 _- o. ^4 X2 K. K         * Step: Set jump memory location for system memory
" Y% S: |6 @# p) u         *       Use address with 4 bytes offset which specifies jump location where program starts
: J5 {1 V" E. c* U; N8 q! ]$ c* |         */
# z; S! z. ]( q& }" q% y# N        SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
* C/ q8 k' @( W" x9 T! y       
" @+ ^. H7 t7 f4 A- ~6 j% q        /**6 {  Q2 Q- r( Q8 Z
         * Step: Set main stack pointer.% z2 p, |% X: B/ Q1 ^
         *       This step must be done last otherwise local variables in this function0 Q6 y  r5 R1 j8 Z5 h$ u8 f
         *       don't have proper value since stack pointer is located on different position
6 }) M/ K0 M# \: q         *
* T4 t; z( e7 t# w$ l         *       Set direct address location which specifies stack pointer in SRAM location
3 Q5 B, V" S% Z, K2 W6 L         *// X) s' ?* A* }7 q: G
        __set_MSP(*(uint32_t *)addr);
* {( W" t# y2 i) X3 c( m! j1 R& b       
! C3 V1 e- l5 i# o' ^2 H        /**
  U/ O, I' o+ J7 x. m         * Step: Actually call our function to jump to set location, F; G: W" q; i8 E$ s# e
         *       This will start system memory execution+ i$ M8 D) H2 j) Q/ U- _$ H8 [
         */
2 c# o, q2 O; m- d7 I( m        SysMemBootJump();% e/ z* x) Y5 b# _$ W2 y
        , c4 p( p' t* ]5 ^4 E$ d
        /**: o6 [0 C6 w8 t6 {
         * Step: Connect USB<->UART converter to dedicated USART pins and test- a+ Q. W5 ]3 l7 u* o
         *       and test with bootloader works with STM32 Flash Loader Demonstrator software
4 A# r/ x6 w9 F, c) _5 k         */" ~9 s+ n- k/ g. V
}. b9 k0 s0 D( q* }) `
然后介绍下测试结果:
* C" i  S9 U: L) V7 B  L& h# D1、F0系列:STM32F030、STM32F051、STM32F070、STM32F071和STM32F072芯片,其中除STM32F070跳转运行ISP运行错误(发现内部ISP代码好像有问题,具体也不确定)外,均可以支持软件跳转ISP后串口方式升级;
% @8 m/ w) K- t2 F9 S2、F1系列:STM32F103和STM32F107芯片,均可以支持软件跳转ISP后串口方式升级;
7 h. j; b2 E5 F: S3、F2系列:无芯片平台验证;
' W8 P# \+ ~6 b9 ~# i# C  m7 D4、F4系列:STM32F407芯片,支持软件跳转ISP后串口方式升级;1 ^* P8 I* u* J% q: p
5、L0系列:STM32L073芯片,支持软件跳转ISP后串口方式升级;
8 M: u7 `; ]' s& C4 w6、L4系列:STM32L4R5芯片,软件跳转ISP后运行直接跳转Hardfault(后续查找原因);0 E0 ]5 n2 n% b1 P+ |  S; j2 C
7、其它系列均无平台验证;
) A4 _$ m8 p! ~& E' r1 r
2 G- \! d: J- Z# n6 ^! x4 ]2 O; l$ r
" R1 D: a9 e$ k! W6 x# m1 G
收藏 评论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 c5 l5 V& X4 e) r我用的开发板是官方的nucleo开发板,连接串口用的是lpuart1
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版