neděle 5. srpna 2012

Back home and another update


Hello again.
I have returned from my trip abroad and so now, I have the time to describe some things from my previous entry in more detail.

The communication protocol

The way in which the micro-controllers communicate with the master computer is specified by a proprietary protocol called Elvis. The structure of an Elvis frame is fairly standard and I don't think it's necessary to describe it here in detail; I mention it only because I may refer to the existence of this protocol later.

The tool-chain


Firstly, I must mention that there already exists a very good tutorial dealing with setting up a toolchain for Cortex-M3 micro-controllers and with introduction to their programming. We referred to it when setting up our own tools but we didn't follow it exactly. I will probably mention this tutorial several times in the following text.
The two essential tools are the C compiler and linker for Cortex-M3. We use a set of them made by one of our own faculty's employees Pavel Píša which are aviliable here.
Next thing to obtain is CMSIS - a set of C macros, definitions and functions which help with programming for Cortex-M3 processors by providing a simple access to various registers, functions to initialise the processor etc. Unfortunately it covers only the core Cortex-M3 functions and does not include anything to help with the peripherals and additional features present on LPC13XX boards.
In order not to have to figure this out from scratch, we used some code from examples in the LPC13XX MDK (microcontroller developement kit) made by a company called Keil and is freely available for download at their site (after registering). Again, these examples don't cover everything so there was still a lot of manual reading going on.

The firmware

In the previous section I have described tools that are freely available and that everyone can get.
Now I will write more about what I have been given to work with that is a part of the MagMan project.
I suppose that the following section will be of interest mainly to the people working on it.
Firstly, I received yet another piece of hardware - a little board that connects to an USB port on a personal computer on one side and to a serial communication PINs on the MagMan module board on the other side. Together with a piece of software called Tolpc, which I will describe later, it is used to program the micro-controllers .
As for software, I have been given the complete firmware up to this point which includes the following:
C files containing the program itself, linker files, Makefile, a piece of Assembly code containing the bootloader and the aready mentioned Tolpc utility.
The C files aren't really that interesting and I can't think of anything special that's worth mentioning about them. They are your standard C files.
The linker files are very similar to these described in the tutorial I have mentioned earlier. They tell the linker where to put what in the micros memory. Unfortunately I have not found a lot of tutorials or resources about linker files, save for the official documentation, but for now I didn't have to tinker with the files much.
The Makefile I got is very complex (I almost want to use the word byzantine here) and I can't honestly say that I understand all of it, but then again, it pretty much automates everything so I don't even have to. It also allows (together with several different linker scripts) to build programs and place them either in FLASH or RAM memory of the LPC13XX. Unlike the linker scripts there is a lot of resources out there dedicated to explaining makefiles around.
The single assembly file contains code of the initial boot-loader which is, again, very similar to the one described in the tutorial except, obviously, ours is written in assembly, not in C. After a reset the micro starts executing from the boot block in the FLASH memory, this is where the boot-loader is placed - It contains the interrupt vector table and interrupt service routine for the reset interrupt. The routine is called and it copies the rest of the program into RAM and then passes the execution to the main function.
The last thing to describe is the Tolpc utility. It serves, together with the hardware gizmo that I have already described, to program the micro. It utilises the LPC13XX ISP (in system programming) features which allow the micro to be (after reset) put into a state where it can be programmed over the serial interface.
What my goal is right now is to make pretty much the same thing as this, only working over the RS485 bus and using IAP (in application programming) functions instead of ISP.

Conclusion

I feel that this post is getting fairly long and I am getting less and less comprehensible, so I think I will stop here for now and leave the description of what I achieved in my experiments working with the FLASH memory for later.
Goodbye.

Žádné komentáře:

Okomentovat