Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ac91630
wrote basic gpio support. Need to test eventually
DolphinGui May 4, 2025
a5edbd4
finally got gpio to work!
DolphinGui May 13, 2025
1721765
probably not actually going to use this, but it's fairly universal an…
DolphinGui May 13, 2025
f500b23
usb serial works!
DolphinGui May 13, 2025
35ba73c
implemented interrupt pins
DolphinGui May 13, 2025
7c544a7
rename files to be less verbose
DolphinGui May 13, 2025
abbb33e
rename namespace to be less verbose
DolphinGui May 13, 2025
0d1158f
renamed files and started on i2c
DolphinGui May 13, 2025
0069dea
i2c has been written. todo actually test later
DolphinGui May 14, 2025
528b049
moved info to it's own file
DolphinGui May 18, 2025
10bd17d
added pwm drivers
DolphinGui May 18, 2025
4129820
wrote the ADC code
DolphinGui May 18, 2025
d131ed1
wrote the spi driver
DolphinGui May 19, 2025
04b281d
cleaned up some stuff, make it more idiomatic to libhal
DolphinGui May 19, 2025
5edf309
constrain spi api using compile time
DolphinGui May 19, 2025
a79d23c
changed header reference to be less verbose
DolphinGui May 19, 2025
743e4f0
wrote the uart driver
DolphinGui May 19, 2025
2599762
added destructors to be consistent
DolphinGui May 19, 2025
d1edce8
apparently the demos init the peripheral before the pins
DolphinGui May 19, 2025
79f4657
change interrupt handler to use a giant array because memory is basic…
DolphinGui May 19, 2025
4c95943
made a timer class, got demos to compile again
DolphinGui May 23, 2025
8743e62
demo works!
DolphinGui May 23, 2025
fcdeb93
Added default params for convenience
DolphinGui May 23, 2025
68c5534
most of the demos compile.
DolphinGui May 23, 2025
a5be003
fixed spi check
DolphinGui May 23, 2025
4a9c327
moved pwm to compiletime checking
DolphinGui May 23, 2025
c544a6a
update to 2.2.0, amongst minor fixes
DolphinGui Sep 9, 2025
cc2f4b4
updating resource_list to be modern
DolphinGui Sep 20, 2025
6ed262f
create a header file to get stuff to build
DolphinGui Sep 20, 2025
d2dc6c6
switch certain interfaces to v4, and switch namespace default to
DolphinGui Sep 26, 2025
99fb1b5
ported pwm to v4
DolphinGui Sep 26, 2025
11cd5e2
ported pwm to v4 interface
DolphinGui Sep 26, 2025
7d6cc4a
fix spi v4 implementation
DolphinGui Sep 26, 2025
7a460e4
builds, does not seem to work. Todo build openocd
DolphinGui Sep 26, 2025
f24e0fa
fix versioning
DolphinGui Feb 9, 2026
1641d18
experimenting with async: todo test
DolphinGui Feb 13, 2026
618625d
do not hardcode PICO_BOARD
DolphinGui Feb 14, 2026
b383471
fix adc async so it actually works
DolphinGui Feb 14, 2026
f92e62e
workaround puts() lto issues by not wrapping libc calls
DolphinGui Feb 14, 2026
5000a35
add function to get core clock
DolphinGui Feb 14, 2026
7ac35f8
fix phase issues
DolphinGui Mar 6, 2026
fa0fd46
do not hardcode board
DolphinGui Mar 7, 2026
f8fbbd2
move enable to runtime, fix minor math errors
DolphinGui Mar 7, 2026
573e016
Add todo regarding fixing spi
DolphinGui Mar 7, 2026
8910463
Generally delete move constructors just in case
DolphinGui Mar 7, 2026
4a61d0d
Merge branch 'rp-async' into rp
DolphinGui Mar 7, 2026
a52ae8c
change picosdk to a version with hardfp support
DolphinGui Mar 7, 2026
ce5f6e8
Expose sleep interface
DolphinGui Mar 8, 2026
95c5b07
expose phase-correct output
DolphinGui Mar 9, 2026
bdbf540
fix overloading not working for chrono literals
DolphinGui Mar 12, 2026
6ad3a40
remove misc dev files
DolphinGui Mar 12, 2026
2dd7380
Merge branch 'main' into rp
DolphinGui Mar 12, 2026
a36a69b
add back header
DolphinGui Mar 12, 2026
f15f3ec
disable default linker scripts, picosdk ships their own
DolphinGui Mar 17, 2026
8c7a32e
disable waiting to allow for faster polling
DolphinGui Mar 19, 2026
29ceffd
correctly handle timeout for usb serial
DolphinGui Mar 25, 2026
492255b
port SPI implementation to V5 properly.
DolphinGui Apr 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 59 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@

