How to configure application properly?


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!
Who is Participating?
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.

(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.
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()?
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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:


#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)?
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).

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.
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

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.