From b6e9c42b0217124aaf47e1d65e4eac39c3d3d681 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 22 Jan 2021 14:58:32 +0700 Subject: update cmake build to work with esp32s2 and rp2040 --- examples/device/board_test/CMakeLists.txt | 13 +-- examples/make.mk | 2 +- examples/rules.mk | 28 ++++-- hw/bsp/esp32s2/family.cmake | 6 ++ hw/bsp/esp32s2/family.mk | 2 - hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c | 99 ---------------------- .../raspberry_pi_pico/board_raspberry_pi_pico.c | 99 ++++++++++++++++++++++ hw/bsp/rp2040/family.cmake | 3 + hw/bsp/rp2040/family_extra.cmake | 1 + 9 files changed, 137 insertions(+), 116 deletions(-) create mode 100644 hw/bsp/esp32s2/family.cmake delete mode 100644 hw/bsp/esp32s2/family.mk delete mode 100644 hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c create mode 100644 hw/bsp/rp2040/boards/raspberry_pi_pico/board_raspberry_pi_pico.c create mode 100644 hw/bsp/rp2040/family.cmake create mode 100644 hw/bsp/rp2040/family_extra.cmake diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt index c09ffe215..ee0d7ef58 100644 --- a/examples/device/board_test/CMakeLists.txt +++ b/examples/device/board_test/CMakeLists.txt @@ -1,15 +1,16 @@ -# The following five lines of boilerplate have to be in your project's -# CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) # TOP is absolute path to root directory of TinyUSB git repo set(TOP "../../..") get_filename_component(TOP "${TOP}" REALPATH) -# Add example src and bsp directories -set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components") +# Check for -DFAMILY= +if(NOT DEFINED FAMILY) + message(FATAL_ERROR "Invalid FAMILY specified") +endif() -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -set(SUPPORTED_TARGETS esp32s2) +include(${TOP}/hw/bsp/${FAMILY}/family.cmake) project(board_test) + +include(${TOP}/hw/bsp/${FAMILY}/family_extra.cmake OPTIONAL) diff --git a/examples/make.mk b/examples/make.mk index bf3b36a62..da0f60d2f 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -40,7 +40,7 @@ ifeq ($(FAMILY),) include $(TOP)/hw/bsp/$(BOARD)/board.mk else # Include Family and Board specific defs - include $(TOP)/$(FAMILY_PATH)/family.mk + -include $(TOP)/$(FAMILY_PATH)/family.mk SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c)) endif diff --git a/examples/rules.mk b/examples/rules.mk index fb1fe76c2..b61af1d55 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -2,34 +2,46 @@ # Common make rules for all examples # --------------------------------------- -ifeq ($(CROSS_COMPILE),xtensa-esp32s2-elf-) +ifeq ($(FAMILY),esp32s2) # Espressif IDF use CMake build system, this add wrapper target to call idf.py .PHONY: all clean flash .DEFAULT_GOAL := all all: - idf.py -B$(BUILD) -DBOARD=$(BOARD) build + idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) build build: all clean: - idf.py -B$(BUILD) -DBOARD=$(BOARD) clean + idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) clean + +fullclean: + idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) fullclean flash: - idf.py -B$(BUILD) -DBOARD=$(BOARD) flash + idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) flash bootloader-flash: - idf.py -B$(BUILD) -DBOARD=$(BOARD) bootloader-flash + idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) bootloader-flash app-flash: - idf.py -B$(BUILD) -DBOARD=$(BOARD) app-flash + idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) app-flash erase: - idf.py -B$(BUILD) -DBOARD=$(BOARD) erase_flash + idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) erase_flash monitor: - idf.py -B$(BUILD) -DBOARD=$(BOARD) monitor + idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) monitor + +else ifeq ($(FAMILY),rp2040) + +all: + [ -d $(BUILD) ] || cmake -S . -B $(BUILD) -DFAMILY=$(FAMILY) -DPICO_BUILD_DOCS=0 + $(MAKE) -C $(BUILD) + +clean: + $(RM) -rf $(BUILD) else # GNU Make build system diff --git a/hw/bsp/esp32s2/family.cmake b/hw/bsp/esp32s2/family.cmake new file mode 100644 index 000000000..c19221b14 --- /dev/null +++ b/hw/bsp/esp32s2/family.cmake @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.5) + +# Add example src and bsp directories +set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components") +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +set(SUPPORTED_TARGETS esp32s2) diff --git a/hw/bsp/esp32s2/family.mk b/hw/bsp/esp32s2/family.mk deleted file mode 100644 index 167ef6226..000000000 --- a/hw/bsp/esp32s2/family.mk +++ /dev/null @@ -1,2 +0,0 @@ -# Cross Compiler for ESP32 -CROSS_COMPILE = xtensa-esp32s2-elf- diff --git a/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c b/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c deleted file mode 100644 index efdb54733..000000000 --- a/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#include "pico/stdlib.h" -#include "../board.h" - -#ifndef LED_PIN -#define LED_PIN PICO_DEFAULT_LED_PIN -#endif - -void board_init(void) -{ - setup_default_uart(); - gpio_init(LED_PIN); - gpio_set_dir(LED_PIN, 1); - - // Button - - // todo probably set up device mode? - -#if TUSB_OPT_HOST_ENABLED - // set portfunc to host !!! -#endif -} - -////--------------------------------------------------------------------+ -//// USB Interrupt Handler -////--------------------------------------------------------------------+ -//void USB_IRQHandler(void) -//{ -//#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST -// tuh_isr(0); -//#endif -// -//#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE -// tud_int_handler(0); -//#endif -//} - -//--------------------------------------------------------------------+ -// Board porting API -//--------------------------------------------------------------------+ - -void board_led_write(bool state) -{ - gpio_put(LED_PIN, state); -} - -uint32_t board_button_read(void) -{ - return 0; -} - -int board_uart_read(uint8_t* buf, int len) -{ - for(int i=0;i