MPLAB X IDE Simulation problems

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

I'm having problems using the simulator in MPLAB X IDE.  It's probably just me, but I can't figure out what I'm doing wrong.

 

I have a simple program:

 

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
  uint16_t apple;

  apple = 0x1234;
  apple += 5;
  apple += 2;
  apple -= 1;

  return (EXIT_SUCCESS);
}

It "Builds" correctly, but when I try to run it with the simulator and any breakpoints I get the following error:

 

Break point at line 8 in file P:/Users/p/Documents/MPLABXProjects/discard-test-12.X/newmain.c cannot be resolved to a valid program memory address

I don't see anything in the MPLAB X IDE about the need to set a starting point for program memory, but I'm guess that I need to do that.  The problem is that I don't know how to do that or even if that's my problem.

 

Any suggestions would be appreciated.

 

Paul

 

This topic has a solution.
Last Edited: Mon. Dec 27, 2021 - 04:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't need an argc or argv for an embedded application. And no return.

You don't need to set an address for program memory.

 

I don't know that those are the problem, but fyi.

 

int main(void)
{
        system_init();//or some such.
        while (1) { //application code.
        }
}

 

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

As well, 'apple' is not really used. So I can't help but wonder if a compiler would optimize it out -- in which case, there'd be no real instruction for the debugger to break at. That would explain the failure.

Just a thought!

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

If printf works, try to print the value of 'apple'. That'd give the program some 'meat'.

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

Thanks, I was under the impression that build for debug turned off most optimization, but I don't know that for a fact.

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

poobar wrote:
You don't need an argc or argv for an embedded application. And no return.

 

That stuff comes with the main.com provided by a new project under MPLAB X IDE.  But I agree that it's not needed.

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

poobar wrote:
If printf works, try to print the value of 'apple'. That'd give the program some 'meat'.

 

I'm not sure about printf, but I'll see if I can send the data to a simulated output port.

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

microPaul wrote:

Thanks, I was under the impression that build for debug turned off most optimization, but I don't know that for a fact.

I wouldn't even call it optimization. Simply put, the program is not doing _anything_.

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

Have a read of this recent thread... 

 

https://www.avrfreaks.net/forum/breakpoints-not-hit

 

My comments in that thread also apply to #1 in this thread. In particular follow the link to the tutorial that hopefully explains all. 

 

Bottom line, if you want to just "test C stuff" and observe it in action you are far better off doing it in a PC development system like Visual Studio (and argc/argv work there too!) 

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

Thank you clawson for the link and the link therein to your tutorial.  I've bookmarked the tutorial.  turning off compiler optimization solved my problems.   I appreciate your advice.

 

Paul

 

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

But turning OFF optimisation is NEVER the right solution. The mode only really exists so the compiler developers can see truly how awful the code generation is before optimization and that their optimizing steps are doing a good/best job.