debugging - AVR/GNU C Compiler and static memory allocation -


update - rephrase question:

since know bug is! how know when statical allocation fails @ compile time in embedded?

older:

i have simple , easy understand code in "c" below running in atmega328p-au 2k sram. use behaved uart library( used many during debugging ) debug strings in pc terminal.

there bug in code: freezes. output...

hello world - loading

i should '+' every loop.

can explain me why freezes , why compiler not inform me allocating statically more memory uc can get.

in code there info may need.

/**************************************************************************************************    info **************************************************************************************************/ /*     device:     atmega328p-au - no arduino     ide:        atmel studio 6.2     compiler:   avr/gnu c compiler : 4.8.1     f_cpu:      8000000 hz defined in makefile     fuses:                 extended:   0x07                 high:       0xd9                 low:        0xe2                 lockbit:    0xff      when compiled show in build output these:                         text    data     bss     dec     hex filename            1088       0      57    1145     479 bug catcher.elf            done executing task "runcompilertask".            task "runoutputfileverifytask"            program memory usage     :   1088 bytes   3,3 % full            data memory usage        :   57 bytes   2,8 % full            done executing task "runoutputfileverifytask".            done building target "corebuild" in project "bug catcher.cproj".            target "postbuildevent" skipped, due false condition; ('$(postbuildevent)' != '') evaluated ('' != '').            target "build" in file "c:\program files\atmel\atmel studio 6.2\vs\avr.common.targets" project "c:\users\tedi\desktop\bug catcher\bug catcher\bug catcher.cproj" (entry point):            done building target "build" in project "bug catcher.cproj".            done building project "bug catcher.cproj".             build succeeded.            ========== rebuild all: 1 succeeded, 0 failed, 0 skipped ==========  */  /**************************************************************************************************    definitions **************************************************************************************************/  #define big_number                  1000  // atmega328p - pin 12 #define soft_uart_rx_ddr            ddrb #define soft_uart_rx_ddr_bit        ddb0 #define soft_uart_rx_port           portb #define soft_uart_rx_port_bit       portb0 #define soft_uart_rx_pin            pinb #define soft_uart_rx_pin_bit        pinb0  // atmega328p pin 13 #define soft_uart_tx_ddr            ddrb #define soft_uart_tx_ddr_bit        ddb1 #define soft_uart_tx_port           portb #define soft_uart_tx_port_bit       portb1 #define soft_uart_tx_pin            pinb #define soft_uart_tx_pin_bit        pinb1  /**************************************************************************************************    includes **************************************************************************************************/  #include "softuart.h"  #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include <string.h>  /**************************************************************************************************    main function **************************************************************************************************/  int main() {        /**********************************************************************************************        setup     **********************************************************************************************/      softuart_init(  &soft_uart_tx_ddr, soft_uart_tx_ddr_bit,                     &soft_uart_tx_port, soft_uart_tx_port_bit,                     &soft_uart_rx_ddr, soft_uart_rx_ddr_bit,                     &soft_uart_rx_pin, soft_uart_rx_pin_bit );      sei();      softuart_puts_p( "\r\n\r\nhello world - loading\r\n\r\n" ); // can use custom uart function.     _delay_ms( 200 );      /**********************************************************************************************        forever loop     **********************************************************************************************/     while(1)     {         char temp[big_number];         memset( temp, '\0', sizeof( temp ) );         {             char temp[big_number];             memset( temp, '\0', sizeof( temp ) );             {                 char temp[big_number];                 memset( temp, '\0', sizeof( temp ) );             }         }         softuart_puts_p("+"); // bug!!!!! never reaches here.         _delay_ms( 500 );     } } 

the linker allocates static storage, in case 57 bytes (data plus bss segments). long have big variable static storage, should see error message linker.

the variable temp[1000] automatic variable, allocated @ run time on stack. ram not statically allocated linker used stack. bug easy case, allocating single variable bigger entire ram of device, kind of error really hard detect. 1 solution check available stack space @ runtime. simple rule: don't allocate big stuff on stack. see fail when function called.

temp[1000] used entire runtime of program, don't loose moving static storage. put "static" in front of , (hopefully) see error message linker.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -