1

I'm trying to print arrays with 256 integers.

I used PlatformIO IDE(VSCode extension), and TeraTerm to print. Selected Board is HiFive1 Rev B(SiFive), and used Freedom E SDK framework.(Of course, I've connected Rev B board to my PC.)

Here is the structure of the array.

typedef struct {
    int32_t coeffs[N];
} poly;

where N is 256.

Then I made a simple C code below to test the structure.

int main() {
    
    poly a, b;
    printf("init poly...\n");
    for(int i = 0; i < N; i++){
        a.coeffs[i] = 0x01;
        b.coeffs[i] = 0x02;
        printf("%d: %08lX  %08lX\n", i, a.coeffs[i], b.coeffs[i]);
    }
    printf("init END...\n");

    printf("for start...\n");
    for(int j = 0; j < N; j++){
        printf("%08lX  %08lX\n", a.coeffs[j], b.coeffs[j]);
        if (j % 16 == 15) {
            printf("\n");
        }
    }
}

Here, N is 256 again.

Build and Upload have done successfully, but I got weird outputs from the code.

Here is the output printed at TeraTerm.

init poly...
0: 00000001  00000002
1: 00000001  00000002
2: 00000001  00000002
...(skipped)
188: 00000001  00000002
189: 00000001  00000002
190: 00000001  00000002
191: 00000001  00000002

As you can see, the expected output after printf("init END...\n"); did not appear. Also, the first for loop looks like 'stopped' after i=192.

I don't think the stack size cause this issue. Because I modified platformio.ini file like below.

[env:hifive1-revb]
platform = sifive
framework = freedom-e-sdk
board = hifive1-revb
monitor_speed = 115200
; Configure stack size
board_build.freedom-e-sdk.heap_size = 0x3000

So I can use 99.4% of the RAM size(used 16288 bytes from 16384 bytes).

But when I use variable a only in the main(deleting variable b), then I can get the expected outputs.

How can I solve this problem? Can't I check the outputs from several arrays with 256 entries?

  • I am not familiar with that micro. Your config file does not mention stack size at all except in a comment. Where do you see that 16288 bytes you mention? Your 2 variables `a` and `b` take 1kB of stack each (assuming integers are 4 bytes). – Gerhardh May 10 '23 at 12:05
  • @Gerhardh I can see the stack size when I upload the code(assuming similar to flashing). It's printed out as a log. As you said, I use a total of 2KB stack for variables, but the log says about the total stack size I configured. 16288 bytes(configured stack size+@) can be changed by modifying ```board_build.freedom-e-sdk.heap_size``` property. As an example, if I set ```board_build.freedom-e-sdk.heap_size=1500```, then the total RAM usage becomes almost half. – Yong Ryeol Choi May 11 '23 at 01:47
  • 1
    So you just assume that any RAM that is not used otherwise can be used as your stack? I would not rely on that and look into the map file where your data is located and if the stack is large enough to hold your data or if you hit other data with those arrays. – Gerhardh May 11 '23 at 15:37
  • 1
    I solved the problem. As you said, ```board_build.freedom-e-sdk.heap_size``` means the heap size. So I changed it into ```board_build.freedom-e-sdk.stack_size``` then it works. I saw ```board_build.freedom-e-sdk.heap_size``` in the reference and it said this command can configure stack size. I think there are some mistakes in the reference. Anyway, the problem was solved. Thanks for your idea. – Yong Ryeol Choi May 12 '23 at 08:35
  • People writing reference manuals also do copy&paste errors. ;) – Gerhardh May 12 '23 at 08:50

0 Answers0