Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8026

SDK • Re: First attempts to use hardware_powman

$
0
0
How about:
Seems to work. A quick test of printing it in a 'main' shows "SP = 0x20041FF4" on RP2040 which seems right to me, three 32-bit words pushed to a stack initialised at 0x20042000.

Which is just as well because I have [re-]discovered the code I have in my own test program only works with '-O0' optimisation, and seems to think there's an extra 32-bit word pushed to the stack; 'SP = 20041FF0'. Yours shows 'SP = 20041FEC' with '-O0' but all are in the same ball-park; '0x20041xxx' which is the important thing.

So many thanks.

I have removed my dodgy code so as not to cause confusion and woes.
Using arg001's sophisticated technique I get this output:

Code:

core0 stack around 20081FF4core1 stack around 20080FC8
Based on Table 11 in the RP2350 datasheet (section 2.2.3), that puts the core0 stack in SRAM9, or scratch_y, and the core1 stack in SRAM8, or scratch_x. As one would expect from the memmap scripts.
That looks like a correct and accurate assessment to me.
The application makes use of both of the local variables whose addresses are shown here, and they work as expected. So I conclude that the code shown further up in the thread does not turn off SRAM1, despite the PICO_OK return value from powman_set_power_state(). Not only that, but it would probably be bad if it did, without changing the stack location.
Seems so to me.

I'd have expected it to crash on the return from turning SRAM1 off when using the API ... unless it's inlined ... or it's being deferred ?

Maybe try a Fibonacci program with SRAM1 turned off as that will definitely use the stack for return frames and local data and should crash if that's not how it should be ...

Code:

#include <stdio.h>#include "pico/stdlib.h"uint32_t GetSp(void) {    int foo = 0;    return (uint32_t) &foo;}uint32_t Fibo(int depth, uint32_t n) {    printf("SP = %08lx %*c %lu\n", GetSp(), depth * 2, ' ', n);    if( n <= 1) { return n;                                       }    else        { return Fibo(depth+1, n-1) + Fibo(depth+1, n-2); }}int main(void) {    stdio_init_all();    while (!stdio_usb_connected()) {        sleep_ms(100);    }    while (true) {        #define FIBO 6 // Fibo(6) = 8        printf("Fibo(%u) = %lu\n", FIBO, Fibo(1, FIBO));        sleep_ms(5000);        printf("\n");    }}
On my RP2040 with '-O0' to disable tail-end recursion optimisations ...

Code:

SP = 20041fcc    6SP = 20041fac      5SP = 20041f8c        4SP = 20041f6c          3SP = 20041f4c            2SP = 20041f2c              1SP = 20041f2c              0SP = 20041f4c            1SP = 20041f6c          2SP = 20041f4c            1SP = 20041f4c            0SP = 20041f8c        3SP = 20041f6c          2SP = 20041f4c            1SP = 20041f4c            0SP = 20041f6c          1SP = 20041fac      4SP = 20041f8c        3SP = 20041f6c          2SP = 20041f4c            1SP = 20041f4c            0SP = 20041f6c          1SP = 20041f8c        2SP = 20041f6c          1SP = 20041f6c          0Fibo(6) = 8

Statistics: Posted by hippy — Mon Aug 26, 2024 4:58 pm



Viewing all articles
Browse latest Browse all 8026

Trending Articles