Controller does not start without debugging

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, I need help with the AT32UC3C2256C.

In the case of using a large amount of memory (for example, half of RAM, or rather I do not know), it does not start without a debugger. For example, a simple program:

int main(void)
{
	watchdogDisable();
	pllInit();
	gpioInit();

	gpioSet(LED_GREEN, 1);

	while (1);
	return 0;
}

I load this code with a debugger. It starts successfully after restarting the controller. But if I add a large array:

#include <string.h>
volatile static char array[20000] = {0};

int main(void)
{
	watchdogDisable();
	pllInit();
	gpioInit();

	memset(array, 1, sizeof(array));

	gpioSet(LED_GREEN, 1);

	while (1);
	return 0;
}

The code runs only after the debugger loads. After restarting the LED does not turn on. Readelf -S result of a broken file:

There are 28 section headers, starting at offset 0x4c44b0:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .reset            PROGBITS        80000000 000400 000008 00  AX  0   0  4
  [ 2] .rela.got         RELA            80000008 000408 000000 0c   A  0  10  4
  [ 3] .init             PROGBITS        80000008 000408 00001c 00  AX  0   0  4
  [ 4] .text             PROGBITS        80000024 000424 000bbc 00  AX  0   0  4
  [ 5] .fini             PROGBITS        80000be0 000fe0 000018 00  AX  0   0  4
  [ 6] .rodata           PROGBITS        80000bf8 000ff8 000068 00   A  0   0  4
  [ 7] .ctors            PROGBITS        00000004 001404 000008 00  WA  0   0  4
  [ 8] .dtors            PROGBITS        0000000c 00140c 000008 00  WA  0   0  4
  [ 9] .jcr              PROGBITS        00000014 001414 000004 00  WA  0   0  4
  [10] .got              PROGBITS        00000018 001418 00000c 04  WA  0   0  4
  [11] .data             PROGBITS        00000024 001424 000504 00  WA  0   0  4
  [12] .bss              NOBITS          00000528 001928 004e68 00  WA  0   0  4
  [13] .comment          PROGBITS        00000000 001928 000030 01  MS  0   0  1
  [14] .debug_aranges    PROGBITS        00000000 001958 0003c0 00      0   0  1
  [15] .debug_pubnames   PROGBITS        00000000 001d18 000623 00      0   0  1
  [16] .debug_info       PROGBITS        00000000 00233b 00a79c 00      0   0  1
  [17] .debug_abbrev     PROGBITS        00000000 00cad7 001b06 00      0   0  1
  [18] .debug_line       PROGBITS        00000000 00e5dd 003a24 00      0   0  1
  [19] .debug_frame      PROGBITS        00000000 012004 0007d4 00      0   0  4
  [20] .debug_str        PROGBITS        00000000 0127d8 001bc9 01  MS  0   0  1
  [21] .debug_loc        PROGBITS        00000000 0143a1 001295 00      0   0  1
  [22] .debug_macinfo    PROGBITS        00000000 015636 4aea19 00      0   0  1
  [23] .stack            NOBITS          0000f000 000400 001000 00  WA  0   0  1
  [24] .debug_ranges     PROGBITS        00000000 4c404f 000368 00      0   0  1
  [25] .shstrtab         STRTAB          00000000 4c43b7 0000f9 00      0   0  1
  [26] .symtab           SYMTAB          00000000 4c4910 000750 10     27  66  4
  [27] .strtab           STRTAB          00000000 4c5060 00040d 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)
readelf: Warning: [ 2]: Link field (0) should index a symtab section.

What could be the problem? Thank.

This topic has a solution.
Last Edited: Tue. Apr 23, 2019 - 03:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The program does not start if the size of the array is more than 18000 bytes. But the address of the entry point does not change - located in flash memory.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your main() should never return. Put in an infinite while loop.

/Jakob Selbing

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know. The problem is not this - there is an infinite loop in the main program.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is my program. What's wrong with it?

...

Array with size 19000 bytes. The program disable watchdog, configure GPIO and set PA22.

Attachment(s): 

Last Edited: Mon. Apr 22, 2019 - 04:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may find more help in the 32 bit community then here in the 8 bit AVR's.

No one knows why the ASF forum is here!

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PazDim wrote:
What could be the problem?
(a WAG)

volatile static char array[20000] = {0};
static char array[20000] = {0};

reason : a linter warning

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for reply.

ki0bk wrote:
You may find more help in the 32 bit community then here in the 8 bit AVR's.
Ooops.  But isn't this a 32-bit forum? "Home » Communities » AVR Freaks » Forums » AVR Microcontrollers » AVR UC3 »"

gchapman wrote:
reason : a linter warning
Can you explain? I added volatile only so that the optimizer does not delete the array. The main program without it also does not start.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Silly question (I don't know UC3) but how much SRAM does the chip have? I assume it does have room for this 20K array? Your combined data+BSS above are about 25K. If this is a 32K RAM device then perhaps large stack frame autos are crashing BSS?

Last Edited: Mon. Apr 22, 2019 - 06:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Silly question (I don't know UC3) but how much SRAM does the chip have? I assume it does have room for this 20K array?

It has 64K. memset fills all bytes in array, I can check it via Memory window. Program works fine, but only via debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Programs that only work with debuggers are often relying on a common GND the debug interface provides

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PazDim wrote:
Can you explain?

	memset(array, 1, sizeof(array));
warning 2450: passing 'volatile char [20000]' to parameter of type 'void *' discards qualifiers

from PC-lint Plus Online Demo - Gimpel Software - The Leader in Static Analysis for C and C++ with PC-lint Plus

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Programs that only work with debuggers are often relying on a common GND the debug interface provides

But if I reduce the size of the array, the program will run without a debugger.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then in addition to your 25K of static allocations do you have a large use of either recursion or stack frame autos or both?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

New version of test:

#include <avr32/uc3c2256c.h>
#include <string.h>

volatile static char array[19000] = {0};

int main(void)
{
//Disable watchdog
	AVR32_WDT.ctrl = (AVR32_WDT_KEY_CONST << AVR32_WDT_CTRL_KEY_OFFSET) |
	(0x1 << AVR32_WDT_CTRL_CEN_OFFSET);
	AVR32_WDT.ctrl = (0xaa << AVR32_WDT_CTRL_KEY_OFFSET) |
	(0x1 << AVR32_WDT_CTRL_CEN_OFFSET);
	while (0x1 == AVR32_WDT.CTRL.en);
	
//Setup GPIO
	AVR32_GPIO.port[0].gper = 1 << 22;
	AVR32_GPIO.port[0].oder = 1 << 22;

//Set GPIO
	AVR32_GPIO.port[0].ovr |= 1 << 22;
	
	memset(array, 0x1, sizeof(array));

	while (1);
	return 0;
}

It is all code. It doesn't run without debugger. But if I change row to "volatile static char array[17000] = {0};", the program will start.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have the WDT enabled at reset by fuse setting then I suspect it is timing out before execution gets to main() due to the time taken to initialize your large block of data in the C startup code.  By default the WDT is disabled during debug operation.  If this is the case I suggest you disable the fuse setting and only enable the WDT by runtime startup code.

Letting the smoke out since 1978

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

digitalDan wrote:

If you have the WDT enabled at reset by fuse setting then I suspect it is timing out before execution gets to main() due to the time taken to initialize your large block of data in the C startup code.  By default the WDT is disabled during debug operation.  If this is the case I suggest you disable the fuse setting and only enable the WDT by runtime startup code.

Great idea, I myself also thought. But the watchdog is enabled by default. Before the main function, a section of code is executed that I cannot control. Is there a way to disable the watchdog timer using a pin controller?

...

Yes, the start code has a cycle of 20,000 (approximately) iterations, filling part of the RAM. But this is bss. From wikipedia: " .bss or bss is used by many compilers and linkers for the portion of an object file or executable containing statically-allocated variables that are not explicitly initialized to any value. ". Why does the code fill the section?

...

Managed from flash memory, right? I'll try to disable, then write the result.

Last Edited: Tue. Apr 23, 2019 - 04:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The "array" is what consumes BSS

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Yes, the problem was this. I turned off the watchdog timer and the program started. Thank you all for the answers.