0

I have this C++ abstraction layer for a STM32F405 board, and I'm trying to interface it with some other code, but I've found that the creation of a large array causes some weird behavior. Here is my main() function:

int main(void)
{
  char test[10000];
  Board board;
  board.init_board();

  while(1)
  {
    board.led0_toggle();
    board.clock_delay(100);
  }
  return 0;
}

When I run this, after the second line, it runs through every interrupt routine, however, if I remove the array, i.e.

int main(void)
{
  Board board;
  board.init_board();

  while(1)
  {
    board.led0_toggle();
    board.clock_delay(100);
  }
  return 0;
}

It runs as expected. Any advice on what might be going on?

superjax
  • 252
  • 2
  • 9
  • 2
    At 10K it's quite possible that you have overrun the stack. – user4581301 Dec 21 '17 at 05:38
  • 2
    You may want to check your linker setting (or project setting) to see how the memory is sectioned. –  Dec 21 '17 at 05:47
  • 1
    This is very basic: your stack space is not unlimited but a fixed number. You must understand where your declared variables end up in memory, or you won't be able to do any form of embedded systems programming. – Lundin Dec 21 '17 at 09:59
  • 1
    It is for you to control to define the stack size appropriate to your application. Depending on your toolchain, the default for STM32 will typically be a between 512 bytes and perhaps two kilobytes. Also where and how you set the stack size will depend on your toolchain. In this case it may be better to declare the array `static` so it is not on the stack at all; but as a dummy test, it is not possible to say what is appropriate - that would be application dependent, but local variables declared in `main()` scope can normally always be static. – Clifford Dec 21 '17 at 10:51

0 Answers0