Archive for 22 diciembre 2012

Ubuntu ARM toolchain compiles Stellaris USB examples correctly


I managed to get the StellarisWare libraries and examples working without Sourcery Codebench. Based on these two articles:

The complete StellarisWare suite compiles without errors, and the examples I tried (including usb_dev_serial and usb_dev_mouse) work correctly. This is an improvement over summon-arm-toolchain, which compiled non-functional USB examples.

Instructions for Ubuntu 12.10:

  1. # Install toolchain
    sudo aptitude install gcc-arm-linux-gnueabi
    # Download and compile newlib (had trouble with the toolchain's libc and libm)
    tar xzf newlib-1.18.0.tar.gz
    cd newlib-1.18.0/
    ./configure --target arm-linux-gnueabi --disable-newlib-supplied-syscalls

    This makes the files libc.a and libm.a in the subdirectory arm-linux-gnueabi/newlib

  2. Unzip the StellarisWare files, and in the root directory edit makedefs. Search for the following settings and change them, replacing something with the directory where you unzipped newlib

    Also change CFLAGS, adding the line with -fno-stack-protector, so it looks like this:

    CFLAGS=-mthumb             \
           ${CPU}              \
           ${FPU}              \
           -Os                 \
           -ffunction-sections \
           -fdata-sections     \
           -MD                 \
           -std=c99            \
           -Wall               \
           -pedantic           \
           -DPART_${PART}      \
           -fno-stack-protector \
  3. To compile everything, run make clean and make

USB Mouse example for Stellaris Launchpad


With some help I got the USB Mouse example from the LM3S9D90 board working on the Stellaris Launchpad. It needed a few changes:

  • Replaced the linker script usb_dev_mouse.ld with one from the Launchpad examples. The only difference was the size and location of the FLASH and SRAM memory regions.
  • Added code to configure the USB pins at startup, as suggested by dellwoodbu.
  • Changed several lines in the Makefile:
    • PART=LM4F120H5QR
    • VARIANT=cm4f
    • Set ROOT to my StellarisWare directory as usual
    • Added a target for programming the board:
      .PHONY: download

      download: ${COMPILER}/usb_dev_mouse.bin
          lm4flash -v $<

    • Replaced all instances of “cm3” with “cm4f”

You can download the example project files. Remember to set ROOT in the Makefile to your StellarisWare directory.

Warning: it does not work when compiled with the Summon Arm Toolchain. It compiles without errors but the device fails to enumerate. It responds to descriptor requests with malformed USB packets (seen with Wireshark). Works fine if compiled with Sourcery Codebench, haven’t tried other toolchains.