Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing stack fails, calculating stack_size too big. #32

Closed
mehmetalianil opened this issue Aug 3, 2023 · 4 comments
Closed

Capturing stack fails, calculating stack_size too big. #32

mehmetalianil opened this issue Aug 3, 2023 · 4 comments

Comments

@mehmetalianil
Copy link

Summary

When stack capture is created, the stack_size is calculated. Debugging our project I see that this is calculated to be 536875968, which is rather large, and seems to rather be a memory address, 0x200013c0.
Screenshot 2023-08-03 at 17 27 37

Story

So I realized that I cannot print the stack capture on start, but fpu and core registers are fine with this:

    if is_capture_made() {
        reset_capture_made();

        info!("STACKCAPTURE {=[u8]:x}", unsafe {
            STACK_CAPTURE
                .assume_init_ref()
                .bytes()
                .collect::<Vec<u8, 0x4000>>()
        });
        info!("CORECAPTURE {=[u8]:x}", unsafe {
            CORE_REGISTERS_CAPTURE
                .assume_init_ref()
                .bytes()
                .collect::<Vec<u8, 128>>()
        });
        info!("FPUCAPTURE {=[u8]:x}", unsafe {
            FPU_REGISTERS_CAPTURE
                .assume_init_ref()
                .bytes()
                .collect::<Vec<u8, 256>>()
        });
0.000000 INFO CORECAPTURE [2, 0, 0, 10, 0, 9c, b6, 3, 20, 28, e7, 0, 20, 70, e7, 0, 20, 27, ea, 0, 20, 28, e7, 0, 20, 70, e7, 0, 20, 28, e7, 0, 20, e8, b6, 3, 20, 6, 0, 0, 0, b0, d3, 0, 20, 1, 0, 0, 0, e7, 7, 0, 0, 0, 0, 0, 0, 98, b6, 3, 20, 21, eb, 3, 0, a0, 75, 4, 0]
└─ src/main.rs:108
0.000000 INFO FPUCAPTURE [2, 0, 1, 20, 0, 0, 0, 8c, 42, 0, 0, a0, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
└─ src/main.rs:114

Then I tried to debug the issue, (but debug itself became the issue, then we solved that) and saw that stack_size value turns out to be something resembling a memory address.

The issue is that I still can't debug in opt = 0 , therefore cannot follow what is going wrong there.
Some data (will provide)

@mehmetalianil
Copy link
Author

mehmetalianil commented Aug 3, 2023

Panic handler

#[defmt::panic_handler]
fn panic() -> ! {
    cortex_m::interrupt::free(|_cs| {
        unsafe {
            stackdump_capture::cortex_m::capture(
                &mut *STACK_CAPTURE.as_mut_ptr(),
                &mut *CORE_REGISTERS_CAPTURE.as_mut_ptr(),
                &mut *FPU_REGISTERS_CAPTURE.as_mut_ptr(),
            );
            // If you want to capture the heap or the static data, then do that here too yourself
        }
        set_capture_made();
    });
    cortex_m::peripheral::SCB::sys_reset(); //panic_reset
                                            //cortex_m::asm::udf() //panic_probe
}
Cargo tree
bart-firmware v1.0.1 (/Users/mali/Documents/Code/bart-firmware/cross)
├── biquad v0.4.2
│   └── libm v0.1.4
├── cortex-m v0.7.7
│   ├── bare-metal v0.2.5
│   │   [build-dependencies]
│   │   └── rustc_version v0.2.3
│   │       └── semver v0.9.0
│   │           └── semver-parser v0.7.0
│   ├── bitfield v0.13.2
│   ├── embedded-hal v0.2.7
│   │   ├── nb v0.1.3
│   │   │   └── nb v1.1.0
│   │   └── void v1.0.2
│   └── volatile-register v0.2.1
│       └── vcell v0.1.3
├── cortex-m-rt v0.7.3
│   └── cortex-m-rt-macros v0.7.0 (proc-macro)
│       ├── proc-macro2 v1.0.66
│       │   └── unicode-ident v1.0.11
│       ├── quote v1.0.32
│       │   └── proc-macro2 v1.0.66 (*)
│       └── syn v1.0.109
│           ├── proc-macro2 v1.0.66 (*)
│           ├── quote v1.0.32 (*)
│           └── unicode-ident v1.0.11
├── defmt v0.3.2
│   ├── bitflags v1.3.2
│   └── defmt-macros v0.3.6 (proc-macro)
│       ├── defmt-parser v0.3.3
│       │   └── thiserror v1.0.44
│       │       └── thiserror-impl v1.0.44 (proc-macro)
│       │           ├── proc-macro2 v1.0.66 (*)
│       │           ├── quote v1.0.32 (*)
│       │           └── syn v2.0.27
│       │               ├── proc-macro2 v1.0.66 (*)
│       │               ├── quote v1.0.32 (*)
│       │               └── unicode-ident v1.0.11
│       ├── proc-macro-error v1.0.4
│       │   ├── proc-macro-error-attr v1.0.4 (proc-macro)
│       │   │   ├── proc-macro2 v1.0.66 (*)
│       │   │   └── quote v1.0.32 (*)
│       │   │   [build-dependencies]
│       │   │   └── version_check v0.9.4
│       │   ├── proc-macro2 v1.0.66 (*)
│       │   ├── quote v1.0.32 (*)
│       │   └── syn v1.0.109 (*)
│       │   [build-dependencies]
│       │   └── version_check v0.9.4
│       ├── proc-macro2 v1.0.66 (*)
│       ├── quote v1.0.32 (*)
│       └── syn v2.0.27 (*)
├── defmt-rtt v0.3.2
│   ├── critical-section v0.2.8
│   │   ├── bare-metal v1.0.0
│   │   └── critical-section v1.1.1
│   └── defmt v0.3.2 (*)
├── embassy-boot v0.1.1 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   ├── embassy-sync v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   ├── cfg-if v1.0.0
│   │   ├── critical-section v1.1.1
│   │   ├── defmt v0.3.2 (*)
│   │   ├── embedded-io v0.4.0
│   │   │   └── defmt v0.3.2 (*)
│   │   ├── futures-util v0.3.28
│   │   │   ├── futures-core v0.3.28
│   │   │   ├── futures-sink v0.3.28
│   │   │   ├── futures-task v0.3.28
│   │   │   ├── pin-project-lite v0.2.10
│   │   │   └── pin-utils v0.1.0
│   │   └── heapless v0.7.16
│   │       ├── hash32 v0.2.1
│   │       │   └── byteorder v1.4.3
│   │       ├── serde v1.0.177
│   │       │   └── serde_derive v1.0.177 (proc-macro)
│   │       │       ├── proc-macro2 v1.0.66 (*)
│   │       │       ├── quote v1.0.32 (*)
│   │       │       └── syn v2.0.27 (*)
│   │       └── stable_deref_trait v1.2.0
│   │       [build-dependencies]
│   │       └── rustc_version v0.4.0
│   │           └── semver v1.0.18
│   ├── embedded-storage v0.3.0
│   ├── embedded-storage-async v0.4.0
│   │   └── embedded-storage v0.3.0
│   └── signature v1.6.4
├── embassy-boot-nrf v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   ├── cfg-if v1.0.0
│   ├── cortex-m v0.7.7 (*)
│   ├── cortex-m-rt v0.7.3 (*)
│   ├── embassy-boot v0.1.1 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   ├── embassy-nrf v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   ├── cfg-if v1.0.0
│   │   ├── cortex-m v0.7.7 (*)
│   │   ├── cortex-m-rt v0.7.3 (*)
│   │   ├── critical-section v1.1.1
│   │   ├── defmt v0.3.2 (*)
│   │   ├── embassy-cortex-m v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   │   ├── atomic-polyfill v1.0.3
│   │   │   │   └── critical-section v1.1.1
│   │   │   ├── cfg-if v1.0.0
│   │   │   ├── cortex-m v0.7.7 (*)
│   │   │   ├── critical-section v1.1.1
│   │   │   ├── embassy-executor v0.1.1 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   │   │   ├── atomic-polyfill v1.0.3 (*)
│   │   │   │   ├── cfg-if v1.0.0
│   │   │   │   ├── critical-section v1.1.1
│   │   │   │   ├── defmt v0.3.2 (*)
│   │   │   │   ├── embassy-macros v0.1.0 (proc-macro) (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   │   │   │   ├── darling v0.13.4
│   │   │   │   │   │   ├── darling_core v0.13.4
│   │   │   │   │   │   │   ├── fnv v1.0.7
│   │   │   │   │   │   │   ├── ident_case v1.0.1
│   │   │   │   │   │   │   ├── proc-macro2 v1.0.66 (*)
│   │   │   │   │   │   │   ├── quote v1.0.32 (*)
│   │   │   │   │   │   │   ├── strsim v0.10.0
│   │   │   │   │   │   │   └── syn v1.0.109 (*)
│   │   │   │   │   │   └── darling_macro v0.13.4 (proc-macro)
│   │   │   │   │   │       ├── darling_core v0.13.4 (*)
│   │   │   │   │   │       ├── quote v1.0.32 (*)
│   │   │   │   │   │       └── syn v1.0.109 (*)
│   │   │   │   │   ├── proc-macro2 v1.0.66 (*)
│   │   │   │   │   ├── quote v1.0.32 (*)
│   │   │   │   │   └── syn v1.0.109 (*)
│   │   │   │   ├── embassy-time v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   │   │   │   ├── atomic-polyfill v1.0.3 (*)
│   │   │   │   │   ├── cfg-if v1.0.0
│   │   │   │   │   ├── critical-section v1.1.1
│   │   │   │   │   ├── defmt v0.3.2 (*)
│   │   │   │   │   ├── embassy-sync v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   │   │   │   │   ├── embedded-hal v0.2.7 (*)
│   │   │   │   │   ├── futures-util v0.3.28 (*)
│   │   │   │   │   └── heapless v0.7.16 (*)
│   │   │   │   ├── futures-util v0.3.28 (*)
│   │   │   │   └── static_cell v1.2.0
│   │   │   │       └── atomic-polyfill v1.0.3 (*)
│   │   │   ├── embassy-hal-common v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   │   │   └── num-traits v0.2.16
│   │   │   │       └── libm v0.2.7
│   │   │   │       [build-dependencies]
│   │   │   │       └── autocfg v1.1.0
│   │   │   ├── embassy-macros v0.1.0 (proc-macro) (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   │   │   └── embassy-sync v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   │   ├── embassy-embedded-hal v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   │   ├── defmt v0.3.2 (*)
│   │   │   ├── embassy-sync v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   │   │   ├── embedded-hal v0.2.7 (*)
│   │   │   ├── embedded-hal v1.0.0-alpha.9
│   │   │   ├── embedded-hal-async v0.2.0-alpha.0
│   │   │   │   └── embedded-hal v1.0.0-alpha.9
│   │   │   ├── embedded-storage v0.3.0
│   │   │   ├── embedded-storage-async v0.4.0 (*)
│   │   │   └── nb v1.1.0
│   │   ├── embassy-executor v0.1.1 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   │   ├── embassy-hal-common v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   │   ├── embassy-sync v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   │   ├── embassy-time v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   │   ├── embassy-usb-driver v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706)
│   │   │   └── defmt v0.3.2 (*)
│   │   ├── embedded-hal v0.2.7 (*)
│   │   ├── embedded-hal v1.0.0-alpha.9
│   │   ├── embedded-hal-async v0.2.0-alpha.0 (*)
│   │   ├── embedded-io v0.4.0 (*)
│   │   ├── embedded-storage v0.3.0
│   │   ├── embedded-storage-async v0.4.0 (*)
│   │   ├── fixed v1.23.1
│   │   │   ├── az v1.2.1
│   │   │   ├── bytemuck v1.13.1
│   │   │   ├── half v2.3.1
│   │   │   │   └── cfg-if v1.0.0
│   │   │   └── typenum v1.16.0
│   │   ├── futures v0.3.28
│   │   │   ├── futures-channel v0.3.28
│   │   │   │   ├── futures-core v0.3.28
│   │   │   │   └── futures-sink v0.3.28
│   │   │   ├── futures-core v0.3.28
│   │   │   ├── futures-io v0.3.28
│   │   │   ├── futures-sink v0.3.28
│   │   │   ├── futures-task v0.3.28
│   │   │   └── futures-util v0.3.28 (*)
│   │   ├── nrf52840-pac v0.12.2
│   │   │   ├── cortex-m v0.7.7 (*)
│   │   │   ├── cortex-m-rt v0.7.3 (*)
│   │   │   └── vcell v0.1.3
│   │   └── rand_core v0.6.4
│   ├── embassy-sync v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
│   ├── embedded-storage v0.3.0
│   ├── embedded-storage-async v0.4.0 (*)
│   └── nrf-softdevice-mbr v0.1.1 (https://github.com/embassy-rs/nrf-softdevice.git?branch=master#3f4913f3)
├── embassy-embedded-hal v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
├── embassy-executor v0.1.1 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
├── embassy-nrf v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
├── embassy-sync v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
├── embassy-time v0.1.0 (https://github.com/embassy-rs/embassy?rev=055597063f2d3f1156a9f8076c601dd300d85542#05559706) (*)
├── embedded-hal v0.2.7 (*)
├── embedded-storage v0.3.0
├── fixed v1.23.1 (*)
├── flash-manager v0.1.0 (/Users/mali/Documents/Code/bart-firmware/flash-manager)
│   ├── defmt v0.3.2 (*)
│   ├── defmt-rtt v0.3.2 (*)
│   ├── embedded-storage v0.3.0
│   ├── modular-bitfield v0.11.2
│   │   ├── modular-bitfield-impl v0.11.2 (proc-macro)
│   │   │   ├── proc-macro2 v1.0.66 (*)
│   │   │   ├── quote v1.0.32 (*)
│   │   │   └── syn v1.0.109 (*)
│   │   └── static_assertions v1.1.0
│   ├── postcard v1.0.6
│   │   ├── cobs v0.2.3
│   │   ├── const_format v0.2.31
│   │   │   └── const_format_proc_macros v0.2.31 (proc-macro)
│   │   │       ├── proc-macro2 v1.0.66 (*)
│   │   │       ├── quote v1.0.32 (*)
│   │   │       └── unicode-xid v0.2.4
│   │   ├── heapless v0.7.16 (*)
│   │   ├── postcard-derive v0.1.1 (proc-macro)
│   │   │   ├── proc-macro2 v1.0.66 (*)
│   │   │   ├── quote v1.0.32 (*)
│   │   │   └── syn v1.0.109 (*)
│   │   └── serde v1.0.177 (*)
│   ├── serde v1.0.177 (*)
│   ├── vib-analyzer v0.1.1 (/Users/mali/Documents/Code/bart-firmware/vib-analyzer)
│   │   ├── defmt v0.3.2 (*)
│   │   ├── heapless v0.7.16 (*)
│   │   ├── microfft v0.5.1
│   │   │   ├── cfg-if v1.0.0
│   │   │   ├── num-complex v0.4.3
│   │   │   │   └── num-traits v0.2.16 (*)
│   │   │   └── static_assertions v1.1.0
│   │   ├── postcard v1.0.6 (*)
│   │   ├── serde v1.0.177 (*)
│   │   └── zerocopy v0.6.1
│   │       ├── byteorder v1.4.3
│   │       └── zerocopy-derive v0.3.2 (proc-macro)
│   │           ├── proc-macro2 v1.0.66 (*)
│   │           ├── quote v1.0.32 (*)
│   │           └── syn v1.0.109 (*)
│   └── zerocopy v0.6.1 (*)
├── futures v0.3.28 (*)
├── heapless v0.7.16 (*)
├── iim42652 v0.1.0 (https://github.com/Grus-BV/iis3dwb-rs.git?branch=development#f953ee7f)
│   ├── accelerometer v0.12.0
│   │   └── micromath v1.1.1
│   │       └── generic-array v0.14.7
│   │           └── typenum v1.16.0
│   │           [build-dependencies]
│   │           └── version_check v0.9.4
│   ├── cortex-m v0.7.7 (*)
│   ├── cortex-m-rt v0.7.3 (*)
│   ├── cortex-m-rtic v0.5.9
│   │   ├── cortex-m v0.6.7
│   │   │   ├── aligned v0.3.5
│   │   │   │   └── as-slice v0.1.5
│   │   │   │       ├── generic-array v0.12.4
│   │   │   │       │   └── typenum v1.16.0
│   │   │   │       ├── generic-array v0.13.3
│   │   │   │       │   └── typenum v1.16.0
│   │   │   │       ├── generic-array v0.14.7 (*)
│   │   │   │       └── stable_deref_trait v1.2.0
│   │   │   ├── bare-metal v0.2.5 (*)
│   │   │   ├── bitfield v0.13.2
│   │   │   ├── cortex-m v0.7.7 (*)
│   │   │   └── volatile-register v0.2.1 (*)
│   │   ├── cortex-m-rtic-macros v0.5.3 (proc-macro)
│   │   │   ├── proc-macro2 v1.0.66 (*)
│   │   │   ├── quote v1.0.32 (*)
│   │   │   ├── rtic-syntax v0.4.0
│   │   │   │   ├── indexmap v1.9.3
│   │   │   │   │   └── hashbrown v0.12.3
│   │   │   │   │   [build-dependencies]
│   │   │   │   │   └── autocfg v1.1.0
│   │   │   │   ├── proc-macro2 v1.0.66 (*)
│   │   │   │   └── syn v1.0.109 (*)
│   │   │   └── syn v1.0.109 (*)
│   │   ├── heapless v0.6.1
│   │   │   ├── as-slice v0.1.5 (*)
│   │   │   ├── generic-array v0.14.7 (*)
│   │   │   ├── hash32 v0.1.1
│   │   │   │   └── byteorder v1.4.3
│   │   │   └── stable_deref_trait v1.2.0
│   │   └── rtic-core v0.3.1
│   │   [build-dependencies]
│   │   └── version_check v0.9.4
│   ├── defmt v0.3.2 (*)
│   ├── defmt-rtt v0.3.2 (*)
│   ├── embedded-hal v0.2.7 (*)
│   ├── micromath v1.1.1 (*)
│   ├── modular-bitfield v0.11.2 (*)
│   ├── num_enum v0.5.11
│   │   └── num_enum_derive v0.5.11 (proc-macro)
│   │       ├── proc-macro2 v1.0.66 (*)
│   │       ├── quote v1.0.32 (*)
│   │       └── syn v1.0.109 (*)
│   └── panic-probe v0.3.1
│       ├── cortex-m v0.7.7 (*)
│       └── defmt v0.3.2 (*)
├── microfft v0.5.1 (*)
├── micromath v2.0.0
├── nrf-softdevice v0.1.0 (https://github.com/embassy-rs/nrf-softdevice#3f4913f3)
│   ├── cortex-m v0.7.7 (*)
│   ├── cortex-m-rt v0.7.3 (*)
│   ├── critical-section v1.1.1
│   ├── defmt v0.3.2 (*)
│   ├── embassy-sync v0.2.0
│   │   ├── cfg-if v1.0.0
│   │   ├── critical-section v1.1.1
│   │   ├── embedded-io v0.4.0 (*)
│   │   ├── futures-util v0.3.28 (*)
│   │   └── heapless v0.7.16 (*)
│   ├── embedded-storage v0.3.0
│   ├── embedded-storage-async v0.4.0 (*)
│   ├── fixed v1.23.1 (*)
│   ├── futures v0.3.28 (*)
│   ├── heapless v0.7.16 (*)
│   ├── nrf-softdevice-macro v0.1.0 (proc-macro) (https://github.com/embassy-rs/nrf-softdevice#3f4913f3)
│   │   ├── Inflector v0.11.4
│   │   │   ├── lazy_static v1.4.0
│   │   │   └── regex v1.9.1
│   │   │       ├── aho-corasick v1.0.2
│   │   │       │   └── memchr v2.5.0
│   │   │       ├── memchr v2.5.0
│   │   │       ├── regex-automata v0.3.3
│   │   │       │   ├── aho-corasick v1.0.2 (*)
│   │   │       │   ├── memchr v2.5.0
│   │   │       │   └── regex-syntax v0.7.4
│   │   │       └── regex-syntax v0.7.4
│   │   ├── darling v0.13.4 (*)
│   │   ├── proc-macro2 v1.0.66 (*)
│   │   ├── quote v1.0.32 (*)
│   │   ├── syn v1.0.109 (*)
│   │   └── uuid v1.4.1
│   ├── nrf-softdevice-s140 v0.1.1 (https://github.com/embassy-rs/nrf-softdevice#3f4913f3)
│   ├── nrf52840-pac v0.12.2 (*)
│   └── num_enum v0.6.1
│       └── num_enum_derive v0.6.1 (proc-macro)
│           ├── proc-macro2 v1.0.66 (*)
│           ├── quote v1.0.32 (*)
│           └── syn v2.0.27 (*)
├── nrf-softdevice-s140 v0.1.1 (https://github.com/embassy-rs/nrf-softdevice#3f4913f3)
├── num v0.4.1
│   ├── num-complex v0.4.3 (*)
│   ├── num-integer v0.1.45
│   │   └── num-traits v0.2.16 (*)
│   │   [build-dependencies]
│   │   └── autocfg v1.1.0
│   ├── num-iter v0.1.43
│   │   ├── num-integer v0.1.45 (*)
│   │   └── num-traits v0.2.16 (*)
│   │   [build-dependencies]
│   │   └── autocfg v1.1.0
│   ├── num-rational v0.4.1
│   │   ├── num-integer v0.1.45 (*)
│   │   └── num-traits v0.2.16 (*)
│   │   [build-dependencies]
│   │   └── autocfg v1.1.0
│   └── num-traits v0.2.16 (*)
├── panic-probe v0.3.1 (*)
├── stackdump-capture v0.4.0
│   ├── arrayvec v0.7.4
│   │   └── serde v1.0.177 (*)
│   └── stackdump-core v0.3.0
│       ├── arrayvec v0.7.4 (*)
│       ├── funty v2.0.0
│       ├── gimli v0.27.3
│       └── serde v1.0.177 (*)
├── static_cell v1.2.0 (*)
├── time v0.3.23
│   └── time-core v0.1.1
├── vib-analyzer v0.1.1 (/Users/mali/Documents/Code/bart-firmware/vib-analyzer) (*)
└── zerocopy v0.6.1 (*)
[dev-dependencies]
└── defmt-test v0.3.0
    ├── cortex-m v0.7.7 (*)
    ├── cortex-m-rt v0.7.3 (*)
    ├── defmt v0.3.2 (*)
    └── defmt-test-macros v0.3.0 (proc-macro)
        ├── proc-macro2 v1.0.66 (*)
        ├── quote v1.0.32 (*)
        └── syn v1.0.109 (*)

@diondokter
Copy link
Collaborator

Hi! Thanks for the elaborate info!

From the cargo tree I saw you're running an nRF52840. I've used this crate on that, so in principle it should work.

Here are your registers decoded:
image

In red we see you have a stackpointer of 0x2003b698 which seems reasonable for your chip.
What I can't see is what the _stack_start is in you elf file. Assuming you're using a normal memory.x for you chip it should be 0x20040000. So your stack size should be 18792 bytes, which would be what is captured max. The capture will be smaller if it doesn't fit in SIZE const generic.

The math checks out and the values I can see from what you've given me seem good.

So my guess is that the debugger displays you a wrong value for the stack size.

But what's the actual problem? Does it crash for you?
If it actually used that size, the stack copy it does would be super likely to get a hardfault.

@mehmetalianil
Copy link
Author

Yes, the stack_start is 0x20040000.
0x2004'0000 │ NONE +G │ │ _stack_start

In my case, the application does not crash, but I can not print the STACK_CAPTURE through defmt.
Actually let me try it with a smaller slice of the data, it might be that I am overwhelming defmt with a 0x4000 size buffer.

The issue I encountered was that when this code is ran when a capture was made:

    if is_capture_made() {
        reset_capture_made();

        info!("STACKCAPTURE {=[u8]:x}", unsafe {
            STACK_CAPTURE
                .assume_init_ref()
                .bytes()
                .collect::<Vec<u8, 0x4000>>()
        });
        info!("CORECAPTURE {=[u8]:x}", unsafe {
            CORE_REGISTERS_CAPTURE
                .assume_init_ref()
                .bytes()
                .collect::<Vec<u8, 128>>()
        });
        info!("FPUCAPTURE {=[u8]:x}", unsafe {
            FPU_REGISTERS_CAPTURE
                .assume_init_ref()
                .bytes()
                .collect::<Vec<u8, 256>>()
        });

The output is this:

0.000000 INFO CORECAPTURE [2, 0, 0, 10, 0, 9c, b6, 3, 20, 28, e7, 0, 20, 70, e7, 0, 20, 27, ea, 0, 20, 28, e7, 0, 20, 70, e7, 0, 20, 28, e7, 0, 20, e8, b6, 3, 20, 6, 0, 0, 0, b0, d3, 0, 20, 1, 0, 0, 0, e7, 7, 0, 0, 0, 0, 0, 0, 98, b6, 3, 20, 21, eb, 3, 0, a0, 75, 4, 0]
└─ src/main.rs:108
0.000000 INFO FPUCAPTURE [2, 0, 1, 20, 0, 0, 0, 8c, 42, 0, 0, a0, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
└─ src/main.rs:114

I never get the first info!, not even an empty array or similiar.

@mehmetalianil
Copy link
Author

Well, it seems that defmt might sometimes now show messages that overwhelm its resources.
Thank you so much for the help, @diondokter. Sorry that this was a flop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants