GitHub Digital Lab

Fox Red Labs / Ports / STM32 to MSPM0

Can STM32 HAL code run on a TI MSPM0 without a rewrite?

Mostly yes: one header and one C file move HAL code for GPIO, pin interrupts, UART (blocking, interrupt and DMA), I2C, SPI, ADC, timers and PWM, flash and the watchdog to the MSPM0 G3507, and the calls keep their ST names. The self-test on the board (2026-11-13) passes 15 of 16 checks and skips 1, the PWM pin level, which needs a wire from PA26 to an input; one unmodified ST library, afiskon/stm32-ssd1306, builds against the shim.

Not yet proven: a device answering on I2C, the PWM pin level and ADC accuracy against a known voltage. CAN, RTC, USB, SD, Ethernet and LL calls are not covered.

Your STM32 code calls HAL functions; the shim, one header and one C file, answers them with TI DriverLib calls; DriverLib drives the MSPM0G3507 and its pins.Your STM32 codeHAL_GPIO_WritePinHAL_UART_TransmitHAL_I2C_Mem_Writecalls keep their ST namesHAL_* callsThe shimstm32_hal_mspm0.hstm32_hal_mspm0.cone header, one C fileanswers withTI DriverLibDL_GPIO_setPinsDL_UART_Main_receiveDataDL_I2C_startControllerTransferMSPM0 SDK driver callsDL_* callsMSPM0G3507 pinsUART0 on PA10, PA11I2C1 on PB2, PB3SPI1 on PB7, PB8, PB9LP-MSPM0G3507

The path of one call. You keep your HAL code; the shim (red edge) is the only new layer, and it answers with TI's own DriverLib calls.

15 of 16self-test checks pass, 1 skippedThe skipped check is the PWM pin level (it needs a wire from PA26 to an input). Run of 2026-11-13 on one MSPM0 G3507. Log: portability/shim/stm32hal_on_mspm0/logs/selftest-final.log
9 of 12areas have a run that checked them3 more build and should work: I2C, ADC, Timers and PWM
0 of 1,907library lines changedafiskon/stm32-ssd1306 builds as upstream ships it; its config file changed on 2 lines

What moves, and how far it is proven

One card per area. Works means a run on the board checked the behavior. Should work means the code builds and no run checked the behavior; the card says what is missing.

GPIOWorks

Self-test calls: HAL_GPIO_Init, HAL_GPIO_WritePin, HAL_GPIO_TogglePin, HAL_GPIO_ReadPin

PA0 set, clear and toggle read back 1, 0, 1; read after a 100 us wait matched the written level.

Pin interruptsWorks

Self-test calls: HAL_GPIO_EXTI_Callback, HAL_GPIO_Init with GPIO_MODE_IT_RISING, HAL_NVIC_EnableIRQ

Five rising edges on PA0 made five callbacks.

Tick and delayWorks

Self-test calls: HAL_GetTick, HAL_Delay

HAL_Delay(100) took 101 ticks.

UART, blockingWorks

Self-test calls: HAL_UART_Transmit, HAL_UART_Receive, HAL_UART_Init

4 bytes out and back in loopback, status 0.

UART with interruptsWorks

Self-test calls: HAL_UART_Transmit_IT, HAL_UART_Receive_IT

Tx callback 1, 8 bytes sent; 8 bytes in loopback, callback 1, data equal.

UART with DMAWorks

Self-test calls: HAL_UART_Transmit_DMA, HAL_UART_Receive_DMA

DMA transmit of 1, 4, 5, 8 and 16 bytes came back byte for byte through the UART loopback, one callback each; after an interrupt transfer, DMA receive of 8 bytes equal, and of 1, 4, 5 and 16 bytes equal; the same test goes red (stale first byte) with the fix compiled out.

I2CShould work

Self-test calls: HAL_I2C_Init, HAL_I2C_Master_Transmit, HAL_I2C_GetError

No device on the bus: HAL_ERROR with error 4 (NACK) at 0 ms with the internal pull-ups on; a device answering is not recorded; afiskon/stm32-ssd1306 builds against it and calls Mem_Write; the display was not attached.

SPIWorks

