How to configure application properly?

Hello:

I am using Keil uVision version 5.40.  I load the application in my target board using
Keil ULINK2 Debugger.  I can jump to my startup code.  When I get to the following instruction:

bx __main()

I cannot single step into Keil's __main(). When I try stepping into it, code starts running.
When I hit stop execution, I end up in the following filename (RT_Agent.c):

void _sys_exit (int return_code) {
  /* Endless loop. */
  while (1);
}

My guess is I'm not configuring my application properly.

Please advise!
LVL 1
naseeamAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

phoffric\Commented:
(Sorry I don't know ARM architecture.) Only suggestion I have is to put breakpoints everywhere you can especially if you are multithreaded. Be sure to put breakpoints on your main(), _sys_exit(), as well as in Keil's __main(). Instead of stepping, try run and see if you can stop on one of your breakpoints. If you are getting to Keil's __main(), but not to main(), then possibly an exception is being thrown by one of your constructors, so advise putting breakpoints in all of your constructors. In some debuggers, I have noticed that Next might fail whereas setting a breakpoint and then Continue will get over the problematic code with no problem.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
naseeamAuthor Commented:
I commented out all my tasks and just inserted while(1) in my main().

I put breakpoint on all exception handlers but I don't break there.
phoffric\Commented:
You could have an uncaught exception from a constructor. Did you put breakpoints in all constructors of objects (and their base classes) that are created before you go to main()?
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

naseeamAuthor Commented:
I put breakpoints in Three constructors.  Code didn't break in any of these constructors.

We are using Keil IDE which includes, makefile, debugger, real time OS, real time librarires, middleware libraries like TCP, USB.

I make it to Keil __main().  Then, there is strange software interrupt instruction as follows:

SWI #AB

#AB is a large number.  Usually these numbers are 1 through 12.  #AB seems questionable.
I think there is no handler for SWI and that's why I end up at while(1)?
phoffric\Commented:
As I mentioned, I don't have experience with ARM and Keil. I looked up SWI and I see it is a Software Interrupt Instruction (SWI).
     http://www.keil.com/support/man/docs/rlarm/rlarm_ar_swi_func.htm

Analogous to other systems, it looks like the argument is an index to SWI functions. The above link has the following:
SWI functions 0..7 are reserved for the RTX kernel.

Do not leave gaps when numbering SWI functions. They must occupy a continuous range of numbers starting from 8.
SWI functions can still be interrupted by FIQ interrupts.

So, I agree that #AB should not be a large number, especially since there should not be "gaps when numbering SWI functions".

I think you have at least narrowed down the source of your problem. Now you have to figure out how #AB got set to this large number. The above link has some configuration (programming) notes on what you have to do if you want to use SWI. It looks to me like the argument is a 5-bit number that you increment by 1 every time you add a new SWI function. Here are the instructions from that link on how to do this:
If you want to use SWI functions in your RTX kernel project, you need to:

1. Copy the SWI_Table.s file to your project folder and include it into your project.
 This file is located in the \Keil\ARM\RL\RTX\SRC\ARM folder. 

2. Declare a function with a __swi(x) attribute. Use the first SWI number, starting from 8, that is free. void __swi(8)  inc_5bit (U32 *cp);

3. Write a function implementation and convert the function name into a __SWI_x function name. This name is referenced later by the linker from SWI_Table.s module. void __SWI_8            (U32 *cp) {
  /* A protected function to increment a 5-bit counter. */
  *cp = (*cp + 1) & 0x1F;
}

4. Add the function __SWI_x to the SWI function table in the SWI_Table.s module.

 First import it from other modules: ; Import user SWI functions here.
                IMPORT  __SWI_8

then add a reference to it into the table: ; Insert user SWI functions here. SWI 0..7 are used by RTL Kernel.
                DCD     __SWI_8                 ; SWI 8  User Function

5. Your SWI function should now look like this: void __swi(8)  inc_5bit (U32 *cp);
void __SWI_8            (U32 *cp) {
  /* A protected function to increment a 5-bit counter. */
  *cp = (*cp + 1) & 0x1F;
}

Open in new window

Did you do follow this procedure? If not, hope this helps.
naseeamAuthor Commented:
Thank you so much for all your help!  I reduced the code and disabled external RAM chip in my target board and now I can jump to main every time.  I replaced the board and now I can get to main() every time withe external RAM chip enabled.  The challenge will be to get to main after I slowly expand code to it's usual size.
phoffric\Commented:
Good that you can finally get to main(). I would check your mapping of the external RAM chip comparing what you have with examples in your documentation. Good luck adding in  more code and enabling the RAM chip.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.