Skip to content

[stm32] Update stm32 boards#2784

Merged
bors[bot] merged 1 commit into
tock:masterfrom
WyliodrinEmbeddedIoT:update_stm32_boards
Aug 20, 2021
Merged

[stm32] Update stm32 boards#2784
bors[bot] merged 1 commit into
tock:masterfrom
WyliodrinEmbeddedIoT:update_stm32_boards

Conversation

@alexandruradovici

@alexandruradovici alexandruradovici commented Aug 16, 2021

Copy link
Copy Markdown
Contributor

Pull Request Overview

This pull request updates the stm32 boards:

  • adds the process console
  • simplifies setting pin interrupts
  • fixes the adc to return 16 bit values

This pull request adds a helper function to make enabling interrupts for gpio easier. The stm32 MCU does not provide a separate interrupt line for all the gpio pins. This makes enabling interrupts a little more difficult and requires some extra code in the board file.

I am not the original author of the code for these boards, so I am not sure why this has been designed the way it is now.

This also enables interrupts for the first gpio exposed pin, allowing the gpio test to succeed.

Testing Strategy

This pull request was tested using a nucleo F429ZI and an STM32F4g Discovery board

TODO or Help Wanted

N/A

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@github-actions github-actions Bot added the chips/stm32 Change pertains to the stm32 family of MCUSs label Aug 16, 2021
@yusefkarim

Copy link
Copy Markdown
Contributor

