Execute code from SRAM on AVR32

Atmel has an application note explaining how to execute code from SDRAM and another document explaining how to use linker scripts. GNU ld and as docs are also useful references.

Create a new section

Add the following section in the SECTIONS of linker script, probably after the .data section. The location pointer should be in the SRAM, usually indicated by a statement such as . = ORIGIN(SRAM)

  .text_sram :

The MEMORY spec in the linker script should place SRAM and FLASH used above in the appropriate memory regions.

Modify functions

Add the following attribute to the functions that will be located in the SRAM


Use objcopy and nm to check the resulting elf

Execute avr32-objcopy on the elf

avr32-objdump -h file.elf

This should list something like

Idx Name          Size      VMA       LMA       File off  Algn
  8 .data         000005d4  00000578  8000e778  0000ed78  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  9 .text_sram    00000044  00000b4c  8000ed4c  0000f34c  2**2
 10 .bss          00004138  00000b90  8000ed90  0000f390  2**2

Use avr32-nm to check location of symbols in memory

avr32-nm file.elf

This lists something like

00000b4c T func

The function func is loaded into FLASH but executed from SRAM.

Adjusting attributes of v4l2src and vp8enc elements for video conferencing

Video conferencing is real time in nature. The default encoding parameters of vp8enc element of GStreamer are not always appropriate. Let us start with the following pipeline

gst-launch v4l2src ! video/x-raw-rgb,width=320,height=240 ! ffmpegcolorspace ! vp8enc ! vp8dec ! ffmpegcolorspace ! ximagesink sync=false

The CPU usage, on a PandaBoard with Ubuntu 11.04, is close to 100% (since there are 2 cores, that translates to 50%).

Now, modify the pipeline as follows

gst-launch v4l2src decimate=3 ! video/x-raw-rgb,width=320,height=240 ! ffmpegcolorspace ! vp8enc speed=2 max-latency=2 quality=5.0 max-keyframe-distance=3 threads=5 ! vp8dec ! ffmpegcolorspace ! ximagesink sync=false

Note the decimate attribute of the v4l2src element, and the attributes speed, max-latency, max-keyframe-distance, threads and quality of the vp8enc element. With these changes the CPU usage drops to 40% and the video playback is more real time.

Write Ubuntu image file to SD card on Windows

I use an 8 GB class 4 SD Card to run the Ubuntu distribution for OMAP4 on a PandaBoard. This post details the procedure I use to prepare the SD Card on Windows.

Download and write Ubuntu image

You’ll need the following tools

  1. 7-zip or other decompressor that can extract gzipped file (extension gz).
  2. Image Writer for Windows to write the img file to the SD Card.
  3. A laptop with SD Card reader, or an external USB SD Card reader.

Here’s the procedure to prepare the SD Card

  1. Download Ubuntu gzipped image file for OMAP4 boards.
  2. Extract img file using 7-zip.
  3. Insert SD Card into reader.
  4. Execute Win32DiskImager.exe – it requests admin privileges on Windows 7.
  5. Select the image file extracted in step 2.
  6. Select the device that corresponds to the SD Card reader.
  7. Write the image file. This will take a while.
  8. Eject the SD Card.

Backup or Clone SD Card

Image Writer for Windows can also be used to read an SD Card. You can write the image file to the same or another SD Card.

Restore SD Card to Original State

The SD Card will be partitioned after the procedure above. To restore it to its original state i.e. create a single partition with all the available space, you’ll need to use the GParted Partition Editor on a Linux box, or from a live CD. Windows 8 Disk Management tool may also work.

Patch for version 0.3 of Image Writer for Windows
Skip this section, it refers to an older version of Image Writer for Windows. Retaining it to provide context for the comments.

Version 0.3 binary of Image Writer has a bug in a call to Win32 SetFilePointer function. The image read is about half the size of my 8 GB SD Card. I built it from source using QT Creator after patching the following two functions in disk.cpp

