Posts Tagged ‘stellaris’

Run applications from RAM in Stellaris Launchpad

02/01/2015

I made a program to load applications to RAM and run them in the Stellaris Launchpad. On reset, it reads an SREC file from the serial port and copies it to RAM. It points the vector table to the load location (so interrupts work normally) and jumps to the application’s main() function.

The first problem was reserving RAM for the loaded application. To do this, I modified my linker script by splitting the RAM into two sections, and keeping the loader in the first section.

Afterwards, the application has to be linked so that it will run from RAM. This means using another linker script that puts it on the second section of RAM. It also places the vector table at the beginning so that the loader knows where it is.

The loader itself is a minimal SREC parser which implements the records that showed up in my SREC files.

To play around with the loader, it’s possible to make SREC files from the SDK example projects. This requires changing the entry point and linker script in the Makefile. For example, to compile project0 we change
SCATTERgcc_project0=project0.ld
ENTRY_project0=ResetISR

to
SCATTERgcc_project0=../linkprogram.ld
ENTRY_project0=main

. Then we have to change the startup script in startup_gcc.c . Normally the reset routine would copy data from Flash to RAM to initialize variables, but this isn’t necessary when running from RAM. So comment out ResetISR and change the reset vector to (void (*)(void) main.

After these changes, the AXF file generated by make will be good for running from RAM. To get the SREC file, use objdump and sed to strip the header:

arm-none-eabi-objcopy -S -O srec --srec-len=8 project0/gcc/project0.axf project0/gcc/project0.srec
# Strip header
sed -i /^S0/d project0/gcc/project0.srec

I’ve automated this last step with a rule in the Makefile. This works successfully with usb_dev_mouse, project0, qs-rgb and probably all the other example projects.

Ubuntu ARM toolchain compiles Stellaris USB examples correctly

22/12/2012

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)
    wget ftp://sources.redhat.com/pub/newlib/newlib-1.18.0.tar.gz
    tar xzf newlib-1.18.0.tar.gz
    cd newlib-1.18.0/
    ./configure --target arm-linux-gnueabi --disable-newlib-supplied-syscalls
    make

    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
    PREFIX=arm-linux-gnueabi
    LIBC=/something/newlib-1.18.0/arm-linux-gnueabi/newlib/libc.a
    LIBM=/something/newlib-1.18.0/arm-linux-gnueabi/newlib/libm.a

    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 \
           -c
  3. To compile everything, run make clean and make

USB Mouse example for Stellaris Launchpad

10/12/2012

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”
    • CFLAGSgcc=-DTARGET_IS_BLIZZARD_RA2

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.

15/11/2012

My Stellaris Launchpad finally arrived. I’ve been following this tutorial for programming it on Linux successfully.

However, I was annoyed at having to run the flashing utility as root. So I created a udev rule that gives the board’s device file the proper permissions. First, create a group called stellaris and add yourself to that group:
sudo addgroup stellaris
sudo adduser $USER stellaris

Then create the udev rule. Create the file /etc/udev/rules.d/45-stellaris.rules with the following contents:
ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", MODE="0664", GROUP="stellaris"
What does this mean? This line consists of key-value pairs separated by commas.

  1. The first two are match keys: when something is plugged in, udev checks if its vendor and product IDs match the ones here.
  2. The last two are assignment keys: if there’s a match, the device file is created with the specified permissions and group. These permissions mean that the owner (root) and members of the the group stellaris can read from and write to the file, while others can only read.

You might have to restart your terminal in order for it to recognize you’re now in the stellaris group. You can also run
exec su -l $USER