I confirmed these changes worked on the WeAct STM32F401CCU6, however I a fault consistently occurred if I rapidly trigger the interrupt multiple times in a row (by pulling the selected pin high). This may not be due to your changes and something more related to Tock 2.0 (or 1.0 haha). If it would be better for me to bring this up elsewhere (it's own issue?), just let me know. The serial debug output is included below:

panicked at 'Process gpio had a fault', kernel/src/process_standard.rs:323:17
	Kernel version release-1.4-4641-gdb4b65f59

---| No debug queue found. You can set it with the DebugQueue component.

---| Cortex-M Fault Status |---
Data Access Violation:              true
Memory Management Stacking Fault:   true
Forced Hard Fault:                  true
Faulting Memory Address:            0x20003FF0
Fault Status Register (CFSR):       0x00000092
Hard Fault Status Register (HFSR):  0x40000000

---| App Status |---
𝐀𝐩𝐩: gpio   -   [Faulted]
 Events Queued: 2   Syscall Count: 259   Dropped Upcall Count: 10
 Restart Count: 0
 Last Syscall: Some(Yield { which: 1, address: 0x0 })


 ╔═══════════╤══════════════════════════════════════════╗
 ║  Address  │ Region Name    Used | Allocated (bytes)  ║
 ╚0x20006000═╪══════════════════════════════════════════╝
             │ ▼ Grant        1160 |   1160
  0x20005B78 ┼───────────────────────────────────────────
             │ Unused
  0x2000515C ┼───────────────────────────────────────────
             │ ▲ Heap         1796 |   4384               S
  0x20004A58 ┼─────────────────────────────────────────── R
             │ Data            600 |    600               A
  0x20004800 ┼─────────────────────────────────────────── M
             │ ▼ Stack        2216 |   2048 EXCEEDED!
  0x20003F58 ┼───────────────────────────────────────────
             │ Unused
  0x20004000 ┴───────────────────────────────────────────
             .....
  0x08022000 ┬─────────────────────────────────────────── F
             │ App Flash      8144                        L
  0x08020030 ┼─────────────────────────────────────────── A
             │ Protected        48                        S
  0x08020000 ┴─────────────────────────────────────────── H

  R0 : 0xBAD00BAD    R6 : 0x20004880
  R1 : 0xBAD00BAD    R7 : 0x20004800
  R2 : 0xBAD00BAD    R8 : 0x20004AD4
  R3 : 0xBAD00BAD    R10: 0x00000000
  R4 : 0x20004880    R11: 0x00000000
  R5 : 0x20004A54    R12: 0xBAD00BAD
  R9 : 0x20004800 (Static Base Register)
  SP : 0x20003F58 (Process Stack Pointer)
  LR : 0xBAD00BAD
  PC : 0xBAD00BAD
 YPC : 0x080202CA

 APSR: N 1 Z 0 C 1 V 1 Q 1
       GE 0 0 0 0
 EPSR: ICI.IT 0x42
       ThumbBit false !!ERROR - Cortex M Thumb only!

 Total number of grant regions defined: 6
  Grant  0 0x1: 0x20005b88  Grant  2 : --          Grant  4 : --
  Grant  1 : --          Grant  3 0x4: 0x20005b78  Grant  5 : --

 Cortex-M MPU
  Region 0: [0x20004000:0x20006000], length: 8192 bytes; ReadWrite (0x3)
    Sub-region 0: [0x20004000:0x20004400], Enabled
    Sub-region 1: [0x20004400:0x20004800], Enabled
    Sub-region 2: [0x20004800:0x20004C00], Enabled
    Sub-region 3: [0x20004C00:0x20005000], Enabled
    Sub-region 4: [0x20005000:0x20005400], Enabled
    Sub-region 5: [0x20005400:0x20005800], Disabled
    Sub-region 6: [0x20005800:0x20005C00], Disabled
    Sub-region 7: [0x20005C00:0x20006000], Disabled
  Region 1: [0x08020000:0x08022000], length: 8192 bytes; UnprivilegedReadOnly (0x2)
    Sub-region 0: [0x08020000:0x08020400], Enabled
    Sub-region 1: [0x08020400:0x08020800], Enabled
    Sub-region 2: [0x08020800:0x08020C00], Enabled
    Sub-region 3: [0x08020C00:0x08021000], Enabled
    Sub-region 4: [0x08021000:0x08021400], Enabled
    Sub-region 5: [0x08021400:0x08021800], Enabled
    Sub-region 6: [0x08021800:0x08021C00], Enabled
    Sub-region 7: [0x08021C00:0x08022000], Enabled
  Region 2: Unused
  Region 3: Unused
  Region 4: Unused
  Region 5: Unused
  Region 6: Unused
  Region 7: Unused

To debug, run `make debug RAM_START=0x20004000 FLASH_INIT=0x8020059`
in the app's folder and open the .lst file.

@alexandruradovici

Copy link
Copy Markdown
Contributor Author

It seems that you have a stack overflow fault. My first guess it that it might be dut to the printf. Can you open a new issue and try the following:

  1. turn on a syscall trace (kernel/src/config.rs) and paste the output
  2. delete the printf from the while statement and run the application. Does it still fault?
  3. replace the printf with an LED toggle and try to run it and see if it faults

Comment thread chips/stm32f4xx/src/gpio.rs Outdated
@bradjc

bradjc commented Aug 17, 2021

Copy link
Copy Markdown
Contributor

A stack overflow can happen if yield is called in a callback in a loop and the stack frames never get a chance to be popped off the stack.

@hudson-ayers hudson-ayers added the tock-2.0 Issues and PRs related to Tock version 2.0. label Aug 18, 2021

@hudson-ayers hudson-ayers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small comments, but this mostly looks good.

I think its a little weird seeing the changes to the touch capsules grouped in here with the other changes, but I realize only STM boards currently use those capsules so I'm not too worried about it.

Comment thread boards/stm32f412gdiscovery/Makefile Outdated
Comment thread boards/stm32f412gdiscovery/Makefile Outdated
@hudson-ayers hudson-ayers changed the title [stm32] Update stm32 boards [stm32] Update stm32 boards + touch capsules Aug 19, 2021
@alexandruradovici

Copy link
Copy Markdown
Contributor Author

A couple small comments, but this mostly looks good.

I think its a little weird seeing the changes to the touch capsules grouped in here with the other changes, but I realize only STM boards currently use those capsules so I'm not too worried about it.

I found the issues while testing the touch panel. I can split them out in two PRs if necessary.

hudson-ayers
hudson-ayers previously approved these changes Aug 19, 2021
lschuermann
lschuermann previously approved these changes Aug 19, 2021

@lschuermann lschuermann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general.

I agree with Hudson it's weird that this contains changes to the ft6x06 device driver (and a pretty large changeset at that). A separate PR with a description of what precisely has been the issue here would've been great.

@alexandruradovici

Copy link
Copy Markdown
Contributor Author

Looks good in general.

I agree with Hudson it's weird that this contains changes to the ft6x06 device driver (and a pretty large changeset at that). A separate PR with a description of what precisely has been the issue here would've been great.

I agree, I'll split it and send new PRs

@alexandruradovici alexandruradovici changed the title [stm32] Update stm32 boards + touch capsules [stm32] Update stm32 boards Aug 19, 2021
@hudson-ayers

Copy link
Copy Markdown
Contributor

It looks like this PR still includes the changes to touch/ft6x06?

@alexandruradovici

Copy link
Copy Markdown
Contributor Author

It looks like this PR still includes the changes to touch/ft6x06?

I'm sorry, fixed it :)

#[no_mangle]
#[link_section = ".stack_buffer"]
pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
pub static mut STACK_MEMORY: [u8; 0x1400] = [0; 0x1400];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it seems the stm32 boards may still need some more stack optimization:

make stack-analysis
stm32f3discovery
----------------------
   main stack frame:
          696     main

   5 largest stack frames:
         4024     _ZN16stm32f3discovery15get_peripherals17h48eb20f8d2a6a9f6E
         2120     rust_begin_unwind
          704     _ZN8capsules15process_console23ProcessConsole$LT$C$GT$11write_state17h724a1bf796a6ceffE
          696     main
          624     _ZN104_$LT$capsules..process_console..ProcessConsole$LT$C$GT$$u20$as$u20$kernel..hil..uart..TransmitClient$GT$18transmitted_buffer17hffe88b7f7ca20846E

@bradjc

bradjc commented Aug 20, 2021

Copy link
Copy Markdown
Contributor

bors r+

@bors

bors Bot commented Aug 20, 2021

Copy link
Copy Markdown
Contributor

@bors bors Bot merged commit 361f8ae into tock:master Aug 20, 2021
sirchnik pushed a commit to sirchnik/tock that referenced this pull request May 12, 2026
2784: [stm32] Update stm32 boards r=bradjc a=alexandruradovici

### Pull Request Overview

This pull request updates the stm32 boards:
- adds the process console
- simplifies setting pin interrupts
- fixes the adc to return 16 bit values

This pull request adds a helper function to make enabling interrupts for gpio easier. The stm32 MCU does not provide a separate interrupt line for all the gpio pins. This makes enabling interrupts a little more difficult and requires some extra code in the board file.

I am not the original author of the code for these boards, so I am not sure why this has been designed the way it is now.

This also enables interrupts for the first gpio exposed pin, allowing the gpio test to succeed.

### Testing Strategy

This pull request was tested using a nucleo F429ZI and an STM32F4g Discovery board


### TODO or Help Wanted

N/A

### Documentation Updated

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make prepush`.


Co-authored-by: Alexandru Radovici <msg4alex@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chips/stm32 Change pertains to the stm32 family of MCUSs tock-2.0 Issues and PRs related to Tock version 2.0.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants