Programming STM32-Discovery using GNU tools. Startup code

Startup code is executed just after microcontroller is reset before the main program. As linker script, startup code usually is implemented as universal code for all the same microcontroller type. So often you don’t need to write one from scratch. Anyway, it is good to know what happens there anyway. As we said, linker script has to go along with the startup code. This means that it will initialize MCU automatically according to data defined in the linker. Startup code initializes variables, copies defined variables from Flash to RAM, initializes stack and then gives resources to the main program. You will find that startup codes usually are written in assembly language, but this can also be done in C, which is easier to read and modify if necessary. First of all, in linker script we have pointed entry point to startup with the following command: So in startup code, this will be the first function called.

Continue reading

Programming STM32-Discovery using GNU tools. Linker script

Previously we went through setting up a development environment for ARM Cortex-M3 microcontroller. We decided that two equal choices will do the same job – either CodeSourcery G++ Lite or Yagarto. Both use the same base of GNU tool-set. Developing with GCC tools To get a working binary, there is a series of tools involved during code development. Several tools are necessary to compile simple applications. These are compiler, assembler, linker and binary generator. Each of them does its task in a chain process. When you start compiling your project, a linker is usually invoked, which with correct parameters links libraries and object files. Once executable is generated, the binary image generator creates a binary image (.bin or .hex) uploaded to MCU. We won’t go into details right now as this will be more convenient to do in later code examples. Let us get directly to the code writing part, which is very important for linker and tasks before the main() routine.

Continue reading

Setting ARM GCC development environment

As we mentioned before, we are going to stick with free software tools. So we are going to use free and open-source GCC compiler to develop programs for ARM Cortex microcontrollers. As we will work from the windows environment, there are a couple of serious choices that are pretty similar. One is using CodeSourcery Lite edition or Yagarto Gnu ARM toolchain. Both tools work the same as they use the same GCC compiler and other tools. Both seem to be supported frequently. CodeSourcery claims that they are updating Lite Edition twice a year, while Yagarto is doing this more regularly depending on updates of separate tools. So your choice won’t affect your final result. When installed you can quickly check if everything works fine by opening command-line tool and writing a simple command that checks the version of ARM GCC compiler: arm-none-eabi-gcc.exe -v Both can be used with Eclipse IDE and require a makefile. The only difference – is a path to tools when compiling. Download any or both of these and install to your machine. Next step is to…

Continue reading