Enabling extra serial ports for the NGW100

In an attempt to get this robot up and running quickly, my plan is to offload the device I/O to a PIC processor connected through a serial port. There are four UART devices (AT91/AT32) built into the AP7000 (system diagram), however only one of them (UART1) is configured in the stock build, and it is reserved for system console use. That could be disabled, but having the console on that port is extremely useful for debugging in case other things go wrong and the network goes down. To enable the other ports, a kernel recompile is necessary.

NOTE: The AVR32 toolchain must be installed before you can do this. I talked about this earlier: http://www.cibomahto.com/?p=90

There are some pretty good directions about recompiling the kernel in a number of places, see:

The patches themselves are located at: http://avr32linux.org/twiki/bin/view/Main/LinuxPatches.

The first step is to get a kernel tree. There are two choices: download a vanilla tree from kernel.org and then apply the Atmel patchset, or download an already-patched version from Atmel. I chose the latter. This is the file to get:


Once the file has been downloaded and untarred, the next step is to modify the configuration file to enable the other serial ports. We won’t enable UART0 as it conflicts with one of the other on-chip peripherals.

The setup file that configures the NGW100 is arch/avr32/boards/atngw100/setup.c. There are two additions that need to be made to the file to enable the serial port.

Change __init setup_board() to:

void __init setup_board(void)
	at32_map_usart(1, 0);	/* USART 1: /dev/ttyS0, DB9 */
	at32_map_usart(2, 1);	/* USART 2: /dev/ttyS1 */
	at32_map_usart(3, 2);	/* USART 3: /dev/ttyS2 */

and add the following lines to the beginning of atngw100_init():

static int __init atngw100_init(void)
	unsigned	i;
	 * ATNGW100 uses 16-bit SDRAM interface, so we don't need to
	 * reserve any pins for it.

This is the only change that has to be made for now- however, this should be a good clue about how to change other things in the future.

Now, compile the kernel (see one of the above references for a better explanation of this):

make ARCH=avr32 CROSS_COMPILE=avr32-linux- atngw100_defconfig
make ARCH=avr32 CROSS_COMPILE=avr32-linux-
make ARCH=avr32 CROSS_COMPILE=avr32-linux- INSTALL_MOD_PATH=./modules modules_install

If you want to customize anything, do an xconfig or menuconfig after the defconfig line.

If things went well, this should result in the creation of a uImage file in arch/avr32/boot/images/, and corresponding modules files in modules/. The other guides suggest copying this over to the root file system, however I ran into a space problem when I tried to do this. Instead, I tested the image by loading it using tftp, and when I was satisfied I copied it over to my board, replacing the original kernel image.

To boot an image using tftp (note that the modules will not be installed and therefore won’t work):

Reboot the board and break into the Uboot prompt by holding down the space key. In this example, my tftp server is running on my computer with ip address, the ngw100 gets the IP address, and the image is located in the root directory of the tftp server and named uImage. The image is loaded and run from memory address 0×10200000 (this works but I don’t know what is recommended)

From the Uboot prompt:

setenv tftpip
setenv ipaddr
tftp 0x10200000 uImage
bootm 0x10200000

This should cause the system to boot, there will probably be a few errors (especially with the modules). To convince yourself that it worked try:

~ # uname -a
Linux robot 2.6.23.atmel.1 #6 Sat Nov 3 16:50:34 MST 2007 avr32 unknown

If you are satisfied, copy over the uImage file to the root filesystem and the modules (as mentioned in the other directions). Note that you don’t need to save the original uImage file- if you need to go back, it can also be booted using tftpd. I kept both modules directories on the system so that I can switch back and forth at will, and I also copied both uImage files to a CF card so that I could switch them without the tftpd server.

Note: It appears that the default configuration for the ngw100 in 2.6.23.atmel.1 compiles the mmc driver into the kernel. If you see

 * probing modules ...           vfat loaded, mmc_block failed, atmel-mci failed, [ OK ]

during boot after following these instructions, it can be ignored. If it bothers you, comment those lines out in the /etc/modules file. Note that if you do that and then decide to go back to the original kernel image, you will need to load those files by hand to use the mmc driver.

This entry was posted in tech. Bookmark the permalink.

