簡體   English   中英

STM32 重置問題

[英]STM32 Reset issues

我已經在 C 和 Rust 中對我的 STM32F401 進行了編程,但是在組裝時遇到了問題。

  • 當我最初使用 Black Magic Probe 加載代碼時,它運行良好
  • 當我的電路板通電或重置時,代碼不會運行。
  • 重置后,在 GDB 中,如果我嘗試C 繼續它,它會拋出異常
  • 重置后,在 GDB 中,如果我嘗試在R上運行它,它運行正常

重置處理程序中的實際代碼是常年“閃爍”。 我確定代碼沒有問題,這“聞起來”某種“初始化問題”?

  • 我是一個巨大的 GDB 菜鳥,但如果我做info registers ,PC 總是我期望的值 - 0x8000198
Disassembly of section .text:

08000000 <vector_table>:
 8000000:   20010000    .word   0x20010000
 8000004:   08000198    .word   0x08000198
 8000008:   08000194    .word   0x08000194
 -- redacted a load from brevity... they're all 0x0800194 
 8000188:   08000194    .word   0x08000194
 800018c:   08000194    .word   0x08000194
 8000190:   08000194    .word   0x08000194

08000194 <Default_handler>:
 8000194:   f7ff bffe   b.w 8000194 <Default_handler>

08000198 <Reset_handler>:

            ; RCC_AHB1ENR := RCC_AHB1ENR OR RCC_AHB1Periph_GPIOC

 8000198:   f643 0030   movw    r0, #14384  ; 0x3830
 800019c:   f2c4 0002   movt    r0, #16386  ; 0x4002
 80001a0:   6802        ldr r2, [r0, #0]
 80001a2:   f042 0204   orr.w   r2, r2, #4
 80001a6:   6002        str r2, [r0, #0]

            ; GPIOC_MODER := GPIO_MODER_13_OUTPUT

 80001a8:   f640 0000   movw    r0, #2048   ; 0x800
 80001ac:   f2c4 0002   movt    r0, #16386  ; 0x4002
 80001b0:   f240 0200   movw    r2, #0
 80001b4:   f2c0 4200   movt    r2, #1024   ; 0x400
 80001b8:   6002        str r2, [r0, #0]

 80001ba:   f240 0220   movw    r2, #32     ;          0b00100000
 80001be:   f2c0 0200   movt    r2, #0

 80001c2:   f640 0019   movw    r0, #2073   ; 0x819    GPIOC_BSRR8
 80001c6:   f2c4 0002   movt    r0, #16386  ; 0x4002
 80001ca:   f640 011b   movw    r1, #2075   ; 0x81b    GPIOC_BSRR24
 80001ce:   f2c4 0102   movt    r1, #16386  ; 0x4002

080001d2 <.loop>:
 80001d2:   7002        strb    r2, [r0, #0] ; set bit

 80001d4:   f240 0300   movw    r3, #0
 80001d8:   f2c0 030d   movt    r3, #13
080001dc <.delay0>:
 80001dc:   3b01        subs    r3, #1
 80001de:   bf18        it  ne
 80001e0:   e7fc        bne.n   80001dc <.delay0>

 80001e2:   700a        strb    r2, [r1, #0] ; reset bit

 80001e4:   f240 0300   movw    r3, #0
 80001e8:   f2c0 030d   movt    r3, #13
080001ec <.delay1>:
 80001ec:   3b01        subs    r3, #1
 80001ee:   bf18        it  ne
 80001f0:   e7fc        bne.n   80001ec <.delay1>

 80001f2:   e7ee        b.n 80001d2 <.loop>
 8000004:   08000198    .word   0x08000198

必須是奇數才能啟動

您需要使用.thumb_func 或.type(如果使用gnu 匯編程序,如果使用另一種匯編語言,則需要針對該語言對其進行分類)

.cpu cortex-m4
.thumb

vector_table:
.word 0x20001000
.word ResetVector

.thumb_func
.globl ResetVector
ResetVector:
   b .

Disassembly of section .text:

08000000 <vector_table>:
 8000000:   20001000    .word   0x20001000
 8000004:   08000009    .word   0x08000009

08000008 <ResetVector>:
 8000008:   e7fe        b.n 8000008 <ResetVector>

這將啟動(或至少會嘗試運行重置處理程序)

沒有:

.cpu cortex-m4
.thumb

vector_table:
.word 0x20001000
.word ResetVector

.globl ResetVector
ResetVector:
   b .

Disassembly of section .text:

08000000 <vector_table>:
 8000000:   20001000    .word   0x20001000
 8000004:   08000008    .word   0x08000008

08000008 <ResetVector>:
 8000008:   e7fe        b.n 8000008 <ResetVector>

這不會啟動

您也可以使用.type,.type 適用於 arm 和 thumb(如果執行 ARM 指令,這是不可能的,因為它是 cortex-m)。

.cpu cortex-m4
.thumb

vector_table:
.word 0x20001000
.word ResetVector

.type ResetVector, %function
.globl ResetVector
ResetVector:
   b .

Disassembly of section .text:

08000000 <vector_table>:
 8000000:   20001000    .word   0x20001000
 8000004:   08000009    .word   0x08000009

08000008 <ResetVector>:
 8000008:   e7fe        b.n 8000008 <ResetVector>

所有其他向量(不是 sp 初始值)必須是奇數。 使用工具不要做一些加一的事情。

您的調試器可能是直接啟動程序而不是重置部件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM