Skip to content

Commit d8c8c67

Browse files
committed
Raspberry Pico Sleep Demo
1 parent 43467b9 commit d8c8c67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+6551
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@
4141
[submodule "lib/pico-sdk"]
4242
path = lib/pico-sdk
4343
url = https://github.com/raspberrypi/pico-sdk.git
44+
[submodule "lib/pico-extras"]
45+
path = lib/pico-extras
46+
url = https://github.com/raspberrypi/pico-extras.git

lib/pico-extras

Submodule pico-extras added at 2309d56

ports/rp2sleep/CMakeLists.txt

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
# Set build type to reduce firmware size
4+
if(NOT CMAKE_BUILD_TYPE)
5+
set(CMAKE_BUILD_TYPE MinSizeRel)
6+
endif()
7+
8+
# Set main target and component locations
9+
set(MICROPY_TARGET firmware)
10+
get_filename_component(MICROPY_DIR "../.." ABSOLUTE)
11+
if (PICO_SDK_PATH_OVERRIDE)
12+
set(PICO_SDK_PATH ${PICO_SDK_PATH_OVERRIDE})
13+
else()
14+
set(PICO_SDK_PATH ../../lib/pico-sdk)
15+
endif()
16+
17+
if (PICO_EXTRAS_PATH_OVERRIDE)
18+
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_PATH_OVERRIDE})
19+
else()
20+
set(PICO_EXTRAS_PATH ../../lib/pico-extras)
21+
endif()
22+
23+
# Use the local tinyusb instead of the one in pico-sdk
24+
set(PICO_TINYUSB_PATH ${MICROPY_DIR}/lib/tinyusb)
25+
26+
# Set the location of this port's directory.
27+
set(MICROPY_PORT_DIR ${CMAKE_SOURCE_DIR})
28+
29+
# Set the board if it's not already set.
30+
if(NOT MICROPY_BOARD)
31+
set(MICROPY_BOARD PICO)
32+
endif()
33+
34+
# Set the PICO_BOARD if it's not already set.
35+
if(NOT PICO_BOARD)
36+
string(TOLOWER ${MICROPY_BOARD} PICO_BOARD)
37+
endif()
38+
39+
# Set the board directory and check that it exists.
40+
if(NOT MICROPY_BOARD_DIR)
41+
set(MICROPY_BOARD_DIR ${MICROPY_PORT_DIR}/boards/${MICROPY_BOARD})
42+
endif()
43+
if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
44+
message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}")
45+
endif()
46+
47+
# Include board config
48+
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
49+
50+
# Include component cmake fragments
51+
include(${MICROPY_DIR}/py/py.cmake)
52+
include(${MICROPY_DIR}/extmod/extmod.cmake)
53+
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
54+
include(pico_extras_import.cmake)
55+
56+
# Define the top-level project
57+
project(${MICROPY_TARGET})
58+
59+
pico_sdk_init()
60+
61+
include(${MICROPY_DIR}/py/usermod.cmake)
62+
63+
add_executable(${MICROPY_TARGET})
64+
65+
set(MICROPY_QSTRDEFS_PORT
66+
${PROJECT_SOURCE_DIR}/qstrdefsport.h
67+
)
68+
69+
set(MICROPY_SOURCE_LIB
70+
${MICROPY_DIR}/lib/littlefs/lfs1.c
71+
${MICROPY_DIR}/lib/littlefs/lfs1_util.c
72+
${MICROPY_DIR}/lib/littlefs/lfs2.c
73+
${MICROPY_DIR}/lib/littlefs/lfs2_util.c
74+
${MICROPY_DIR}/lib/oofatfs/ff.c
75+
${MICROPY_DIR}/lib/oofatfs/ffunicode.c
76+
${MICROPY_DIR}/shared/netutils/netutils.c
77+
${MICROPY_DIR}/shared/readline/readline.c
78+
${MICROPY_DIR}/shared/runtime/gchelper_m0.s
79+
${MICROPY_DIR}/shared/runtime/gchelper_native.c
80+
${MICROPY_DIR}/shared/runtime/mpirq.c
81+
${MICROPY_DIR}/shared/runtime/pyexec.c
82+
${MICROPY_DIR}/shared/runtime/stdout_helpers.c
83+
${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
84+
${MICROPY_DIR}/shared/timeutils/timeutils.c
85+
)
86+
87+
set(MICROPY_SOURCE_DRIVERS
88+
${MICROPY_DIR}/drivers/bus/softspi.c
89+
)
90+
91+
set(MICROPY_SOURCE_PORT
92+
fatfs_port.c
93+
machine_adc.c
94+
machine_i2c.c
95+
machine_pin.c
96+
machine_rtc.c
97+
machine_spi.c
98+
machine_timer.c
99+
machine_uart.c
100+
machine_wdt.c
101+
main.c
102+
modpicosleep.c
103+
modmachine.c
104+
modrp2.c
105+
moduos.c
106+
modutime.c
107+
mphalport.c
108+
mpthreadport.c
109+
rp2_flash.c
110+
rp2_pio.c
111+
tusb_port.c
112+
uart.c
113+
)
114+
115+
set(MICROPY_SOURCE_QSTR
116+
${MICROPY_SOURCE_PY}
117+
${MICROPY_SOURCE_EXTMOD}
118+
${MICROPY_SOURCE_USERMOD}
119+
${MICROPY_DIR}/shared/runtime/mpirq.c
120+
${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
121+
${PROJECT_SOURCE_DIR}/machine_adc.c
122+
${PROJECT_SOURCE_DIR}/machine_i2c.c
123+
${PROJECT_SOURCE_DIR}/machine_pin.c
124+
${PROJECT_SOURCE_DIR}/machine_rtc.c
125+
${PROJECT_SOURCE_DIR}/machine_spi.c
126+
${PROJECT_SOURCE_DIR}/machine_timer.c
127+
${PROJECT_SOURCE_DIR}/machine_uart.c
128+
${PROJECT_SOURCE_DIR}/machine_wdt.c
129+
${PROJECT_SOURCE_DIR}/modpicosleep.c
130+
${PROJECT_SOURCE_DIR}/modmachine.c
131+
${PROJECT_SOURCE_DIR}/modrp2.c
132+
${PROJECT_SOURCE_DIR}/moduos.c
133+
${PROJECT_SOURCE_DIR}/modutime.c
134+
${PROJECT_SOURCE_DIR}/rp2_flash.c
135+
${PROJECT_SOURCE_DIR}/rp2_pio.c
136+
)
137+
138+
set(PICO_SDK_COMPONENTS
139+
hardware_adc
140+
hardware_base
141+
hardware_clocks
142+
hardware_dma
143+
hardware_flash
144+
hardware_gpio
145+
hardware_i2c
146+
hardware_irq
147+
hardware_pio
148+
hardware_pwm
149+
hardware_regs
150+
hardware_rtc
151+
hardware_rosc
152+
hardware_sleep
153+
hardware_spi
154+
hardware_structs
155+
hardware_sync
156+
hardware_timer
157+
hardware_uart
158+
hardware_watchdog
159+
pico_base_headers
160+
pico_binary_info
161+
pico_bootrom
162+
pico_multicore
163+
pico_platform
164+
pico_runtime
165+
pico_stdio
166+
pico_stdlib
167+
pico_sync
168+
pico_time
169+
pico_unique_id
170+
pico_util
171+
tinyusb_common
172+
tinyusb_device
173+
)
174+
175+
if(MICROPY_PY_BLUETOOTH)
176+
list(APPEND MICROPY_SOURCE_PORT mpbthciport.c)
177+
target_compile_definitions(${MICROPY_TARGET} PRIVATE
178+
MICROPY_PY_BLUETOOTH=1
179+
MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE=1
180+
MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING=1
181+
MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS=1
182+
)
183+
endif()
184+
185+
if(MICROPY_BLUETOOTH_NIMBLE)
186+
list(APPEND MICROPY_SOURCE_PORT mpnimbleport.c)
187+
target_compile_definitions(${MICROPY_TARGET} PRIVATE
188+
MICROPY_BLUETOOTH_NIMBLE=1
189+
MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY=0
190+
)
191+
target_compile_options(${MICROPY_TARGET} PRIVATE
192+
# TODO: This flag is currently needed to make nimble build.
193+
-Wno-unused-but-set-variable
194+
)
195+
include(${MICROPY_DIR}/extmod/nimble/nimble.cmake)
196+
target_link_libraries(${MICROPY_TARGET} micropy_extmod_nimble)
197+
get_target_property(NIMBLE_INCLUDE micropy_extmod_nimble INTERFACE_INCLUDE_DIRECTORIES)
198+
list(APPEND MICROPY_INC_CORE ${NIMBLE_INCLUDE})
199+
endif()
200+
201+
# Define mpy-cross flags and frozen manifest
202+
set(MICROPY_CROSS_FLAGS -march=armv7m)
203+
if (NOT MICROPY_FROZEN_MANIFEST)
204+
set(MICROPY_FROZEN_MANIFEST ${PROJECT_SOURCE_DIR}/boards/manifest.py)
205+
endif()
206+
207+
target_sources(${MICROPY_TARGET} PRIVATE
208+
${MICROPY_SOURCE_PY}
209+
${MICROPY_SOURCE_EXTMOD}
210+
${MICROPY_SOURCE_LIB}
211+
${MICROPY_SOURCE_DRIVERS}
212+
${MICROPY_SOURCE_PORT}
213+
)
214+
215+
target_link_libraries(${MICROPY_TARGET} usermod)
216+
217+
target_include_directories(${MICROPY_TARGET} PRIVATE
218+
${MICROPY_INC_CORE}
219+
${MICROPY_INC_USERMOD}
220+
${MICROPY_BOARD_DIR}
221+
"${PROJECT_SOURCE_DIR}"
222+
"${CMAKE_BINARY_DIR}"
223+
)
224+
225+
target_compile_options(${MICROPY_TARGET} PRIVATE
226+
-Wall
227+
-Werror
228+
)
229+
230+
set_source_files_properties(
231+
${PICO_SDK_PATH}/src/rp2_common/pico_double/double_math.c
232+
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_math.c
233+
PROPERTIES
234+
COMPILE_OPTIONS "-Wno-error=uninitialized"
235+
)
236+
237+
set_source_files_properties(
238+
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/dcd_rp2040.c
239+
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/rp2040_usb.c
240+
PROPERTIES
241+
COMPILE_OPTIONS "-Wno-error=array-bounds;-Wno-error=unused-but-set-variable"
242+
)
243+
244+
target_compile_definitions(${MICROPY_TARGET} PRIVATE
245+
FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
246+
LFS1_NO_MALLOC LFS1_NO_DEBUG LFS1_NO_WARN LFS1_NO_ERROR LFS1_NO_ASSERT
247+
LFS2_NO_MALLOC LFS2_NO_DEBUG LFS2_NO_WARN LFS2_NO_ERROR LFS2_NO_ASSERT
248+
PICO_FLOAT_PROPAGATE_NANS=1
249+
PICO_STACK_SIZE=0x2000
250+
PICO_CORE1_STACK_SIZE=0
251+
PICO_PROGRAM_NAME="MicroPython"
252+
PICO_NO_PROGRAM_VERSION_STRING=1 # do it ourselves in main.c
253+
MICROPY_BUILD_TYPE="${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} ${CMAKE_BUILD_TYPE}"
254+
PICO_NO_BI_STDIO_UART=1 # we call it UART REPL
255+
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
256+
)
257+
258+
target_link_libraries(${MICROPY_TARGET}
259+
${PICO_SDK_COMPONENTS}
260+
)
261+
262+
if (MICROPY_HW_ENABLE_DOUBLE_TAP)
263+
# Enable double tap reset into bootrom.
264+
target_link_libraries(${MICROPY_TARGET}
265+
pico_bootsel_via_double_reset
266+
)
267+
endif()
268+
269+
# todo this is a bit brittle, but we want to move a few source files into RAM (which requires
270+
# a linker script modification) until we explicitly add macro calls around the function
271+
# defs to move them into RAM.
272+
if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
273+
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp.ld)
274+
endif()
275+
276+
pico_add_extra_outputs(${MICROPY_TARGET})
277+
278+
add_custom_command(TARGET ${MICROPY_TARGET}
279+
POST_BUILD
280+
COMMAND arm-none-eabi-size --format=berkeley ${PROJECT_BINARY_DIR}/${MICROPY_TARGET}.elf
281+
VERBATIM
282+
)
283+
284+
# Collect all the include directories and compile definitions for the pico-sdk components.
285+
foreach(comp ${PICO_SDK_COMPONENTS})
286+
micropy_gather_target_properties(${comp})
287+
micropy_gather_target_properties(${comp}_headers)
288+
endforeach()
289+
290+
# Include the main MicroPython cmake rules.
291+
include(${MICROPY_DIR}/py/mkrules.cmake)

ports/rp2sleep/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Makefile for micropython on Raspberry Pi RP2
2+
#
3+
# This is a simple wrapper around cmake
4+
5+
BOARD ?= PICO
6+
7+
BUILD ?= build-$(BOARD)
8+
9+
$(VERBOSE)MAKESILENT = -s
10+
11+
CMAKE_ARGS = -DMICROPY_BOARD=$(BOARD)
12+
13+
ifdef USER_C_MODULES
14+
CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
15+
endif
16+
17+
all:
18+
[ -d $(BUILD) ] || cmake -S . -B $(BUILD) -DPICO_BUILD_DOCS=0 ${CMAKE_ARGS}
19+
$(MAKE) $(MAKESILENT) -C $(BUILD)
20+
21+
clean:
22+
$(RM) -rf $(BUILD)
23+
24+
GIT_SUBMODULES += lib/pico-sdk lib/tinyusb
25+
26+
submodules:
27+
$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="$(GIT_SUBMODULES)" submodules

0 commit comments

Comments
 (0)