char *readSectorDataFromHandle(HANDLE handle, unsigned long long startsector, unsigned long long numsectors, unsigned long long sectorsize)
	unsigned long bytesread;
	char *data = new char[sectorsize * numsectors];
	li.QuadPart = startsector * sectorsize;
	SetFilePointer(handle, li.LowPart, &li.HighPart, FILE_BEGIN);
	if (!ReadFile(handle, data, sectorsize * numsectors, &bytesread, NULL))
		char *errormessage=NULL;
		QMessageBox::critical(NULL, "Read Error", QString("An error occurred when attempting to read data from handle.\nError %1: %2").arg(GetLastError()).arg(errormessage));
		delete data;
		data = NULL;
	return data;

bool writeSectorDataToHandle(HANDLE handle, char *data, unsigned long long startsector, unsigned long long numsectors, unsigned long long sectorsize)
	unsigned long byteswritten;
	BOOL bResult;
	li.QuadPart = startsector * sectorsize;
	SetFilePointer(handle, li.LowPart, &li.HighPart, FILE_BEGIN);
	bResult = WriteFile(handle, data, sectorsize * numsectors, &byteswritten, NULL);
	if (!bResult)
		char *errormessage=NULL;
		QMessageBox::critical(NULL, "Write Error", QString("An error occurred when attempting to write data from handle.\nError %1: %2").arg(GetLastError()).arg(errormessage));
	return (bResult == TRUE);

That fixed the problem with reading and writing large SD Cards.

Data applications on MOTOTRBO radios

MOTOTRBO two-way radios implement the Digital Mobile Radio (DMR) standard. They use a channel bandwidth of 6.25 KHz. Small IP datagrams can be sent between radios over the air. This air data network is called the Common Air Interface (CAI) network. A 24-bit radio ID is used along with an 8-bit CAI network ID to form a unique IP v4 address for each radio. Radios that have the same channel configuration can then exchange datagrams using IP addresses.

IP Peripheral

MOTOTRBO radios can be connected to an IP peripheral, such as a PC, over a USB 1.1 link. A radio acts like a router between the CAI network and the PC. The PC also receives a CAI IP address and can be addressed by other radios. A radio can be configured to forward all datagrams it receives, to the PC.

Generic Option Board

The radio can also host an embedded board called the Generic Option Board (GOB), designed around an Atmel AVR32 SoC. An application on the GOB can receive raw datagrams sent to a virtual port on the radio. Connectivity to the PC and extensibility using the GOB make the MOTOTRBO radio an attractive platform for delivering small-data applications.

Non-IP Peripheral

The MOTOTRBO radio can also be connected to a PC or other host as a Non-IP Peripheral, over a USB 1.1 link. Messages sent by other radios, or the GOB, are forwarded to the host over a USB bulk transfer endpoint.

Bluetooth support

The expanded portfolio MOTOTRBO radios also support Bluetooth. Bluetooth profiles supported are: serial port profile, headset profile, and personal area networking profile. The radio can route data from the connected Bluetooth peripheral to the GOB, and to other radios on the CAI network. This is a paid feature, an additional license is required per radio.

MOTOTRBO Configurations

MOTOTRBO radios support different configurations to connect with other radios. The simplest configuration is one where one radio broadcasts directly to other radios. Other configurations involve using repeaters. Repeaters, besides extending the range of RF communication, can be interconnected to increase range, and capacity i.e. number of available channels. Repeaters also enable applications to communicate with radios without requiring an intermediary radio.

Licensed Application Developer

To develop applications for MOTOTRBO radios you need a developer license from Motorola Solutions Inc. Licenses are usually issued on a per app basis for a particular geographical region.

How taxes in Brazil hamper innovation

I am doing a research and development project for a client outside Brazil. They sent us (via a well known courier service) a development board for prototyping, with a declared value of USD 326.00 or BRL 520.30. Here’s the breakdown of the taxes charged by the tax office of our state (Pernambuco, Brazil) on entry:

Importation Tax – BRL 312.18 (60% of declared value)

ICMS / GNRE (state sales tax) – BRL 170.51 (20.48% of declared value+importation tax)

Administrative charge – BRL 44.97

Total taxes and charges – BRL 527.66

In other words, the total taxes and other charges amount to approximately the declared value (100%) of the development board.

Now, that is no way to go about encouraging innovation!

idioCyncracies: operator precedence

I get a tingle when I see C code such as

while (*string != 0)

How do you suppose the compiler evaluates the expression *string++? Here’s the operator precedence table to help you figure that out.