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-08-17 21:49:42 +00:00
# use directory name for project id
#get_filename_component(PROJECT "Dragon Probe" NAME)
set ( PROJECT "DragonProbe" )
2021-01-31 03:43:09 +00:00
set ( PROJECT ${ BOARD } - ${ PROJECT } )
2021-06-28 19:39:19 +00:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
2021-01-31 03:43:09 +00:00
# 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
2021-06-28 20:04:40 +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 )
2022-07-08 00:22:02 +00:00
include ( pico_sdk_import.cmake )
set ( TOP "${PICO_SDK_PATH}/lib/tinyusb" )
get_filename_component ( TOP "${TOP}" REALPATH )
2021-05-30 02:20:53 +00:00
2022-07-08 00:22:02 +00:00
include ( ${ TOP } /hw/bsp/family_support.cmake ) # tinyusb stuff
2021-06-13 18:07:54 +00:00
family_get_project_name ( PROJECT ${ CMAKE_CURRENT_LIST_DIR } )
2022-07-08 00:22:02 +00:00
project ( ${ PROJECT } C CXX )
2021-06-13 18:07:54 +00:00
family_initialize_project ( PROJECT ${ CMAKE_CURRENT_LIST_DIR } ) # calls pico_sdk_init()
#pico_sdk_init()
2021-06-20 21:58:26 +00:00
#pico_set_program_name(${PROJECT} "${PROJECT}")
#pico_set_program_version(${PROJECT} "0.1")
2021-06-19 20:26:18 +00:00
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
2021-09-24 01:41:25 +00:00
#pico_enable_stdio_uart(${PROJECT} 0)
2021-06-12 19:35:46 +00:00
target_compile_definitions ( ${ PROJECT } PUBLIC USE_USBCDC_FOR_STDIO=1 PICO_STDIO_USB=1 )
else ( )
2021-09-24 01:41:25 +00:00
#pico_enable_stdio_uart(${PROJECT} 1)
2021-06-12 19:35:46 +00:00
endif ( )
2021-09-24 01:41:25 +00:00
pico_enable_stdio_uart ( ${ PROJECT } 1 )
2021-06-06 03:10:36 +00:00
pico_enable_stdio_usb ( ${ PROJECT } 0 )
2021-06-14 00:01:35 +00:00
else ( )
message ( FATAL_ERROR "Invalid FAMILY '${FAMILY}' specified" )
endif ( )
2021-06-06 03:10:36 +00:00
2021-06-14 00:01:35 +00:00
target_sources ( ${ PROJECT } PUBLIC
2021-07-19 01:17:03 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / n o _ m a l l o c . c
2021-06-14 00:01:35 +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-09-15 23:37:22 +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 - 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 - 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 - 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 - 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 - D A P / F i r m w a r e / S o u r c e / S W _ D P . c
2021-09-20 22:22:02 +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 - D A P / F i r m w a r e / S o u r c e / U A R T . c
2021-06-14 00:01:35 +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 } / u n i q u e . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m a i n . c
2021-07-19 01:17:03 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / a l l o c . c
2021-06-30 17:32:22 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m o d e s e t . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / t h r e a d . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / t u s b _ p l t . S
2021-07-01 01:12:51 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / u s b _ d e s c r i p t o r s . c
2021-06-30 17:32:22 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / v n d _ c f g . c
2021-07-03 00:12:53 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ d e f a u l t / _ d e f a u l t . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ d e f a u l t / c d c _ 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 } / s r c / m _ d e f a u l t / t e m p s e n s o r . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ d e f a u l t / v n d _ i 2 c t i n y u s b . c
2021-10-05 14:47:32 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ i s p / _ i s p . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ i s p / m e h f e t . c
2021-08-01 02:05:43 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ j s c a n / _ j s c a n . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ j s c a n / j s c a n . c
2021-07-18 20:03:58 +00:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ s u m p / _ s u m p . c
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c / m _ s u m p / c d c _ s u m p . c
2021-07-03 00:12:53 +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 } / m _ d e f a u l t / c d c _ u a r t . c
2021-09-24 01:41:25 +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 } / m _ d e f a u l t / d a p _ j t a g . c
$ { 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 } / m _ d e f a u l t / d a p _ s w d . c
2021-09-20 22:22:02 +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 } / m _ d e f a u l t / d a p _ u a r t . c
2021-08-08 16:10:44 +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 } / m _ d e f a u l t / d a p _ s w o . c
2021-07-03 00:12:53 +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 } / m _ d e f a u l t / i 2 c _ t i n y u s b . c
$ { 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 } / m _ d e f a u l t / 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 } / b s p / $ { F A M I L Y } / m _ d e f a u l t / t e m p s e n s o r . c
2021-10-05 14:47:32 +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 } / m _ i s p / m e h f e t _ h w . c
$ { 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 } / m _ i s p / s b w _ h w . c
2021-08-01 02:05:43 +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 } / m _ j s c a n / j s c a n _ h w . c
2021-07-18 20:03:58 +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 } / m _ s u m p / s u m p _ h w . c
2021-06-14 00:01:35 +00:00
)
if ( USE_USBCDC_FOR_STDIO )
2021-01-31 03:43:09 +00:00
target_sources ( ${ PROJECT } PUBLIC
2021-06-14 00:01:35 +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 _ s t d i o . c
2021-01-31 03:43:09 +00:00
)
2021-06-14 00:01:35 +00:00
endif ( )
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 } / s r c /
$ { 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-09-15 23:37:22 +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 - 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 - D A P / C o 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 - D A P / D r i v e r / I n c l u d e /
2021-09-20 22:22:02 +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 - D A P / R T O S 2 / I n c l u d e /
2021-06-14 00:01:35 +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-01-31 03:43:09 +00:00
2021-08-08 16:10:44 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror=implicit-function-declaration -Werror=return-type" )
2021-06-28 19:19:46 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" )
add_custom_target ( fix_db ALL WORKING_DIRECTORY ${ OUTPUT_DIR }
C O M M A N D " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s c r i p t s / f i x _ c l a n g _ d b . p y " )
2021-06-21 14:22:01 +00:00
2021-06-14 00:01:35 +00:00
if ( FAMILY STREQUAL "rp2040" )
2021-07-19 01:17:03 +00:00
# NOTE: do NOT enable pico_runtime here, as it pulls in malloc!
2021-06-06 03:10:36 +00:00
target_link_libraries ( ${ PROJECT } pico_stdlib pico_unique_id hardware_spi
2021-07-18 20:03:58 +00:00
h a r d w a r e _ i 2 c h a r d w a r e _ a d c h a r d w a r e _ p i o h a r d w a r e _ d m a h a r d w a r e _ p w m
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
2021-06-13 18:07:54 +00:00
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_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-09-24 01:41:25 +00:00
pico_generate_pio_header ( ${ PROJECT } ${ CMAKE_CURRENT_SOURCE_DIR } /bsp/ ${ FAMILY } /m_default/dap_jtag.pio )
2021-09-25 11:22:09 +00:00
pico_generate_pio_header ( ${ PROJECT } ${ CMAKE_CURRENT_SOURCE_DIR } /bsp/ ${ FAMILY } /m_default/dap_swd.pio )
2021-09-15 23:37:22 +00:00
pico_generate_pio_header ( ${ PROJECT } ${ CMAKE_CURRENT_SOURCE_DIR } /bsp/ ${ FAMILY } /m_default/swo_uart_rx.pio )
pico_generate_pio_header ( ${ PROJECT } ${ CMAKE_CURRENT_SOURCE_DIR } /bsp/ ${ FAMILY } /m_default/swo_manchester_encoding.pio )
2021-10-05 14:47:32 +00:00
pico_generate_pio_header ( ${ PROJECT } ${ CMAKE_CURRENT_SOURCE_DIR } /bsp/ ${ FAMILY } /m_isp/sbw.pio )
2021-08-08 16:10:44 +00:00
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 ( )