cmake_minimum_required(VERSION 3.15)

if(DEFINED ENV{PICO_SDK_PATH})
set(PICO_CXX_ENABLE_EXCEPTIONS 1)
set(PICO_NO_PICOTOOL 1)
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
endif()
set(CMAKE_COLOR_DIAGNOSTICS ON)

project(libhal-arm-mcu LANGUAGES CXX)
project(libhal-arm-mcu LANGUAGES CXX C ASM)

libhal_test_and_make_library(
LIBRARY_NAME libhal-arm-mcu

SOURCES
# Exceptions code size reducer
src/terminate_handler.cpp

# cortex_m
# Should probably refine this to actually not compile
# drivers for all platforms all the time, but for now this
# serves my purposes
if(NOT DEFINED ENV{PICO_SDK_PATH})
set(source_list
src/system_controller.cpp
src/dwt_counter.cpp
src/interrupt.cpp
Expand Down Expand Up @@ -92,8 +94,10 @@ libhal_test_and_make_library(

# stm32f40
src/stm32f40/output_pin.cpp
)

TEST_SOURCES
set(
test_sources
# cortex_m
tests/dwt_counter.test.cpp
tests/interrupt.test.cpp
Expand Down Expand Up @@ -124,6 +128,49 @@ libhal_test_and_make_library(
# stm32f411
tests/stm32f411/output_pin.test.cpp
tests/stm32f411/spi.test.cpp
)

else()
set(source_list
src/rp/gpio.cpp
src/rp/serial.cpp
src/rp/i2c.cpp
src/rp/pwm.cpp
src/rp/adc.cpp
src/rp/spi.cpp
src/rp/time.cpp
src/system_controller.cpp
src/dwt_counter.cpp
src/interrupt.cpp
)

pico_sdk_init()

set(pico_dep
hardware_gpio_headers
pico_time_headers
pico_stdio_headers
hardware_sync_headers
hardware_i2c_headers
hardware_pwm_headers
hardware_adc_headers
hardware_spi_headers
hardware_uart_headers
hardware_timer_headers
hardware_dma_headers
)

endif()

libhal_test_and_make_library(
LIBRARY_NAME libhal-arm-mcu

SOURCES
${source_list}
src/terminate_handler.cpp

TEST_SOURCES
${test_sources}

PACKAGES
libhal
Expand All @@ -136,4 +183,6 @@ libhal_test_and_make_library(
libhal::util
nonstd::ring-span-lite
nonstd::scope-lite
${pico_dep}
)

56 changes: 56 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# limitations under the License.

from conan import ConanFile
from conan.tools.cmake import CMakeDeps, CMakeToolchain
from conan.tools.env import VirtualBuildEnv
from conan.errors import ConanInvalidConfiguration
from pathlib import Path
import os

Expand Down Expand Up @@ -43,6 +46,8 @@ class libhal_arm_mcu_conan(ConanFile):
"use_libhal_exceptions": [True, False],
"use_picolibc": [True, False],
"use_default_linker_script": [True, False],
"variant": [None, "ANY"],
"board": [None, "ANY"],
"replace_std_terminate": [True, False],
"use_semihosting": [True, False],
}
Expand All @@ -53,6 +58,8 @@ class libhal_arm_mcu_conan(ConanFile):
"use_default_linker_script": True,
"replace_std_terminate": True,
"use_semihosting": True,
"variant": None,
"board": None,
}
options_description = {
"platform": "Specifies which platform to provide binaries and build information for",
Expand Down Expand Up @@ -83,6 +90,13 @@ def requirements(self):
OSLIB = "semihost" if self.options.use_semihosting else None
self.requires("prebuilt-picolibc/" + CV,
options={"crt0": CRT0, "oslib": OSLIB})

if str(self.options.platform).startswith("rp2"):
self.requires("picosdk/2.2.1-alpha")
self.tool_requires("pioasm/2.2.0")
if self.options.board.value.startswith("libhal_"):
board = self.options.board.value.removeprefix('libhal_').replace('_', '-')
self.requires(f"rp-board-header-{board}/latest", visible=True)

def handle_stm32f1_linker_scripts(self):
linker_script_name = list(str(self.options.platform))
Expand All @@ -97,18 +111,60 @@ def handle_stm32f1_linker_scripts(self):
"-T" + str(Path("libhal-stm32f1") / linker_script_name + ".ld"),
])

def _macro(self, string):
return string.upper().replace("-", "_")

def generate(self):
virt = VirtualBuildEnv(self)
virt.generate()
tc = CMakeToolchain(self)
if str(self.options.platform).startswith("rp2"):
tc.cache_variables["DO_NOT_BUILD_BOOT_HAL"] = True
tc.preprocessor_definitions["PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS"] = "0"
if self.options.board:
tc.cache_variables["PICO_BOARD"] = str(self.options.board)
if self.options.variant:
tc.preprocessor_definitions["LIBHAL_VARIANT_" + self._macro(str(self.options.variant))] = "1"
tc.preprocessor_definitions["LIBHAL_PLATFORM_" + self._macro(str(self.options.platform))] = "1"
tc.generate()
cmake = CMakeDeps(self)
cmake.generate()

def validate(self):
if str(self.options.platform).startswith("rp2"):
if self.options.use_default_linker_script:
raise ConanInvalidConfiguration("Default linker scripts are not compatible with RP chips, use pico-sdk linker scripts instead")
if not self.options.board:
raise ConanInvalidConfiguration("RP board not specified")
if "rp2350" in str(self.options.platform):
if not self.options.variant:
raise ConanInvalidConfiguration("RP2350 variant not specified")
if self.options.variant not in ["rp2350a", "rp2350b"]:
raise ConanInvalidConfiguration("Invalid RP2350 variant specified")
if not self.options.board:
raise ConanInvalidConfiguration("Board must be specified during build")
super().validate()

def package_info(self):
self.cpp_info.libs = ["libhal-arm-mcu"]
self.cpp_info.set_property("cmake_target_name", "libhal::arm-mcu")
self.cpp_info.set_property("cmake_target_aliases", [
"libhal::lpc40",
"libhal::stm32f1",
"libhal::stm32f4",
"libhal::rp2350"
])

PLATFORM = str(self.options.platform)
self.buildenv_info.define("LIBHAL_PLATFORM", PLATFORM)
self.buildenv_info.define("LIBHAL_PLATFORM_LIBRARY", "arm-mcu")
if str(self.options.platform).startswith("rp2"):
defines = []
if self.options.variant:
defines.append("LIBHAL_VARIANT_" + self._macro(str(self.options.variant)) + "=1")
defines.append("LIBHAL_PLATFORM_" + self._macro(str(self.options.platform)) + "=1")
defines.append("PICO_STDIO_SHORT_CIRCUIT_CLIB_FUNCS=0")
self.cpp_info.defines = defines

self.cpp_info.exelinkflags = []
if self.settings.os == "baremetal":
Expand Down
65 changes: 60 additions & 5 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,53 @@

cmake_minimum_required(VERSION 4.0)

project(demos LANGUAGES CXX)
if(DEFINED ENV{PICO_SDK_PATH})
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
endif()

libhal_build_demos(
DEMOS
project(demos LANGUAGES CXX C ASM)

find_package(libhal-arm-mcu CONFIG REQUIRED)

if(DEFINED ENV{PICO_SDK_PATH})
pico_sdk_init()

pico_enable_stdio_usb(libhal::arm-mcu 1)
pico_enable_stdio_uart(libhal::arm-mcu 0)

set(demo_deps
pico_stdlib
hardware_gpio
pico_stdio
hardware_i2c
hardware_adc
hardware_spi
)

# not all of the demos work at the moment
set(demos
adc
blinker
# can
# dac
gpio
i2c
interrupt_pin
uart
pwm
pwm16
spi
blank
# stream_dac
# watchdog
# timer
# usb_cdc_raw
# semihost
)

else()

set(demos
adc
blinker
can
Expand All @@ -30,11 +73,23 @@ libhal_build_demos(
pwm16
spi
blank
stream_dac
watchdog
# stream_dac
timer
usb_cdc_raw
semihost
)

set(demo_deps
minimp3::minimp3
)
endif()

set(ENV{LIBHAL_PLATFORM_LIBRARY} arm-mcu)

libhal_build_demos(
DEMOS
${demos}

PACKAGES
minimp3
Expand All @@ -43,5 +98,5 @@ libhal_build_demos(
.

LINK_LIBRARIES
minimp3::minimp3
${demo_deps}
)
16 changes: 15 additions & 1 deletion demos/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from conan import ConanFile
import os

from conan import ConanFile
from conan.tools.cmake import CMake

class demos(ConanFile):
python_requires = "libhal-bootstrap/[>=4.3.0 <5]"
Expand All @@ -24,3 +26,15 @@ class demos(ConanFile):
def requirements(self):
self.requires("libhal-arm-mcu/latest")
self.requires("minimp3/cci.20211201")

# This is kinda sketch, but needs to be done manually until https://github.com/conan-io/conan/issues/13372
# gets implemented
def build(self):
cmake = CMake(self)
defs = {
"CMAKE_ASM_FLAGS_INIT": "-mcpu=cortex-m33 -mfloat-abi=soft",
"PICO_BOARD": "rp2350_micromod",
"PICO_CXX_ENABLE_EXCEPTIONS": "1"
}
cmake.configure(variables = defs)
cmake.build()
11 changes: 11 additions & 0 deletions demos/flash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/sh

set -e

BUILDDIR=build/rp2350-arm-s/RelWithDebInfo
source $BUILDDIR/generators/conanbuild.sh

picotool uf2 convert $BUILDDIR/$1.elf $BUILDDIR/$1.uf2
picotool load $BUILDDIR/$1.uf2 -f
sleep 1
plink -serial /dev/ttyACM0 -sercfg 115200,8,1,n,X
28 changes: 25 additions & 3 deletions demos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,35 @@

#include <libhal-util/serial.hpp>
#include <libhal-util/steady_clock.hpp>
#include <libhal/error.hpp>
#include <libhal-exceptions/control.hpp>

#include <resource_list.hpp>
#include "resource_list.hpp"

[[noreturn]] void terminate_handler() noexcept
{

// spin here forever
while (true) {
continue;
}
}

int main()
{
initialize_platform();
application();
hal::set_terminate(terminate_handler);

try {
application();
} catch (hal::bad_optional_ptr_access const& e) {
auto console = resources::console();
hal::print(*console,
"A resource required by the application was not"
"available!\n"
"Calling terminate!\n");

} // Allow any other exceptions to terminate the application

std::terminate();
}

Expand Down
Loading
Loading