OpenOCD for AT91SAM7SE - Part 6
This is part 6 of our OpenOCD for AT91SAM7SE tutorial.
Flashing the Target
Almost all tiny to medium sized microcontrollers today offer flash memory, either for an initial boot loader or to contain the complete application code. JTAG doesn't provide any native support for flash memory programming. Instead, JTAG is used to access hardware registers. Some of them, which are part of the CPU's JTAG interface, may even be used to mimic code and data values, making the CPU running code without any real memory available. This feature can be used to run code fragments, which act as drivers for the flash controller.
OpenOCD Drivers
A few standards had been established for external flash programming, but internal flash programming, like the one on the AT91SAM7 series, is typically incompatible among chip vendors. OpenOCD contains a number of hard coded flash drivers, including one named at91sam7, which works fine for the internal flash of the AT91SAM7SE CPU and even allows to program the GPNVM bits.
Flash memory is typically divided into so called flash banks. Note, that a single chip may contain one or more banks. While the AT91SAM7SE256 contains a single bank only, the AT91SAM7SE512 got two of them. This is important to know, at least when your firmware image grows above 256kBytes. Each flash bank must be declared separately in the configuration file with the flash bank command. Its general form is
flash bank <name> <driver> <base> <size> <chip_width> <bus_width> <target> <driver_options>
A lot of parameters, though, most of them are relevant for external flash only and ignored by drivers for internal flash. For our CPU we declare the two banks as follows.
flash bank sam7se512.flash.0 at91sam7 0 0 0 0 sam7se512.cpu 0 0 0 0 0 0 0 18432 flash bank sam7se512.flash.1 at91sam7 0 0 0 0 sam7se512.cpu 1 0 0 0 0 0 0 18432
After adding the two lines to openocd.cfg and restarting OpenOCD, you should be able to retrieve the flash memory information by entering the following commands in a Telnet session.
flash info 0 flash info 1
You probably noticed, that these commands take time. Actually flashing the chip will take a lot more time, an unacceptable long time. We will try to solve this issue in our next part.