2021-06-08 00:56:10 +00:00
option ( USE_SYSTEMWIDE_PICOSDK "Use the systemwide Pico SDK instead of relying on the one from a deeply nested Git submodule (OFF by default)" OFF )
option ( PICO_NO_FLASH "Disable writing the compiled program to flash, and only load it to RAM. Useful for testing, but not much else (OFF by default)." OFF )
option ( PICO_COPY_TO_RAM "Run all code in RAM, while the program is also stored on flash. On bootup, everything will be copied to RAM (OFF by default)." OFF )
2021-06-12 19:35:46 +00:00
option ( USE_USBCDC_FOR_STDIO "Export an extra USB-CDC interface for stdio, instead of echoing it to a UART port (and requiring UART loopback for receiving stdio output on a host computer)." OFF )
2021-06-08 00:56:10 +00:00
set ( FAMILY "rp2040" CACHE STRING "Board/MCU family, decides which drivers to use. Set to RP2040 by default." )
set ( BOARD "raspberry_pi_pico" CACHE STRING "Board used, determines the pinout. Defaults to the Raspberry Pi Pico." )
2021-01-31 03:43:09 +00:00
# use directory name for project id
get_filename_component ( PROJECT ${ CMAKE_CURRENT_SOURCE_DIR } NAME )
set ( PROJECT ${ BOARD } - ${ PROJECT } )
# TOP is absolute path to root directory of TinyUSB git repo
set ( TOP "./tinyusb" )
get_filename_component ( TOP "${TOP}" REALPATH )
# Check for -DFAMILY=
if ( FAMILY STREQUAL "rp2040" )
cmake_minimum_required ( VERSION 3.12 )
2021-05-30 02:20:53 +00:00
if ( USE_SYSTEMWIDE_PICOSDK )
2021-06-13 18:07:54 +00:00
set ( TOP "$ENV{PICO_SDK_PATH}/lib/tinyusb" )
get_filename_component ( TOP "${TOP}" REALPATH )
2021-05-30 02:20:53 +00:00
include ( pico_sdk_import.cmake )
else ( )
set ( PICO_SDK_PATH ${ TOP } /hw/mcu/raspberrypi/pico-sdk )
include ( ${ PICO_SDK_PATH } /pico_sdk_init.cmake )
endif ( )
2021-06-13 18:07:54 +00:00
include ( ${ TOP } /hw/bsp/ ${ FAMILY } /family.cmake ) # tinyusb stuff
family_get_project_name ( PROJECT ${ CMAKE_CURRENT_LIST_DIR } )
2021-01-31 03:43:09 +00:00
project ( ${ PROJECT } )
2021-06-13 18:07:54 +00:00
family_initialize_project ( PROJECT ${ CMAKE_CURRENT_LIST_DIR } ) # calls pico_sdk_init()
#pico_sdk_init()
2021-01-31 03:43:09 +00:00
add_executable ( ${ PROJECT } )
2021-06-06 03:10:36 +00:00
# need uart stdio, usb is busy doing other stuff
2021-06-12 19:35:46 +00:00
if ( USE_USBCDC_FOR_STDIO )
# we're going to manually implement this case
pico_enable_stdio_uart ( ${ PROJECT } 0 )
target_compile_definitions ( ${ PROJECT } PUBLIC USE_USBCDC_FOR_STDIO=1 PICO_STDIO_USB=1 )
else ( )
pico_enable_stdio_uart ( ${ PROJECT } 1 )
endif ( )
2021-06-06 03:10:36 +00:00
pico_enable_stdio_usb ( ${ PROJECT } 0 )
2021-01-31 03:43:09 +00:00
target_sources ( ${ PROJECT } PUBLIC
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / m a i n . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / u s b _ d e s c r i p t o r s . c
2021-06-07 23:22:55 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / l i b c o / l i b c o . S
2021-02-01 16:25:49 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C M S I S _ 5 / C M S I S / D A P / F i r m w a r e / S o u r c e / D A P . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C M S I S _ 5 / C M S I S / D A P / F i r m w a r e / S o u r c e / J T A G _ D P . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C M S I S _ 5 / C M S I S / D A P / F i r m w a r e / S o u r c e / D A P _ v e n d o r . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C M S I S _ 5 / C M S I S / D A P / F i r m w a r e / S o u r c e / S W O . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C M S I S _ 5 / C M S I S / D A P / F i r m w a r e / S o u r c e / S W _ D P . c
2021-02-25 23:45:13 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / b s p / $ { F A M I L Y } / c d c _ u a r t . c
2021-06-06 03:10:36 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / b s p / $ { F A M I L Y } / s p i _ s e r p r o g . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c d c _ s e r p r o g . c
2021-06-12 19:35:06 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / r t c o n f . c
2021-01-31 03:43:09 +00:00
)
target_include_directories ( ${ PROJECT } PUBLIC
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } /
2021-06-07 23:22:55 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / l i b c o /
2021-02-01 16:25:49 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C M S I S _ 5 / C M S I S / D A P / F i r m w a r e / I n c l u d e /
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / C M S I S _ 5 / C M S I S / C o r e / I n c l u d e /
2021-01-31 03:43:09 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / b s p / $ { F A M I L Y } /
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / b s p / d e f a u l t /
)
2021-06-06 03:10:36 +00:00
target_link_libraries ( ${ PROJECT } pico_stdlib pico_unique_id hardware_spi
2021-06-13 18:07:54 +00:00
p i c o _ f i x _ r p 2 0 4 0 _ u s b _ d e v i c e _ e n u m e r a t i o n
t i n y u s b _ d e v i c e t i n y u s b _ b o a r d t i n y u s b _ a d d i t i o n s )
2021-01-31 03:43:09 +00:00
2021-06-12 19:35:46 +00:00
if ( USE_USBCDC_FOR_STDIO )
target_sources ( ${ PROJECT } PUBLIC
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / b s p / $ { F A M I L Y } / c d c _ s t d i o . c
)
target_include_directories ( ${ PROJECT } PUBLIC
$ { P I C O _ S D K _ P A T H } / s r c / r p 2 _ c o m m o n / p i c o _ s t d i o _ u s b / i n c l u d e /
)
# extremely ugly hack to prevent the Pico SDK to declare *its* TinyUSB config
2021-06-13 18:07:54 +00:00
# and also to modify the tinyusb board.h file a bit
2021-06-12 19:35:46 +00:00
target_compile_definitions ( ${ PROJECT } PUBLIC
_ P I C O _ S T D I O _ U S B _ T U S B _ C O N F I G _ H = 1
2021-06-13 18:07:54 +00:00
B O A R D _ H _ = 1
2021-06-12 19:35:46 +00:00
)
target_link_libraries ( ${ PROJECT } pico_stdio )
endif ( )
2021-01-31 03:43:09 +00:00
pico_add_extra_outputs ( ${ PROJECT } )
else ( )
2021-06-08 00:56:10 +00:00
message ( FATAL_ERROR "Invalid FAMILY '${FAMILY}' specified" )
2021-01-31 03:43:09 +00:00
endif ( )