24 Responses to Enabling extra serial ports for the NGW100

  1. Shrift says:

    Hey, i’m interested in ngw100 and adding extra serial ports. It is okay how had you compiled it in a new kernel, but is there any documentation where to connect the cables on the board?
    Can u reply me in email or here?
    Thank you very much,

  2. mahto says:

    Hey Shrift-
    maybe you found it already, but I think what you are looking for is the ngw100 expansion connectors page: http://www.avrfreaks.net/wiki/index.php/Documentation:NGW/NGW100_Expansion_connectors


  3. Shrift says:

    Yes :) thank you very much ;)

    Have a good year, and a nice day :)


  4. iulydj says:

    I recompile the kernel, and the led il blink-ing because the board doesn’t load the drivers for mmc module. How I can stop that led blinking.10x.

  5. mahto says:

    Hi iulydj,
    I’m not really sure what is happening for you- did you change the configuation in any way? the default one should give the same set of drivers. They did add a heartbeat light, but as far as i can tell it is harmless. I use mine with an SD card with no problems.

  6. Toth Lasylo says:

    Please send NGW100 image file ( extra serial port and pio access)
    I copy cp firmware.img /dev/mtdblock


  7. mahto says:

    Hi Toth,

    I didn’t build a new board image, I simply replaced the kernel in the reference image. If you want, you can try using my kernel. Rename it to uImage and then follow the directions above. Note that you will need to set up a tftp server to get it to work.

    My kernel image is here:

    Good luck!

  8. Pucci says:

    Cool! I just build the kernel and now I´m making the conections. Do you have some practice with serial ports? Could you answer some doubts? Now with the new kernel I have /dev/ttyS1 and ttyS2. On the pins configurations it have usart 0,1,2,3. WIch configuration is for wich port? (ttyS1,S2). In the pins configuration have a complete port with clock. Some just tx,rx. I read some documents. They say that in some cases just tx and tx can do the job. But you have to set the flow control. With clock speed this wouldn´t be necessary? I´m trying to make this board to control my network with layer 7 and cqb then if it´s possible i´ll put a squid with cache using the card. Is your robot finished already?

  9. mahto says:

    Hi Pucci, sorry for the late reply. I did use two of the serial ports. If you have ttyS1 and ttyS2, my *guess* is that they are ports 1 and 2. If you set the flow control to software or none, you can get away with only using the TX and RX lines (thats what I do). You can also use software flow control, if the device you are connecting also supports it. I’m not sure what the clock would be for- perhaps the serial hardware can also do synchronous serial (i2c, spi, etc). You won’t need that for rs232.

    What do you mean by cqb?

    Unfortunately, I gave up on that version of the robot. The way I had the control system hooked up was too slow, and I couldn’t get it to move repeatably. I bought all of the stuff to control it with stepper motors, but then I got distracted :-). I hope to make a CPLD-based stepper motor controller to connect to one of the processor buses, but I haven’t gotten that far yet.

  10. Pucci says:

    cbq and htb associated with layer7 (see sourcefourge) are ways to control the internet speed. So my skype would have priority against the web, and the web have priority against the youtube flash videos download, that have priority against p2p traffic.
    So it controls de network doing trafic shapping and everybody shares the net with more pleasure. This is for countries where the internet link offered is expensive and slow. (my 600kbs down, 15kbp up costs 144 dollars). Brazil

  11. Pucci says:

    Ehh… just explaining some speed confusions. On the internet explorer. The max speed that i get is 60 kbps. On the marketing they say that the link is 600kbps. but then we have the kilobytes, kilobits and other parameters and marketing competition. So for comparison, remember the download speed on the iexplorer. the number that i get is 60… upload 15….

  12. mahto says:

    Thanks for the explanation, now I think I get what you are doing. What are you plans for the serial ports? Sorry to hear that you connection is so expensive; do you split it with neighbors? I get about 850kbps down / 650 up.

  13. Pucci says:

    I´m doing computer engineering, we live in 9 guys and share the poor net haha. The serial ports is for a little project at my job (trainee). One for lcd serializer(google) and other for a bar code scanner(ser2net). So i can chat with a display after I receive barcode information through the network.I´m implementing a factory floor control so the company can put the low level employees to insert information into database without manual insertion. There is a quality team just to insert this data that can be automatic. At home, i was thinking in receiving phone information through the serial port. So I can split the phone bill automatically using a atmel 8051 pbx with rs232. But now I´m in the 3rd year and having so much work and no time to do anything.

  14. Pucci says:

    Worked! Max 232 on the usart ok! terminal on ttyS1. =)

  15. mahto says:

    Haha, at least you make good use of the internet connection then! Awesome! Good luck with your projects, they sound pretty cool!

  16. Pucci says:

    Hello again,

    The usart is ttl level? Didn´t find information about it. But I guess it is. What do you think?

  17. Pucci says:

    Newbie question. Already solved. the project is ending soon. I´ll post on my blog and tell you so you can see it!
    3.3V. Learning a lot with the project.

  18. mahto says:

    Hi Pucci! Sorry that I missed your comment, I have been on vacation. I look forward to seeing your project!

  19. Rob says:

    Great tutorial, I found it really handy as someone who’s just starting out with the ngw and linux kernel.

    I’m guessing that this automatically makes the serial ports work through the ttyS1 and ttyS2 devices? If I want to change the inner workings of the serial driver, where would I find the code for that? Is it in at32ap7000.c?
    Is /drivers/serial/atmel_serial.c related to this, or is it something different?


  20. mahto says:

    Hi Rob,
    Yeah, this makes the serial ports work. Good question about where the driver is defined. The drivers/serial/atmel_serial.c file looks like it is correct. Can I ask what you plan to do with a modified serial driver :-)?

  21. Rob says:

    Thanks – I learned a bit more about the linux serial driver layer, and it turns out changing the serial driver isn’t what I want to do after all. I’m working on writing line discipline drivers for the serial port to implement simple protocols for peripheral devices.

    I like your idea of offloading IO to a microcontroller. How realistic do you think it would be to use this to add more serial ports through a SPI connection? I think it might work, although I would have to write a custom driver…


  22. mahto says:

    Hey Rob,
    sorry about the late comment. I’m not sure that what you are talking about makes sense to me- do you need a large number of RS/232 ports or something? I don’t know too much about the Linux serial drivers, but I would imagine it would be a big pain to try and channel a bunch of serial ports through a single SPI connection. If that is really what you need, you might be better off getting a bunch of hardware serial devices (http://en.wikipedia.org/wiki/UART) and connecting them to the parallel data bus on the development board. But that seems really ugly to me.

  23. abd says:

    can we use one avilable serial port used for consol for other purposes or for example another serial port have to be soldered and if that is the case where can i find the other serial port pins.

  24. Augusto says:

    I have some questions. How to use the tftp to transfer the uImage into the NGW100?and how can I transfer the Modules?, which files exactly should I install into the NGW100?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>