move sdkconfig and board.h to boards folder

update combine.py to take build folder and output filename
run combine.py as postbuild
This commit is contained in:
hathach 2025-06-03 11:02:28 +07:00
parent 662b31ebc2
commit 40b28eae7e
No known key found for this signature in database
GPG key ID: 26FAB84F615C3C52
10 changed files with 135 additions and 105 deletions

View file

@ -41,7 +41,7 @@ jobs:
- name: Build
run: |
docker run --rm -v $PWD:/project -w /project espressif/idf:$IDF_VERSION /bin/bash -c "git config --global --add safe.directory /project && idf.py -DBOARD=${{ matrix.board }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} build"
python combine.py
# combine.py is auto run as postbuild
if [ "${{ matrix.build_type }}" == "Debug" ]; then
# add debug suffix to the bin file
mv NINA_ADAFRUIT*.bin "$(echo NINA_ADAFRUIT*.bin | sed 's/.bin/_Debug.bin/')"

View file

@ -10,16 +10,14 @@ else ()
message(FATAL_ERROR "Unsupported BOARD: ${BOARD}. Supported boards are: fruitjam_c6, esp32")
endif ()
# SDKCONFIG & SDKCONFIG_DEFAULTS for each target
set(SDKCONFIG ${CMAKE_SOURCE_DIR}/sdkconfig.${IDF_TARGET})
# caused by esp-idf/components/bt/controller/esp32c6/bt.c:253:11: In function 'esp_bt_controller_log_init':
# error: 'task_create' may be used uninitialized [-Werror=maybe-uninitialized]
if (IDF_TARGET STREQUAL "esp32c6")
add_compile_options(-Wno-maybe-uninitialized)
endif ()
set(SDKCONFIG_DEFAULTS sdkconfig.defaults sdkconfig.defaults.${BOARD})
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
set(SDKCONFIG_DEFAULTS sdkconfig.defaults ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/sdkconfig)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND SDKCONFIG_DEFAULTS sdkconfig.debug)
endif ()
@ -34,5 +32,13 @@ STRING(TOUPPER ${BOARD} BOARD_UPPER)
add_compile_definitions(
BOARD_${BOARD_UPPER}
)
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/boards)
project(nina-fw)
# Post build to run combine.py
add_custom_command(TARGET app POST_BUILD
COMMAND python ${CMAKE_CURRENT_LIST_DIR}/combine.py -b ${CMAKE_BINARY_DIR} NINA_ADAFRUIT-${BOARD}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
VERBATIM
)

3
boards/CMakeLists.txt Normal file
View file

@ -0,0 +1,3 @@
idf_component_register(
INCLUDE_DIRS . ${BOARD}
)

18
boards/esp32/board.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef BOARD_H
#define BOARD_H
// SPIS for WiFi
#define AIRLIFT_MOSI 14
#define AIRLIFT_MISO 23
#define AIRLIFT_SCK 18
#define AIRLIFT_CS 5
#define AIRLIFT_BUSY 33 // ready
// UART for BLE HCI
#define AIRLIFT_RTS AIRLIFT_BUSY
#define AIRLIFT_CTS 0 // BOOT PIN
// #define CONFIG_BT_LE_HCI_UART_RTS_PIN 33 // ESP_BUSY (ready)
// #define CONFIG_BT_LE_HCI_UART_CTS_PIN 0 // GPIO0
#endif

View file

@ -0,0 +1,11 @@
#ifndef BOARD_H
#define BOARD_H
// SPIS for WiFi
#define AIRLIFT_MOSI 21
#define AIRLIFT_MISO 6
#define AIRLIFT_SCK 22
#define AIRLIFT_CS 7
#define AIRLIFT_BUSY CONFIG_BT_LE_HCI_UART_RTS_PIN // ready
#endif

View file

