main function not executed in SAMD21 custom board

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

Dear all, 

I am quite new with ATMEL STUDIO. 

After checking some example codes from DEV Tools XPRO boards I have made my own PCB, including a SAMD21 MCU. Attached picture.

My first intentention is switching on a led. The initial code obtained from ATMEL START is loaded to the ucontroller. Debugging, I concentrate in the file "startup_samd21.c". Well most of the times I can't see the Yellow right arrow indicating the code execution. I have the feeling that the main call (where ports are initialized in another function) is not executed. And I find the yellow right arrow stuck in the while on the Dummy_Handler() function. Phisically I expect to measure some voltage after the main, that does not happen.

I am suspecting that the main function is not called. 

Can you please give some idea? 

Thank you. 

 

Attachment(s): 

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

It looks like it's hanging in libc_init_array(). Try clicking  "break all" in the debug menu to see where it's hanging

Jerry

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

jerryr wrote:

It looks like it's hanging in libc_init_array(). Try clicking  "break all" in the debug menu to see where it's hanging

Jerry

 

Hi Jerry. 

It branches to the Dummy_Handler() function from several points of the code.

Sometimes makes the for @Line229 and even some time has passed through the main but does not reach the code I could see something.

 

Then I found this thread https://community.atmel.com/foru...

and I am quite desperated, even after ugrading to 7.0.1931. I am not so skilled.

 

Ideas are welcome. 
Thank you. 

 

 

 

 

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

It looks like you'd have to provide your complete code in order to find the reason for bug

One can also look at the stack with the debugger to see what was happening at the time

While debugging open the I/O window and look at the NVIC registers. The ISPR is the Interrupt Set Pending Register. A bit in this register is set when a peripheral generates an interrupt, and the program jumps to the corresponding address in the interrupt vector, which you can see in the source file Device_Startup/startup_samd21.h. The bit numbers for each peripheral are in section 11.2.2 Interrupt Line Mapping of the datasheet. The flag in the ISPR is cleared when you clear the bit in the peripheral INTFLAG at the end of the interrupt handler.

The usual cause is that one hasn't defined a handler for the particular peripheral, and the default handler is always Dummy_Handler()

Good luck!

Jerry

PS I'm away from home and debugger for a week

PPS I meant file Device_Startup/startup_samd21.c, not the .h file. You can also write a dummy interrupt handler for each peripheral which only clears all possible interrupts for the particular peripheral, and put a breakpoint in each one. Then look at the stack to see where it came from. I've seen similar errors when the program tried to set a bit in the CTRLA register after the peripheral had already been enabled (ENABLE protected)

Last Edited: Wed. Feb 20, 2019 - 08:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear Jerryr, 

Thanks for you ideas.

 

I have watched several times the debugging while checking the ISPR registers. These, all the time keep at 0. 
But I find some strange behaviour because sometimes I reach at Dummy Handler from line 223, others from line 243 or 245. The debugging flow is not always the same.

I think it is not possible to enter into ___libc_initarray(). I mean "step into". 

 

I will try to check if the clocks are well set. 

 

This code comes from ATMEL Start and I have soldered a second PCB without any pheripheral. Just the microcontroller. 

 

Keep working. 

Ideas welcome. 

Thank you. 

 

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

I have created a handler for a HardFault. It is entering. Now, need to know what causes. Keep investigating. Thnaks.