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

STM32L4R5ZIT6软件跳转ISP运行Hardfault问题

[复制链接]
yklstudent 发布时间:2019-11-14 14:08
最近研究ST芯片的内容ISP升级方法,按照官方推荐方式,需要设置BOOT引脚电平进入内容System Bootloader升级,感觉这种方式麻烦,所以查找是否可以软件方式直接跳转ISP进行升级;经过百度和各论坛查找资料,终于找到解决办法,并且经过验证大部分是可行的,少部分不行(暂时还没有搞清楚原因)
' K7 W# s/ Y, W, @8 v! E以下是软件跳转内容ISP的代码,可以直接调用即可:
" V, m; C, \# _7 z! v" p/**
6 D+ M6 c) p# V8 V, ^  x5 {) n: ^2 v * Function to perform jump to system memory boot from user application8 |) y1 E0 |( g( `9 D6 f" Q
*$ Q1 N. M6 E( t- L9 e2 m$ W# }
* Call function when you want to jump to system memory9 g' ]1 I, z* i* S& S" G, O
*/6 s% W+ ?+ q8 \6 o# M! w
void JumpToBootloader(void) {
; U2 S3 a- v8 C) d0 w* E4 x        void (*SysMemBootJump)(void);
/ r. |! H. @& p$ \. |        0 J- u3 N: Y* L9 L5 S3 ?
        /**; b8 @7 B; Z6 O. v
         * Step: Set system memory address. % i5 j+ C1 ^" L# Q4 D4 {( ?
         *       5 S3 E$ I# r7 M
         *       For STM32F429, system memory is on 0x1FFF 0000
$ c! f% Y) z' ^4 O5 ]; Z. Y& X         *       For other families, check AN2606 document table 110 with descriptions of memory addresses ! \3 o# A$ z8 X# b1 M
         */
) N0 ]  F' a; s/ u0 c8 I) h        //volatile uint32_t addr = 0x1FFF0000;! G- d7 w6 L1 z9 c" E" F* [
    /*** P+ T# E) X* q. V  A
         * Step: Set system memory address. 4 T) r+ ~# [* c& ]" U7 u
         *       8 C& B1 i& L1 K. J, A; |8 {
         *       For STM32F103, system memory is on 0x1FFF F000# g0 [7 @& u" a! O' P; X
         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
9 H( F, M% p, l* t5 C3 E0 }1 s         */, q! @2 t1 r! D9 E
        //volatile uint32_t addr = 0x1FFFF000;6 \; N- u3 a4 a' R
    /**
% C9 }+ C& ?9 J# u& r/ _         * Step: Set system memory address.   k- @4 q$ j: P
         *       * b5 y. w. _1 ^/ T
         *       For STM32F107, system memory is on 0x1FFF B000
4 t9 t5 @2 y1 z# X# D         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
5 k* D, Q4 }7 m4 {; U, j% E         */8 V2 J# {. f: {! T
        //volatile uint32_t addr = 0x1FFFB000;
