2

I am not getting answers on the AVR Freaks forum and wonder if someone here could help me.

The answer might lie in this SO question, but I am not sure why it would be necessary.

Basically, I have my fist ever Atmel project (AVR studio 6, UC3 processor). The code compiles and links and I can load it to the Atmel board and step through in the debugger.

However, when I try to step over (or run until a breakpoint on the line after) a (valid) call to sprintf(), malloc() or memcpy() (there may be more, which I have not yet discovered), the IDE never returns to the next line of my code, just seeming to hang, or run forever.

[Note] Compiler optimization is off

Do I need to set some linker options (e.g link static (which I tried & it didn't help)? Or build with some library?

What confuses me is that the code compilers and links - what is being linked when I call these standard functions? If I need something else I would expect a compiler or linker error, but get none - so why won't my code run?

Sorry for such a stupid n00nb question, but it is my first micro-controller project.

Community
  • 1
  • 1
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 1
    Have you tried stepping *into* the calls? You might end up in AVR-assembly-land, but at least you might be able to find out what crashes. – nneonneo Feb 16 '13 at 08:03

3 Answers3

2

I discovered that the CPU on my board is an Engineering Sample and not supported by Atmel Studio without a new io.h file.

I sort of figured that out from this question: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=106652

Sorry to have troubled you.

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
1

what is being linked when I call these standard functions?

The AVR-libc, the implementation of the C standard library ported to the AVR platform.

so why won't my code run?

Compiler errors and runtime errors are not even related. Both of these lines are valid C and they compile, however, on most systems, I'd expect them to dump core:

int x = 1 / 0;
*(int *)0 = 41;

So it might be either:

  • a bug in the standard library (very unlikely), or
  • a bug in the online debugger (very unlikely), or
  • maybe you just expect something that is not supposed to happen?
  • +1 @H2CO3 +1 Point taken about invalid, but : I tried some very simple examples at the start of my main(). `char s[32]; sprintf(s, "forty two =%d \n", 42);` etc. For memcpy() I made sure the source was non-null, dest had enough space, that source & dest don't overlap. Etc, etc In short I am convinced the code is ok, especially as it runs in the AVR Studio's simulator mode and also udner Netbeans with Cygwin. I strongly belive this is just n00b ignorance fo project settings, maybe linker settings on my part. Can you help? – Mawg says reinstate Monica Feb 16 '13 at 08:00
  • 1
    @Mawg Does it run on the AVR itself without debugging? I. e. just start it in "release mode" or whatever, without attaching the debugger. –  Feb 16 '13 at 08:05
  • +1 Good point; I will have to check tml. But, obviously, something that I can't debug isn't of much use to me; it is a *large* project – Mawg says reinstate Monica Feb 16 '13 at 10:18
1

Instead of trying to step over, what happens if you set a breakpoint at next line after the line you want to step over?

Also, does the operation change if you turn off compiler optimization?

Jeff
  • 1,364
  • 1
  • 8
  • 17