Self-test calls: HAL_SPI_Init, HAL_SPI_TransmitReceive

16 of 16 bytes equal.

ADCShould work

Self-test calls: HAL_ADC_Init, HAL_ADC_ConfigChannel, HAL_ADC_Start, HAL_ADC_PollForConversion, HAL_ADC_GetValue

Converted eight times with the pin unwired; all eight read 0, so the conversion path completes but no value was checked.

Timers and PWMShould work

Self-test calls: HAL_TIM_Base_Start_IT, HAL_TIM_PeriodElapsedCallback, __HAL_TIM_SET_COMPARE, __HAL_TIM_GET_COMPARE, HAL_TIM_PWM_ConfigChannel, HAL_TIM_PWM_Init, HAL_TIM_Base_Init, HAL_TIM_PWM_Start, HAL_TIM_PWM_Stop

10 callbacks in 1050 ms for a 100 ms period; counter-side check: pulse 250 of 1000 gave 25.6 percent, pulse 750 gave 74.3 percent; the pad level was not read.

FlashWorks

Self-test calls: HAL_FLASHEx_Erase, HAL_FLASH_Lock, HAL_FLASH_Program, HAL_FLASH_Unlock

Page 124 erased and read blank; 0x1122334455667788 programmed and read back.

WatchdogWorks

Self-test calls: HAL_IWDG_Init, HAL_IWDG_Refresh

Alive after 1.2 s of 200 ms refreshes; reset cause WWDT0 after refreshing stopped.

WorksShould work

Move your project in four steps

Run the commands from the top of the repository folder. A copy of the repository is on GitHub (link at the end of this page).

  1. Delete what the shim replaces

    Keep your ST source files. Delete the *_it.c interrupt handlers (the shim owns GROUP1_IRQHandler, UART0_IRQHandler, TIMG0_IRQHandler and DMA_IRQHandler), the HAL_*_MspInit functions and SystemClock_Config. The clock stays at SysConfig's 32 MHz default.

  2. Start the HAL the TI way

    At the top of main, call the SysConfig start-up first, then the HAL. A one-module SysConfig file is enough: portability/shim/stm32hal_on_mspm0/test/selftest.syscfg.

    SYSCFG_DL_init();
    HAL_Init();
  3. Build from the top of the repository folder

    The script force-includes stm32_hal_mspm0.h and supplies stm32g0xx_hal.h, stm32f4xx_hal.h, stm32l4xx_hal.h and the other family header names.

    OUT=$PWD/out portability/shim/stm32hal_on_mspm0/build.sh <name> <file.syscfg> <your .c files> [-I<dir>]
  4. Back the board up, check the image, flash

    Back the LaunchPad kit up first, then check the image before you flash it. python3 tools/frl/frl.py detect lists the probe serial; the console is the board's serial port: on a Mac the /dev/cu.usbmodem port whose name ends in 1, on Linux /dev/ttyACM0, on Windows the COM port named “XDS110 Class Application/User UART” (per-system table). The script and its capture were run on a Mac only. The script flashes, captures the backchannel UART (115200 8N1) for 22 seconds into run.log and prints it. Each check prints one PASS or SKIP line.

    python3 tools/frl/frl.py backup --board mspm0g3507
    python3 tools/preflight_image.py mspm0g3507 <image.out>
    PROBE=<your probe serial> CONSOLE=<your serial port> portability/shim/stm32hal_on_mspm0/run.sh out/<name>/<name>.out run.log 22

Which STM32 peripheral lands on which pin

The handle types keep ST's field names. The instances map to what the LaunchPad kit wires out. For another board, change the pin lines in stm32_hal_mspm0.c.

