Skip to content

First Use

This guide walks you through using embsec/dev for the first time.

Starting the Environment

  1. Navigate to your project folder:

    cd ~/embedded-security/lab1
    

  2. Start the development environment:

    embsec up
    

This will: - Start the Docker container - Mount your current directory to /workspace - Connect any plugged-in TM4C123G boards - Open VS Code in your browser

VS Code Interface

When VS Code opens, you'll see:

  • File Explorer (left): Your project files
  • Editor (center): Write your code here
  • Terminal (bottom): Run commands
  • Extensions (left sidebar): Pre-installed embedded tools

Pre-installed Extensions

  • C/C++: Syntax highlighting and IntelliSense
  • Cortex-Debug: Hardware debugging support
  • Python: For scripting and analysis

Creating Your First Program

  1. In VS Code, create a new file: blink.c

  2. Copy this starter code:

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/gpio.h"
    #include "driverlib/sysctl.h"
    
    int main(void) {
        // Set clock to 80MHz
        SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | 
                       SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    
        // Enable Port F
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
        // Set PF2 (Blue LED) as output
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
    
        while(1) {
            // Toggle LED
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
            SysCtlDelay(SysCtlClockGet() / 3);  // ~1 second
    
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
            SysCtlDelay(SysCtlClockGet() / 3);
        }
    }
    

Building Your Code

In the VS Code terminal:

# Compile
arm-none-eabi-gcc -o blink.elf blink.c \
    -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard \
    -ffunction-sections -fdata-sections -g -gdwarf-2 \
    -MMD -MP -static -Wl,--gc-sections \
    -Wl,-T,TM4C123GH6PM.ld \
    -I/workspace/inc \
    -L/workspace/driverlib \
    -ldriver

# Convert to binary
arm-none-eabi-objcopy -O binary blink.elf blink.bin

Flashing to TM4C123G

Make sure your TM4C123G is connected via USB, then:

# Flash the binary
lm4flash blink.bin

You should see:

Found ICDI device with serial: XXXXXX
Erasing target...
Flashing target...
Resetting target...
Done.

The blue LED on your board should now be blinking!

Debugging

To debug your program:

# Start GDB
arm-none-eabi-gdb blink.elf

# In GDB:
(gdb) target extended-remote :3333
(gdb) monitor reset halt
(gdb) load
(gdb) break main
(gdb) continue

Useful Commands

Inside the container terminal:

# Check USB connection
lsusb

# View serial output
screen /dev/ttyACM0 115200

# Exit screen
Ctrl-A, K, Y

# Python for quick calculations
python3
>>> hex(0x400253FC)  # GPIO register address

Saving Your Work

Your files are automatically saved to your host machine. The /workspace folder in the container maps to wherever you ran embsec up.

Stopping the Environment

When you're done:

# From another terminal on your host
embsec down

Or just close the browser tab - the container keeps running so you can reconnect.

Tips

  • Auto-save: VS Code auto-saves your files
  • Multiple terminals: Click the + in the terminal panel
  • Command history: Use ↑/↓ arrows in terminal
  • Quick restart: embsec down && embsec up

Next Steps