Memory out of bounds or read error - usart_serial_putchar

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

I am working on a library for the SAMD21 and ATAES132a. In my program's main loop, I do a scanf to get the users input. One of the options runs a complete test of the ATAES132a and can take about 10 seconds to complete. After that function finishes, it is suppose to return to the main loop, but never does. In debug, the function finishes but never returns. The SAMD21 hangs in the Dummy Handler. Inspecting the stack trace, I see its waiting for usart_serial_getchar. I am a bit stump!

 

scanf("%c", & menuOneCommand);
if (menuOneCommand == '1') {
  printf("** Scan i2c bus ** \n\r"); // require /r/n to trigger
  scan_i2c();

} else if (menuOneCommand == '2') {
  ..do something
} else if (menuOneCommand == '9') {

  ret = aes_get_aes132a_details( & mydetails);
  if (ret != 0) {
    printf("aes_get_aes132a_details() failed with code %d ", ret);
    printst(ret);
    return 0;
  }
  if (mydetails.lock_keys == 0x55 || mydetails.lock_config == 0x55) {
    printf("Device is not locked. Can not run tests!\n\r");
  } else {
    ret = run_tests(); // finishes but never returns
    printf("Completed Tests\n\r");
    if (ret != 0) {
      // handle error
      return 0;
    }
  }
} else if (menuOneCommand == 'A') {
  ..do something
} else if (menuOneCommand == '\n' || menuOneCommand == '\r') {
  // ignore
}

Here is what AS7 looks like in debug

 

 

This topic has a solution.

"When all else fails, read the directions"

Last Edited: Sat. Aug 11, 2018 - 11:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PhillyNJ wrote:
The SAMD21 hangs in the Dummy Handler

So some interrupt/exception has occurred for which you haven't provided a handler.

 

Do you have a Hard Fault handler ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Do you have a Hard Fault handler ... ?

 

Not sure what you mean.. Can you elaborate? 

"When all else fails, read the directions"

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

You need to get a copy of Joseph Yiu's book, "The Definitive Guide to ARM® Cortex®-M0 and Cortex-M0+ Processors"

The Definitive Guide to ARM® Cortex®-M0 and Cortex-M0+ Processors - 2nd Edition - ISBN: 9780128032770, 9780128032787

https://www.elsevier.com/books/the-definitive-guide-to-arm-cortex-m0-and-cortex-m0-processors/yiu/978-0-12-803277-0

 

It explains the Fault mechanism, and gives an example handler.

 

Also google "Cortex M0 Hard Fault"; eg,

 

Cortex-M0 Devices Generic User Guide: 2.4. Fault handling: http://infocenter.arm.com/help/i...

 

https://www.embedded.com/design/mcus-processors-and-socs/4457540/Debugging-hard-faults-in-ARM-Cortex-M0-based-SoCs

 

https://mcuoneclipse.com/2017/01/13/debugging-arm-cortex-m0-hardfaults/

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
You need to get a copy of Joseph Yiu's book, "The Definitive Guide to ARM® Cortex®-M0 and Cortex-M0+ Processors"

Thanks. The links were helpful. I will definitely pick up this book. As for the issue, I want to shoot my self :) - in part of my code I was doing a memcpy and the length was incorrect...like really incorrect. It was clear while watching the Memory in debug mode and see my memory turn red with the changes!

 

 

"When all else fails, read the directions"