Why does the program counter not reach the start of main()?

There are a few possible causes. Here are some causes to consider:

  1. The device linker script or linker command line is inadvertently modified. Check to see if a linker file is in the project tree since this means that a custom linker is used (MPLAB® XC16, XC32), or for command line linkers (MPLAB XC8), start a new project with the same device, and see if the build output command line is different between the new project and the project with the issue.
  2. The default C startup code is not linked to the project.
  3. The C startup code is being customized and the branch to main is never reached due to a bug in the modified C startup code.
  4. The device is resetting before main() can be reached due to a POR, BOR, WDT, or another reset.
  5. The clock is failing (often a hardware issue). Use an internal oscillator if available for test purposes.
  6. The device is not experiencing a proper POR. (VDD slew rate specs are being violated or the device is not released from reset).
  7. The entry point into main() is not defined by the linker.
  8. There is a hardware issue, like a single disconnected VDD pin. Attempting to duplicating the issue on a Microchip demo platform usually isolates the problem to your hardware when the root cause of the issue lies in the hardware.
  9. The device errata sheets have not been investigated.
  10. An unresolved breakpoint is placed at the start of main() (due to optimizations) and you interpret this as main() never being called.
  11. You have two projects open at once and they are debugging the wrong project and expecting main() to be reached in an inactive project.
  12. The device has suffered electrical damage. Swap the device with a new one and see if the issue remains.
  13. The device is only partially programmed. In the device development tool settings, manual memories and ranges have been selected in a way that cuts off the startup code.
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.