I found the solution. I believe the code was working fine but that serial communication wasn’t configured properly which was leading me to believe there were larger issues.
Difficulty with getting USB serial [USB CDC] working - #30 by umar.techboy This post was helpful.
I introduced these build flags and was able to run my hello world program successfully without issue:
build_flags = -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC -D USBCON -D USBD_USE_CDC -D USB_MANUFACTURER="Unknown" -D USB_PRODUCT="STM32F4" -D USBD_PID=0x0029 -D USBD_VID=0x1B4F
I’m not sure how many of them are especially relevant. I derived PID and VID by declaring USBD_VID inside of ArduinoIDE and then right-clicking on it to take me to its definition. I found it in variant_MICROMOD_F405_DFU.h
but these values will be different for other product lines.
I started to realize something was wrong when I right-clicked on Serial
inside of ArduinoIDE and was taken to a different code location than when I right-clicked it from within PlatformIO. This led me to realizing that I needed the USBCON
build flags.