@ -1,9 +1,9 @@
#!/usr/bin/env python
import json
import re
import sys
import argparse
import os
def extract_firmware_version():
with open('main/CommandHandler.cpp', 'r') as file:
@ -15,15 +15,24 @@ def extract_firmware_version():
return version
raise RuntimeError("FIRMWARE_VERSION not found in CommandHandler.cpp")
def get_idf_target():
with open("build/config.env") as file:
def get_idf_target(build_dir):
with open(f"{build_dir}/config.env") as file:
config = json.load(file)
return config["IDF_TARGET"]
bootloaderData = open("build/bootloader/bootloader.bin", "rb").read()
partitionData = open("build/partition_table/partition-table.bin", "rb").read()
def main():
parser = argparse.ArgumentParser()
parser.add_argument('outfile', help='output file')
parser.add_argument('-b', '--build_dir', default='build', help='build directory')
args = parser.parse_args()
outfile = args.outfile
build_dir = os.path.normpath(args.build_dir)
bootloaderData = open(f"{build_dir}/bootloader/bootloader.bin", "rb").read()
partitionData = open(f"{build_dir}/partition_table/partition-table.bin", "rb").read()
#phyData = open("data/phy.bin", "rb").read()
appData = open("build/nina-fw.bin", "rb").read()
appData = open(f"{build_dir}/nina-fw.bin", "rb").read()
# remove everything between certificate markers to save space. There might be comments and other information.
certsData = b""
@ -52,10 +61,10 @@ BOOTLOADER_OFFSET = {
}
try:
target = get_idf_target()
bootloader_offset = BOOTLOADER_OFFSET[get_idf_target()]
idf_target = get_idf_target(build_dir)
bootloader_offset = BOOTLOADER_OFFSET[idf_target]
except KeyError:
raise RuntimeError(f"unsupported IDF_TARGET: {target}")
raise RuntimeError(f"unsupported IDF_TARGET: {idf_target}")
for i in range(0, len(bootloaderData)):
outputData[bootloader_offset + i] = bootloaderData[i]
@ -76,11 +85,13 @@ for i in range(0, len(appData)):
outputData[0x30000 + i] = appData[i]
version = extract_firmware_version()
outputFilename = f"NINA_ADAFRUIT-{target}-{version}.bin"
if len(sys.argv) > 1:
outputFilename = sys.argv[1]
outputFilename = f"{outfile}-{version}.bin"
# write out
with open(outputFilename, "w+b") as f:
f.seek(0)
f.write(outputData)
if __name__ == '__main__':
main()

View file

@ -1,5 +1,5 @@
idf_component_register(SRCS CommandHandler.cpp http_client.c sketch.ino.cpp
REQUIRES bt esp_http_client spiffs SPIS
REQUIRES bt esp_http_client spiffs SPIS boards
PRIV_INCLUDE_DIRS "."
INCLUDE_DIRS "." $ENV{IDF_PATH}/components/esp_netif
)

View file

@ -51,24 +51,18 @@ int debug = 1;
//--------------------------------------------------------------------
// ADAFRUIT CHANGE
//--------------------------------------------------------------------
// contains SPIS and BT/BLE UART pin definitions
#if !__has_include("board.h")
#error "Board is not supported, please add -DBOARD=<board_name> to the build command"
#endif
#include "board.h"
#define AIRLIFT 1 // Adafruit Airlift
#define NINA_PRINTF(...) do { if (debug) { ets_printf(__VA_ARGS__); } } while (0)
#if defined(CONFIG_IDF_TARGET_ESP32)
// SPIS for WiFi
#define AIRLIFT_MOSI 14
#define AIRLIFT_MISO 23
#define AIRLIFT_SCK 18
#define AIRLIFT_CS 5
#define AIRLIFT_BUSY 33 // ready
// UART for BLE HCI
#define AIRLIFT_RTS AIRLIFT_BUSY
#define AIRLIFT_CTS 0 // BOOT PIN
// #define CONFIG_BT_LE_HCI_UART_RTS_PIN 33 // ESP_BUSY (ready)
// #define CONFIG_BT_LE_HCI_UART_CTS_PIN 0 // GPIO0
extern const struct __sFILE_fake __sf_fake_stdin;
extern const struct __sFILE_fake __sf_fake_stdout;
extern const struct __sFILE_fake __sf_fake_stderr;
@ -78,9 +72,8 @@ SPISClass SPIS(VSPI_HOST, 1, AIRLIFT_MOSI, AIRLIFT_MISO, AIRLIFT_SCK, AIRLIFT_CS
#endif
#if defined(CONFIG_IDF_TARGET_ESP32C6)
// UART for BLE HCI
// CONFIG_BT_LE_HCI_UART_RTS_PIN and CONFIG_BT_LE_HCI_UART_CTS_PIN are defined in sdkconfig.defaults.BOARD
// CONFIG_BT_LE_HCI_UART_RTS_PIN and CONFIG_BT_LE_HCI_UART_CTS_PIN are defined in boards/{BOARD}/sdkconfig
// and used by hci_driver_uart_config() in hci_driver_uart.c. It should matches with BUSY and BOOT pins.
#ifndef CONFIG_BT_LE_HCI_INTERFACE_USE_UART
#error "Please Enable Uart for HCI"
@ -90,18 +83,6 @@ SPISClass SPIS(VSPI_HOST, 1, AIRLIFT_MOSI, AIRLIFT_MISO, AIRLIFT_SCK, AIRLIFT_CS
#error "CTS pin must be the same as BOOT pin"
#endif
// SPIS for WiFi
#define AIRLIFT_BUSY CONFIG_BT_LE_HCI_UART_RTS_PIN // ready
#if defined(BOARD_FRUITJAM_C6)
#define AIRLIFT_MOSI 21
#define AIRLIFT_MISO 6
#define AIRLIFT_SCK 22
#define AIRLIFT_CS 7
#else
#error "Board is not supported, please add -DBOARD=<board_name> to the build command"
#endif
// dev, dma, mosi, miso, sclk, cs, ready
SPISClass SPIS(SPI2_HOST, SPI_DMA_CH_AUTO,
AIRLIFT_MOSI, AIRLIFT_MISO, AIRLIFT_SCK, AIRLIFT_CS, AIRLIFT_BUSY);