TI TIVA libopencm3 blink example stuck on reset_handler() (?)

Hello,

I’m trying to get my tiva C EK-TM4C123GXL evaluation board to execute the libopencm3 example provided by PlatformIO. The example code should cycle colors on the onboard RGB LED upon pressing user switch SW2. The board does nothing after upload. Bear in mind, this is my first dive into trying to program a board using C. I have done some previous course work using Code Composer Studio; nothing too involved so, I’m excited to play around with the libopencm3 framework.

Interestingly enough, the energia example works just fine. I used the PIO Unified debugger on the libopencm3 example and it seems that in the file vector.c (part of the cm3 framework), when executing reset_handler(), I cannot step into the call to main() (vector.c:94). Whenever I try to step into main(), the board seems to be in an infinite loop. When I pause execution, the board is stuck executing blocking_handler() (vector.c:103), which indeed is just an infinite loop.

My goal is to get this program to work so I can then step through it and learn what the libopencm3 functions are doing so I can whip up something simple of my own. What are some things that I could do to resolve this? Is there anything else I can provide y’all with to make resolving this easier?

Thanks in advanced!

Can you see in the debugger the call trace / stack frames that led up to the blocking_handler being called? What code is executed before it hard crashes? Can you link to the exact code and platformio.ini you’re using?

Hey max, all the code I’m running is from this repo. main.c and platformio.ini files are from there.

I made minimal progress, but not by changing anything. I can now successfully see the debugger start in main().
The code that is being executed right before the crash is line 140 of main.c. I’ve tried commenting out that particular line and it crashes again on the following line.

The call stack right before the crash:

main@0x000002f4 (/Users/pugsley/Documents/PlatformIO/Projects/180509-152037-libopencm3-blink/src/main.c:139)

Call stack at crash:

blocking_handler@0x00000648 (/Users/pugsley/.platformio/packages/framework-libopencm3/lib/cm3/vector.c:104)
signal handler called>@0xfffffff9 (Unknown Source:0)
vector_table@0x00000000 (Unknown Source:0)

I did some digging around. Line 140 in the provided main.c is gpio_enable_ahb_aperture(). As defined in the libopencm3 docs, that function performs one thing: SYSCTL_GPIOHBCTL = 0xffffffff;

I looked around the MCU’s data sheet and found that memory address (http://www.ti.com/lit/ds/spms376e/spms376e.pdf, page 258):

It looks like only 5 bits need to be set to enable AHB aperture for all ports of the MCU, all other bits are reserved. That makes me wonder, should gpio_enable_ahb_aperture() really be doing this:
SYSCTL_GPIOHBCTL = 0x1F; ?

I might be chasing my tail here. Any clues?

Also, should I move this thread out of Troubleshooting?

EDIT: Whenever I step into the first line of main.c the debugger throws this message:

Error: memory read failed: 0x7

UPDATE:
I fixed it!
What was wrong was that the linker script for LM4F that is in the libopencm3 package that PIO downloads does not define memory regions.

The file is:

~/.platformio/packages/framework-libopencm3/lib/lm4f/libopencm3_lm4f.ld

I added the following at line 24:

MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 256K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
}

I payed closer attention to the compiling messages and noticed that it threw a warning relating to memory regions “ram” and “rom” not being defined. So I looked around, found the file and modified it.

Following links also gave me the ideas to look around for this stuff:

I understand what the addition does, but I would not have gotten it right without the following post (where I got the code syntax): Custom board with linker script for libOpenCM3 · Issue #474 · platformio/platformio-core · GitHub

Additionally, STM32 and TI TIVA have different ROM origins: Error debugging Stellaris LaunchPad from Windows - SparkFun Electronics Forum. Basically, STM32 ROM origin is 0x08000000 and TI TIVA ROM origin is 0x00000000.

Memory block sizes I got from TIs webpage for the MCU.

I feel like this should have been noted somewhere in the PIO docs, no? From the docs I got the feeling that TI TIVA platform was ready to use with the libopencm3 framework but it will not work with that addition, at least for me. Further thoughts?

There is definitely something strange going on. When you look in the board file for your EK-TM4C123GXL board (which is here, board target lptm4c1230c3pm) it says

"ldscript": "lm4fcpp_blizzard.ld",

Which references this file, in which it says