( g- r4 c( e2 D* M3 r    /**
, Q+ x) s! B! M$ [5 F         * Step: Set system memory address.
* Q) A8 `: k! Z, @% E' D         *       # z5 E$ J& x- A) f3 d
         *       For STM32F303, system memory is on 0x1FFF D800
1 F% U! W& F7 R3 q" b         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
! s7 k+ Z0 i' v, q6 r         */: {; @3 @' h% {' X
        //volatile uint32_t addr = 0x1FFFD800;( h) d& p1 J) v8 d3 f6 j& y- m
        /*** k: K% r2 L% W
         * Step: Set system memory address.
2 R% @1 T5 Q# X0 p         *       7 z9 x# k$ _& O! l
         *       For STM32L073, system memory is on 0x1FF0 0000
* d, _0 j/ _1 M% _) y; y5 Y         *       For other families, check AN2606 document table 110 with descriptions of memory addresses
! i: D, `% J* X4 p         */0 q9 h9 C1 n+ ^* e- K  [% v
        volatile uint32_t addr = 0x1FF00000;
6 p' c* J+ U' a$ F: f5 u: v  {       
' n: ]7 U& Q9 q! u& t! p2 X2 l) j        /**4 v$ Y0 k2 x# x3 J% Q+ i0 u
         * Step: Disable RCC, set it to default (after reset) settings
& Q( \# ?/ k+ p, A8 ?$ Q         *       Internal clock, no PLL, etc.+ b# ~/ N$ ~* j. u4 ~% }
         */
  J' k; L( [4 [! o$ f  _" F: s#if defined(USE_HAL_DRIVER)
+ y8 U! ?. M* t9 J7 }        HAL_RCC_DeInit();
5 U, ?5 @' ?' ]$ h5 {& Y' V#endif /* defined(USE_HAL_DRIVER) */9 v- }0 h1 L- M6 @
#if defined(USE_FULL_LL_DRIVER)
: w& T4 s' a. O7 r6 i        LL_RCC_DeInit();/ F, h- \# W* K
#endif5 ~0 C7 ]) _$ @! y9 t  Y3 s
#if defined(USE_STDPERIPH_DRIVER)# W8 @3 `, Q6 N1 A$ w+ s( x
        RCC_DeInit();
  {7 s* ?) @; y9 l7 d) r#endif /* defined(USE_STDPERIPH_DRIVER) */- S: z6 H0 d* p  b5 l$ g! }
        & P! p+ j, `: F7 w
        /**. @/ Z/ t$ l' c  T) T# k+ H
         * Step: Disable systick timer and reset it to default values
' S- V, U- c3 X# m/ @         */
2 c/ T& B% z, w9 T0 O+ m* Y5 r& _        SysTick->CTRL = 0;8 T: t3 E1 l, a( G$ i
        SysTick->LOAD = 0;
. I& c& J, N3 T        SysTick->VAL = 0;
. j1 t. u0 M% t- p4 j
2 P8 p: }+ \+ e' ]8 I1 g        /**
4 E) z, g" S. \- ^         * Step: Disable all interrupts4 j; L) \; M7 {4 p5 _$ c
         */
0 {, F, {; ?, [4 \1 E1 F0 `1 v        __disable_irq();
, J) ^3 l3 v0 h8 a        * I( Z1 [3 J+ Z, \3 E3 w
        /**
; c* B* D! O7 w, X8 ~% w' w  ]' R- Z) M         * Step: Remap system memory to address 0x0000 0000 in address space
5 ?' r0 \8 j' d5 H         *       For each family registers may be different. $ e7 G/ g4 x- m: l
         *       Check reference manual for each family.2 ~5 g. [$ p1 W+ U7 k2 ?
         *
% Q% L7 ^1 V# p6 W) d: w5 o         *       For STM32F4xx, MEMRMP register in SYSCFG is used (bits[1:0])# u  Q8 y  ?1 Q# W6 f$ ~
         *       For STM32F0xx, CFGR1 register in SYSCFG is used (bits[1:0])
* P7 c5 }5 }9 ~2 `) H- L         *       For others, check family reference manual
& a, N2 p, b& e9 K7 p         */
: d$ j. O# D7 Y8 S2 g% {0 O        //Remap by hand... {3 a# f1 o7 `, e4 {, i2 M4 Z3 _8 [; J
#if defined(STM32F4)8 j8 t6 |( \2 u3 L/ Q$ V$ ^( L5 j
        SYSCFG->MEMRMP = 0x01;
' N+ V/ f+ R9 r; U! H9 i) W#endif8 ^1 k+ |' P+ C- I* d& C
#if defined(STM32L0)
; o! H, F5 y; f  T( X        SYSCFG->CFGR1 = 0x01;
6 d/ g" c; @7 K" {$ T4 U" Z0 }#endif
( X( e7 ], j* X2 S#if defined(STM32F0)" [8 j8 N+ z) @( Y
        SYSCFG->CFGR1 = 0x01;8 O1 J9 }" f; r4 C6 ]
#endif( P+ b' n! p5 a
        //} ...or if you use HAL drivers& A! U3 U, r% {2 L# L- \, C
        //__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();        //Call HAL macro to do this for you
' K4 d. W# Z" A        ( B" c) k; ~8 I2 o1 t* `
        /**0 ^9 z6 d" i; }! {8 }8 L6 H
         * Step: Set jump memory location for system memory
1 `; i$ @; V5 v6 x, K! {- ?+ p         *       Use address with 4 bytes offset which specifies jump location where program starts
! c+ V% B. i+ y$ f+ Q9 z. a# |         */+ [& X( J0 Y2 ]  j2 F. Y
        SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));7 g. }: ]* j% ~, f  t& p* R9 C
       
# P( I0 L$ p& ]  Q1 o6 Y1 h% d7 X        /**
% Y# e" x) B% L. d- R% y" {+ o* m         * Step: Set main stack pointer.9 n& j2 T6 w, N  S
         *       This step must be done last otherwise local variables in this function
5 B# X; S: i9 M8 j0 r5 H         *       don't have proper value since stack pointer is located on different position% i  A1 c8 r- e0 O9 G! e
         *
$ h! Q& y/ V! H5 {; |' C- d6 @, q! A         *       Set direct address location which specifies stack pointer in SRAM location
8 x& D* ]2 U2 `! z' X" I" j) j         */8 b5 ^: {8 v6 v& i& r6 f! \2 ?$ c
        __set_MSP(*(uint32_t *)addr);
& O3 N( q, o! a8 d       
" A0 U9 p3 w  P5 G- n4 z        /**" s: L: D8 ~  L) p1 K  L- G
         * Step: Actually call our function to jump to set location& S" Q/ H' q1 l
         *       This will start system memory execution
  }" U' v3 {5 h+ P         */. _. l. K/ J) I
        SysMemBootJump();
8 h9 i) z( A. ^' ^& ]       
: N. [3 T- z& f* t0 e- t- M7 @        /**
( N5 `" z  R  V4 p" ?1 _7 {" N         * Step: Connect USB<->UART converter to dedicated USART pins and test
6 g  u$ ]; b8 w: |* |" M  b( U         *       and test with bootloader works with STM32 Flash Loader Demonstrator software9 T4 Z* M* c. m/ y" o
         */
& p* I: m7 z  J3 Z" z}
3 n7 y" U) {8 M& U) s4 T然后介绍下测试结果:5 J( Q: |: q: q& R- g- w. D
1、F0系列:STM32F030、STM32F051、STM32F070、STM32F071和STM32F072芯片,其中除STM32F070跳转运行ISP运行错误(发现内部ISP代码好像有问题,具体也不确定)外,均可以支持软件跳转ISP后串口方式升级;  X  F5 T! [* E" }/ d: N( C$ K
2、F1系列:STM32F103和STM32F107芯片,均可以支持软件跳转ISP后串口方式升级;
8 \& X7 E# f2 L7 j3、F2系列:无芯片平台验证;* w; L& E6 |4 l; J6 N( x
4、F4系列:STM32F407芯片,支持软件跳转ISP后串口方式升级;; G6 ^0 i4 B( M4 G! ?
5、L0系列:STM32L073芯片,支持软件跳转ISP后串口方式升级;
( ^7 y* s9 N% O1 ^( i" J6、L4系列:STM32L4R5芯片,软件跳转ISP后运行直接跳转Hardfault(后续查找原因);4 X2 v& p7 {; Y: a- C7 v
7、其它系列均无平台验证;2 q2 g' ?8 ]$ O# _

( ?; M6 p2 o8 Q0 T$ C" v. n
" R  u. M& S% b2 N% k  H" F
收藏 评论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工具,也不能进行升级呢。
* ?5 Q; v* z9 {8 x8 `  |3 J* B我用的开发板是官方的nucleo开发板,连接串口用的是lpuart1
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版