Your STM32 instanceOn the MSPM0G3507Pads and header pinsNote
USART1UART0PA10 (TX), PA11 (RX)The LaunchPad backchannel to your computer; no wire to the header.
I2C1I2C1J1 pin 9 (PB2, SCL), J1 pin 10 (PB3, SDA)Power a device from J1 pin 1 (3V3) and J2 pin 20 (GND). The shim turns on the internal pull-ups; use outside 4.7 kOhm pull-ups for real work.
SPI1SPI1PB9 (SCLK), PB8 (PICO), PB7 (POCI)Chip select is a GPIO you drive.
ADC1, channels 0 to 3ADC0PA27, PA26, PA25, PA24Only these four channels are routed. PA27 and PA26 are also the PWM pins below: use one function at a time.
TIM1 and TIM3TIMG7PA26 (channel 1), PA27 (channel 2)PWM output. TIM1 and TIM3 are the same timer here, so a project that uses both conflicts. PA26 and PA27 are also ADC channels 1 and 0.
TIM6TIMG0nonePeriodic interrupt only.

One library, no source change

afiskon/stm32-ssd1306 (MIT) drives an SSD1306 OLED through HAL_I2C_Mem_Write. It builds with none of its 1,907 lines changed: 15.7 kB of flash and 1.7 kB of RAM. With no display attached it ran: the probe at 0x3C came back NACK (error 4) and 50 frames of the loop completed (ports/stm32-hal-shim/ssd1306/logs/ssd1306-nodisplay.log). That proves the call path and the error path, not pixels, so this row stays at Should work until a display is wired.

If you see this, do that (11 differences)
  • If you see: A read right after a write returns the old pin levelThe input register follows the pad a few cycles later. Wait about 100 us before reading back an output.
  • If you see: HAL_I2C_Master_Transmit returns HAL_TIMEOUT instead of an error on an empty busWithout pull-ups the START cannot finish. The shim turns on the internal pull-ups, which gives an immediate NACK error; use outside 4.7 kOhm pull-ups for real work.
  • If you see: A 100 ms timer comes out at 64 msThe 8-bit prescaler and the divide-by-8 give a total divide of 2048 at most; ST's 16-bit prescaler goes to 65536. The shim moves the excess into the period (an exact result is not always possible). PWM refuses a prescaler above 2048.
  • If you see: PWM duty is the wrong way roundThe counter counts down: the compare register holds period minus the pulse. Use __HAL_TIM_SET_COMPARE, never the register.
  • If you see: The PWM pin reads 0 through the GPIO input registerA pin driven by a timer is not visible there. Check the duty with a wire to another pin or an analyzer.
  • If you see: FLASH_PAGE_SIZE is 1024A literal 2048 from a G0 project erases two pages and the program afterwards lands in the wrong one.
  • If you see: The watchdog cannot be stopped once started, and its periods are powers of two (1 s is 2^15 cycles of 32.768 kHz)A debugger halt does not guarantee it stops counting: refresh it in any loop you single-step.
  • If you see: UART receive by DMA delivers one stale byte first, and loses the last byte, after bytes were received by interruptThe DMA's RX trigger stays latched, so the DMA reads the empty FIFO once when the event is switched on. The shim arms a throwaway one-byte transfer first; if you write your own, do the same and start the sender after the arm call.
  • If you see: A UART receive needs a reader within 4 bytesThe FIFO is 4 deep; arm HAL_UART_Receive_IT before the sender starts.
  • If you see: ST's HAL_IncTick in your _it.c and the shim's own SysTick count twiceKeep one.
  • If you see: Pin numbers are not translatedThe shim looks up PINCM numbers by pin name; the pins you choose for a peripheral must be valid ones for the package.

Each of these has an entry with the symptom, the cause and the fix in the LP-MSPM0G3507 FAQ.

What is not covered

  • HAL for CAN, RTC, USB, SD and Ethernet
  • The interrupt and DMA forms of I2C and SPI
  • ADC by DMA (a proven pattern exists, but it is not a shim call)
  • Circular UART receive with idle-line detection (a redesign, not a shim call)
  • LL (low-layer) calls and every STM32 clock-tree call

Only UART0, I2C1, SPI1, ADC0 channels 0 to 3, TIMG7 and TIMG0 are routed. The shim is a way to get an existing project running on the kit, not a library to build a product on. Other STM32 routes:

Get the code

Checked 2026-11-12 with MSPM0 SDK 2.11.00.07, SysConfig 1.28.0 and TI Arm Clang 5.1.1.LTS on one MSPM0 G3507. The table has every HAL call, the TI call that answers it, what differs and the run that checked it.