MEMORY 
{
    flash (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000 
    ram  (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 
}

Which is correct according to what you said above (just the same numbers in hex). So the linker script you reference shouldn’t actually be used. But if adding the memory region defines in that other file fixed it they somehow were used. Can you provide a full verbose build log to see what actual linker script is used? Execute pio settings set force_verbose Yes and clean and recompile.

Unfortunetly I don’t have the hardware to reproduce this, so debugging is hard. Next steps would be to open an issue on either GitHub - platformio/platform-titiva: TI TIVA: development platform for PlatformIO or GitHub - libopencm3/libopencm3: Open source ARM Cortex-M microcontroller library to further understand this issue, I think.

1 Like

Here is the verbose build log:

[Thu May 10 09:58:25 2018] Processing lptm4c1230c3pm (platform: titiva; board: lptm4c1230c3pm; framework: libopencm3)


PLATFORM: TI TIVA > TI LaunchPad (Tiva C) w/ tm4c123 (80MHz)
SYSTEM: LPTM4C1230C3PM 80MHz 32KB RAM (256KB Flash)
DEBUG: CURRENT(ti-icdi) ON-BOARD(ti-icdi)
Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
LDF MODES: FINDER(chain) COMPATIBILITY(light)
Collected 0 compatible libraries
Framework incompatible library /Users/pugsley/.platformio/lib/HttpClient_ID46
Scanning dependencies…
More details about “Library Compatibility Mode”: Redirecting...
No dependencies
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/src/main.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc src/main.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/lm4f/gpio.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/lm4f/gpio.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/vector.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/cm3/vector.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/assert.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/cm3/assert.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/lm4f/systemcontrol.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/lm4f/systemcontrol.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/lm4f/rcc.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/lm4f/rcc.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/lm4f/uart.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/lm4f/uart.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/usb/usb_lm4f.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/usb/usb_lm4f.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/usb/usb.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3-I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/usb/usb.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/usb/usb_control.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/usb/usb_control.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/usb/usb_standard.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/usb/usb_standard.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/systick.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503-DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/cm3/systick.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/scb.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3-I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/cm3/scb.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/nvic.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/cm3/nvic.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/sync.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3 -I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/cm3/sync.c
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/dwt.o -c -std=gnu11 -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib -mcpu=cortex-m4 -DF_CPU=80000000L -DPLATFORMIO=30503 -DENERGIA_ARCH_TIVAC -DENERGIA_EK_TM4C123GXL -DLM4F -I/Users/pugsley/.platformio/packages/framework-libopencm3-I/Users/pugsley/.platformio/packages/framework-libopencm3/include -Isrc /Users/pugsley/.platformio/packages/framework-libopencm3/lib/cm3/dwt.c
arm-none-eabi-ar rc .pioenvs/lptm4c1230c3pm/libFrameworkLibOpenCM3.a .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/lm4f/gpio.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/vector.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/assert.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/lm4f/systemcontrol.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/lm4f/rcc.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/lm4f/uart.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/usb/usb_lm4f.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/usb/usb.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/usb/usb_control.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/usb/usb_standard.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/systick.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/scb.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/nvic.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/sync.o .pioenvs/lptm4c1230c3pm/FrameworkLibOpenCM3/lib/cm3/dwt.o
arm-none-eabi-ranlib .pioenvs/lptm4c1230c3pm/libFrameworkLibOpenCM3.a
arm-none-eabi-gcc -o .pioenvs/lptm4c1230c3pm/firmware.elf -Os -mthumb -nostartfiles -nostdlib -mcpu=cortex-m4 -Wl,-T"/Users/pugsley/.platformio/packages/framework-libopencm3/lib/lm4f/libopencm3_lm4f.ld" .pioenvs/lptm4c1230c3pm/src/main.o -L/Users/pugsley/.platformio/platforms/titiva/ldscripts -L.pioenvs/lptm4c1230c3pm -Wl,–start-group -lc -lgcc -lm .pioenvs/lptm4c1230c3pm/libFrameworkLibOpenCM3.a -Wl,–end-group
arm-none-eabi-size -B -d .pioenvs/lptm4c1230c3pm/firmware.elf
arm-none-eabi-objcopy -O binary .pioenvs/lptm4c1230c3pm/firmware.elf .pioenvs/lptm4c1230c3pm/firmware.bin
text data bss dec hex filename
2836 4 8 2848 b20 .pioenvs/lptm4c1230c3pm/firmware.elf
======================================= [SUCCESS] Took 1.71 seconds =======================================

================================================ [SUMMARY] ================================================
Environment lptm4c1230c3pm [SUCCESS]
Environment lplm4f120h5qr [SKIP]
Environment lptm4c1294ncpdt [SKIP]
======================================= [SUCCESS] Took 1.71 seconds =======================================

Hm, most interestingly uses ~/.platformio/packages/framework-libopencm3/lib/lm4f/libopencm3_lm4f.ld and not lm4fcpp_blizzard.ld as I read it from the JSON file. You should open an issue on Issues · platformio/platform-titiva · GitHub. (@ivankravets is that the right repository this?)

1 Like

Yes! @mauguer, please file an issue at Issues · platformio/platform-titiva · GitHub

1 Like

Done! thread

Took me a while to get around doing it. Thank you for your help max and ivan.