I'm interested in learning about what's under the hood, or what's hidden from you by an IDE, by which I mean, compiler, linker, makefiles - that type of thing. I have a few specific, if potentially misguided questions about what I think I should be doing with it so far, but am also very open to general advice about this kind of thing.
The reason this is important to me now, after doing various microcontroller things in university, which were only taught using IDES, is I'm trying to learn a unit testing framework.
Specifically, this framework is Unity, and from what I understand so far, you can't just survive under the protection of IDES any more if you want to use it.
For example it seems, for each 'module' you want to test (eg module.c and module.h) you should create a testModule.c which has a separate main() containing file of its own to run the tests (I believe this would be the 'test runner'. The problem for me here is if I did this in Keil uvision, it would rightfully get upset because you can't have more than one main(). So therefore I need to tell the linker to either compile the module with 'proper' main() or the test one. I don't know how to do that though.
I would also probably then be interested in running my test executable on the native environment rather than the target (which I think means running it on the pc on which I wrote the firmware rather than downloading code to a microcontroller and hitting go or debug in the ide).
This is a problem I don't know how to invoke my pcs' c compiler (cl.exe) compiler to build anything than a simple helloWorld.c type program with no dependencies on header files outside of the local directory.
Advice general or specific in making headway in this area will be welcomed.
The microcontroller I have is stm32F4 on a discovery board, so cortex m4. I use keil uvision and windows 7 to program
Hello,
In order to do this testing, you could use conditional compilation of code sections.
For instance if TESTMODE is not declared, you only compile, link and flash the core software and if TESTMODE is declared, you do everything.
This way you can have 2 main() in the same file.
These also work without an IDE.
Example
// #DEFINE TESTMODE // Uncomment this line to include test code and test main #IFDEF TESTMODE // The following code will only be compiled if TESTMODE exists. void main(void) { SetupMyModules(); SetupMyTest(); Runest();MyT } #ENDIF
#IFNDEF TESTMODE // The following code will only be compiled if TESTMODE does NOT exist void main(void) { SetupMyModules(); RunMyApplicationTest(); } #ENDIF
You can also combine within the code:
void main(void) { SetupMyModules(); #IFDEF TESTMODE // The following code will only be compiled if TESTMODE exists.SetupMyTest(); SetupMyTest(); RunMyTest(); #ENDIF RunMyApplicationTest(); }
I have found the following articles you might find interesting.
It gives you explanation on the compiler and linker parameters.
To read Part 2 go to Startup code and low level initialization.
To read Part 3, go to The Linker Script.To read Part 4, go to Compiler options for C and C++.To read Part 5, go to Fine-tuning the application.To read Part 6 , go to General Description of Interrupt Handling.
To read Part 7, go to Interrupt locking and unlocking policy.To read Part 8, go to Low level interrupt wrapper functions.To read Part 9, to to C-level ISRs and other ARM exceptions.To read Part 10, go to Test Strategies.