fweiss / tm4c-led-pwm

Simple exploration of tm4c123g using PIO and C++
0 stars 0 forks source link

PIO LED PWM

A POC to create an object-oriented HAL/API for the Texas Instruments TM4C123g MCU, geared toward recreating the sample app. The app flashes and dims the RGB LEDs on the development board.

Development environment

Since this is a POC, a bare-bones environment is used.

Development platform has been Macbook Pro, but others should work as well.

Running and testing on hardware

Use the following hardware:

Choose the "lptm4c123gh6pm" PIO environment. Build, flash and debug using PlatformIO IDE.

The upload log shows an error. Everything seems to work. Will try to clean that up.

Testing

Currently there are no automated unit tests. Manual testing via:

There are currently two manual HIL test scenarios which are selected via the EXPERIMENT_1 and EXPERIMENT_2 #defines in src/main.cc. Each scenario uses a different port and timer to verify the code is working correctly.

Inspecting the compiled code

An important part of this POC is to verify that the compiled code is optimized and achieves the C++ zero-overhead principle.

To inspect the compiled code, build the "asm-listing" environemnt. The compiled Cortex M4 code is written to .pio/build/asm-listing/src/main.o

What you should see is that the C++ code:

Port<PortIndex::PortF> port;
port.highPerformanceBusEnable = true;

results in the machine code:

    ldr r3, .L10
    ldr r2, [r3]
    orr r2, r2, #32
    str r2, [r3]
...
.L10
    .word   1074782316

which is as good as hand-coding and what libopencm3 generates.

The asm-listing build log shows an error. Haven't figured out what it is or how to clear it.

MCU concepts

PWM notes

Links and references

Simple PWM example using the library

https://github.com/yuvadm/tiva-c/blob/master/boards/ek-tm4c123gxl/qs-rgb/qs-rgb.c

https://github.com/libopencm3/libopencm3-examples/blob/master/examples/tiva/lm4f/stellaris-ek-lm4f120xl/miniblink/miniblink.c

https://libopencm3.org/docs/latest/stm32l0/html/group__timer__file.html

Tiva TM4C123G Lanchpad schematic

Good overview guide to the TM4C123G MCU

Datasheet

User Manual with examples

Modern C++ for embedded