From a5bf0bad6eb972e80b00ea9b44ae835be7a35246 Mon Sep 17 00:00:00 2001 From: Takashi Matsuoka Date: Thu, 2 Feb 2023 17:24:35 +0900 Subject: [PATCH 01/40] Support for no button --- src/boards/boards.c | 9 +++++++++ src/boards/boards.h | 10 ++++------ src/main.c | 4 ++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/boards/boards.c b/src/boards/boards.c index e86edd6..8872a93 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -44,6 +44,9 @@ #endif //------------- IMPLEMENTATION -------------// + +#if defined(BUTTON_DFU) || defined(BUTTON_FRESET) + void button_init(uint32_t pin) { if ( BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN ) @@ -62,6 +65,8 @@ bool button_pressed(uint32_t pin) return nrf_gpio_pin_read(pin) == active_state; } +#endif + // This is declared so that a board specific init can be called from here. void __attribute__((weak)) board_init_extra(void) { } void board_init(void) @@ -73,8 +78,12 @@ void board_init(void) NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC; NRF_CLOCK->TASKS_LFCLKSTART = 1UL; +#ifdef BUTTON_DFU button_init(BUTTON_DFU); +#endif +#ifdef BUTTON_FRESET button_init(BUTTON_FRESET); +#endif NRFX_DELAY_US(100); // wait for the pin state is stable #if LEDS_NUMBER > 0 diff --git a/src/boards/boards.h b/src/boards/boards.h index 8aa0ece..e11acf2 100644 --- a/src/boards/boards.h +++ b/src/boards/boards.h @@ -37,11 +37,11 @@ #define UF2_VOLUME_LABEL "NRF52BOOT " #endif -#ifndef BUTTON_DFU +#if !defined(BUTTON_DFU) && defined(BUTTON_1) #define BUTTON_DFU BUTTON_1 #endif -#ifndef BUTTON_FRESET +#if !defined(BUTTON_FRESET) && defined(BUTTON_2) #define BUTTON_FRESET BUTTON_2 #endif @@ -104,13 +104,11 @@ void led_tick(void); //--------------------------------------------------------------------+ // BUTTONS //--------------------------------------------------------------------+ -// Make sure we have at least two buttons (DFU + FRESET since DFU+FRST=OTA) -#if BUTTONS_NUMBER < 2 -#error "At least two buttons required in the BSP (see 'BUTTONS_NUMBER')" -#endif +#if defined(BUTTON_DFU) || defined(BUTTON_FRESET) void button_init(uint32_t pin); bool button_pressed(uint32_t pin); +#endif bool is_ota(void); diff --git a/src/main.c b/src/main.c index 47386ca..c6f5963 100644 --- a/src/main.c +++ b/src/main.c @@ -259,10 +259,14 @@ static void check_dfu_mode(void) /*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/ // DFU button pressed +#if defined(BUTTON_DFU) dfu_start = dfu_start || button_pressed(BUTTON_DFU); +#endif // DFU + FRESET are pressed --> OTA +#if defined(BUTTON_DFU) && defined(BUTTON_FRESET) _ota_dfu = _ota_dfu || ( button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) ) ; +#endif bool const valid_app = bootloader_app_is_valid(); bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP; From f5ab453f75dbd2b1f6dde58611f5907b40e206b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 00:31:39 -0300 Subject: [PATCH 02/40] Allow BLE characteristics to support both WriteWithoutResponse (for compatibility with Nordic DFU apps) and WriteWithResponse (for improved reliability) --- lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c index ea716cb..2a4ede8 100644 --- a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c +++ b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c @@ -17,6 +17,7 @@ #include #include "sdk_common.h" +#define DFU_PKT_ENABLE_WR_WO_RESPONSE_ONLY 0 /**< Enable Write Without Response on Data Endpoint ONLY (otherwise both With and Without response will be supported)*/ #define MAX_DFU_PKT_LEN 20 /**< Maximum length (in bytes) of the DFU Packet characteristic. */ #define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ #define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ @@ -57,7 +58,12 @@ static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu) memset(&char_md, 0, sizeof(char_md)); +#if DFU_PKT_ENABLE_WR_WO_RESPONSE_ONLY char_md.char_props.write_wo_resp = 1; +#else + char_md.char_props.write = 1; // For those improved apps that can take advantage of ACK + char_md.char_props.write_wo_resp = 1; // Nordic IOS DFU app REQUIRES Write Without Response */ +#endif char_md.p_char_user_desc = NULL; char_md.p_char_pf = NULL; char_md.p_user_desc_md = NULL; From 2910556adc5960618ca8adf5c5b919f6669feb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 00:36:14 -0300 Subject: [PATCH 03/40] Wait until notification queue has enough room so no notifications of completed operations to the DFU app are lost --- .../ble/ble_services/ble_dfu/ble_dfu.c | 122 ++++++++++-------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c index 2a4ede8..685fdea 100644 --- a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c +++ b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c @@ -561,29 +561,35 @@ uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_b return NRF_ERROR_INVALID_STATE; } - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; + uint32_t err_code; + do { - // Encode the Op Code. - m_notif_buffer[index++] = OP_CODE_RESPONSE; + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + // Encode the Op Code. + m_notif_buffer[index++] = OP_CODE_RESPONSE; + + // Encode the Reqest Op Code. + m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ; + + // Encode the Response Value. + m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS; + + index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; + + err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + } while (err_code == NRF_ERROR_RESOURCES); - // Encode the Reqest Op Code. - m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ; - - // Encode the Response Value. - m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS; - - index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); - - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + return err_code; } @@ -599,22 +605,28 @@ uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_by return NRF_ERROR_INVALID_STATE; } - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; + uint32_t err_code; + do { - m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF; + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF; + + index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; - index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); + err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + } while (err_code == NRF_ERROR_RESOURCES); - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + return err_code; } @@ -632,24 +644,30 @@ uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu, return NRF_ERROR_INVALID_STATE; } - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; + uint32_t err_code; + do { - m_notif_buffer[index++] = OP_CODE_RESPONSE; + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + m_notif_buffer[index++] = OP_CODE_RESPONSE; + + // Encode the Request Op code + m_notif_buffer[index++] = (uint8_t)dfu_proc; + + // Encode the Response Value. + m_notif_buffer[index++] = (uint8_t)resp_val; + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; + + err_code = sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + } while (err_code == NRF_ERROR_RESOURCES); - // Encode the Request Op code - m_notif_buffer[index++] = (uint8_t)dfu_proc; - - // Encode the Response Value. - m_notif_buffer[index++] = (uint8_t)resp_val; - - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); + return err_code; } From b5ddc1879e062621d927c263e13bd593ba51d801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 00:41:16 -0300 Subject: [PATCH 04/40] Fix improper processing of Flash WRITE/ERASE completion notifications that was causing the DFU firmware update to sometimes crash --- .../components/drivers_nrf/pstorage/pstorage_raw.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c b/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c index f9404fe..a6ac067 100644 --- a/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c +++ b/lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c @@ -280,6 +280,10 @@ static void app_notify(uint32_t result, cmd_queue_element_t * p_elem) */ void pstorage_sys_event_handler(uint32_t sys_evt) { + // Do not bother processing events we are not interested in + if (sys_evt != NRF_EVT_FLASH_OPERATION_SUCCESS && + sys_evt != NRF_EVT_FLASH_OPERATION_ERROR) return; + uint32_t retval = NRF_SUCCESS; // The event shall only be processed if requested by this module. @@ -339,6 +343,7 @@ void pstorage_sys_event_handler(uint32_t sys_evt) * @brief Function for processing of commands and issuing flash access request to the SoftDevice. * * @return The return value received from SoftDevice. + * @remark This function is only called when m_cmd_queue.flash_access == false */ static uint32_t cmd_process(void) { @@ -352,6 +357,9 @@ static uint32_t cmd_process(void) storage_addr = p_cmd->storage_addr.block_id; + // Let's assume we will do a flash access + m_cmd_queue.flash_access = true; + switch (p_cmd->op_code) { case PSTORAGE_STORE_OP_CODE: @@ -396,9 +404,10 @@ static uint32_t cmd_process(void) break; } - if (retval == NRF_SUCCESS) + // An error means we will not do it + if (retval != NRF_SUCCESS) { - m_cmd_queue.flash_access = true; + m_cmd_queue.flash_access = false; } return retval; From 04d029a5bd9ccc367faee2c8a4d0bac5b886e7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 00:43:27 -0300 Subject: [PATCH 05/40] Allow overriding device name in DFU mode --- .../components/libraries/bootloader_dfu/dfu_transport_ble.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 2715dce..35d9ba4 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -47,7 +47,9 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define BLE_HANDLE_MAX 0xFFFF /**< Max handle value is BLE. */ // limit of 8 chars +#ifndef DEVICE_NAME #define DEVICE_NAME "AdaDFU" /**< Name of device. Will be included in the advertising data. */ +#endif #define MIN_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(10, UNIT_1_25_MS)) /**< Minimum acceptable connection interval (11.25 milliseconds). */ #define MAX_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(30, UNIT_1_25_MS)) /**< Maximum acceptable connection interval (15 milliseconds). */ From 36422ba612fca418bad9044eab63047d8fe345ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 00:46:27 -0300 Subject: [PATCH 06/40] Speedup FLASH writes by temporarily increasing BLE stack local latency --- .../bootloader_dfu/dfu_transport_ble.c | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 35d9ba4..63767e4 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -55,6 +55,7 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define MAX_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(30, UNIT_1_25_MS)) /**< Maximum acceptable connection interval (15 milliseconds). */ #define SLAVE_LATENCY 0 /**< Slave latency. */ #define CONN_SUP_TIMEOUT (4 * 100) /**< Connection supervisory timeout (4 seconds). */ +#define SPEEDUP_FLASH_WRITES 1 /**< Speedup FLASH writes by changing Softdevice local latency */ #define APP_ADV_INTERVAL MSEC_TO_UNITS(25, UNIT_0_625_MS) /**< The advertising interval (25 ms.). */ #define APP_ADV_TIMEOUT BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED /**< The advertising timeout in units of seconds. This is set to @ref BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED so that the advertisement is done as long as there there is a call to @ref dfu_transport_close function.*/ @@ -210,6 +211,34 @@ static ble_dfu_resp_val_t nrf_err_code_translate(uint32_t err_c } } +static void prioritize_ble_over_flash_writes(void) +{ +#ifdef SPEEDUP_FLASH_WRITES + // We set the local latency to 0: That will revert latency to the negotiated one with the host. + // That will increase throughput to the maximum possible + ble_opt_t opt; + varclr(&opt); + opt.gap_opt.local_conn_latency.conn_handle = m_conn_handle;/**< Connection Handle */ + opt.gap_opt.local_conn_latency.requested_latency = 0; /**< Requested local connection latency. */ + opt.gap_opt.local_conn_latency.p_actual_latency = NULL; /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */ + sd_ble_opt_set(BLE_GAP_OPT_LOCAL_CONN_LATENCY, &opt); +#endif +} + +static void prioritize_flash_writes_over_ble(void) +{ +#ifdef SPEEDUP_FLASH_WRITES + // We set the local latency to the maximum possible: That will make FLASH writes faster, as BLE comms will + // be delayed (even losing RXd packets, but this is the same as a poor connection and will be handled by + // the protocol itself) + ble_opt_t opt; + varclr(&opt); + opt.gap_opt.local_conn_latency.conn_handle = m_conn_handle;/**< Connection Handle */ + opt.gap_opt.local_conn_latency.requested_latency = 50; /**< Requested local connection latency. */ + opt.gap_opt.local_conn_latency.p_actual_latency = NULL; /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */ + sd_ble_opt_set(BLE_GAP_OPT_LOCAL_CONN_LATENCY, &opt); +#endif +} /**@brief Function for handling the callback events from the dfu module. * Callbacks are expected when \ref dfu_data_pkt_handle has been executed. @@ -228,6 +257,9 @@ static void dfu_cb_handler(uint32_t packet, uint32_t result, uint8_t * p_data) case DATA_PACKET: if (result != NRF_SUCCESS) { + // Restore latency to the negotiated one + prioritize_ble_over_flash_writes(); + // Disconnect from peer. if (IS_CONNECTED()) { @@ -244,6 +276,9 @@ static void dfu_cb_handler(uint32_t packet, uint32_t result, uint8_t * p_data) // If the callback matches final data packet received then the peer is notified. if (mp_final_packet == p_data) { + // Restore latency to the negotiated one + prioritize_ble_over_flash_writes(); + // Notify the DFU Controller about the success of the procedure. err_code = ble_dfu_response_send(&m_dfu, BLE_DFU_RECEIVE_APP_PROCEDURE, @@ -254,6 +289,10 @@ static void dfu_cb_handler(uint32_t packet, uint32_t result, uint8_t * p_data) break; case START_PACKET: + + // Restore latency to the negotiated one + prioritize_ble_over_flash_writes(); + // Translate the err_code returned by the above function to DFU Response Value. resp_val = nrf_err_code_translate(result, BLE_DFU_START_PROCEDURE); @@ -326,9 +365,15 @@ static void start_data_process(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt) start_packet.bl_image_size = uint32_decode(p_length_data + BL_IMAGE_SIZE_OFFSET); start_packet.app_image_size = uint32_decode(p_length_data + APP_IMAGE_SIZE_OFFSET); + // Prioritize FLASH writes over BLE comms + prioritize_flash_writes_over_ble(); + err_code = dfu_start_pkt_handle(&update_packet); if (err_code != NRF_SUCCESS) { + // Prioritize BLE over flash writes + prioritize_ble_over_flash_writes(); + // Translate the err_code returned by the above function to DFU Response Value. ble_dfu_resp_val_t resp_val; From d28c2e08717b4f48423185bc15760d79b4a201ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 01:03:53 -0300 Subject: [PATCH 07/40] Enable negotiation of MTU sizes above 20. This will significatively increase DFU write speed --- .../ble/ble_services/ble_dfu/ble_dfu.c | 16 ++++----- .../bootloader_dfu/dfu_transport_ble.c | 35 +++++++++++++++---- src/main.c | 32 ++++++++++++++--- src/sdk_config.h | 2 +- 4 files changed, 65 insertions(+), 20 deletions(-) diff --git a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c index 685fdea..a630971 100644 --- a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c +++ b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c @@ -17,14 +17,14 @@ #include #include "sdk_common.h" -#define DFU_PKT_ENABLE_WR_WO_RESPONSE_ONLY 0 /**< Enable Write Without Response on Data Endpoint ONLY (otherwise both With and Without response will be supported)*/ -#define MAX_DFU_PKT_LEN 20 /**< Maximum length (in bytes) of the DFU Packet characteristic. */ -#define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ -#define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ -#define PKT_RCPT_NOTIF_REQ_LEN 3 /**< Length (in bytes) of the Packet Receipt Notification Request. */ -#define MAX_PKTS_RCPT_NOTIF_LEN 6 /**< Maximum length (in bytes) of the Packets Receipt Notification. */ -#define MAX_RESPONSE_LEN 7 /**< Maximum length (in bytes) of the response to a Control Point command. */ -#define MAX_NOTIF_BUFFER_LEN MAX(MAX_PKTS_RCPT_NOTIF_LEN, MAX_RESPONSE_LEN) /**< Maximum length (in bytes) of the buffer needed by DFU Service while sending notifications to peer. */ +#define DFU_PKT_ENABLE_WR_WO_RESPONSE_ONLY 0 /**< Enable Write Without Response on Data Endpoint ONLY (otherwise both With and Without response will be supported)*/ +#define MAX_DFU_PKT_LEN 244 /**< Maximum length (in bytes) of the DFU Packet characteristic. */ +#define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ +#define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ +#define PKT_RCPT_NOTIF_REQ_LEN 3 /**< Length (in bytes) of the Packet Receipt Notification Request. */ +#define MAX_PKTS_RCPT_NOTIF_LEN 6 /**< Maximum length (in bytes) of the Packets Receipt Notification. */ +#define MAX_RESPONSE_LEN 7 /**< Maximum length (in bytes) of the response to a Control Point command. */ +#define MAX_NOTIF_BUFFER_LEN MAX(MAX_PKTS_RCPT_NOTIF_LEN, MAX_RESPONSE_LEN) /**< Maximum length (in bytes) of the buffer needed by DFU Service while sending notifications to peer. */ enum { diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 63767e4..06017a9 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -36,8 +36,7 @@ #include "sdk_common.h" -#define BLEGAP_EVENT_LENGTH 6 -#define BLEGATT_ATT_MTU_MAX 23 +#define BLEGATT_ATT_MTU_MAX 247 enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define DFU_REV_MAJOR 0x00 /** DFU Major revision number to be exposed. */ @@ -51,15 +50,15 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define DEVICE_NAME "AdaDFU" /**< Name of device. Will be included in the advertising data. */ #endif -#define MIN_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(10, UNIT_1_25_MS)) /**< Minimum acceptable connection interval (11.25 milliseconds). */ +#define MIN_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(15, UNIT_1_25_MS)) /**< Minimum acceptable connection interval (11.25 milliseconds). */ #define MAX_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(30, UNIT_1_25_MS)) /**< Maximum acceptable connection interval (15 milliseconds). */ #define SLAVE_LATENCY 0 /**< Slave latency. */ -#define CONN_SUP_TIMEOUT (4 * 100) /**< Connection supervisory timeout (4 seconds). */ +#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(8000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds). */ #define SPEEDUP_FLASH_WRITES 1 /**< Speedup FLASH writes by changing Softdevice local latency */ #define APP_ADV_INTERVAL MSEC_TO_UNITS(25, UNIT_0_625_MS) /**< The advertising interval (25 ms.). */ #define APP_ADV_TIMEOUT BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED /**< The advertising timeout in units of seconds. This is set to @ref BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED so that the advertisement is done as long as there there is a call to @ref dfu_transport_close function.*/ -#define APP_DIRECTED_ADV_TIMEOUT 50 /**< number of direct advertisement (each lasting 1.28seconds). */ +#define APP_DIRECTED_ADV_TIMEOUT 50 /**< number of direct advertisement (each lasting 1.28seconds). */ #define PEER_ADDRESS_TYPE_INVALID 0xFF /**< Value indicating that no valid peer address exists. This will be the case when a private resolvable address is used in which case there is no address available but instead an IRK is present. */ #define PEER_ADDRESS_TYPE_INVALID 0xFF /**< Value indicating that no valid peer address exists. This will be the case when a private resolvable address is used in which case there is no address available but instead an IRK is present. */ @@ -790,8 +789,22 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: - m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; - m_is_advertising = false; + { + m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; + m_is_advertising = false; + + // Force changing the slave latency to try to improve transfer throughput (bandwidth) + // But Android and IOS will override it with their minimum supported value + ble_gap_conn_params_t p_conn_params; + p_conn_params.min_conn_interval = p_ble_evt->evt.gap_evt.params.connected.conn_params.min_conn_interval; + p_conn_params.max_conn_interval = p_ble_evt->evt.gap_evt.params.connected.conn_params.max_conn_interval; + p_conn_params.slave_latency = SLAVE_LATENCY; + p_conn_params.conn_sup_timeout = p_ble_evt->evt.gap_evt.params.connected.conn_params.conn_sup_timeout; + + err_code = sd_ble_gap_conn_param_update(m_conn_handle, &p_conn_params); + APP_ERROR_CHECK(err_code); + + } break; case BLE_GAP_EVT_DISCONNECTED: @@ -821,6 +834,9 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) break; + case BLE_GAP_EVT_CONN_PARAM_UPDATE: + break; + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: { ble_gap_sec_keyset_t keys; @@ -947,6 +963,11 @@ static void on_ble_evt(ble_evt_t * p_ble_evt) case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: { uint16_t att_mtu = MIN(p_ble_evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu, BLEGATT_ATT_MTU_MAX); + + // Round it to a multiple of 4 plus 3 bytes, as we need data packets to be multiple of 4 bytes + att_mtu &= 0xFFFCU; + att_mtu |= 3; + PRINTF("GAP ATT MTU is changed to %d\r\n", att_mtu); APP_ERROR_CHECK( sd_ble_gatts_exchange_mtu_reply(m_conn_handle, att_mtu) ); } diff --git a/src/main.c b/src/main.c index 9ebc9e9..0011640 100644 --- a/src/main.c +++ b/src/main.c @@ -115,8 +115,11 @@ extern void tusb_hal_nrf_power_event(uint32_t event); #define APP_ASKS_FOR_SINGLE_TAP_RESET() (*((uint32_t*)(DFU_BANK_0_REGION_START + 0x200)) == 0x87eeb07c) // These value must be the same with one in dfu_transport_ble.c -#define BLEGAP_EVENT_LENGTH 6 -#define BLEGATT_ATT_MTU_MAX 23 +#define BLEGAP_EVENT_LENGTH 12 +#define BLEGATT_ATT_MTU_MAX 247 +#define BLEGATTS_HVN_QSIZE 12 +#define BLEGATTC_WRCMD_QSIZE 2 + enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; @@ -371,11 +374,23 @@ static uint32_t ble_stack_init(void) { blecfg.conn_cfg.params.gap_conn_cfg.event_length = BLEGAP_EVENT_LENGTH; sd_ble_cfg_set(BLE_CONN_CFG_GAP, &blecfg, ram_start); + // HVN queue size + varclr(&blecfg); + blecfg.conn_cfg.conn_cfg_tag = BLE_CONN_CFG_HIGH_BANDWIDTH; + blecfg.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = BLEGATTS_HVN_QSIZE; + sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &blecfg, ram_start); + + // WRITE COMMAND queue size + varclr(&blecfg); + blecfg.conn_cfg.conn_cfg_tag = BLE_CONN_CFG_HIGH_BANDWIDTH; + blecfg.conn_cfg.params.gattc_conn_cfg.write_cmd_tx_queue_size = BLEGATTC_WRCMD_QSIZE; + sd_ble_cfg_set(BLE_CONN_CFG_GATTC, &blecfg, ram_start); + // Enable BLE stack. // Note: Interrupt state (enabled, forwarding) is not work properly if not enable ble sd_ble_enable(&ram_start); -#if 0 +#if BLEGATT_ATT_MTU_MAX > 23 ble_opt_t opt; varclr(&opt); opt.common_opt.conn_evt_ext.enable = 1; // enable Data Length Extension @@ -401,10 +416,19 @@ uint32_t proc_ble(void) { if (NRF_SUCCESS == err) { switch (evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: + { + // Try to enable 2M phy,if phone allows it + ble_gap_phys_t const phys = + { + .rx_phys = BLE_GAP_PHY_AUTO, + .tx_phys = BLE_GAP_PHY_AUTO, + }; + sd_ble_gap_phy_update(evt->evt.gap_evt.conn_handle, &phys); + _ota_connected = true; led_state(STATE_BLE_CONNECTED); break; - + } case BLE_GAP_EVT_DISCONNECTED: _ota_connected = false; led_state(STATE_BLE_DISCONNECTED); diff --git a/src/sdk_config.h b/src/sdk_config.h index 50e8196..bef8bc7 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -66,7 +66,7 @@ #define HCI_MEM_POOL_ENABLED 1 #define HCI_TX_BUF_SIZE 600 // not used #define HCI_RX_BUF_SIZE 600 -#define HCI_RX_BUF_QUEUE_SIZE 8 // must be power of 2 +#define HCI_RX_BUF_QUEUE_SIZE 16 // must be power of 2 //========================================================== // UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver From ca46deb0a24a1888809e9067d7a684dbb2d13397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 01:14:50 -0300 Subject: [PATCH 08/40] Factor out FLASH erase procedure (non OTA), fix FLASH write procedure (non OTA), use them instead of repeating code --- .../bootloader_dfu/dfu_single_bank.c | 131 +++++++++--------- src/flash_nrf5x.c | 96 +++++++++---- src/flash_nrf5x.h | 3 +- 3 files changed, 132 insertions(+), 98 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index fa69ec8..ee2d342 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -88,31 +88,24 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle, */ static void dfu_prepare_func_app_erase(uint32_t image_size) { - mp_storage_handle_active = &m_storage_handle_app; + mp_storage_handle_active = &m_storage_handle_app; - // Doing a SoftDevice update thus current application must be cleared to ensure enough space - // for new SoftDevice. - m_dfu_state = DFU_STATE_PREPARING; + // Doing a SoftDevice update thus current application must be cleared to ensure enough space + // for new SoftDevice. + m_dfu_state = DFU_STATE_PREPARING; - if ( is_ota() ) - { - uint32_t err_code = pstorage_clear(&m_storage_handle_app, m_image_size); - APP_ERROR_CHECK(err_code); - } - else - { - uint32_t const page_count = NRFX_CEIL_DIV(m_image_size, CODE_PAGE_SIZE); - - for ( uint32_t i = 0; i < page_count; i++ ) + if ( is_ota() ) { - uint32_t const addr = DFU_BANK_0_REGION_START + i * CODE_PAGE_SIZE; - PRINTF("Erase 0x%08lX\r\n", addr); - nrfx_nvmc_page_erase(addr); + uint32_t err_code = pstorage_clear(&m_storage_handle_app, m_image_size); + APP_ERROR_CHECK(err_code); } + else + { + flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_image_size); - // invoke complete callback - pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); - } + // invoke complete callback + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + } } @@ -136,14 +129,14 @@ static void dfu_cleared_func_app(void) uint32_t offset_calculate(uint32_t sd_image_size) { uint32_t offset = 0; - + if (m_start_packet.sd_image_size > DFU_BANK_0_REGION_START) { uint32_t page_mask = (CODE_PAGE_SIZE - 1); uint32_t diff = m_start_packet.sd_image_size - DFU_BANK_0_REGION_START; - + offset = diff & ~page_mask; - + // Align offset to next page if image size is not page sized. if ((diff & page_mask) > 0) { @@ -189,8 +182,7 @@ static uint32_t dfu_activate_sd(void) */ static uint32_t dfu_activate_app(void) { - uint32_t err_code = NRF_SUCCESS; - dfu_update_status_t update_status; + dfu_update_status_t update_status = { 0 }; memset(&update_status, 0, sizeof(dfu_update_status_t )); update_status.status_code = DFU_UPDATE_APP_COMPLETE; @@ -199,7 +191,7 @@ static uint32_t dfu_activate_app(void) bootloader_dfu_update_process(update_status); - return err_code; + return NRF_SUCCESS; } @@ -213,7 +205,7 @@ static uint32_t dfu_activate_app(void) */ static uint32_t dfu_activate_bl(void) { - dfu_update_status_t update_status; + dfu_update_status_t update_status = {0}; update_status.status_code = DFU_UPDATE_BOOT_COMPLETE; update_status.app_crc = m_image_crc; @@ -267,7 +259,7 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) // - SoftDevice // - Bootloader // - SoftDevice with Bootloader - if (IS_UPDATING_APP(m_start_packet) && + if (IS_UPDATING_APP(m_start_packet) && (IS_UPDATING_SD(m_start_packet) || IS_UPDATING_BL(m_start_packet))) { // App update is only supported independently. @@ -284,7 +276,7 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) m_image_size = m_start_packet.sd_image_size + m_start_packet.bl_image_size + m_start_packet.app_image_size; - + if (m_start_packet.bl_image_size > DFU_BL_IMAGE_MAX_SIZE) { return NRF_ERROR_DATA_SIZE; @@ -296,7 +288,7 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) } m_functions.prepare = dfu_prepare_func_app_erase; m_functions.cleared = dfu_cleared_func_app; - + if (IS_UPDATING_SD(m_start_packet)) { m_functions.activate = dfu_activate_sd; @@ -358,13 +350,13 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) if ( is_ota() ) { - err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); - VERIFY_SUCCESS(err_code); + err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); + VERIFY_SUCCESS(err_code); } else { - flash_nrf5x_write(DFU_BANK_0_REGION_START + m_data_received, p_data, data_length, false); - pstorage_callback_handler(mp_storage_handle_active, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_data, data_length); + flash_nrf5x_write(DFU_BANK_0_REGION_START + m_data_received, p_data, data_length, false); + pstorage_callback_handler(mp_storage_handle_active, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_data, data_length); } m_data_received += data_length; @@ -376,10 +368,10 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) } else { - if ( !is_ota() ) flash_nrf5x_flush(false); + if ( !is_ota() ) flash_nrf5x_flush(false); - // The entire image has been received. Return NRF_SUCCESS. - err_code = NRF_SUCCESS; + // The entire image has been received. Return NRF_SUCCESS. + err_code = NRF_SUCCESS; } break; @@ -395,14 +387,14 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) uint32_t dfu_init_pkt_complete(void) { uint32_t err_code = NRF_ERROR_INVALID_STATE; - + // DFU initialization has been done and a start packet has been received. if (IMAGE_WRITE_IN_PROGRESS()) { // Image write is already in progress. Cannot handle an init packet now. return NRF_ERROR_INVALID_STATE; } - + if (m_dfu_state == DFU_STATE_RX_INIT_PKT) { err_code = dfu_init_prevalidate(m_init_packet, m_init_packet_length, m_start_packet.dfu_update_mode); @@ -513,7 +505,7 @@ uint32_t dfu_image_activate() void dfu_reset(void) { - dfu_update_status_t update_status; + dfu_update_status_t update_status = { 0 }; update_status.status_code = DFU_RESET; @@ -547,13 +539,13 @@ static uint32_t dfu_copy_sd(uint32_t * src, uint32_t * dst, uint32_t len) } -static uint32_t dfu_sd_img_block_swap(uint32_t * src, - uint32_t * dst, - uint32_t len, +static uint32_t dfu_sd_img_block_swap(uint32_t * src, + uint32_t * dst, + uint32_t len, uint32_t block_size) { // It is neccesarry to swap the new SoftDevice in 3 rounds to ensure correct copy of data - // and verifucation of data in case power reset occurs during write to flash. + // and verification of data in case power reset occurs during write to flash. // To ensure the robustness of swapping the images are compared backwards till start of // image swap. If the back is identical everything is swapped. uint32_t err_code = dfu_compare_block(src, dst, len); @@ -564,9 +556,9 @@ static uint32_t dfu_sd_img_block_swap(uint32_t * src, if ((uint32_t)dst > SOFTDEVICE_REGION_START) { - err_code = dfu_sd_img_block_swap((uint32_t *)((uint32_t)src - block_size), - (uint32_t *)((uint32_t)dst - block_size), - block_size, + err_code = dfu_sd_img_block_swap((uint32_t *)((uint32_t)src - block_size), + (uint32_t *)((uint32_t)dst - block_size), + block_size, block_size); VERIFY_SUCCESS(err_code); } @@ -588,37 +580,37 @@ uint32_t dfu_sd_image_swap(void) { return NRF_SUCCESS; } - + if ((SOFTDEVICE_REGION_START + boot_settings.sd_image_size) > boot_settings.sd_image_start) { uint32_t err_code; uint32_t sd_start = SOFTDEVICE_REGION_START; uint32_t block_size = (boot_settings.sd_image_start - sd_start) / 2; - + /* ##### FIX START ##### */ - block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); - /* ##### FIX END ##### */ - + block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); + /* ##### FIX END ##### */ + uint32_t image_end = boot_settings.sd_image_start + boot_settings.sd_image_size; uint32_t img_block_start = boot_settings.sd_image_start + 2 * block_size; uint32_t sd_block_start = sd_start + 2 * block_size; - + if (SD_SIZE_GET(MBR_SIZE) < boot_settings.sd_image_size) { // This will clear a page thus ensuring the old image is invalidated before swapping. - err_code = dfu_copy_sd((uint32_t *)(sd_start + block_size), - (uint32_t *)(sd_start + block_size), + err_code = dfu_copy_sd((uint32_t *)(sd_start + block_size), + (uint32_t *)(sd_start + block_size), sizeof(uint32_t)); VERIFY_SUCCESS(err_code); err_code = dfu_copy_sd((uint32_t *)sd_start, (uint32_t *)sd_start, sizeof(uint32_t)); VERIFY_SUCCESS(err_code); } - - return dfu_sd_img_block_swap((uint32_t *)img_block_start, - (uint32_t *)sd_block_start, - image_end - img_block_start, + + return dfu_sd_img_block_swap((uint32_t *)img_block_start, + (uint32_t *)sd_block_start, + image_end - img_block_start, block_size); } else @@ -626,7 +618,7 @@ uint32_t dfu_sd_image_swap(void) if (boot_settings.sd_image_size != 0) { return dfu_copy_sd((uint32_t *)boot_settings.sd_image_start, - (uint32_t *)SOFTDEVICE_REGION_START, + (uint32_t *)SOFTDEVICE_REGION_START, boot_settings.sd_image_size); } } @@ -646,7 +638,7 @@ uint32_t dfu_bl_image_swap(void) { uint32_t bl_image_start = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_0_REGION_START : - bootloader_settings.sd_image_start + + bootloader_settings.sd_image_start + bootloader_settings.sd_image_size; sd_mbr_cmd.command = SD_MBR_COMMAND_COPY_BL; @@ -695,17 +687,18 @@ uint32_t dfu_sd_image_validate(void) { return NRF_SUCCESS; } - + if ((SOFTDEVICE_REGION_START + bootloader_settings.sd_image_size) > bootloader_settings.sd_image_start) { uint32_t sd_start = SOFTDEVICE_REGION_START; uint32_t block_size = (bootloader_settings.sd_image_start - sd_start) / 2; - uint32_t image_end = bootloader_settings.sd_image_start + + uint32_t image_end = bootloader_settings.sd_image_start + bootloader_settings.sd_image_size; /* ##### FIX START ##### */ - block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); - /* ##### FIX END ##### */ + block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); + /* ##### FIX END ##### */ + uint32_t img_block_start = bootloader_settings.sd_image_start + 2 * block_size; uint32_t sd_block_start = sd_start + 2 * block_size; @@ -714,12 +707,12 @@ uint32_t dfu_sd_image_validate(void) return NRF_ERROR_NULL; } - return dfu_sd_img_block_swap((uint32_t *)img_block_start, - (uint32_t *)sd_block_start, - image_end - img_block_start, + return dfu_sd_img_block_swap((uint32_t *)img_block_start, + (uint32_t *)sd_block_start, + image_end - img_block_start, block_size); } - + sd_mbr_cmd.command = SD_MBR_COMMAND_COMPARE; sd_mbr_cmd.params.compare.ptr1 = (uint32_t *)SOFTDEVICE_REGION_START; sd_mbr_cmd.params.compare.ptr2 = (uint32_t *)bootloader_settings.sd_image_start; diff --git a/src/flash_nrf5x.c b/src/flash_nrf5x.c index 12c6797..ddea500 100644 --- a/src/flash_nrf5x.c +++ b/src/flash_nrf5x.c @@ -26,48 +26,88 @@ #include "nrf_sdm.h" #include "flash_nrf5x.h" #include "boards.h" +#include "dfu_types.h" -#define FLASH_PAGE_SIZE 4096 #define FLASH_CACHE_INVALID_ADDR 0xffffffff static uint32_t _fl_addr = FLASH_CACHE_INVALID_ADDR; -static uint8_t _fl_buf[FLASH_PAGE_SIZE] __attribute__((aligned(4))); +static uint8_t _fl_buf[CODE_PAGE_SIZE] __attribute__((aligned(4))); + +void flash_nrf5x_erase (uint32_t dst, uint32_t len) +{ + uint32_t page_addr = dst & ~(CODE_PAGE_SIZE - 1); + uint32_t const page_count = NRFX_CEIL_DIV(len, CODE_PAGE_SIZE); + for ( uint32_t i = 0; i < page_count; i++ ) + { + uint32_t const addr = page_addr + i * CODE_PAGE_SIZE; + PRINTF("Erase 0x%08lX\r\n", addr); + nrfx_nvmc_page_erase(addr); + } +} + void flash_nrf5x_flush (bool need_erase) { - if ( _fl_addr == FLASH_CACHE_INVALID_ADDR ) return; + if ( _fl_addr == FLASH_CACHE_INVALID_ADDR ) + return; - // skip the write if contents matches - if ( memcmp(_fl_buf, (void *) _fl_addr, FLASH_PAGE_SIZE) != 0 ) - { - // - nRF52832 dfu via uart can miss incoming byte when erasing because cpu is blocked for > 2ms. - // Since dfu_prepare_func_app_erase() already erase the page for us, we can skip it here. - // - nRF52840 dfu serial/uf2 are USB-based which are DMA and should have no problems. - // - // Note: MSC uf2 does not erase page in advance like dfu serial - if ( need_erase ) + // skip the write if contents matches + if ( memcmp(_fl_buf, (void *) _fl_addr, CODE_PAGE_SIZE) != 0 ) { - PRINTF("Erase and "); - nrfx_nvmc_page_erase(_fl_addr); + // - nRF52832 dfu via uart can miss incoming byte when erasing because cpu is blocked for > 2ms. + // Since dfu_prepare_func_app_erase() already erase the page for us, we can skip it here. + // - nRF52840 dfu serial/uf2 are USB-based which are DMA and should have no problems. + // + // Note: MSC uf2 does not erase page in advance like dfu serial + if ( need_erase ) + { + PRINTF("Erase and "); + nrfx_nvmc_page_erase(_fl_addr); + } + + PRINTF("Write 0x%08lX\r\n", _fl_addr); + nrfx_nvmc_words_write(_fl_addr, (uint32_t *) _fl_buf, CODE_PAGE_SIZE / 4); } - PRINTF("Write 0x%08lX\r\n", _fl_addr); - nrfx_nvmc_words_write(_fl_addr, (uint32_t *) _fl_buf, FLASH_PAGE_SIZE / 4); - } - - _fl_addr = FLASH_CACHE_INVALID_ADDR; + _fl_addr = FLASH_CACHE_INVALID_ADDR; } -void flash_nrf5x_write (uint32_t dst, void const *src, int len, bool need_erase) +void flash_nrf5x_write (uint32_t dst, void const *src, uint32_t len, bool need_erase) { - uint32_t newAddr = dst & ~(FLASH_PAGE_SIZE - 1); + // While something to write... + while (len > 0) { - if ( newAddr != _fl_addr ) - { - flash_nrf5x_flush(need_erase); - _fl_addr = newAddr; - memcpy(_fl_buf, (void *) newAddr, FLASH_PAGE_SIZE); - } - memcpy(_fl_buf + (dst & (FLASH_PAGE_SIZE - 1)), src, len); + // Align to start of page + uint32_t page_addr = dst & ~(CODE_PAGE_SIZE - 1); + + // If page changed, write modified contents + if ( page_addr != _fl_addr ) + { + flash_nrf5x_flush(need_erase); + + // Remember new page + _fl_addr = page_addr; + + // And read its contents + memcpy(_fl_buf, (void *) page_addr, CODE_PAGE_SIZE); + } + + // Compute the write offset into the current page + uint32_t offset_in_page = dst & (CODE_PAGE_SIZE - 1); + + // Compute how many bytes remaining to complete the page + uint32_t bytes_to_end = CODE_PAGE_SIZE - offset_in_page; + + // Limit the count to the available bytes in the current page + uint32_t max_bytes = bytes_to_end < len ? bytes_to_end : len; + + // Copy contents to our buffer + memcpy(_fl_buf + offset_in_page, src, max_bytes); + + // Update variables + len -= max_bytes; + dst += max_bytes; + src = (void const *) ((uint8_t*)src + max_bytes); + }; } diff --git a/src/flash_nrf5x.h b/src/flash_nrf5x.h index 9ab4619..d3fbb49 100644 --- a/src/flash_nrf5x.h +++ b/src/flash_nrf5x.h @@ -34,7 +34,8 @@ extern "C" { #endif -void flash_nrf5x_write (uint32_t dst, void const *src, int len, bool need_erase); +void flash_nrf5x_erase (uint32_t dst, uint32_t len); +void flash_nrf5x_write (uint32_t dst, void const *src, uint32_t len, bool need_erase); void flash_nrf5x_flush (bool need_erase); #ifdef __cplusplus From efe383d0905dafe9119d5834f31092759cb06f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 01:19:15 -0300 Subject: [PATCH 09/40] Add DFU mode exit timeout of 3 minutes. If the user enters DFU mode BUT does nothing, in about 3 minutes, the bootloader will exit and start executing the user application --- .../bootloader_dfu/dfu_bank_internal.h | 2 + .../bootloader_dfu/dfu_single_bank.c | 87 ++++++++++++++++++- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h index 03d20f6..f84d111 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_bank_internal.h @@ -40,6 +40,8 @@ typedef enum DFU_STATE_WAIT_4_ACTIVATE /**< State for: waiting for dfu_image_activate(). */ } dfu_state_t; +#define DFU_TIMEOUT_INTERVAL APP_TIMER_TICKS(360000) /**< DFU timeout interval in milliseconds. */ + #define IS_UPDATING_SD(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_SD) /**< Macro for determining if a SoftDevice update is ongoing. */ #define IS_UPDATING_BL(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_BL) /**< Macro for determining if a Bootloader update is ongoing. */ #define IS_UPDATING_APP(START_PKT) ((START_PKT).dfu_update_mode & DFU_UPDATE_APP) /**< Macro for determining if a Application update is ongoing. */ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index ee2d342..a01e0ba 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -35,6 +35,9 @@ static uint8_t m_init_packet[64]; /**< Init packet static uint8_t m_init_packet_length; /**< Length of init packet received. */ static uint16_t m_image_crc; /**< Calculated CRC of the image received. */ +APP_TIMER_DEF(m_dfu_timer_id); /**< Application timer id. */ +static bool m_dfu_timed_out = false; /**< Boolean flag value for tracking DFU timer timeout state. */ + static pstorage_handle_t m_storage_handle_app; /**< Pstorage handle for the application area (bank 0). Bank used when updating a SoftDevice w/wo bootloader. Handle also used when swapping received application from bank 1 to bank 0. */ static pstorage_handle_t * mp_storage_handle_active; /**< Pointer to the pstorage handle for the active bank for receiving of data packets. */ @@ -80,6 +83,47 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle, APP_ERROR_CHECK(result); } + +/**@brief Function for handling the DFU timeout. + * + * @param[in] p_context The timeout context. + */ +static void dfu_timeout_handler(void * p_context) +{ + UNUSED_PARAMETER(p_context); + dfu_update_status_t update_status; + + m_dfu_timed_out = true; + update_status.status_code = DFU_TIMEOUT; + + bootloader_dfu_update_process(update_status); +} + + +/**@brief Function for restarting the DFU Timer. + * + * @details This function will stop and restart the DFU timer. This function will be called by the + * functions handling any DFU packet received from the peer that is transferring a firmware + * image. + */ +static uint32_t dfu_timer_restart(void) +{ + if (m_dfu_timed_out) + { + // The DFU timer had already timed out. + return NRF_ERROR_INVALID_STATE; + } + + uint32_t err_code = app_timer_stop(m_dfu_timer_id); + APP_ERROR_CHECK(err_code); + + err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL); + APP_ERROR_CHECK(err_code); + + return err_code; +} + + /**@brief Function for preparing of flash before receiving SoftDevice image. * * @details This function will erase current application area to ensure sufficient amount of @@ -236,6 +280,16 @@ uint32_t dfu_init(void) m_storage_handle_app.block_id = DFU_BANK_0_REGION_START; + // Create the timer to monitor the activity by the peer doing the firmware update. + err_code = app_timer_create(&m_dfu_timer_id, + APP_TIMER_MODE_SINGLE_SHOT, + dfu_timeout_handler); + APP_ERROR_CHECK(err_code); + + // Start the DFU timer. + err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL); + APP_ERROR_CHECK(err_code); + m_data_received = 0; m_dfu_state = DFU_STATE_IDLE; @@ -251,6 +305,8 @@ void dfu_register_callback(dfu_callback_t callback_handler) uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) { + uint32_t err_code; + m_start_packet = *(p_packet->params.start_packet); // Check that the requested update procedure is supported. @@ -304,6 +360,10 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) if ( DFU_STATE_IDLE != m_dfu_state ) return NRF_ERROR_INVALID_STATE; + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + m_functions.prepare(m_image_size); return NRF_SUCCESS; @@ -346,6 +406,10 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) return NRF_ERROR_DATA_SIZE; } + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + p_data = (uint32_t *)p_packet->params.data_packet.p_data_packet; if ( is_ota() ) @@ -413,6 +477,7 @@ uint32_t dfu_init_pkt_complete(void) uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet) { + uint32_t err_code = NRF_SUCCESS; uint32_t length; switch (m_dfu_state) @@ -430,6 +495,10 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet) return NRF_ERROR_INVALID_STATE; } + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + length = p_packet->params.data_packet.packet_length * sizeof(uint32_t); if ((m_init_packet_length + length) > sizeof(m_init_packet)) { @@ -469,9 +538,16 @@ uint32_t dfu_image_validate() { m_dfu_state = DFU_STATE_VALIDATE; - err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, m_image_size); - VERIFY_SUCCESS(err_code); - m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE; + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + if (err_code == NRF_SUCCESS) + { + err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, + m_image_size); + VERIFY_SUCCESS(err_code); + + m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE; + } } break; @@ -491,6 +567,11 @@ uint32_t dfu_image_activate() switch (m_dfu_state) { case DFU_STATE_WAIT_4_ACTIVATE: + + // Stop the DFU Timer because the peer activity need not be monitored any longer. + err_code = app_timer_stop(m_dfu_timer_id); + APP_ERROR_CHECK(err_code); + err_code = m_functions.activate(); break; From 450ce3b3c6b0c480c34f60b62b994496626bba59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 01:22:12 -0300 Subject: [PATCH 10/40] Definitions for DUAL BANKED firmware updates (storing 2 copies of the firmware, so if a firmware update fails, the bootloader can revert to the previously working firmware) --- lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h index 4148e1c..f86a684 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h @@ -74,8 +74,12 @@ static inline bool is_sd_existed(void) #endif #define DFU_IMAGE_MAX_SIZE_FULL (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED) /**< Maximum size of an application, excluding save data from the application. */ +#define DFU_IMAGE_MAX_SIZE_BANKED (((DFU_IMAGE_MAX_SIZE_FULL) - \ + (DFU_IMAGE_MAX_SIZE_FULL % (2 * CODE_PAGE_SIZE)))/2) /**< Maximum size of an application, excluding save data from the application. */ + #define DFU_BL_IMAGE_MAX_SIZE (BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS - BOOTLOADER_REGION_START) /**< Maximum size of a bootloader, excluding save data from the current bootloader. */ #define DFU_BANK_0_REGION_START CODE_REGION_1_START /**< Bank 0 region start. */ +#define DFU_BANK_1_REGION_START (DFU_BANK_0_REGION_START + DFU_IMAGE_MAX_SIZE_BANKED) /**< Bank 1 region start. */ #define EMPTY_FLASH_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */ From 88eab38a6c8692c3a4902639148013373de1e303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 01:26:03 -0300 Subject: [PATCH 11/40] Allow flashing of a SINGLE BANK bootloader after a DUAL BANKED bootloader was installed. Without this patch, the SINGLE BANK bootloader will end in a continuous loop and no recovery without a JTAG programmer is possible --- .../bootloader_dfu/dfu_single_bank.c | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index a01e0ba..6017e1f 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -731,27 +731,38 @@ uint32_t dfu_bl_image_swap(void) return NRF_SUCCESS; } - uint32_t dfu_bl_image_validate(void) { bootloader_settings_t bootloader_settings; - sd_mbr_command_t sd_mbr_cmd; + + sd_mbr_command_t sd_mbr_cmd_1; + sd_mbr_command_t sd_mbr_cmd_2; bootloader_settings_get(&bootloader_settings); if (bootloader_settings.bl_image_size != 0) { - uint32_t bl_image_start = (bootloader_settings.sd_image_size == 0) ? + uint32_t bl_image_start_1 = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_0_REGION_START : bootloader_settings.sd_image_start + bootloader_settings.sd_image_size; - sd_mbr_cmd.command = SD_MBR_COMMAND_COMPARE; - sd_mbr_cmd.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; - sd_mbr_cmd.params.compare.ptr2 = (uint32_t *)(bl_image_start); - sd_mbr_cmd.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + sd_mbr_cmd_1.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd_1.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; + sd_mbr_cmd_1.params.compare.ptr2 = (uint32_t *)(bl_image_start_1); + sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); - return sd_mbr_command(&sd_mbr_cmd); + uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? + DFU_BANK_1_REGION_START : + bootloader_settings.sd_image_start + + bootloader_settings.sd_image_size; + + sd_mbr_cmd_2.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd_2.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; + sd_mbr_cmd_2.params.compare.ptr2 = (uint32_t *)(bl_image_start_2); + sd_mbr_cmd_2.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + + return sd_mbr_command(&sd_mbr_cmd_1) && sd_mbr_command(&sd_mbr_cmd_2); } return NRF_SUCCESS; } From d8c27bb7fd9dd0a167af2437431964bcfbb97568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 01:31:36 -0300 Subject: [PATCH 12/40] If there is no application in FLASH, or flash was corrupted, make sure to restart in DFU mode --- src/main.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 0011640..1111220 100644 --- a/src/main.c +++ b/src/main.c @@ -48,7 +48,10 @@ #include "nrf_soc.h" #include "nrf_nvic.h" #include "app_error.h" +#include "nrf_gpio.h" #include "ble.h" +#include "nrf.h" +#include "ble_hci.h" #include "app_scheduler.h" #include "nrf_error.h" @@ -56,10 +59,13 @@ #include "pstorage_platform.h" #include "nrf_mbr.h" +#include "pstorage.h" +#include "nrfx_nvmc.h" #ifdef NRF_USBD #include "uf2/uf2.h" +#include "nrf_usbd.h" #include "tusb.h" void usb_init(bool cdc_only); @@ -218,6 +224,9 @@ int main(void) { bootloader_app_start(); } + // No application was loaded, reset the system with the OTA DFU update + NRF_POWER->GPREGRET = 0xA8; + NVIC_SystemReset(); } @@ -242,17 +251,14 @@ static void check_dfu_mode(void) { (((*dbl_reset_mem) == DFU_DBL_RESET_MAGIC) && reason_reset_pin); // Clear GPREGRET if it is our values - if (dfu_start || dfu_skip) { - NRF_POWER->GPREGRET = 0; - } + if (dfu_start || dfu_skip) NRF_POWER->GPREGRET = 0; // skip dfu entirely - if (dfu_skip) { - return; - } + if (dfu_skip) return; /*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/ - dfu_start = dfu_start || button_pressed(BUTTON_DFU); // DFU button pressed + // DFU button pressed + dfu_start = dfu_start || button_pressed(BUTTON_DFU); // DFU + FRESET are pressed --> OTA _ota_dfu = _ota_dfu || (button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET)); @@ -260,16 +266,16 @@ static void check_dfu_mode(void) { bool const valid_app = bootloader_app_is_valid(); bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP; - if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) { - dfu_start = 1; - } + if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) dfu_start = 1; // App mode: Double Reset detection or DFU startup for nrf52832 if (!(just_start_app || dfu_start || !valid_app)) { #ifdef NRF52832_XXAA /* Even DFU is not active, we still force an 1000 ms dfu serial mode when startup * to support auto programming from Arduino IDE - * Note: Double Reset WONT work with nrf52832 since all its SRAM got cleared with GPIO reset. */ + * + * Note: Double Reset WONT work with nrf52832 since all its SRAM got cleared with GPIO reset. + */ bootloader_dfu_start(false, DFU_SERIAL_STARTUP_INTERVAL, false); #else // Note: RESETREAS is not clear by bootloader, it should be cleared by application upon init() From f20bfe9f633bd7aa209a2a84c36d9866f3a144f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 01:40:51 -0300 Subject: [PATCH 13/40] Add DUAL_BANK functionality (disabled by default, can be enabled passing DUAL_BANK=1 to the Makefile in the make command line --- Makefile | 13 +- .../libraries/bootloader_dfu/dfu_dual_bank.c | 891 ++++++++++++++++++ src/main.c | 5 + 3 files changed, 905 insertions(+), 4 deletions(-) create mode 100644 lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c diff --git a/Makefile b/Makefile index dba3c83..48a4d4d 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ #------------------------------------------------------------------------------ # CONFIGURE -# - SDK_PATH : path to SDK directory +# - SDK_PATH : path to SDK directory # -# - SD_NAME : e.g s132, s140 -# - SD_VERSION : SoftDevice version e.g 6.0.0 -# - SD_HEX : to bootloader hex binary +# - SD_NAME : e.g s132, s140 +# - SD_VERSION : SoftDevice version e.g 6.0.0 +# - SD_HEX : to bootloader hex binary +# - DUALBANK_FW : If bootloader will implement a dual bank feature to allow autorecover from failed #------------------------------------------------------------------------------ # local customization @@ -163,7 +164,11 @@ C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_settings.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/bootloader_util.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_serial.c C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_transport_ble.c +ifeq ($(DUALBANK_FW), 1) +C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_dual_bank.c +else C_SRC += $(SDK11_PATH)/libraries/bootloader_dfu/dfu_single_bank.c +endif C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dfu/ble_dfu.c C_SRC += $(SDK11_PATH)/ble/ble_services/ble_dis/ble_dis.c C_SRC += $(SDK11_PATH)/drivers_nrf/pstorage/pstorage_raw.c diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c new file mode 100644 index 0000000..4516e4f --- /dev/null +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c @@ -0,0 +1,891 @@ +/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +#include +#include "dfu.h" +#include +#include "dfu_bank_internal.h" +#include "nrf.h" +#include "nrf_sdm.h" +#include "app_error.h" +#include "app_timer.h" +#include "bootloader.h" +#include "bootloader_types.h" +#include "pstorage.h" +#include "nrf_mbr.h" +#include "dfu_init.h" +#include "sdk_common.h" + +static dfu_state_t m_dfu_state; /**< Current DFU state. */ +static uint32_t m_image_size; /**< Size of the image that will be transmitted. */ + +static dfu_start_packet_t m_start_packet; /**< Start packet received for this update procedure. Contains update mode and image sizes information to be used for image transfer. */ +static uint8_t m_init_packet[128]; /**< Init packet, can hold CRC, Hash, Signed Hash and similar, for image validation, integrety check and authorization checking. */ +static uint8_t m_init_packet_length; /**< Length of init packet received. */ +static uint16_t m_image_crc; /**< Calculated CRC of the image received. */ + +APP_TIMER_DEF(m_dfu_timer_id); /**< Application timer id. */ +static bool m_dfu_timed_out = false; /**< Boolean flag value for tracking DFU timer timeout state. */ + +static pstorage_handle_t m_storage_handle_swap; /**< Pstorage handle for the swap area (bank 1). Bank used when updating an application or bootloader without SoftDevice. */ +static pstorage_handle_t m_storage_handle_app; /**< Pstorage handle for the application area (bank 0). Bank used when updating a SoftDevice w/wo bootloader. Handle also used when swapping received application from bank 1 to bank 0. */ +static pstorage_handle_t * mp_storage_handle_active; /**< Pointer to the pstorage handle for the active bank for receiving of data packets. */ + +static dfu_callback_t m_data_pkt_cb; /**< Callback from DFU Bank module for notification of asynchronous operation such as flash prepare. */ +static dfu_bank_func_t m_functions; /**< Structure holding operations for the selected update process. */ + + +/**@brief Function for handling callbacks from pstorage module. + * + * @details Handles pstorage results for clear and storage operation. For detailed description of + * the parameters provided with the callback, please refer to \ref pstorage_ntf_cb_t. + */ +static void pstorage_callback_handler(pstorage_handle_t * p_handle, + uint8_t op_code, + uint32_t result, + uint8_t * p_data, + uint32_t data_len) +{ + switch (op_code) + { + case PSTORAGE_STORE_OP_CODE: + if ((m_dfu_state == DFU_STATE_RX_DATA_PKT) && (m_data_pkt_cb != NULL)) + { + m_data_pkt_cb(DATA_PACKET, result, p_data); + } + break; + + case PSTORAGE_CLEAR_OP_CODE: + if (m_dfu_state == DFU_STATE_PREPARING) + { + m_functions.cleared(); + m_dfu_state = DFU_STATE_RDY; + if (m_data_pkt_cb != NULL) + { + m_data_pkt_cb(START_PACKET, result, p_data); + } + } + break; + + default: + break; + } + APP_ERROR_CHECK(result); +} + + +/**@brief Function for handling the DFU timeout. + * + * @param[in] p_context The timeout context. + */ +static void dfu_timeout_handler(void * p_context) +{ + UNUSED_PARAMETER(p_context); + dfu_update_status_t update_status = {0}; + + m_dfu_timed_out = true; + update_status.status_code = DFU_TIMEOUT; + + bootloader_dfu_update_process(update_status); +} + + +/**@brief Function for restarting the DFU Timer. + * + * @details This function will stop and restart the DFU timer. This function will be called by the + * functions handling any DFU packet received from the peer that is transferring a firmware + * image. + */ +static uint32_t dfu_timer_restart(void) +{ + if (m_dfu_timed_out) + { + // The DFU timer had already timed out. + return NRF_ERROR_INVALID_STATE; + } + + uint32_t err_code = app_timer_stop(m_dfu_timer_id); + APP_ERROR_CHECK(err_code); + + err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL); + APP_ERROR_CHECK(err_code); + + return err_code; +} + + +/**@brief Function for preparing of flash before receiving SoftDevice image. + * + * @details This function will erase current application area to ensure sufficient amount of + * storage for the SoftDevice image. Upon erase complete a callback will be done. + * See \ref dfu_bank_prepare_t for further details. + */ +static void dfu_prepare_func_app_erase(uint32_t image_size) +{ + mp_storage_handle_active = &m_storage_handle_app; + + // Doing a SoftDevice update thus current application must be cleared to ensure enough space + // for new SoftDevice. + m_dfu_state = DFU_STATE_PREPARING; + + if ( is_ota() ) + { + uint32_t err_code = pstorage_clear(&m_storage_handle_app, m_image_size); + APP_ERROR_CHECK(err_code); + } + else + { + flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_image_size); + + // invoke complete callback + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + } +} + + +/**@brief Function for preparing swap before receiving application or bootloader image. + * + * @details This function will erase current swap area to ensure flash is ready for storage of the + * Application or Bootloader image. Upon erase complete a callback will be done. + * See \ref dfu_bank_prepare_t for further details. + */ +static void dfu_prepare_func_swap_erase(uint32_t image_size) +{ + mp_storage_handle_active = &m_storage_handle_swap; + + m_dfu_state = DFU_STATE_PREPARING; + + if ( is_ota() ) + { + uint32_t err_code = pstorage_clear(&m_storage_handle_swap, image_size); + APP_ERROR_CHECK(err_code); + } + else + { + flash_nrf5x_erase(DFU_BANK_1_REGION_START, image_size); + + // invoke complete callback + pstorage_callback_handler(&m_storage_handle_swap, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + } +} + + +/**@brief Function for handling behaviour when clear operation has completed. + */ +static void dfu_cleared_func_swap(void) +{ + // Do nothing. +} + + +/**@brief Function for handling behaviour when clear operation has completed. + */ +static void dfu_cleared_func_app(void) +{ + dfu_update_status_t update_status = { 0 }; + update_status.status_code = DFU_BANK_0_ERASED; + bootloader_dfu_update_process(update_status); +} + + +/**@brief Function for calculating storage offset for receiving SoftDevice image. + * + * @details When a new SoftDevice is received it will be temporary stored in flash before moved to + * address 0x0. In order to succesfully validate transfer and relocation it is important + * that temporary image and final installed image does not ovwerlap hence an offset must + * be calculated in case new image is larger than currently installed SoftDevice. + */ +uint32_t offset_calculate(uint32_t sd_image_size) +{ + uint32_t offset = 0; + + if (m_start_packet.sd_image_size > DFU_BANK_0_REGION_START) + { + uint32_t page_mask = (CODE_PAGE_SIZE - 1); + uint32_t diff = m_start_packet.sd_image_size - DFU_BANK_0_REGION_START; + + offset = diff & ~page_mask; + + // Align offset to next page if image size is not page sized. + if ((diff & page_mask) > 0) + { + offset += CODE_PAGE_SIZE; + } + } + + return offset; +} + + +/**@brief Function for activating received SoftDevice image. + * + * @note This function will not move the SoftDevice image. + * The bootloader settings will be marked as SoftDevice update complete and the swapping of + * current SoftDevice will occur after system reset. + * + * @return NRF_SUCCESS on success. + */ +static uint32_t dfu_activate_sd(void) +{ + dfu_update_status_t update_status = {0}; + + update_status.status_code = DFU_UPDATE_SD_COMPLETE; + update_status.app_crc = m_image_crc; + update_status.sd_image_start = DFU_BANK_0_REGION_START; + update_status.sd_size = m_start_packet.sd_image_size; + update_status.bl_size = m_start_packet.bl_image_size; + update_status.app_size = m_start_packet.app_image_size; + + bootloader_dfu_update_process(update_status); + + return NRF_SUCCESS; +} + + +/**@brief Function for activating received Application image. + * + * @details This function will move the received application image fram swap (bank 1) to + * application area (bank 0). + * + * @return NRF_SUCCESS on success. Error code otherwise. + */ +static uint32_t dfu_activate_app(void) +{ + uint32_t err_code = NRF_SUCCESS; + + // Erase BANK 0. + if ( is_ota() ) + { + err_code = pstorage_clear(&m_storage_handle_app, m_start_packet.app_image_size); + APP_ERROR_CHECK(err_code); + + err_code = pstorage_store(&m_storage_handle_app, + (uint8_t *)m_storage_handle_swap.block_id, + m_start_packet.app_image_size, + 0); + } + else + { + flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_start_packet.app_image_size); + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + + flash_nrf5x_write(DFU_BANK_0_REGION_START, (uint8_t *)DFU_BANK_1_REGION_START, m_start_packet.app_image_size, false); + flash_nrf5x_flush(false); + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) DFU_BANK_1_REGION_START, m_start_packet.app_image_size); + } + + if (err_code == NRF_SUCCESS) + { + dfu_update_status_t update_status = { 0 }; + + memset(&update_status, 0, sizeof(dfu_update_status_t )); + update_status.status_code = DFU_UPDATE_APP_COMPLETE; + update_status.app_crc = m_image_crc; + update_status.app_size = m_start_packet.app_image_size; + + bootloader_dfu_update_process(update_status); + } + + return err_code; +} + + +/**@brief Function for activating received Bootloader image. + * + * @note This function will not move the bootloader image. + * The bootloader settings will be marked as Bootloader update complete and the swapping of + * current bootloader will occur after system reset. + * + * @return NRF_SUCCESS on success. + */ +static uint32_t dfu_activate_bl(void) +{ + dfu_update_status_t update_status = {0}; + + update_status.status_code = DFU_UPDATE_BOOT_COMPLETE; + update_status.app_crc = m_image_crc; + update_status.sd_size = m_start_packet.sd_image_size; + update_status.bl_size = m_start_packet.bl_image_size; + update_status.app_size = m_start_packet.app_image_size; + + bootloader_dfu_update_process(update_status); + + return NRF_SUCCESS; +} + + +uint32_t dfu_init(void) +{ + uint32_t err_code; + pstorage_module_param_t storage_module_param = {.cb = pstorage_callback_handler}; + + m_init_packet_length = 0; + m_image_crc = 0; + + err_code = pstorage_register(&storage_module_param, &m_storage_handle_app); + if (err_code != NRF_SUCCESS) + { + m_dfu_state = DFU_STATE_INIT_ERROR; + return err_code; + } + + m_storage_handle_app.block_id = DFU_BANK_0_REGION_START; + m_storage_handle_swap = m_storage_handle_app; + m_storage_handle_swap.block_id = DFU_BANK_1_REGION_START; + + // Create the timer to monitor the activity by the peer doing the firmware update. + err_code = app_timer_create(&m_dfu_timer_id, + APP_TIMER_MODE_SINGLE_SHOT, + dfu_timeout_handler); + APP_ERROR_CHECK(err_code); + + // Start the DFU timer. + err_code = app_timer_start(m_dfu_timer_id, DFU_TIMEOUT_INTERVAL, NULL); + APP_ERROR_CHECK(err_code); + + m_data_received = 0; + m_dfu_state = DFU_STATE_IDLE; + + return NRF_SUCCESS; +} + + +void dfu_register_callback(dfu_callback_t callback_handler) +{ + m_data_pkt_cb = callback_handler; +} + + +uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) +{ + uint32_t err_code; + + m_start_packet = *(p_packet->params.start_packet); + + // Check that the requested update procedure is supported. + // Currently the following combinations are allowed: + // - Application + // - SoftDevice + // - Bootloader + // - SoftDevice with Bootloader + if (IS_UPDATING_APP(m_start_packet) && + (IS_UPDATING_SD(m_start_packet) || IS_UPDATING_BL(m_start_packet))) + { + // App update is only supported independently. + return NRF_ERROR_NOT_SUPPORTED; + } + + if (!(IS_WORD_SIZED(m_start_packet.sd_image_size) && + IS_WORD_SIZED(m_start_packet.bl_image_size) && + IS_WORD_SIZED(m_start_packet.app_image_size))) + { + // Image_sizes are not a multiple of 4 (word size). + return NRF_ERROR_NOT_SUPPORTED; + } + + m_image_size = m_start_packet.sd_image_size + m_start_packet.bl_image_size + + m_start_packet.app_image_size; + + if (m_start_packet.bl_image_size > DFU_BL_IMAGE_MAX_SIZE) + { + return NRF_ERROR_DATA_SIZE; + } + + if (IS_UPDATING_SD(m_start_packet)) + { + if (m_image_size > (DFU_IMAGE_MAX_SIZE_FULL)) + { + return NRF_ERROR_DATA_SIZE; + } + m_functions.prepare = dfu_prepare_func_app_erase; + m_functions.cleared = dfu_cleared_func_app; + m_functions.activate = dfu_activate_sd; + } + else + { + if (m_image_size > DFU_IMAGE_MAX_SIZE_BANKED) + { + return NRF_ERROR_DATA_SIZE; + } + + m_functions.prepare = dfu_prepare_func_swap_erase; + m_functions.cleared = dfu_cleared_func_swap; + if (IS_UPDATING_BL(m_start_packet)) + { + m_functions.activate = dfu_activate_bl; + } + else + { + m_functions.activate = dfu_activate_app; + } + } + + if ( DFU_STATE_IDLE != m_dfu_state ) + return NRF_ERROR_INVALID_STATE; + + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + + m_functions.prepare(m_image_size); + + return NRF_SUCCESS; +} + + +uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) +{ + uint32_t data_length; + uint32_t err_code; + uint32_t * p_data; + + VERIFY_PARAM_NOT_NULL(p_packet); + + // Check pointer alignment. + if (!is_word_aligned(p_packet->params.data_packet.p_data_packet)) + { + // The p_data_packet is not word aligned address. + return NRF_ERROR_INVALID_ADDR; + } + + switch (m_dfu_state) + { + case DFU_STATE_RDY: + case DFU_STATE_RX_INIT_PKT: + return NRF_ERROR_INVALID_STATE; + + case DFU_STATE_RX_DATA_PKT: + data_length = p_packet->params.data_packet.packet_length * sizeof(uint32_t); + + if ((m_data_received + data_length) > m_image_size) + { + // The caller is trying to write more bytes into the flash than the size provided to + // the dfu_image_size_set function. This is treated as a serious error condition and + // an unrecoverable one. Hence point the variable mp_app_write_address to the top of + // the flash area. This will ensure that all future application data packet writes + // will be blocked because of the above check. + m_data_received = 0xFFFFFFFF; + + return NRF_ERROR_DATA_SIZE; + } + + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + + p_data = (uint32_t *)p_packet->params.data_packet.p_data_packet; + + if ( is_ota() ) + { + err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); + VERIFY_SUCCESS(err_code); + } + else + { + flash_nrf5x_write( + (mp_storage_handle_active == &m_storage_handle_app + ? DFU_BANK_0_REGION_START + : DFU_BANK_1_REGION_START) + + m_data_received, p_data, data_length, false); + pstorage_callback_handler(mp_storage_handle_active, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_data, data_length); + } + + m_data_received += data_length; + + if (m_data_received != m_image_size) + { + // The entire image is not received yet. More data is expected. + err_code = NRF_ERROR_INVALID_LENGTH; + } + else + { + if ( !is_ota() ) flash_nrf5x_flush(false); + + // The entire image has been received. Return NRF_SUCCESS. + err_code = NRF_SUCCESS; + } + break; + + default: + err_code = NRF_ERROR_INVALID_STATE; + break; + } + + return err_code; +} + + +uint32_t dfu_init_pkt_complete(void) +{ + uint32_t err_code = NRF_ERROR_INVALID_STATE; + + // DFU initialization has been done and a start packet has been received. + if (IMAGE_WRITE_IN_PROGRESS()) + { + // Image write is already in progress. Cannot handle an init packet now. + return NRF_ERROR_INVALID_STATE; + } + + if (m_dfu_state == DFU_STATE_RX_INIT_PKT) + { + err_code = dfu_init_prevalidate(m_init_packet, m_init_packet_length, m_start_packet.dfu_update_mode); + if (err_code == NRF_SUCCESS) + { + m_dfu_state = DFU_STATE_RX_DATA_PKT; + } + else + { + m_init_packet_length = 0; + } + } + return err_code; +} + + +uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet) +{ + uint32_t err_code = NRF_SUCCESS; + uint32_t length; + + switch (m_dfu_state) + { + case DFU_STATE_RDY: + m_dfu_state = DFU_STATE_RX_INIT_PKT; + // When receiving init packet in state ready just update and fall through this case. + /* FALLTHRU */ + + case DFU_STATE_RX_INIT_PKT: + // DFU initialization has been done and a start packet has been received. + if (IMAGE_WRITE_IN_PROGRESS()) + { + // Image write is already in progress. Cannot handle an init packet now. + return NRF_ERROR_INVALID_STATE; + } + + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + + length = p_packet->params.data_packet.packet_length * sizeof(uint32_t); + if ((m_init_packet_length + length) > sizeof(m_init_packet)) + { + return NRF_ERROR_INVALID_LENGTH; + } + + memcpy(&m_init_packet[m_init_packet_length], + &p_packet->params.data_packet.p_data_packet[0], + length); + m_init_packet_length += length; + break; + + default: + // Either the start packet was not received or dfu_init function was not called before. + return NRF_ERROR_INVALID_STATE; + } + + return NRF_SUCCESS; +} + + +uint32_t dfu_image_validate() +{ + uint32_t err_code; + + switch (m_dfu_state) + { + case DFU_STATE_RX_DATA_PKT: + // Check if the application image write has finished. + if (m_data_received != m_image_size) + { + // Image not yet fully transfered by the peer or the peer has attempted to write + // too much data. Hence the validation should fail. + err_code = NRF_ERROR_INVALID_STATE; + } + else + { + m_dfu_state = DFU_STATE_VALIDATE; + + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + if (err_code == NRF_SUCCESS) + { + err_code = dfu_init_postvalidate((uint8_t *)mp_storage_handle_active->block_id, + m_image_size); + VERIFY_SUCCESS(err_code); + + m_dfu_state = DFU_STATE_WAIT_4_ACTIVATE; + } + } + break; + + default: + err_code = NRF_ERROR_INVALID_STATE; + break; + } + + return err_code; +} + + +uint32_t dfu_image_activate() +{ + uint32_t err_code; + + switch (m_dfu_state) + { + case DFU_STATE_WAIT_4_ACTIVATE: + + // Stop the DFU Timer because the peer activity need not be monitored any longer. + err_code = app_timer_stop(m_dfu_timer_id); + APP_ERROR_CHECK(err_code); + + err_code = m_functions.activate(); + break; + + default: + err_code = NRF_ERROR_INVALID_STATE; + break; + } + + return err_code; +} + + +void dfu_reset(void) +{ + dfu_update_status_t update_status = { 0 }; + + update_status.status_code = DFU_RESET; + + bootloader_dfu_update_process(update_status); +} + + +static uint32_t dfu_compare_block(uint32_t * ptr1, uint32_t * ptr2, uint32_t len) +{ + sd_mbr_command_t sd_mbr_cmd; + + sd_mbr_cmd.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd.params.compare.ptr1 = ptr1; + sd_mbr_cmd.params.compare.ptr2 = ptr2; + sd_mbr_cmd.params.compare.len = len / sizeof(uint32_t); + + return sd_mbr_command(&sd_mbr_cmd); +} + + +static uint32_t dfu_copy_sd(uint32_t * src, uint32_t * dst, uint32_t len) +{ + sd_mbr_command_t sd_mbr_cmd; + + sd_mbr_cmd.command = SD_MBR_COMMAND_COPY_SD; + sd_mbr_cmd.params.copy_sd.src = src; + sd_mbr_cmd.params.copy_sd.dst = dst; + sd_mbr_cmd.params.copy_sd.len = len / sizeof(uint32_t); + + return sd_mbr_command(&sd_mbr_cmd); +} + + +static uint32_t dfu_sd_img_block_swap(uint32_t * src, + uint32_t * dst, + uint32_t len, + uint32_t block_size) +{ + // It is neccesarry to swap the new SoftDevice in 3 rounds to ensure correct copy of data + // and verifucation of data in case power reset occurs during write to flash. + // To ensure the robustness of swapping the images are compared backwards till start of + // image swap. If the back is identical everything is swapped. + uint32_t err_code = dfu_compare_block(src, dst, len); + if (err_code == NRF_SUCCESS) + { + return err_code; + } + + if ((uint32_t)dst > SOFTDEVICE_REGION_START) + { + err_code = dfu_sd_img_block_swap((uint32_t *)((uint32_t)src - block_size), + (uint32_t *)((uint32_t)dst - block_size), + block_size, + block_size); + VERIFY_SUCCESS(err_code); + } + + err_code = dfu_copy_sd(src, dst, len); + VERIFY_SUCCESS(err_code); + + return dfu_compare_block(src, dst, len); +} + + +uint32_t dfu_sd_image_swap(void) +{ + bootloader_settings_t boot_settings; + + bootloader_settings_get(&boot_settings); + + if (boot_settings.sd_image_size == 0) + { + return NRF_SUCCESS; + } + + if ((SOFTDEVICE_REGION_START + boot_settings.sd_image_size) > boot_settings.sd_image_start) + { + uint32_t err_code; + uint32_t sd_start = SOFTDEVICE_REGION_START; + uint32_t block_size = (boot_settings.sd_image_start - sd_start) / 2; + + /* ##### FIX START ##### */ + block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); + /* ##### FIX END ##### */ + + uint32_t image_end = boot_settings.sd_image_start + boot_settings.sd_image_size; + + uint32_t img_block_start = boot_settings.sd_image_start + 2 * block_size; + uint32_t sd_block_start = sd_start + 2 * block_size; + + if (SD_SIZE_GET(MBR_SIZE) < boot_settings.sd_image_size) + { + // This will clear a page thus ensuring the old image is invalidated before swapping. + err_code = dfu_copy_sd((uint32_t *)(sd_start + block_size), + (uint32_t *)(sd_start + block_size), + sizeof(uint32_t)); + VERIFY_SUCCESS(err_code); + + err_code = dfu_copy_sd((uint32_t *)sd_start, (uint32_t *)sd_start, sizeof(uint32_t)); + VERIFY_SUCCESS(err_code); + } + + return dfu_sd_img_block_swap((uint32_t *)img_block_start, + (uint32_t *)sd_block_start, + image_end - img_block_start, + block_size); + } + else + { + if (boot_settings.sd_image_size != 0) + { + return dfu_copy_sd((uint32_t *)boot_settings.sd_image_start, + (uint32_t *)SOFTDEVICE_REGION_START, + boot_settings.sd_image_size); + } + } + + return NRF_SUCCESS; +} + + +uint32_t dfu_bl_image_swap(void) +{ + bootloader_settings_t bootloader_settings; + sd_mbr_command_t sd_mbr_cmd; + + bootloader_settings_get(&bootloader_settings); + + if (bootloader_settings.bl_image_size != 0) + { + uint32_t bl_image_start = (bootloader_settings.sd_image_size == 0) ? + DFU_BANK_1_REGION_START : + bootloader_settings.sd_image_start + + bootloader_settings.sd_image_size; + + sd_mbr_cmd.command = SD_MBR_COMMAND_COPY_BL; + sd_mbr_cmd.params.copy_bl.bl_src = (uint32_t *)(bl_image_start); + sd_mbr_cmd.params.copy_bl.bl_len = bootloader_settings.bl_image_size / sizeof(uint32_t); + + return sd_mbr_command(&sd_mbr_cmd); + } + return NRF_SUCCESS; +} + + +uint32_t dfu_bl_image_validate(void) +{ + bootloader_settings_t bootloader_settings;\ + + sd_mbr_command_t sd_mbr_cmd_1; + sd_mbr_command_t sd_mbr_cmd_2; + + bootloader_settings_get(&bootloader_settings); + + if (bootloader_settings.bl_image_size != 0) + { + uint32_t bl_image_start_1 = (bootloader_settings.sd_image_size == 0) ? + DFU_BANK_0_REGION_START : + bootloader_settings.sd_image_start + + bootloader_settings.sd_image_size; + + sd_mbr_cmd_1.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd_1.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; + sd_mbr_cmd_1.params.compare.ptr2 = (uint32_t *)(bl_image_start_1); + sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + + uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? + DFU_BANK_1_REGION_START : + bootloader_settings.sd_image_start + + bootloader_settings.sd_image_size; + + sd_mbr_cmd_2.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd_2.params.compare.ptr1 = (uint32_t *)BOOTLOADER_REGION_START; + sd_mbr_cmd_2.params.compare.ptr2 = (uint32_t *)(bl_image_start_2); + sd_mbr_cmd_2.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + + return sd_mbr_command(&sd_mbr_cmd_1) && sd_mbr_command(&sd_mbr_cmd_2); + } + return NRF_SUCCESS; +} + + +uint32_t dfu_sd_image_validate(void) +{ + bootloader_settings_t bootloader_settings; + sd_mbr_command_t sd_mbr_cmd; + + bootloader_settings_get(&bootloader_settings); + + if (bootloader_settings.sd_image_size == 0) + { + return NRF_SUCCESS; + } + + if ((SOFTDEVICE_REGION_START + bootloader_settings.sd_image_size) > bootloader_settings.sd_image_start) + { + uint32_t sd_start = SOFTDEVICE_REGION_START; + uint32_t block_size = (bootloader_settings.sd_image_start - sd_start) / 2; + uint32_t image_end = bootloader_settings.sd_image_start + + bootloader_settings.sd_image_size; + + /* ##### FIX START ##### */ + block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); + /* ##### FIX END ##### */ + + uint32_t img_block_start = bootloader_settings.sd_image_start + 2 * block_size; + uint32_t sd_block_start = sd_start + 2 * block_size; + + if (SD_SIZE_GET(MBR_SIZE) < bootloader_settings.sd_image_size) + { + return NRF_ERROR_NULL; + } + + return dfu_sd_img_block_swap((uint32_t *)img_block_start, + (uint32_t *)sd_block_start, + image_end - img_block_start, + block_size); + } + + sd_mbr_cmd.command = SD_MBR_COMMAND_COMPARE; + sd_mbr_cmd.params.compare.ptr1 = (uint32_t *)SOFTDEVICE_REGION_START; + sd_mbr_cmd.params.compare.ptr2 = (uint32_t *)bootloader_settings.sd_image_start; + sd_mbr_cmd.params.compare.len = bootloader_settings.sd_image_size / sizeof(uint32_t); + + return sd_mbr_command(&sd_mbr_cmd); +} diff --git a/src/main.c b/src/main.c index 1111220..3909651 100644 --- a/src/main.c +++ b/src/main.c @@ -39,8 +39,13 @@ #include #include "nrfx.h" +#include "nrf_clock.h" #include "nrfx_power.h" +#include "nrfx_pwm.h" + +#include "nordic_common.h" #include "sdk_common.h" +#include "dfu_transport.h" #include "bootloader.h" #include "bootloader_util.h" From c8af92c4d8af6ea6836025b36e0552078d399b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 01:53:57 -0300 Subject: [PATCH 14/40] Implement signed firmware verification: If enabled (Disabled by default), the bootloader will reject and not flash any firmware that is not digitally signed with the proper key --- .gitmodules | 3 + Makefile | 49 ++- .../bootloader_dfu/dfu_single_bank.c | 2 +- src/dfu_init.c | 287 ++++++++++++------ src/main.c | 4 + src/usb/tusb_config.h | 2 + src/usb/usb.c | 2 + src/usb/usb_desc.c | 16 + 8 files changed, 269 insertions(+), 96 deletions(-) diff --git a/.gitmodules b/.gitmodules index bd80adc..f8d4023 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,3 +8,6 @@ path = lib/uf2 url = https://github.com/microsoft/uf2.git +[submodule "lib/tinycrypt"] + path = lib/tinycrypt + url = https://github.com/intel/tinycrypt diff --git a/Makefile b/Makefile index 48a4d4d..45dc1df 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,15 @@ # - SD_NAME : e.g s132, s140 # - SD_VERSION : SoftDevice version e.g 6.0.0 # - SD_HEX : to bootloader hex binary +# - SIGNED_FW : if bootloader will ONLY accept signed firmware +# - SIGNED_FW_QX : Qx for signed firmware verification +# - SIGNED_FW_QY : Qy for signed firmware verification # - DUALBANK_FW : If bootloader will implement a dual bank feature to allow autorecover from failed +# - FORCE_UF2 : if SIGNED_FW is 1, will force to include UF2 support (UNSECURE, UF2 does NOT validate signature!) #------------------------------------------------------------------------------ +PYTHON = python + # local customization -include Makefile.user @@ -17,6 +23,7 @@ SDK_PATH = lib/sdk/components SDK11_PATH = lib/sdk11/components TUSB_PATH = lib/tinyusb/src +TCRYPT_PATH = lib/tinycrypt/lib NRFX_PATH = lib/nrfx SD_PATH = lib/softdevice/$(SD_FILENAME) @@ -150,6 +157,15 @@ C_SRC += \ src/screen.c \ src/images.c \ +# if using a signed firmware +ifeq ($(SIGNED_FW), 1) +C_SRC += \ + $(TCRYPT_PATH)/source/sha256.c \ + $(TCRYPT_PATH)/source/ecc.c \ + $(TCRYPT_PATH)/source/ecc_dsa.c \ + $(TCRYPT_PATH)/source/utils.c +endif + # all files in boards C_SRC += src/boards/boards.c @@ -202,10 +218,10 @@ C_SRC += src/boards/$(BOARD)/pinconfig.c # USB Application ( MSC + UF2 ) C_SRC += \ - src/usb/msc_uf2.c \ src/usb/usb_desc.c \ - src/usb/usb.c \ - src/usb/uf2/ghostfat.c + src/usb/msc_uf2.c \ + src/usb/uf2/ghostfat.c \ + src/usb/usb.c # TinyUSB stack C_SRC += \ @@ -216,9 +232,9 @@ C_SRC += \ $(TUSB_PATH)/class/cdc/cdc_device.c \ $(TUSB_PATH)/class/msc/msc_device.c \ $(TUSB_PATH)/tusb.c - endif + #------------------------------------------------------------------------------ # Assembly Files #------------------------------------------------------------------------------ @@ -236,6 +252,11 @@ IPATH += \ src/cmsis/include \ src/usb \ $(TUSB_PATH) + +ifeq ($(SIGNED_FW), 1) +IPATH += \ + $(TCRYPT_PATH)/include +endif # nrfx IPATH += \ @@ -331,6 +352,16 @@ CFLAGS += -DSOFTDEVICE_PRESENT CFLAGS += -DUF2_VERSION='"$(GIT_VERSION)"' CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"' +ifeq ($(SIGNED_FW), 1) +CFLAGS += -DSIGNED_FW +CFLAGS += -DSIGNED_FW_QX='$(SIGNED_FW_QX)' +CFLAGS += -DSIGNED_FW_QY='$(SIGNED_FW_QY)' +endif + +ifeq ($(FORCE_UF2), 1) +CFLAGS += -DFORCE_UF2 +endif + _VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION)))) CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)) << 8) + $(word 3,$(_VER))' @@ -354,9 +385,9 @@ CFLAGS += -DDFU_APP_DATA_RESERVED=$(DFU_APP_DATA_RESERVED) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 # Fixes for gcc version 12, 13 and 14. -ifneq (,$(filter 12.% 13.% 14.%,$(shell $(CC) -dumpversion 2>/dev/null))) +#ifneq (,$(filter 12.% 13.% 14.%,$(shell $(CC) -dumpversion 2>/dev/null))) CFLAGS += --param=min-pagesize=0 -endif +#endif #------------------------------------------------------------------------------ # Linker Flags @@ -449,17 +480,17 @@ $(BUILD)/$(OUT_NAME).hex: $(BUILD)/$(OUT_NAME).out # Hex file with mbr (still no SD) $(BUILD)/$(OUT_NAME)_nosd.hex: $(BUILD)/$(OUT_NAME).hex @echo Create $(notdir $@) - @python3 tools/hexmerge.py --overlap=replace -o $@ $< $(MBR_HEX) + @$(PYTHON) tools/hexmerge.py --overlap=replace -o $@ $< $(MBR_HEX) # Bootolader self-update uf2 $(BUILD)/update-$(OUT_NAME)_nosd.uf2: $(BUILD)/$(OUT_NAME)_nosd.hex @echo Create $(notdir $@) - @python3 lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID_BOOTLOADER) -c -o $@ $^ + $(PYTHON) lib/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID_BOOTLOADER) -c -o $@ $^ # merge bootloader and sd hex together $(BUILD)/$(MERGED_FILE).hex: $(BUILD)/$(OUT_NAME).hex @echo Create $(notdir $@) - @python3 tools/hexmerge.py -o $@ $< $(SD_HEX) + @$(PYTHON) tools/hexmerge.py -o $@ $< $(SD_HEX) # Create pkg zip file for bootloader+SD combo to use with DFU CDC $(BUILD)/$(MERGED_FILE).zip: $(BUILD)/$(OUT_NAME).hex diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index 6017e1f..bf003c6 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -31,7 +31,7 @@ static dfu_state_t m_dfu_state; /**< Current DFU static uint32_t m_image_size; /**< Size of the image that will be transmitted. */ static dfu_start_packet_t m_start_packet; /**< Start packet received for this update procedure. Contains update mode and image sizes information to be used for image transfer. */ -static uint8_t m_init_packet[64]; /**< Init packet, can hold CRC, Hash, Signed Hash and similar, for image validation, integrety check and authorization checking. */ +static uint8_t m_init_packet[128]; /**< Init packet, can hold CRC, Hash, Signed Hash and similar, for image validation, integrety check and authorization checking. */ static uint8_t m_init_packet_length; /**< Length of init packet received. */ static uint16_t m_image_crc; /**< Calculated CRC of the image received. */ diff --git a/src/dfu_init.c b/src/dfu_init.c index e19cffa..c848d26 100644 --- a/src/dfu_init.c +++ b/src/dfu_init.c @@ -66,16 +66,24 @@ * If the init packet is signed by a trusted source, it must be decrypted before it can be * processed. */ - + #include "dfu_init.h" #include #include #include #include "nrf_error.h" + +#ifndef SIGNED_FW #include "crc16.h" +#else +#include +#include +#include +#include +#endif /* ADAFRUIT - * - All firmware init data must has Device Type ADAFRUIT_DEVICE_TYPE (nrf52832 and nrf52840) + * - All firmware init data must have Device Type ADAFRUIT_DEVICE_TYPE (nrf52832 and nrf52840) * - SD + Bootloader upgrade must have correct Device Revision to make sure bootloader is not flashed * on the wrong device (e.g flah nRF52832's bootloader on nRF52840 board and vice versa) * - nrf52832 dev-rev is 0xADAF @@ -93,7 +101,52 @@ #error Unknown MCU #endif +#ifdef SIGNED_FW +// The following is the layout of the extended init packet if using image length and sha256 to validate image +// and NIST P-256 + SHA256 to sign the init_package including the extended part +#define DFU_INIT_PACKET_POS_EXT_IDENTIFIER 0 //< Position of the identifier for the ext package +#define DFU_INIT_PACKET_POS_EXT_IMAGE_LENGTH 4 //< Position of the image length +#define DFU_INIT_PACKET_POS_EXT_IMAGE_HASH256 8 //< Position of the 256 +#define DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_R 40 //< Position of the Signature R +#define DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_S 72 //< Position of the Signature S +#define DFU_INIT_PACKET_EXT_LENGTH_SIGNED 40 //< Length of the extended init packet that is part of the signed data +#define DFU_INIT_PACKET_EXT_BEGIN + +#define DFU_SHA256_DIGEST_LENGTH 32 //< Length of SHA-256 digest +#define DFU_SIGNATURE_R_LENGTH 32 //< Length of the signature part r +#define DFU_SIGNATURE_S_LENGTH 32 //< Length of the signature part s + +#define DFU_INIT_PACKET_USES_CRC16 (0) +#define DFU_INIT_PACKET_USES_HASH (1) +#define DFU_INIT_PACKET_USES_ECDS (2) + +#if !defined(SIGNED_FW_QX) || !defined(SIGNED_FW_QY) +# error Missing definitions for SIGNED_FW_QX and/or SIGNED_FW_QY required for signed firmware verification +#endif + +/** @snippet [DFU BLE Signing public key curve points] */ +static const uint8_t pk[] = { + /* x-coord : static uint8_t Qx[] = {*/ + SIGNED_FW_QX + /* 0x39, 0xb0, 0x58, 0x3d, 0x27, 0x07, 0x91, 0x38, + 0x6a, 0xa3, 0x36, 0x0f, 0xa2, 0xb5, 0x86, 0x7e, + 0xae, 0xba, 0xf7, 0xa3, 0xf4, 0x81, 0x5f, 0x78, + 0x02, 0xf2, 0xa1, 0x21, 0xd5, 0x21, 0x84, 0x12 */ + /* };*/ + , + /* y-coord : static uint8_t Qy[] = {*/ + SIGNED_FW_QY + /* 0x4a, 0x0d, 0xfe, 0xa4, 0x77, 0x50, 0xb1, 0xb5, 0x26, 0xc0, 0x9d, 0xdd, 0xf0, 0x24, 0x90, 0x57, 0x6c, 0x64, 0x3b, 0xd3, 0xdf, 0x92, 0x3b, 0xb3, 0x47, 0x97, 0x83, 0xd4, 0xfc, 0x76, 0xf5, 0x9d */ + /* };*/ +}; +/** @snippet [DFU BLE Signing public key curve points] */ + +// Helper macros for stringification +//#define VSTRINGIFY(...) #__VA_ARGS__ +//#define TO_STRING(...) VSTRINGIFY(__VA_ARGS__) +//#pragma message ("Qx: " TO_STRING(SIGNED_FW_QX)) +//#pragma message ("Qy: " TO_STRING(SIGNED_FW_QY)) #define DFU_INIT_PACKET_EXT_LENGTH_MIN 2 //< Minimum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a minimum value of two in order to hold a CRC. */ #define DFU_INIT_PACKET_EXT_LENGTH_MAX 10 //< Maximum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a maximum value of 10 in order to hold a CRC and any padded data on transport layer without overflow. */ @@ -101,114 +154,176 @@ static uint8_t m_extended_packet[DFU_INIT_PACKET_EXT_LENGTH_MAX]; //< Data array for storage of the extended data received. The extended data follows the normal init data of type \ref dfu_init_packet_t. Extended data can be used for a CRC, hash, signature, or other data. */ static uint8_t m_extended_packet_length; //< Length of the extended data received with init packet. */ - uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len, uint8_t image_type) { - uint32_t i = 0; - - // In order to support signing or encryption then any init packet decryption function / library - // should be called from here or implemented at this location. + uint32_t i = 0; + + // In order to support signing or encryption then any init packet decryption function / library + // should be called from here or implemented at this location. - // Length check to ensure valid data are parsed. - if (init_data_len < sizeof(dfu_init_packet_t)) - { - return NRF_ERROR_INVALID_LENGTH; - } + // Length check to ensure valid data are parsed. + if (init_data_len < sizeof(dfu_init_packet_t)) + { + return NRF_ERROR_INVALID_LENGTH; + } - // Current template uses clear text data so they can be casted for pre-check. - dfu_init_packet_t * p_init_packet = (dfu_init_packet_t *)p_init_data; + // Current template uses clear text data so they can be casted for pre-check. + dfu_init_packet_t * p_init_packet = (dfu_init_packet_t *)p_init_data; - m_extended_packet_length = ((uint32_t)p_init_data + init_data_len) - - (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len]; - if (m_extended_packet_length < DFU_INIT_PACKET_EXT_LENGTH_MIN) - { - return NRF_ERROR_INVALID_LENGTH; - } + m_extended_packet_length = ((uint32_t)p_init_data + init_data_len) - + (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len]; + if (m_extended_packet_length < DFU_INIT_PACKET_EXT_LENGTH_MIN) + { + return NRF_ERROR_INVALID_LENGTH; + } - if (((uint32_t)p_init_data + init_data_len) < - (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len]) - { - return NRF_ERROR_INVALID_LENGTH; - } + if (((uint32_t)p_init_data + init_data_len) < + (uint32_t)&p_init_packet->softdevice[p_init_packet->softdevice_len]) + { + return NRF_ERROR_INVALID_LENGTH; + } - memcpy(m_extended_packet, - &p_init_packet->softdevice[p_init_packet->softdevice_len], - m_extended_packet_length); + memcpy(m_extended_packet, + &p_init_packet->softdevice[p_init_packet->softdevice_len], + m_extended_packet_length); - /** [DFU init application version] */ - // To support application versioning, this check should be updated. - // This template allows for any application to be installed. However, - // customers can place a revision number at the bottom of the application - // to be verified by the bootloader. This can be done at a location - // relative to the application, for example the application start - // address + 0x0100. - /** [DFU init application version] */ - - // First check to verify the image to be transfered matches the device type. - // If no Device type is present in DFU_DEVICE_INFO then any image will be accepted. + /** [DFU init application version] */ + // To support application versioning, this check should be updated. + // This template allows for any application to be installed. However, + // customers can place a revision number at the bottom of the application + // to be verified by the bootloader. This can be done at a location + // relative to the application, for example the application start + // address + 0x0100. + /** [DFU init application version] */ + + // First check to verify the image to be transfered matches the device type. + // If no Device type is present in DFU_DEVICE_INFO then any image will be accepted. // if ((DFU_DEVICE_INFO->device_type != DFU_DEVICE_TYPE_EMPTY) && // (p_init_packet->device_type != DFU_DEVICE_INFO->device_type)) // { // return NRF_ERROR_INVALID_DATA; // } - - // Second check to verify the image to be transfered matches the device revision. - // If no Device revision is present in DFU_DEVICE_INFO then any image will be accepted. - // if ((DFU_DEVICE_INFO->device_rev != DFU_DEVICE_REVISION_EMPTY) && - // (p_init_packet->device_rev != DFU_DEVICE_INFO->device_rev)) + + // Second check to verify the image to be transfered matches the device revision. + // If no Device revision is present in DFU_DEVICE_INFO then any image will be accepted. + // if ((DFU_DEVICE_INFO->device_rev != DFU_DEVICE_REVISION_EMPTY) && + // (p_init_packet->device_rev != DFU_DEVICE_INFO->device_rev)) - if ( p_init_packet->device_type != ADAFRUIT_DEVICE_TYPE ) - { - return NRF_ERROR_FORBIDDEN; - } + if ( p_init_packet->device_type != ADAFRUIT_DEVICE_TYPE ) + { + return NRF_ERROR_FORBIDDEN; + } - // Adafruit unlock code must match to upgrade SoftDevice and/or Bootloader - if ( image_type & (DFU_UPDATE_SD | DFU_UPDATE_BL) ) - { - if (p_init_packet->device_rev != ADAFRUIT_DEV_REV) - { - return NRF_ERROR_FORBIDDEN; - } - } + // Adafruit unlock code must match to upgrade SoftDevice and/or Bootloader + if ( image_type & (DFU_UPDATE_SD | DFU_UPDATE_BL) ) + { + if (p_init_packet->device_rev != ADAFRUIT_DEV_REV) + { + return NRF_ERROR_FORBIDDEN; + } + } - // Third check: Check the array of supported SoftDevices by this application. - // If the installed SoftDevice does not match any SoftDevice in the list then an - // error is returned. - while (i < p_init_packet->softdevice_len) - { - if (p_init_packet->softdevice[i] == DFU_SOFTDEVICE_ANY || - p_init_packet->softdevice[i++] == SD_FWID_GET(MBR_SIZE)) - { - return NRF_SUCCESS; - } - } - - // No matching SoftDevice found - Return NRF_ERROR_INVALID_DATA. - return NRF_ERROR_INVALID_DATA; + // Third check: Check the array of supported SoftDevices by this application. + // If the installed SoftDevice does not match any SoftDevice in the list then an + // error is returned. + while (i < p_init_packet->softdevice_len) + { + if (p_init_packet->softdevice[i] == DFU_SOFTDEVICE_ANY || + p_init_packet->softdevice[i] == SD_FWID_GET(MBR_SIZE)) + { + // Found a match. Break the loop. + break; + } + ++i; + } + + // No matching SoftDevice found - Return NRF_ERROR_INVALID_DATA. + if (i >= p_init_packet->softdevice_len) + return NRF_ERROR_INVALID_DATA; + +#ifndef SIGNED_FW + return NRF_SUCCESS; +#else + // Check that we have the correct identifier indicating that ECDS is used + if(*(uint32_t*)&m_extended_packet[DFU_INIT_PACKET_POS_EXT_IDENTIFIER] != DFU_INIT_PACKET_USES_ECDS) + { + return NRF_ERROR_INVALID_DATA; + } + + uint8_t* msg = p_init_data; + size_t msg_len = (init_data_len - m_extended_packet_length) + DFU_INIT_PACKET_EXT_LENGTH_SIGNED; + + // Create a sha256 digest + struct tc_sha256_state_struct state = {0}; + uint8_t digest[TC_SHA256_DIGEST_SIZE]; + if (tc_sha256_init(&state) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + if (tc_sha256_update(&state,msg,msg_len) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + if (tc_sha256_final(digest,&state) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + + // And verify signature + const struct uECC_Curve_t * curve = uECC_secp256r1(); + if (uECC_valid_public_key(pk, curve) != 0) + return NRF_ERROR_INVALID_DATA; + + if (uECC_valid_public_key(pk, curve) != 0) + return NRF_ERROR_INVALID_DATA; + + unsigned char* sig = &m_extended_packet[DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_R]; +# if (DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_S - DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_R) != DFU_SIGNATURE_R_LENGTH +# error Incorrect layout: r and s must be contiguous! +# endif + + return uECC_verify(pk, digest, sizeof(digest), sig, curve) == 1 ? NRF_SUCCESS : NRF_ERROR_INVALID_DATA; +#endif } uint32_t dfu_init_postvalidate(uint8_t * p_image, uint32_t image_len) { - uint16_t image_crc; - uint16_t received_crc; - - // In order to support hashing (and signing) then the (decrypted) hash should be fetched and - // the corresponding hash should be calculated over the image at this location. - // If hashing (or signing) is added to the system then the CRC validation should be removed. +#ifndef SIGNED_FW + uint16_t image_crc; + uint16_t received_crc; + + // calculate CRC from active block. + image_crc = crc16_compute(p_image, image_len, NULL); - // calculate CRC from active block. - image_crc = crc16_compute(p_image, image_len, NULL); + // Decode the received CRC from extended data. + received_crc = uint16_decode((uint8_t *)&m_extended_packet[0]); - // Decode the received CRC from extended data. - received_crc = uint16_decode((uint8_t *)&m_extended_packet[0]); + // Compare the received and calculated CRC. + if (image_crc != received_crc) + { + return NRF_ERROR_INVALID_DATA; + } - // Compare the received and calculated CRC. - if (image_crc != received_crc) - { - return NRF_ERROR_INVALID_DATA; - } + return NRF_SUCCESS; + +#else + + // Compare image size received with signed init_packet data + if(image_len != *(uint32_t*)&m_extended_packet[DFU_INIT_PACKET_POS_EXT_IMAGE_LENGTH]) + { + return NRF_ERROR_INVALID_DATA; + } - return NRF_SUCCESS; + uint8_t image_digest[DFU_SHA256_DIGEST_LENGTH]; + uint8_t * received_digest; + + // Create a sha256 digest + struct tc_sha256_state_struct state = {0}; + if (tc_sha256_init(&state) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + if (tc_sha256_update(&state, p_image, image_len) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + if (tc_sha256_final(image_digest, &state) != TC_CRYPTO_SUCCESS) return NRF_ERROR_INVALID_DATA; + + received_digest = &m_extended_packet[DFU_INIT_PACKET_POS_EXT_IMAGE_HASH256]; + + // Compare the received and calculated digests. + if (memcmp(&image_digest[0], received_digest, DFU_SHA256_DIGEST_LENGTH) != 0) + { + return NRF_ERROR_INVALID_DATA; + } + + return NRF_SUCCESS; +#endif } diff --git a/src/main.c b/src/main.c index 3909651..a5110ba 100644 --- a/src/main.c +++ b/src/main.c @@ -411,6 +411,10 @@ static uint32_t ble_stack_init(void) { return NRF_SUCCESS; } +/*------------------------------------------------------------------*/ +/* SoftDevice Event handler + *------------------------------------------------------------------*/ + // Process BLE event from SD uint32_t proc_ble(void) { __ALIGN(4) uint8_t ev_buf[BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX)]; diff --git a/src/usb/tusb_config.h b/src/usb/tusb_config.h index b76c87b..e75a63d 100644 --- a/src/usb/tusb_config.h +++ b/src/usb/tusb_config.h @@ -53,7 +53,9 @@ //------------- Class enabled -------------// #define CFG_TUD_CDC 1 +#if !defined(SIGNED_FW) || defined(FORCE_UF2) #define CFG_TUD_MSC 1 +#endif /*------------------------------------------------------------------*/ /* CLASS DRIVER diff --git a/src/usb/usb.c b/src/usb/usb.c index 30d91c0..331a9f9 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -94,7 +94,9 @@ void usb_init(bool cdc_only) { } usb_desc_init(cdc_only); +#if !defined(SIGNED_FW) || defined(FORCE_UF2) uf2_init(); +#endif tusb_init(); #ifdef DISPLAY_PIN_SCK diff --git a/src/usb/usb_desc.c b/src/usb/usb_desc.c index ac1a8ac..25c9b1d 100644 --- a/src/usb/usb_desc.c +++ b/src/usb/usb_desc.c @@ -30,11 +30,15 @@ enum { STRID_PRODUCT , STRID_SERIAL , STRID_CDC , +#if !defined(SIGNED_FW) || defined(FORCE_UF2) STRID_MSC +#endif }; +#if !defined(SIGNED_FW) || defined(FORCE_UF2) // CDC + MSC or CDC only mode static bool _cdc_only = false; +#endif // Serial is 64-bit DeviceID -> 16 chars len static char desc_str_serial[1+16]; @@ -84,6 +88,7 @@ enum { ITF_NUM_TOTAL }; +#if !defined(SIGNED_FW) || defined(FORCE_UF2) uint8_t desc_configuration_cdc_msc[] = { // Interface count, string index, total length, attribute, power in mA @@ -95,6 +100,7 @@ uint8_t desc_configuration_cdc_msc[] = // Interface number, string index, EP Out & EP In address, EP size TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, STRID_MSC, 0x03, 0x83, 64), }; +#endif uint8_t desc_configuration_cdc_only[] = { @@ -112,19 +118,27 @@ uint8_t desc_configuration_cdc_only[] = uint8_t const * tud_descriptor_configuration_cb(uint8_t index) { (void) index; // for multiple configurations +#if !defined(SIGNED_FW) || defined(FORCE_UF2) return _cdc_only ? desc_configuration_cdc_only : desc_configuration_cdc_msc; +#else + return desc_configuration_cdc_only; +#endif } // Enumerate as CDC + MSC or CDC only void usb_desc_init(bool cdc_only) { +#if !defined(SIGNED_FW) || defined(FORCE_UF2) _cdc_only = cdc_only; if ( cdc_only ) { +#endif // Change PID to CDC only desc_device.idProduct = USB_DESC_CDC_ONLY_PID; +#if !defined(SIGNED_FW) || defined(FORCE_UF2) } +#endif // Create Serial string descriptor uint8_t const* device_id = (uint8_t const*) &NRF_FICR->DEVICEID; @@ -154,7 +168,9 @@ char const* string_desc_arr [] = BLEDIS_MODEL, // 2: Product desc_str_serial, // 3: Serials, should use chip ID "nRF Serial", // 4: CDC Interface +#if !defined(SIGNED_FW) || defined(FORCE_UF2) "nRF UF2", // 5: MSC Interface +#endif }; // up to 64 unicode characters From 01290c728bfca9ba48779844cf37117c5f9add2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 02:35:05 -0300 Subject: [PATCH 15/40] Improved documentation on dual bank and signed bootloader --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fda77a..611c63d 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ In addition, there is also lots of other 3rd-party boards which are added by oth - Self-upgradable via Serial and OTA - DFU using UF2 (https://github.com/Microsoft/uf2) (application only) - Auto-enter DFU briefly on startup for DTR auto-reset trick (832 only) +- Supports dual bank firmware updates (disabled by default) +- Supports signed firmware updates (disabled by default) ## How to use @@ -101,7 +103,7 @@ Pre-builtin binaries are available on GitHub [releases](https://github.com/adafr Note: The bootloader can be downgraded. Since the binary release is a merged version of both bootloader and the Nordic SoftDevice, you can freely upgrade/downgrade to any version you like. -## How to compile and build +## How to compile and build You should only continue if you are looking to develop bootloader for your own. You must have have a J-Link available to "unbrick" your device. @@ -206,6 +208,57 @@ To flash MBR only make BOARD=feather_nrf52840_express flash-mbr ``` +### Dual bank firmware support: + +This bootloader can split the FLASH memory into 2 partitions, one for the last successfully uploaded firmware, and the other for the new firmware that is being uploaded. In case the firmware upload fails, the bootloader will revert to the last working firmware version. The only drawback is that the maximum firmware size is half of the device FLASH size: That is why it is disabled by default. +You can enable this feature by passing DUALBANK_FW=1 to the make process while compiling the bootloader + +### Signed firmware support: +This bootloader can validate that the uploaded firmware is digitally signed, and refuse to install unsigned or signed with the improper key firmware. Because this will make Arduino uploads stop working (because they are not digitally signed), this feature is disabled by default. +But if you want to ensure noone else is allowed to upload firmware to your device, this option is probably what you want to enable. + +To create a signing key, you will need the adafruit-nrfutil utility. First, generate a signing key and store at given path by using + +``` +adafruit-nrfutil keys --gen-key stored_key.pem +``` + +This command will create a signing key and store it in the file stored_key.pem. STORE THIS FILE IN A SAFE PLACE, as without it, you won't be able to sign your firmware packages, and the bootloader will refuse to flash them!! + +Now, you must show the verification key (that is calculated from the signing key): + +``` +adafruit-nrfutil keys --show-vk code stored_key.pem +``` + +This command will read your signing key (from the file stored_key.pem) and display C source code with the Qx and Qy arrays: Something along the lines + +``` +static uint8_t Qx[] = { ... }; +static uint8_t Qy[] = { ... }; +``` + +You must save thw Qx and Qy values, remove all spaces, an pass them to the make command line +``` +make BOARD=feather_nrf52840_express SIGNED_FW=1 SIGNED_FW_QX='Qx values' SIGNED_FW_QY='Qy values' +``` + +And replace Qx values with the Qx array values, and the Qy values with the Qy array values. That will create a bootloader that ONLY accepts firmware signed with the stored_key.pem signing key. Take into account that the option SIGNED_FW=1 is what enables to build a bootloader that enforces signing, and will ALSO result in disabling UF2 support, as UF2 format does NOT support signing keys. There is an option (only for testing!) called FORCE_UF2 that will FORCE UF2 support on bootloaders that enforce firmware security. It is there to bypass security so you can test a secure bootloader and have a way to recover it something goes wrong, but should NEVER be used if you want to enforce security + +Finally, to create a signed firmware application/bootloader update package, you can use, for example + +``` +adafruit-nrfutil dfu genpkg --dev-type 0x0052 --sd-req 0x0123 --application "application.hex" --key-file "stored_key.pem" "application_package.zip" +``` + +Please, use full paths for all files. The examples omit them for clarity! + +And, to upload it to your device, + +``` +adafruit-nrfutil.exe --verbose dfu serial -pkg "application_package.zip" -p /dev/tty0 -b 115200 +``` + ### Common makefile problems #### `arm-none-eabi-gcc`: No such file or directory From 33070836f9a98311f02ddf522f0dbe88a150ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 02:38:13 -0300 Subject: [PATCH 16/40] Add missing tinycrypt dependency --- lib/tinycrypt | 1 + 1 file changed, 1 insertion(+) create mode 160000 lib/tinycrypt diff --git a/lib/tinycrypt b/lib/tinycrypt new file mode 160000 index 0000000..cf24c90 --- /dev/null +++ b/lib/tinycrypt @@ -0,0 +1 @@ +Subproject commit cf24c907a61c01bc2c4e1ee0ae24457c27a840a2 From 0623a20120da328edec15600d0f4947d3339a7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 02:51:01 -0300 Subject: [PATCH 17/40] Fixed compilation --- src/dfu_init.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dfu_init.c b/src/dfu_init.c index c848d26..ae6244f 100644 --- a/src/dfu_init.c +++ b/src/dfu_init.c @@ -148,8 +148,12 @@ static const uint8_t pk[] = { //#pragma message ("Qx: " TO_STRING(SIGNED_FW_QX)) //#pragma message ("Qy: " TO_STRING(SIGNED_FW_QY)) -#define DFU_INIT_PACKET_EXT_LENGTH_MIN 2 //< Minimum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a minimum value of two in order to hold a CRC. */ -#define DFU_INIT_PACKET_EXT_LENGTH_MAX 10 //< Maximum length of the extended init packet. The extended init packet may contain a CRC, a HASH, or other data. This value must be changed according to the requirements of the system. The template uses a maximum value of 10 in order to hold a CRC and any padded data on transport layer without overflow. */ +_Static_assert(sizeof(pk) == 64, "Public key must be 64 bytes in size"); + +#endif + +#define DFU_INIT_PACKET_EXT_LENGTH_MIN 2 //< Minimum length of the extended init packet. Init packet and CRC16 +#define DFU_INIT_PACKET_EXT_LENGTH_MAX 104 //< Identifier (4 bytes) + Image length (4 bytes) + SHA-256 digest (32 bytes) + NIST P-256 using SHA-256 (64 bytes) static uint8_t m_extended_packet[DFU_INIT_PACKET_EXT_LENGTH_MAX]; //< Data array for storage of the extended data received. The extended data follows the normal init data of type \ref dfu_init_packet_t. Extended data can be used for a CRC, hash, signature, or other data. */ static uint8_t m_extended_packet_length; //< Length of the extended data received with init packet. */ From 6b5158a6827b22d49cbf4ed684a13be0e01d6ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 15:31:16 -0300 Subject: [PATCH 18/40] Removed redundant call to verify if the supplied public key is valid --- src/dfu_init.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/dfu_init.c b/src/dfu_init.c index ae6244f..612fed9 100644 --- a/src/dfu_init.c +++ b/src/dfu_init.c @@ -269,9 +269,6 @@ uint32_t dfu_init_prevalidate(uint8_t * p_init_data, uint32_t init_data_len, uin if (uECC_valid_public_key(pk, curve) != 0) return NRF_ERROR_INVALID_DATA; - if (uECC_valid_public_key(pk, curve) != 0) - return NRF_ERROR_INVALID_DATA; - unsigned char* sig = &m_extended_packet[DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_R]; # if (DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_S - DFU_INIT_PACKET_POS_EXT_INIT_SIGNATURE_R) != DFU_SIGNATURE_R_LENGTH # error Incorrect layout: r and s must be contiguous! From 16477539d9ec7d40e57eaa8d571239bf9b77b8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 15:43:59 -0300 Subject: [PATCH 19/40] Fix autodetection of workarounds for GCC 12.x 13.x and 14.x under Windows --- Makefile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 45dc1df..0c9ccd6 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,15 @@ SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex MBR_HEX = lib/softdevice/mbr/hex/mbr_nrf52_2.4.1_mbr.hex +# Detect the operating system +# The "OS" environment variable on Windows is always "Windows_NT" +# when running under a modern shell like cmd.exe or powershell +ifeq ($(OS),Windows_NT) + NULL_DEVICE = NUL +else + NULL_DEVICE = /dev/null +endif + # linker by MCU eg. nrf52840.ld ifeq ($(DEBUG), 1) LD_FILE = linker/$(MCU_SUB_VARIANT)_debug.ld @@ -385,9 +394,9 @@ CFLAGS += -DDFU_APP_DATA_RESERVED=$(DFU_APP_DATA_RESERVED) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 # Fixes for gcc version 12, 13 and 14. -#ifneq (,$(filter 12.% 13.% 14.%,$(shell $(CC) -dumpversion 2>/dev/null))) +ifneq (,$(filter 12.% 13.% 14.%,$(shell $(CC) -dumpversion 2>$(NULL_DEVICE)))) CFLAGS += --param=min-pagesize=0 -#endif +endif #------------------------------------------------------------------------------ # Linker Flags From 827edd212b9560cd8994576848b76f85da3aad1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Thu, 15 Jan 2026 19:14:41 -0300 Subject: [PATCH 20/40] Bumped SLAVE_LATENCY to 4. Does not make any difference in our tests, but https://stackoverflow.com/questions/32588325/ios-bluetooth-le-code-6-the-connection-has-timed-out-unexpectedly suggests this is the best to solve the ConnectionTimedOutUnexpectedly on IOS --- .../components/libraries/bootloader_dfu/dfu_transport_ble.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 06017a9..08893d0 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -52,7 +52,7 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define MIN_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(15, UNIT_1_25_MS)) /**< Minimum acceptable connection interval (11.25 milliseconds). */ #define MAX_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(30, UNIT_1_25_MS)) /**< Maximum acceptable connection interval (15 milliseconds). */ -#define SLAVE_LATENCY 0 /**< Slave latency. */ +#define SLAVE_LATENCY 4 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(8000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds). */ #define SPEEDUP_FLASH_WRITES 1 /**< Speedup FLASH writes by changing Softdevice local latency */ From 3e87e079213cc09a37df5059690bf61856c16a71 Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Wed, 21 Jan 2026 09:06:12 +0700 Subject: [PATCH 21/40] fix typo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 2 +- .../libraries/bootloader_dfu/dfu_dual_bank.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 611c63d..583f6d3 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,7 @@ static uint8_t Qx[] = { ... }; static uint8_t Qy[] = { ... }; ``` -You must save thw Qx and Qy values, remove all spaces, an pass them to the make command line +You must save the Qx and Qy values, remove all spaces, and pass them to the make command line ``` make BOARD=feather_nrf52840_express SIGNED_FW=1 SIGNED_FW_QX='Qx values' SIGNED_FW_QY='Qy values' ``` diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c index 4516e4f..1bbeffa 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c @@ -29,7 +29,7 @@ static dfu_state_t m_dfu_state; /**< Current DFU static uint32_t m_image_size; /**< Size of the image that will be transmitted. */ static dfu_start_packet_t m_start_packet; /**< Start packet received for this update procedure. Contains update mode and image sizes information to be used for image transfer. */ -static uint8_t m_init_packet[128]; /**< Init packet, can hold CRC, Hash, Signed Hash and similar, for image validation, integrety check and authorization checking. */ +static uint8_t m_init_packet[128]; /**< Init packet, can hold CRC, Hash, Signed Hash and similar, for image validation, integrity check and authorization checking. */ static uint8_t m_init_packet_length; /**< Length of init packet received. */ static uint16_t m_image_crc; /**< Calculated CRC of the image received. */ @@ -200,8 +200,8 @@ static void dfu_cleared_func_app(void) /**@brief Function for calculating storage offset for receiving SoftDevice image. * * @details When a new SoftDevice is received it will be temporary stored in flash before moved to - * address 0x0. In order to succesfully validate transfer and relocation it is important - * that temporary image and final installed image does not ovwerlap hence an offset must + * address 0x0. In order to successfully validate transfer and relocation it is important + * that temporary image and final installed image does not overlap hence an offset must * be calculated in case new image is larger than currently installed SoftDevice. */ uint32_t offset_calculate(uint32_t sd_image_size) @@ -253,7 +253,7 @@ static uint32_t dfu_activate_sd(void) /**@brief Function for activating received Application image. * - * @details This function will move the received application image fram swap (bank 1) to + * @details This function will move the received application image from swap (bank 1) to * application area (bank 0). * * @return NRF_SUCCESS on success. Error code otherwise. @@ -606,7 +606,7 @@ uint32_t dfu_image_validate() // Check if the application image write has finished. if (m_data_received != m_image_size) { - // Image not yet fully transfered by the peer or the peer has attempted to write + // Image not yet fully transferred by the peer or the peer has attempted to write // too much data. Hence the validation should fail. err_code = NRF_ERROR_INVALID_STATE; } @@ -701,8 +701,8 @@ static uint32_t dfu_sd_img_block_swap(uint32_t * src, uint32_t len, uint32_t block_size) { - // It is neccesarry to swap the new SoftDevice in 3 rounds to ensure correct copy of data - // and verifucation of data in case power reset occurs during write to flash. + // It is necessary to swap the new SoftDevice in 3 rounds to ensure correct copy of data + // and verification of data in case power reset occurs during write to flash. // To ensure the robustness of swapping the images are compared backwards till start of // image swap. If the back is identical everything is swapped. uint32_t err_code = dfu_compare_block(src, dst, len); @@ -810,7 +810,7 @@ uint32_t dfu_bl_image_swap(void) uint32_t dfu_bl_image_validate(void) { - bootloader_settings_t bootloader_settings;\ + bootloader_settings_t bootloader_settings; sd_mbr_command_t sd_mbr_cmd_1; sd_mbr_command_t sd_mbr_cmd_2; From 3c4470889b52052e9b420aa536adc5f43f412898 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 23 Jan 2026 14:30:58 +0700 Subject: [PATCH 22/40] minor clean up and fix dfu_bl_image_validate() return nrf error code --- CMakeLists.txt | 49 ++++++++++++++- README.md | 6 +- .../ble/ble_services/ble_dfu/ble_dfu.c | 11 +--- .../libraries/bootloader_dfu/dfu_dual_bank.c | 7 ++- .../bootloader_dfu/dfu_single_bank.c | 7 ++- .../bootloader_dfu/dfu_transport_ble.c | 61 +++++++++---------- src/main.c | 46 +++++++------- src/sdk_config.h | 8 ++- src/usb/usb.c | 2 +- src/usb/usb_desc.c | 17 +++--- 10 files changed, 132 insertions(+), 82 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 401acc2..5b50cfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,13 @@ set(SDK_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/sdk/components) set(SOFTDEVICE_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/softdevice) set(MBR_HEX ${SOFTDEVICE_DIR}/mbr/hex/mbr_nrf52_2.4.1_mbr.hex) set(TINYUSB_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/tinyusb/src) +set(TCRYPT_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/tinycrypt/lib) + +option(SIGNED_FW "Enable signed firmware verification" OFF) +option(DUALBANK_FW "Enable dual bank DFU support" OFF) +option(FORCE_UF2 "Force UF2 support even with SIGNED_FW" OFF) +set(SIGNED_FW_QX "" CACHE STRING "Public key Qx (comma-separated bytes)") +set(SIGNED_FW_QY "" CACHE STRING "Public key Qy (comma-separated bytes)") set(UF2CONV_PY ${CMAKE_CURRENT_LIST_DIR}/lib/uf2/utils/uf2conv.py) set(UF2_FAMILY_ID_BOOTLOADER 0xd663823c) @@ -58,7 +65,6 @@ add_executable(bootloader ${SDK11_DIR}/libraries/bootloader_dfu/bootloader_util.c ${SDK11_DIR}/libraries/bootloader_dfu/dfu_transport_serial.c ${SDK11_DIR}/libraries/bootloader_dfu/dfu_transport_ble.c - ${SDK11_DIR}/libraries/bootloader_dfu/dfu_single_bank.c ${SDK11_DIR}/ble/ble_services/ble_dfu/ble_dfu.c ${SDK11_DIR}/ble/ble_services/ble_dis/ble_dis.c ${SDK11_DIR}/drivers_nrf/pstorage/pstorage_raw.c @@ -75,6 +81,30 @@ add_executable(bootloader # startup ${NRFX_DIR}/mdk/gcc_startup_${MCU_VARIANT}.S ) + +if (DUALBANK_FW) + target_sources(bootloader PUBLIC + ${SDK11_DIR}/libraries/bootloader_dfu/dfu_dual_bank.c + ) +else () + target_sources(bootloader PUBLIC + ${SDK11_DIR}/libraries/bootloader_dfu/dfu_single_bank.c + ) +endif () + +if (SIGNED_FW) + target_sources(bootloader PUBLIC + ${TCRYPT_DIR}/source/sha256.c + ${TCRYPT_DIR}/source/ecc.c + ${TCRYPT_DIR}/source/ecc_dsa.c + ${TCRYPT_DIR}/source/utils.c + ) + + target_include_directories(bootloader PUBLIC + ${TCRYPT_DIR}/include + ) +endif () + target_include_directories(bootloader PUBLIC src src/boards @@ -149,6 +179,23 @@ target_compile_definitions(bootloader PUBLIC __STARTUP_CLEAR_BSS ) +if (SIGNED_FW) + if (SIGNED_FW_QX STREQUAL "" OR SIGNED_FW_QY STREQUAL "") + message(FATAL_ERROR "SIGNED_FW requires SIGNED_FW_QX and SIGNED_FW_QY to be set") + endif () + string(REPLACE " " "" SIGNED_FW_QX_STR "${SIGNED_FW_QX}") + string(REPLACE " " "" SIGNED_FW_QY_STR "${SIGNED_FW_QY}") + target_compile_definitions(bootloader PUBLIC + SIGNED_FW + "SIGNED_FW_QX=${SIGNED_FW_QX_STR}" + "SIGNED_FW_QY=${SIGNED_FW_QY_STR}" + ) +endif () + +if (FORCE_UF2) + target_compile_definitions(bootloader PUBLIC FORCE_UF2) +endif () + if (TRACE_ETM STREQUAL "1") # ENABLE_TRACE will cause system_nrf5x.c to set up ETM trace target_compile_definitions(bootloader PUBLIC ENABLE_TRACE) diff --git a/README.md b/README.md index 583f6d3..8d16b37 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,17 @@ In addition, there is also lots of other 3rd-party boards which are added by oth ## Features -- DFU over Serial and OTA ( application, Bootloader+SD ) +- DFU over Serial and OTA (application, Bootloader+SD) - Self-upgradable via Serial and OTA - DFU using UF2 (https://github.com/Microsoft/uf2) (application only) - Auto-enter DFU briefly on startup for DTR auto-reset trick (832 only) - Supports dual bank firmware updates (disabled by default) - Supports signed firmware updates (disabled by default) +Note: For OTA, `Packet Receipt Notification` (PRN) must be 8 or less, which can be configured in nRF DFU. Otherwise, the +bootloader will run out of +memory. + ## How to use There are two pins, `DFU` and `FRST` that bootloader will check upon reset/power: diff --git a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c index a630971..a79e4cb 100644 --- a/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c +++ b/lib/sdk11/components/ble/ble_services/ble_dfu/ble_dfu.c @@ -17,8 +17,7 @@ #include #include "sdk_common.h" -#define DFU_PKT_ENABLE_WR_WO_RESPONSE_ONLY 0 /**< Enable Write Without Response on Data Endpoint ONLY (otherwise both With and Without response will be supported)*/ -#define MAX_DFU_PKT_LEN 244 /**< Maximum length (in bytes) of the DFU Packet characteristic. */ +#define MAX_DFU_PKT_LEN (BLEGATT_ATT_MTU_MAX - 3) /**< Maximum length (in bytes) of the DFU Packet characteristic. */ #define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ #define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ #define PKT_RCPT_NOTIF_REQ_LEN 3 /**< Length (in bytes) of the Packet Receipt Notification Request. */ @@ -58,12 +57,8 @@ static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu) memset(&char_md, 0, sizeof(char_md)); -#if DFU_PKT_ENABLE_WR_WO_RESPONSE_ONLY - char_md.char_props.write_wo_resp = 1; -#else - char_md.char_props.write = 1; // For those improved apps that can take advantage of ACK - char_md.char_props.write_wo_resp = 1; // Nordic IOS DFU app REQUIRES Write Without Response */ -#endif + char_md.char_props.write = 1; // For those improved apps that can take advantage of ACK + char_md.char_props.write_wo_resp = 1; // Nordic IOS DFU app REQUIRES Write Without Response */ char_md.p_char_user_desc = NULL; char_md.p_char_pf = NULL; char_md.p_user_desc_md = NULL; diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c index 1bbeffa..94feef1 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c @@ -829,6 +829,11 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_1.params.compare.ptr2 = (uint32_t *)(bl_image_start_1); sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + uint32_t err_code = sd_mbr_command(&sd_mbr_cmd_1); + if (err_code != NRF_SUCCESS) { + return err_code; + } + uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_1_REGION_START : bootloader_settings.sd_image_start + @@ -839,7 +844,7 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_2.params.compare.ptr2 = (uint32_t *)(bl_image_start_2); sd_mbr_cmd_2.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); - return sd_mbr_command(&sd_mbr_cmd_1) && sd_mbr_command(&sd_mbr_cmd_2); + return sd_mbr_command(&sd_mbr_cmd_2); } return NRF_SUCCESS; } diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index bf003c6..5a4677f 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -752,6 +752,11 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_1.params.compare.ptr2 = (uint32_t *)(bl_image_start_1); sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + uint32_t err_code = sd_mbr_command(&sd_mbr_cmd_1); + if (err_code != NRF_SUCCESS) { + return err_code; + } + uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_1_REGION_START : bootloader_settings.sd_image_start + @@ -762,7 +767,7 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_2.params.compare.ptr2 = (uint32_t *)(bl_image_start_2); sd_mbr_cmd_2.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); - return sd_mbr_command(&sd_mbr_cmd_1) && sd_mbr_command(&sd_mbr_cmd_2); + return sd_mbr_command(&sd_mbr_cmd_2); } return NRF_SUCCESS; } diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index 08893d0..be6b672 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -35,10 +35,6 @@ #include "nrf_delay.h" #include "sdk_common.h" - -#define BLEGATT_ATT_MTU_MAX 247 -enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; - #define DFU_REV_MAJOR 0x00 /** DFU Major revision number to be exposed. */ #define DFU_REV_MINOR 0x08 /** DFU Minor revision number to be exposed. */ #define DFU_REVISION ((DFU_REV_MAJOR << 8) | DFU_REV_MINOR) /** DFU Revision number to be exposed. Combined of major and minor versions. */ @@ -54,7 +50,7 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define MAX_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(30, UNIT_1_25_MS)) /**< Maximum acceptable connection interval (15 milliseconds). */ #define SLAVE_LATENCY 4 /**< Slave latency. */ #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(8000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds). */ -#define SPEEDUP_FLASH_WRITES 1 /**< Speedup FLASH writes by changing Softdevice local latency */ +#define SPEEDUP_FLASH_WRITES 1 /**< Speedup FLASH writes by changing Softdevice local latency */ #define APP_ADV_INTERVAL MSEC_TO_UNITS(25, UNIT_0_625_MS) /**< The advertising interval (25 ms.). */ #define APP_ADV_TIMEOUT BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED /**< The advertising timeout in units of seconds. This is set to @ref BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED so that the advertisement is done as long as there there is a call to @ref dfu_transport_close function.*/ @@ -77,8 +73,9 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 }; #define IS_CONNECTED() (m_conn_handle != BLE_CONN_HANDLE_INVALID) /**< Macro to determine if the device is in connected state. */ -#define APP_FEATURE_NOT_SUPPORTED BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2 /**< Reply when unsupported features are requested. */ -#define SD_IMAGE_SIZE_OFFSET 0 /**< Offset in start packet for the size information for SoftDevice. */ +#define APP_FEATURE_NOT_SUPPORTED \ + (BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2) /**< Reply when unsupported features are requested. */ +#define SD_IMAGE_SIZE_OFFSET 0 /**< Offset in start packet for the size information for SoftDevice. */ #define BL_IMAGE_SIZE_OFFSET 4 /**< Offset in start packet for the size information for bootloader. */ #define APP_IMAGE_SIZE_OFFSET 8 /**< Offset in start packet for the size information for application. */ @@ -210,35 +207,35 @@ static ble_dfu_resp_val_t nrf_err_code_translate(uint32_t err_c } } -static void prioritize_ble_over_flash_writes(void) -{ #ifdef SPEEDUP_FLASH_WRITES - // We set the local latency to 0: That will revert latency to the negotiated one with the host. - // That will increase throughput to the maximum possible - ble_opt_t opt; - varclr(&opt); - opt.gap_opt.local_conn_latency.conn_handle = m_conn_handle;/**< Connection Handle */ - opt.gap_opt.local_conn_latency.requested_latency = 0; /**< Requested local connection latency. */ - opt.gap_opt.local_conn_latency.p_actual_latency = NULL; /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */ - sd_ble_opt_set(BLE_GAP_OPT_LOCAL_CONN_LATENCY, &opt); -#endif +static void prioritize_ble_over_flash_writes(void) { + // We set the local latency to 0: That will revert latency to the negotiated one with the host. + // That will increase throughput to the maximum possible + ble_opt_t opt; + varclr(&opt); + opt.gap_opt.local_conn_latency.conn_handle = m_conn_handle; /**< Connection Handle */ + opt.gap_opt.local_conn_latency.requested_latency = 0; /**< Requested local connection latency. */ + opt.gap_opt.local_conn_latency.p_actual_latency = + NULL; /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */ + sd_ble_opt_set(BLE_GAP_OPT_LOCAL_CONN_LATENCY, &opt); } -static void prioritize_flash_writes_over_ble(void) -{ -#ifdef SPEEDUP_FLASH_WRITES - // We set the local latency to the maximum possible: That will make FLASH writes faster, as BLE comms will - // be delayed (even losing RXd packets, but this is the same as a poor connection and will be handled by - // the protocol itself) - ble_opt_t opt; - varclr(&opt); - opt.gap_opt.local_conn_latency.conn_handle = m_conn_handle;/**< Connection Handle */ - opt.gap_opt.local_conn_latency.requested_latency = 50; /**< Requested local connection latency. */ - opt.gap_opt.local_conn_latency.p_actual_latency = NULL; /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */ - sd_ble_opt_set(BLE_GAP_OPT_LOCAL_CONN_LATENCY, &opt); -#endif +static void prioritize_flash_writes_over_ble(void) { + // We set the local latency to the maximum possible: That will make FLASH writes faster, as BLE comms will + // be delayed (even losing RXd packets, but this is the same as a poor connection and will be handled by + // the protocol itself) + ble_opt_t opt; + varclr(&opt); + opt.gap_opt.local_conn_latency.conn_handle = m_conn_handle; /**< Connection Handle */ + opt.gap_opt.local_conn_latency.requested_latency = 50; /**< Requested local connection latency. */ + opt.gap_opt.local_conn_latency.p_actual_latency = + NULL; /**< Pointer to storage for the actual local connection latency (can be set to NULL to skip return value). */ + sd_ble_opt_set(BLE_GAP_OPT_LOCAL_CONN_LATENCY, &opt); } - +#else + #define prioritize_ble_over_flash_writes() + #define prioritize_flash_writes_over_ble() +#endif /**@brief Function for handling the callback events from the dfu module. * Callbacks are expected when \ref dfu_data_pkt_handle has been executed. * diff --git a/src/main.c b/src/main.c index a5110ba..d428fd7 100644 --- a/src/main.c +++ b/src/main.c @@ -43,9 +43,7 @@ #include "nrfx_power.h" #include "nrfx_pwm.h" -#include "nordic_common.h" #include "sdk_common.h" -#include "dfu_transport.h" #include "bootloader.h" #include "bootloader_util.h" @@ -65,7 +63,6 @@ #include "pstorage_platform.h" #include "nrf_mbr.h" #include "pstorage.h" -#include "nrfx_nvmc.h" #ifdef NRF_USBD @@ -125,15 +122,9 @@ extern void tusb_hal_nrf_power_event(uint32_t event); // DFU_DBL_RESET magic is used to determined which mode is entered #define APP_ASKS_FOR_SINGLE_TAP_RESET() (*((uint32_t*)(DFU_BANK_0_REGION_START + 0x200)) == 0x87eeb07c) -// These value must be the same with one in dfu_transport_ble.c #define BLEGAP_EVENT_LENGTH 12 -#define BLEGATT_ATT_MTU_MAX 247 #define BLEGATTS_HVN_QSIZE 12 -#define BLEGATTC_WRCMD_QSIZE 2 - -enum { - BLE_CONN_CFG_HIGH_BANDWIDTH = 1 -}; +#define BLEGATTC_WRCMD_QSIZE 2 //--------------------------------------------------------------------+ // @@ -230,8 +221,8 @@ int main(void) { } // No application was loaded, reset the system with the OTA DFU update - NRF_POWER->GPREGRET = 0xA8; - + NRF_POWER->GPREGRET = DFU_MAGIC_OTA_RESET; + NVIC_SystemReset(); } @@ -256,14 +247,17 @@ static void check_dfu_mode(void) { (((*dbl_reset_mem) == DFU_DBL_RESET_MAGIC) && reason_reset_pin); // Clear GPREGRET if it is our values - if (dfu_start || dfu_skip) NRF_POWER->GPREGRET = 0; + if (dfu_start || dfu_skip) { + NRF_POWER->GPREGRET = 0; + } // skip dfu entirely - if (dfu_skip) return; + if (dfu_skip) { + return; + } /*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/ - // DFU button pressed - dfu_start = dfu_start || button_pressed(BUTTON_DFU); + dfu_start = dfu_start || button_pressed(BUTTON_DFU); // DFU button pressed // DFU + FRESET are pressed --> OTA _ota_dfu = _ota_dfu || (button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET)); @@ -271,16 +265,16 @@ static void check_dfu_mode(void) { bool const valid_app = bootloader_app_is_valid(); bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP; - if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) dfu_start = 1; + if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) { + dfu_start = 1; + } // App mode: Double Reset detection or DFU startup for nrf52832 if (!(just_start_app || dfu_start || !valid_app)) { #ifdef NRF52832_XXAA /* Even DFU is not active, we still force an 1000 ms dfu serial mode when startup * to support auto programming from Arduino IDE - * - * Note: Double Reset WONT work with nrf52832 since all its SRAM got cleared with GPIO reset. - */ + * Note: Double Reset WONT work with nrf52832 since all its SRAM got cleared with GPIO reset. */ bootloader_dfu_start(false, DFU_SERIAL_STARTUP_INTERVAL, false); #else // Note: RESETREAS is not clear by bootloader, it should be cleared by application upon init() @@ -414,7 +408,8 @@ static uint32_t ble_stack_init(void) { /*------------------------------------------------------------------*/ /* SoftDevice Event handler *------------------------------------------------------------------*/ - +extern void ble_evt_dispatch(ble_evt_t *p_ble_evt); + // Process BLE event from SD uint32_t proc_ble(void) { __ALIGN(4) uint8_t ev_buf[BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX)]; @@ -430,8 +425,7 @@ uint32_t proc_ble(void) { // Handle valid event, ignore error if (NRF_SUCCESS == err) { switch (evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: - { + case BLE_GAP_EVT_CONNECTED: { // Try to enable 2M phy,if phone allows it ble_gap_phys_t const phys = { @@ -444,6 +438,7 @@ uint32_t proc_ble(void) { led_state(STATE_BLE_CONNECTED); break; } + case BLE_GAP_EVT_DISCONNECTED: _ota_connected = false; led_state(STATE_BLE_DISCONNECTED); @@ -454,7 +449,6 @@ uint32_t proc_ble(void) { } // from dfu_transport_ble - extern void ble_evt_dispatch(ble_evt_t* p_ble_evt); ble_evt_dispatch(evt); } @@ -475,7 +469,9 @@ uint32_t proc_soc(void) { (soc_evt == NRF_EVT_POWER_USB_POWER_READY) ? NRFX_POWER_USB_EVT_READY : (soc_evt == NRF_EVT_POWER_USB_REMOVED) ? NRFX_POWER_USB_EVT_REMOVED : -1; - if (usbevt >= 0) tusb_hal_nrf_power_event((uint32_t) usbevt); + if (usbevt >= 0) { + tusb_hal_nrf_power_event((uint32_t)usbevt); + } #endif } diff --git a/src/sdk_config.h b/src/sdk_config.h index bef8bc7..b61b1f0 100644 --- a/src/sdk_config.h +++ b/src/sdk_config.h @@ -38,8 +38,6 @@ * */ - - #ifndef SDK_CONFIG_H #define SDK_CONFIG_H @@ -119,6 +117,12 @@ #define CRC16_ENABLED 1 #define NRF_STRERROR_ENABLED 1 +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ +#define BLEGATT_ATT_MTU_MAX 247 +#define BLE_CONN_CFG_HIGH_BANDWIDTH 1 + #endif //SDK_CONFIG_H diff --git a/src/usb/usb.c b/src/usb/usb.c index 331a9f9..ecc881b 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -94,7 +94,7 @@ void usb_init(bool cdc_only) { } usb_desc_init(cdc_only); -#if !defined(SIGNED_FW) || defined(FORCE_UF2) +#if CFG_TUD_MSC uf2_init(); #endif tusb_init(); diff --git a/src/usb/usb_desc.c b/src/usb/usb_desc.c index 25c9b1d..4db68ec 100644 --- a/src/usb/usb_desc.c +++ b/src/usb/usb_desc.c @@ -30,9 +30,7 @@ enum { STRID_PRODUCT , STRID_SERIAL , STRID_CDC , -#if !defined(SIGNED_FW) || defined(FORCE_UF2) STRID_MSC -#endif }; #if !defined(SIGNED_FW) || defined(FORCE_UF2) @@ -88,7 +86,7 @@ enum { ITF_NUM_TOTAL }; -#if !defined(SIGNED_FW) || defined(FORCE_UF2) +#if CFG_TUD_MSC uint8_t desc_configuration_cdc_msc[] = { // Interface count, string index, total length, attribute, power in mA @@ -118,7 +116,7 @@ uint8_t desc_configuration_cdc_only[] = uint8_t const * tud_descriptor_configuration_cb(uint8_t index) { (void) index; // for multiple configurations -#if !defined(SIGNED_FW) || defined(FORCE_UF2) +#if CFG_TUD_MSC return _cdc_only ? desc_configuration_cdc_only : desc_configuration_cdc_msc; #else return desc_configuration_cdc_only; @@ -128,17 +126,16 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index) // Enumerate as CDC + MSC or CDC only void usb_desc_init(bool cdc_only) { -#if !defined(SIGNED_FW) || defined(FORCE_UF2) - _cdc_only = cdc_only; + (void)cdc_only; // for non MSC build +#if CFG_TUD_MSC + _cdc_only = cdc_only; if ( cdc_only ) - { #endif + { // Change PID to CDC only desc_device.idProduct = USB_DESC_CDC_ONLY_PID; -#if !defined(SIGNED_FW) || defined(FORCE_UF2) } -#endif // Create Serial string descriptor uint8_t const* device_id = (uint8_t const*) &NRF_FICR->DEVICEID; @@ -168,7 +165,7 @@ char const* string_desc_arr [] = BLEDIS_MODEL, // 2: Product desc_str_serial, // 3: Serials, should use chip ID "nRF Serial", // 4: CDC Interface -#if !defined(SIGNED_FW) || defined(FORCE_UF2) +#if CFG_TUD_MSC "nRF UF2", // 5: MSC Interface #endif }; From e1ea1c6dd135a45fdd920a908fbf32ee738ca9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Mon, 26 Jan 2026 00:44:54 -0300 Subject: [PATCH 23/40] Wait until FLASH operation queue has enough available room, instead of silently dropping operations --- .../libraries/bootloader_dfu/bootloader.c | 28 ++- .../libraries/bootloader_dfu/bootloader.h | 2 + .../libraries/bootloader_dfu/dfu_dual_bank.c | 172 +++++++++++------- .../bootloader_dfu/dfu_single_bank.c | 38 +++- src/pstorage_platform.h | 2 +- 5 files changed, 174 insertions(+), 68 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 875ab6c..7955790 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -186,10 +186,34 @@ static void bootloader_settings_save(bootloader_settings_t * p_settings) { if ( is_ota() ) { - uint32_t err_code = pstorage_clear(&m_bootsettings_handle, sizeof(bootloader_settings_t)); + uint32_t err_code; + while(1) { + err_code = pstorage_clear(&m_bootsettings_handle, sizeof(bootloader_settings_t)); + if (err_code != NRF_ERROR_NO_MEM) + break; + // This means the write/erase queue of commands was completely full - Should not + // happen, but better safe than sorry, wait until space becomes available - + // the pstorage event handler is only run from the main loop, and we are also + // running from a BLE event on the main loop: This means if we wait here, the FLASH + // completion events will never be handled (will be queued by app_scheduler, but + // not handled, and that means this wait will never end... So, process SOC events + // from the SD (but NOT BLE events!) - This will free entries on the pstorage queue + // as soon as operations are complete, allowing this op to be queued + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } APP_ERROR_CHECK(err_code); - err_code = pstorage_store(&m_bootsettings_handle, (uint8_t *) p_settings, sizeof(bootloader_settings_t), 0); + while(1) { + err_code = pstorage_store(&m_bootsettings_handle, (uint8_t *) p_settings, sizeof(bootloader_settings_t), 0); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } APP_ERROR_CHECK(err_code); } else diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h index efd72e7..5f94e7b 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h @@ -92,6 +92,8 @@ uint32_t bootloader_dfu_sd_update_finalize(void); void bootloader_mbr_addrs_populate(void); +extern uint32_t proc_soc(void); + #endif // BOOTLOADER_H__ /**@} */ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c index 4516e4f..00956e7 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c @@ -82,7 +82,6 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle, APP_ERROR_CHECK(result); } - /**@brief Function for handling the DFU timeout. * * @param[in] p_context The timeout context. @@ -136,19 +135,28 @@ static void dfu_prepare_func_app_erase(uint32_t image_size) // Doing a SoftDevice update thus current application must be cleared to ensure enough space // for new SoftDevice. m_dfu_state = DFU_STATE_PREPARING; - - if ( is_ota() ) - { - uint32_t err_code = pstorage_clear(&m_storage_handle_app, m_image_size); - APP_ERROR_CHECK(err_code); - } - else - { - flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_image_size); + + if ( is_ota() ) + { + uint32_t err_code; + while(1) { + err_code = pstorage_clear(&m_storage_handle_app, m_image_size); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + APP_ERROR_CHECK(err_code); + } + else + { + flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_image_size); - // invoke complete callback - pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); - } + // invoke complete callback + pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + } } @@ -163,19 +171,28 @@ static void dfu_prepare_func_swap_erase(uint32_t image_size) mp_storage_handle_active = &m_storage_handle_swap; m_dfu_state = DFU_STATE_PREPARING; - - if ( is_ota() ) - { - uint32_t err_code = pstorage_clear(&m_storage_handle_swap, image_size); - APP_ERROR_CHECK(err_code); - } - else - { - flash_nrf5x_erase(DFU_BANK_1_REGION_START, image_size); + + if ( is_ota() ) + { + uint32_t err_code; + while(1) { + err_code = pstorage_clear(&m_storage_handle_swap, image_size); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + APP_ERROR_CHECK(err_code); + } + else + { + flash_nrf5x_erase(DFU_BANK_1_REGION_START, image_size); - // invoke complete callback - pstorage_callback_handler(&m_storage_handle_swap, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); - } + // invoke complete callback + pstorage_callback_handler(&m_storage_handle_swap, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); + } } @@ -263,26 +280,45 @@ static uint32_t dfu_activate_app(void) uint32_t err_code = NRF_SUCCESS; // Erase BANK 0. - if ( is_ota() ) - { - err_code = pstorage_clear(&m_storage_handle_app, m_start_packet.app_image_size); - APP_ERROR_CHECK(err_code); - - err_code = pstorage_store(&m_storage_handle_app, - (uint8_t *)m_storage_handle_swap.block_id, - m_start_packet.app_image_size, - 0); - } - else - { + if ( is_ota() ) + { + while(1) { + err_code = pstorage_clear(&m_storage_handle_app, m_start_packet.app_image_size); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + APP_ERROR_CHECK(err_code); + + while(1) { + err_code = pstorage_store(&m_storage_handle_app, + (uint8_t *)m_storage_handle_swap.block_id, + m_start_packet.app_image_size, + 0); + + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + VERIFY_SUCCESS(err_code); + + } + else + { flash_nrf5x_erase(DFU_BANK_0_REGION_START, m_start_packet.app_image_size); pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0); - + flash_nrf5x_write(DFU_BANK_0_REGION_START, (uint8_t *)DFU_BANK_1_REGION_START, m_start_packet.app_image_size, false); - flash_nrf5x_flush(false); + flash_nrf5x_flush(false); pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) DFU_BANK_1_REGION_START, m_start_packet.app_image_size); - } - + } + if (err_code == NRF_SUCCESS) { dfu_update_status_t update_status = { 0 }; @@ -430,13 +466,13 @@ uint32_t dfu_start_pkt_handle(dfu_update_packet_t * p_packet) } if ( DFU_STATE_IDLE != m_dfu_state ) - return NRF_ERROR_INVALID_STATE; - - // Valid peer activity detected. Hence restart the DFU timer. - err_code = dfu_timer_restart(); - VERIFY_SUCCESS(err_code); - - m_functions.prepare(m_image_size); + return NRF_ERROR_INVALID_STATE; + + // Valid peer activity detected. Hence restart the DFU timer. + err_code = dfu_timer_restart(); + VERIFY_SUCCESS(err_code); + + m_functions.prepare(m_image_size); return NRF_SUCCESS; } @@ -486,17 +522,25 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) if ( is_ota() ) { - err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); - VERIFY_SUCCESS(err_code); + while(1) { + err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } + VERIFY_SUCCESS(err_code); } else { - flash_nrf5x_write( - (mp_storage_handle_active == &m_storage_handle_app - ? DFU_BANK_0_REGION_START - : DFU_BANK_1_REGION_START) - + m_data_received, p_data, data_length, false); - pstorage_callback_handler(mp_storage_handle_active, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_data, data_length); + flash_nrf5x_write( + (mp_storage_handle_active == &m_storage_handle_app + ? DFU_BANK_0_REGION_START + : DFU_BANK_1_REGION_START) + + m_data_received, p_data, data_length, false); + pstorage_callback_handler(mp_storage_handle_active, PSTORAGE_STORE_OP_CODE, NRF_SUCCESS, (uint8_t *) p_data, data_length); } m_data_received += data_length; @@ -508,8 +552,8 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) } else { - if ( !is_ota() ) flash_nrf5x_flush(false); - + if ( !is_ota() ) flash_nrf5x_flush(false); + // The entire image has been received. Return NRF_SUCCESS. err_code = NRF_SUCCESS; } @@ -561,7 +605,7 @@ uint32_t dfu_init_pkt_handle(dfu_update_packet_t * p_packet) case DFU_STATE_RDY: m_dfu_state = DFU_STATE_RX_INIT_PKT; // When receiving init packet in state ready just update and fall through this case. - /* FALLTHRU */ + /* FALLTHRU */ case DFU_STATE_RX_INIT_PKT: // DFU initialization has been done and a start packet has been received. @@ -811,7 +855,7 @@ uint32_t dfu_bl_image_swap(void) uint32_t dfu_bl_image_validate(void) { bootloader_settings_t bootloader_settings;\ - + sd_mbr_command_t sd_mbr_cmd_1; sd_mbr_command_t sd_mbr_cmd_2; @@ -829,6 +873,10 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_1.params.compare.ptr2 = (uint32_t *)(bl_image_start_1); sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + uint32_t err_code = sd_mbr_command(&sd_mbr_cmd_1); + if (err_code == NRF_SUCCESS) + return NRF_SUCCESS; + uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_1_REGION_START : bootloader_settings.sd_image_start + @@ -839,7 +887,7 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_2.params.compare.ptr2 = (uint32_t *)(bl_image_start_2); sd_mbr_cmd_2.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); - return sd_mbr_command(&sd_mbr_cmd_1) && sd_mbr_command(&sd_mbr_cmd_2); + return sd_mbr_command(&sd_mbr_cmd_2); } return NRF_SUCCESS; } @@ -863,7 +911,7 @@ uint32_t dfu_sd_image_validate(void) uint32_t block_size = (bootloader_settings.sd_image_start - sd_start) / 2; uint32_t image_end = bootloader_settings.sd_image_start + bootloader_settings.sd_image_size; - + /* ##### FIX START ##### */ block_size &= ~(uint32_t)(CODE_PAGE_SIZE - 1); /* ##### FIX END ##### */ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index bf003c6..af25970 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -140,7 +140,16 @@ static void dfu_prepare_func_app_erase(uint32_t image_size) if ( is_ota() ) { - uint32_t err_code = pstorage_clear(&m_storage_handle_app, m_image_size); + uint32_t err_code; + while(1) { + err_code = pstorage_clear(&m_storage_handle_app, m_image_size); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } APP_ERROR_CHECK(err_code); } else @@ -414,7 +423,15 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet) if ( is_ota() ) { - err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); + while(1) { + err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received); + if (err_code != NRF_ERROR_NO_MEM) + break; + // No space, wait until an entry in the queue is freed + while (NRF_ERROR_NOT_FOUND != proc_soc()) { + // nothing + } + } VERIFY_SUCCESS(err_code); } else @@ -742,6 +759,17 @@ uint32_t dfu_bl_image_validate(void) if (bootloader_settings.bl_image_size != 0) { + /* + * The problem with updating the bootloader from a dual to single bank bootloader is that the new + * bootloader expects the firmware image to be at the start of BANK 0, while it's actually loaded + * to BANK1 by the old bootloader. After the update the new single bank bootloader verifies that + * the image was correctly written to flash by comparing itself with the firmware image that it + * expects to be located in BANK0. Since the actual firmware image is in BANK 1 this check will + * fail and the new bootloader updates itself with whatever data located in BANK0 using the MBR. + + * The fix is to modify the dfu_bl_image_validate() function in dfu_single_bank.c run verification + * on both addresses (BANK0 and BANK1) + */ uint32_t bl_image_start_1 = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_0_REGION_START : bootloader_settings.sd_image_start + @@ -752,6 +780,10 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_1.params.compare.ptr2 = (uint32_t *)(bl_image_start_1); sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); + uint32_t err_code = sd_mbr_command(&sd_mbr_cmd_1); + if (err_code == NRF_SUCCESS) + return NRF_SUCCESS; + uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_1_REGION_START : bootloader_settings.sd_image_start + @@ -762,7 +794,7 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_2.params.compare.ptr2 = (uint32_t *)(bl_image_start_2); sd_mbr_cmd_2.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); - return sd_mbr_command(&sd_mbr_cmd_1) && sd_mbr_command(&sd_mbr_cmd_2); + return sd_mbr_command(&sd_mbr_cmd_2); } return NRF_SUCCESS; } diff --git a/src/pstorage_platform.h b/src/pstorage_platform.h index bbc573c..959005c 100644 --- a/src/pstorage_platform.h +++ b/src/pstorage_platform.h @@ -78,7 +78,7 @@ static __INLINE uint32_t pstorage_flash_page_end() #define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR #define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */ -#define PSTORAGE_CMD_QUEUE_SIZE 10 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ +#define PSTORAGE_CMD_QUEUE_SIZE 18 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ /**@breif Define this flag in case Raw access to persistent memory is to be enabled. Raw mode * unlike the data mode is for uses other than storing data from various mode. This mode is From 794aef2053e05497e0957696a9abcfe996abb5c4 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 26 Jan 2026 17:27:57 +0700 Subject: [PATCH 24/40] clean up --- src/boards/boards.c | 1 - src/boards/boards.h | 1 - src/main.c | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/boards/boards.c b/src/boards/boards.c index 5bf70dc..9f98632 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -63,7 +63,6 @@ bool button_pressed(uint32_t pin) { uint32_t const active_state = (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN ? 1 : 0); return nrf_gpio_pin_read(pin) == active_state; } - #endif // This is declared so that a board specific init can be called from here. diff --git a/src/boards/boards.h b/src/boards/boards.h index 2841b70..583e044 100644 --- a/src/boards/boards.h +++ b/src/boards/boards.h @@ -104,7 +104,6 @@ void led_tick(void); //--------------------------------------------------------------------+ // BUTTONS //--------------------------------------------------------------------+ - #if defined(BUTTON_DFU) || defined(BUTTON_FRESET) void button_init(uint32_t pin); bool button_pressed(uint32_t pin); diff --git a/src/main.c b/src/main.c index 938f220..2e2fc0c 100644 --- a/src/main.c +++ b/src/main.c @@ -264,7 +264,7 @@ static void check_dfu_mode(void) { // DFU + FRESET are pressed --> OTA #if defined(BUTTON_DFU) && defined(BUTTON_FRESET) - _ota_dfu = _ota_dfu || ( button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) ) ; + _ota_dfu = _ota_dfu || (button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET)); #endif bool const valid_app = bootloader_app_is_valid(); From 210c6f4a40f66b437af0f4f6e827ebabdef7e1df Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 26 Jan 2026 18:17:14 +0700 Subject: [PATCH 25/40] add AGENTs.md, remove unused BUTTONS_NUMBER --- AGENTS.md | 25 +++ src/boards/adm_b_nrf52840_1/board.h | 1 - src/boards/ae_bl652_bo/board.h | 1 - src/boards/aramcon2_badge/board.h | 1 - src/boards/aramcon_badge_2019/board.h | 1 - .../arcade_feather_nrf52840_express/board.h | 139 +++++++++-------- src/boards/arduino_nano_33_ble/board.h | 1 - src/boards/bast_ble/board.h | 1 - src/boards/bluemicro_nrf52833/board.h | 1 - src/boards/bluemicro_nrf52840/board.h | 1 - src/boards/challenger_840_ble/board.h | 145 +++++++++--------- src/boards/circuitplayground_nrf52840/board.h | 1 - src/boards/clue_nrf52840/board.h | 1 - src/boards/ebyte_e104_bt5032a/board.h | 131 ++++++++-------- src/boards/ebyte_e73_tbb/board.h | 133 ++++++++-------- src/boards/electronut_labs_papyr/board.h | 1 - src/boards/feather_nrf52832/board.h | 123 ++++++++------- src/boards/feather_nrf52833_express/board.h | 137 ++++++++--------- src/boards/feather_nrf52840_express/board.h | 139 +++++++++-------- src/boards/feather_nrf52840_sense/board.h | 1 - src/boards/feather_nrf52840_sense_tft/board.h | 1 - src/boards/ikigaisense_vita/board.h | 137 ++++++++--------- src/boards/itsybitsy_nrf52840_express/board.h | 1 - src/boards/ledglasses_nrf52840/board.h | 1 - src/boards/m60_keyboard/board.h | 1 - src/boards/mbn52832dk/board.h | 125 ++++++++------- src/boards/mdk_nrf52840_dongle/board.h | 1 - src/boards/metro_nrf52840_express/board.h | 1 - src/boards/mikoto/board.h | 1 - src/boards/nRF52840_connect_kit/board.h | 1 - src/boards/nice_nano/board.h | 1 - src/boards/nrf52840_bboard/board.h | 1 - src/boards/nrf52840_m2/board.h | 1 - src/boards/nrfmicro/board.h | 131 ++++++++-------- src/boards/ohs2020_badge/board.h | 1 - src/boards/omnimo_nrf52840/board.h | 143 +++++++++-------- src/boards/particle_argon/board.h | 139 +++++++++-------- src/boards/particle_boron/board.h | 139 +++++++++-------- src/boards/particle_xenon/board.h | 139 +++++++++-------- src/boards/pca10056/board.h | 1 - src/boards/pca10059/board.h | 1 - src/boards/pca10100/board.h | 1 - src/boards/pillbug/board.h | 1 - src/boards/pitaya_go/board.h | 1 - src/boards/raytac_mdbt50q_db_40/board.h | 1 - src/boards/raytac_mdbt50q_rx/board.h | 1 - src/boards/sparkfun_nrf52840_micromod/board.h | 1 - src/boards/t1000_e/board.h | 1 - src/boards/waveshare_nrf52840_eval/board.h | 1 - src/boards/xiao_nrf52840_ble/board.h | 135 ++++++++-------- src/boards/xiao_nrf52840_ble_sense/board.h | 135 ++++++++-------- 51 files changed, 1102 insertions(+), 1127 deletions(-) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..4df910e --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,25 @@ +# Agent Instructions + +## Style +- Follow the repo `.clang-format` when making changes. + +## Build / Verify +- Prefer CMake for testing/verification. +- Always build both boards during verification: + - `feather_nrf52832` + - `feather_nrf52840_express` + +### CMake (preferred) +```bash +cmake -S . -B cmake-build-feather_nrf52832 -DBOARD=feather_nrf52832 +cmake --build cmake-build-feather_nrf52832 + +cmake -S . -B cmake-build-feather_nrf52840_express -DBOARD=feather_nrf52840_express +cmake --build cmake-build-feather_nrf52840_express +``` + +### Make (alternate) +```bash +make BOARD=feather_nrf52832 all +make BOARD=feather_nrf52840_express all +``` diff --git a/src/boards/adm_b_nrf52840_1/board.h b/src/boards/adm_b_nrf52840_1/board.h index 49ea04b..11c041a 100644 --- a/src/boards/adm_b_nrf52840_1/board.h +++ b/src/boards/adm_b_nrf52840_1/board.h @@ -38,7 +38,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 11) #define BUTTON_2 _PINNUM(0, 12) diff --git a/src/boards/ae_bl652_bo/board.h b/src/boards/ae_bl652_bo/board.h index c4b78db..1636ccf 100644 --- a/src/boards/ae_bl652_bo/board.h +++ b/src/boards/ae_bl652_bo/board.h @@ -36,7 +36,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 11 // BTN1 #define BUTTON_2 15 // BTN2 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/aramcon2_badge/board.h b/src/boards/aramcon2_badge/board.h index f651915..788fa3b 100644 --- a/src/boards/aramcon2_badge/board.h +++ b/src/boards/aramcon2_badge/board.h @@ -40,7 +40,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 2) // left Button #define BUTTON_2 _PINNUM(0, 29) // middle button #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/aramcon_badge_2019/board.h b/src/boards/aramcon_badge_2019/board.h index 3dc666d..c545880 100644 --- a/src/boards/aramcon_badge_2019/board.h +++ b/src/boards/aramcon_badge_2019/board.h @@ -41,7 +41,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 2) // left Button #define BUTTON_2 _PINNUM(0, 29) // middle button #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/arcade_feather_nrf52840_express/board.h b/src/boards/arcade_feather_nrf52840_express/board.h index aed04ed..b8b91f5 100644 --- a/src/boards/arcade_feather_nrf52840_express/board.h +++ b/src/boards/arcade_feather_nrf52840_express/board.h @@ -1,70 +1,69 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _ARCARDE_FEATHER_NRF52840_H -#define _ARCARDE_FEATHER_NRF52840_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52840 Express" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x002A - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" -#define UF2_VOLUME_LABEL "ARCADE-N4" -#define UF2_BOARD_ID "nRF52840-Feather-revD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" - -#endif // _ARCARDE_FEATHER_NRF52840_H - +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _ARCARDE_FEATHER_NRF52840_H +#define _ARCARDE_FEATHER_NRF52840_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN _PINNUM(1, 15) +#define LED_SECONDARY_PIN _PINNUM(1, 10) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL _PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(1, 02) +#define BUTTON_2 _PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52840 Express" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x002A + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" +#define UF2_VOLUME_LABEL "ARCADE-N4" +#define UF2_BOARD_ID "nRF52840-Feather-revD" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" + +#endif // _ARCARDE_FEATHER_NRF52840_H + diff --git a/src/boards/arduino_nano_33_ble/board.h b/src/boards/arduino_nano_33_ble/board.h index 00fb2ef..d29fc36 100644 --- a/src/boards/arduino_nano_33_ble/board.h +++ b/src/boards/arduino_nano_33_ble/board.h @@ -37,7 +37,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 11) // D2 switch #define BUTTON_2 _PINNUM(1, 12) // D3 switch #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/bast_ble/board.h b/src/boards/bast_ble/board.h index fb6e8cb..93a0eb6 100644 --- a/src/boards/bast_ble/board.h +++ b/src/boards/bast_ble/board.h @@ -36,7 +36,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 05) #define BUTTON_2 _PINNUM(0, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/bluemicro_nrf52833/board.h b/src/boards/bluemicro_nrf52833/board.h index 9b647c3..763a0f4 100644 --- a/src/boards/bluemicro_nrf52833/board.h +++ b/src/boards/bluemicro_nrf52833/board.h @@ -42,7 +42,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all #define BUTTON_1 _PINNUM(0, 18) // unusable: RESET #define BUTTON_2 _PINNUM(1, 1) // no connection on E73-2G4M08S1E Module #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/bluemicro_nrf52840/board.h b/src/boards/bluemicro_nrf52840/board.h index 393e538..f590dfe 100644 --- a/src/boards/bluemicro_nrf52840/board.h +++ b/src/boards/bluemicro_nrf52840/board.h @@ -38,7 +38,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all #define BUTTON_1 _PINNUM(0, 18) // unusable: RESET #define BUTTON_2 _PINNUM(1, 1) // no connection on E73-2G4M08S1C Module #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/challenger_840_ble/board.h b/src/boards/challenger_840_ble/board.h index 371be08..25d4c6e 100644 --- a/src/boards/challenger_840_ble/board.h +++ b/src/boards/challenger_840_ble/board.h @@ -1,73 +1,72 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries, 2022 Invector Labs - * - * 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. - */ - -#ifndef _CHALLENGER_840_BLE_H -#define _CHALLENGER_840_BLE_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 12) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL _PINNUM(1, 8) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 19) -#define BUTTON_2 _PINNUM(0, 8) // Pulls flash cs high -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -/*------------------------------------------------------------------*/ -/* On board LDO control - *------------------------------------------------------------------*/ -#define LDO_CONTROL_PIN _PINNUM(1, 9) // Enables external pwr - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Invector Labs" -#define BLEDIS_MODEL "Challenger 840 BLE" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x7380 -#define USB_DESC_CDC_ONLY_PID 0x7381 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "ILabs Challenger 840" -#define UF2_VOLUME_LABEL "CH840BOOT" -#define UF2_BOARD_ID "nRF52840-Challenger-840" -#define UF2_INDEX_URL "https://www.ilabs.se" - -#endif // _CHALLENGER_840_BLE_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries, 2022 Invector Labs + * + * 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. + */ + +#ifndef _CHALLENGER_840_BLE_H +#define _CHALLENGER_840_BLE_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(0, 12) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL _PINNUM(1, 8) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(0, 19) +#define BUTTON_2 _PINNUM(0, 8) // Pulls flash cs high +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* On board LDO control + *------------------------------------------------------------------*/ +#define LDO_CONTROL_PIN _PINNUM(1, 9) // Enables external pwr + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Invector Labs" +#define BLEDIS_MODEL "Challenger 840 BLE" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x7380 +#define USB_DESC_CDC_ONLY_PID 0x7381 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "ILabs Challenger 840" +#define UF2_VOLUME_LABEL "CH840BOOT" +#define UF2_BOARD_ID "nRF52840-Challenger-840" +#define UF2_INDEX_URL "https://www.ilabs.se" + +#endif // _CHALLENGER_840_BLE_H diff --git a/src/boards/circuitplayground_nrf52840/board.h b/src/boards/circuitplayground_nrf52840/board.h index 5544502..62a537e 100644 --- a/src/boards/circuitplayground_nrf52840/board.h +++ b/src/boards/circuitplayground_nrf52840/board.h @@ -41,7 +41,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 02) // left button #define BUTTON_2 _PINNUM(1, 15) // right button #define BUTTON_PULL NRF_GPIO_PIN_PULLDOWN diff --git a/src/boards/clue_nrf52840/board.h b/src/boards/clue_nrf52840/board.h index 818f2f4..61466e3 100644 --- a/src/boards/clue_nrf52840/board.h +++ b/src/boards/clue_nrf52840/board.h @@ -41,7 +41,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 02) // left button #define BUTTON_2 _PINNUM(1, 10) // right button #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/ebyte_e104_bt5032a/board.h b/src/boards/ebyte_e104_bt5032a/board.h index da20812..3cc675d 100644 --- a/src/boards/ebyte_e104_bt5032a/board.h +++ b/src/boards/ebyte_e104_bt5032a/board.h @@ -1,66 +1,65 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Pierre Constantineau - * - * 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. - */ - -#ifndef _EBYTE_E104_BT5032A_H -#define _EBYTE_E104_BT5032A_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 31 // Red - named "Data" -#define LED_SECONDARY_PIN 30 // Blue - named "Link" (also a red one on the Test Board) -#define LED_STATE_ON 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 29 // DISC Button on E104-BT5032A-TB Test Board - // BUTTON_1 is DFU. The module does not have reset circuitry. - // The Test Board from Ebyte (E104-BT5032A-TB) also does not have reset circuitry - // To be able to upload using the Arduino IDE, (To enter DFU mode) - // Press "DISC", press and release "RST", then release "DISC" -#define BUTTON_2 28 // No button - WKP pin -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 14 -#define TX_PIN_NUMBER 18 -#define CTS_PIN_NUMBER 20 -#define RTS_PIN_NUMBER 19 -#define HWFC false // leaving it false to make GPIO available - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "CDEBYTE" -#define BLEDIS_MODEL "E104-BT5032A" - -#define UF2_PRODUCT_NAME "Ebyte E104-BT5032A nRF52832" -#define UF2_INDEX_URL "https://www.ebyte.com/en/product-view-news.html?id=756" - -#endif // _EBYTE_E104_BT5032A_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Pierre Constantineau + * + * 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. + */ + +#ifndef _EBYTE_E104_BT5032A_H +#define _EBYTE_E104_BT5032A_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 31 // Red - named "Data" +#define LED_SECONDARY_PIN 30 // Blue - named "Link" (also a red one on the Test Board) +#define LED_STATE_ON 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 29 // DISC Button on E104-BT5032A-TB Test Board + // BUTTON_1 is DFU. The module does not have reset circuitry. + // The Test Board from Ebyte (E104-BT5032A-TB) also does not have reset circuitry + // To be able to upload using the Arduino IDE, (To enter DFU mode) + // Press "DISC", press and release "RST", then release "DISC" +#define BUTTON_2 28 // No button - WKP pin +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* UART (only used by nRF52832) + *------------------------------------------------------------------*/ +#define RX_PIN_NUMBER 14 +#define TX_PIN_NUMBER 18 +#define CTS_PIN_NUMBER 20 +#define RTS_PIN_NUMBER 19 +#define HWFC false // leaving it false to make GPIO available + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "CDEBYTE" +#define BLEDIS_MODEL "E104-BT5032A" + +#define UF2_PRODUCT_NAME "Ebyte E104-BT5032A nRF52832" +#define UF2_INDEX_URL "https://www.ebyte.com/en/product-view-news.html?id=756" + +#endif // _EBYTE_E104_BT5032A_H diff --git a/src/boards/ebyte_e73_tbb/board.h b/src/boards/ebyte_e73_tbb/board.h index 30976e6..f6f4c90 100644 --- a/src/boards/ebyte_e73_tbb/board.h +++ b/src/boards/ebyte_e73_tbb/board.h @@ -1,67 +1,66 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Pierre Constantineau - * - * 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. - */ - -#ifndef _EBYTE_E73_TBB_H -#define _EBYTE_E73_TBB_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // Red - named "LED1" -#define LED_SECONDARY_PIN 18 // Blue - named "LED2" (also a red one on the Test Board) -#define LED_STATE_ON 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 14 // BUTTON_1 is DFU. SW1 on E73-TBB Test Board. - // This Test board uses the E73-2G4M04S1B module which contains a nrf52832. - // The module does not have reset circuitry. - // The Test Board from Ebyte (E73-TBB) also does not have reset circuitry - // To be able to upload using the Arduino IDE, (To enter DFU mode) - // Press "SW1", momentarily ground "RST/P0.21", then release "SW1" -#define BUTTON_2 13 // SW2 on board -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 5 -#define RTS_PIN_NUMBER 7 -#define HWFC false // leaving it false to make GPIO available - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "CDEBYTE" -#define BLEDIS_MODEL "E73-TBB" - -#define UF2_PRODUCT_NAME "Ebyte E73-TBB nRF52832" -#define UF2_INDEX_URL "https://www.ebyte.com/en/product-view-news.aspx?id=889" - -#endif // _EBYTE_E73_TBB_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2021 Pierre Constantineau + * + * 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. + */ + +#ifndef _EBYTE_E73_TBB_H +#define _EBYTE_E73_TBB_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // Red - named "LED1" +#define LED_SECONDARY_PIN 18 // Blue - named "LED2" (also a red one on the Test Board) +#define LED_STATE_ON 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 14 // BUTTON_1 is DFU. SW1 on E73-TBB Test Board. + // This Test board uses the E73-2G4M04S1B module which contains a nrf52832. + // The module does not have reset circuitry. + // The Test Board from Ebyte (E73-TBB) also does not have reset circuitry + // To be able to upload using the Arduino IDE, (To enter DFU mode) + // Press "SW1", momentarily ground "RST/P0.21", then release "SW1" +#define BUTTON_2 13 // SW2 on board +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* UART (only used by nRF52832) + *------------------------------------------------------------------*/ +#define RX_PIN_NUMBER 8 +#define TX_PIN_NUMBER 6 +#define CTS_PIN_NUMBER 5 +#define RTS_PIN_NUMBER 7 +#define HWFC false // leaving it false to make GPIO available + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "CDEBYTE" +#define BLEDIS_MODEL "E73-TBB" + +#define UF2_PRODUCT_NAME "Ebyte E73-TBB nRF52832" +#define UF2_INDEX_URL "https://www.ebyte.com/en/product-view-news.aspx?id=889" + +#endif // _EBYTE_E73_TBB_H diff --git a/src/boards/electronut_labs_papyr/board.h b/src/boards/electronut_labs_papyr/board.h index 2dd931c..70fa231 100644 --- a/src/boards/electronut_labs_papyr/board.h +++ b/src/boards/electronut_labs_papyr/board.h @@ -42,7 +42,6 @@ // App can trigger OTA bootloader by writing DFU_MAGIC_OTA_APPJUM to // GPREGRET register if softdevice is not initialized; or by // writing DFU_MAGIC_OTA_RESET in case softdevice is initialized. -#define BUTTONS_NUMBER 2 #define BUTTON_1 18 // RESET also by default #define BUTTON_2 1 // P0.1 not exposed anywhere, FRST n/a #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/feather_nrf52832/board.h b/src/boards/feather_nrf52832/board.h index a31bafa..dfb6175 100644 --- a/src/boards/feather_nrf52832/board.h +++ b/src/boards/feather_nrf52832/board.h @@ -1,62 +1,61 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _FEATHER_NRF52832_H -#define _FEATHER_NRF52832_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // Red -#define LED_SECONDARY_PIN 19 // Blue -#define LED_STATE_ON 1 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 20 -#define BUTTON_2 22 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52832" - -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52832" -#define UF2_INDEX_URL "https://www.adafruit.com/product/3406" - -#endif // _FEATHER_NRF52832_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _FEATHER_NRF52832_H +#define _FEATHER_NRF52832_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // Red +#define LED_SECONDARY_PIN 19 // Blue +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 20 +#define BUTTON_2 22 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* UART (only used by nRF52832) + *------------------------------------------------------------------*/ +#define RX_PIN_NUMBER 8 +#define TX_PIN_NUMBER 6 +#define CTS_PIN_NUMBER 0 +#define RTS_PIN_NUMBER 0 +#define HWFC false + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52832" + +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52832" +#define UF2_INDEX_URL "https://www.adafruit.com/product/3406" + +#endif // _FEATHER_NRF52832_H diff --git a/src/boards/feather_nrf52833_express/board.h b/src/boards/feather_nrf52833_express/board.h index af0e1ec..e52dc86 100644 --- a/src/boards/feather_nrf52833_express/board.h +++ b/src/boards/feather_nrf52833_express/board.h @@ -1,69 +1,68 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _FEATHER_NRF52833_H -#define _FEATHER_NRF52833_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52833 Express" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 // TODO change later -#define USB_DESC_CDC_ONLY_PID 0x002A // TODO change later - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52833 Express" -#define UF2_VOLUME_LABEL "FTHR833BOOT" -#define UF2_BOARD_ID "nRF52833-Feather-revD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" // TODO change later - -#endif +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _FEATHER_NRF52833_H +#define _FEATHER_NRF52833_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN _PINNUM(1, 15) +#define LED_SECONDARY_PIN _PINNUM(1, 10) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL _PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(1, 02) +#define BUTTON_2 _PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52833 Express" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 // TODO change later +#define USB_DESC_CDC_ONLY_PID 0x002A // TODO change later + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52833 Express" +#define UF2_VOLUME_LABEL "FTHR833BOOT" +#define UF2_BOARD_ID "nRF52833-Feather-revD" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" // TODO change later + +#endif diff --git a/src/boards/feather_nrf52840_express/board.h b/src/boards/feather_nrf52840_express/board.h index 49994f0..cec7e68 100644 --- a/src/boards/feather_nrf52840_express/board.h +++ b/src/boards/feather_nrf52840_express/board.h @@ -1,70 +1,69 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _FEATHER_NRF52840_H -#define _FEATHER_NRF52840_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXEL_POWER_PIN _PINNUM(1, 14) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52840 Express" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x002A - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" -#define UF2_VOLUME_LABEL "FTHR840BOOT" -#define UF2_BOARD_ID "nRF52840-Feather-revE" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" - -#endif // _FEATHER_NRF52840_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _FEATHER_NRF52840_H +#define _FEATHER_NRF52840_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN _PINNUM(1, 15) +#define LED_SECONDARY_PIN _PINNUM(1, 10) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL _PINNUM(0, 16) +#define NEOPIXEL_POWER_PIN _PINNUM(1, 14) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(1, 02) +#define BUTTON_2 _PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52840 Express" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x002A + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" +#define UF2_VOLUME_LABEL "FTHR840BOOT" +#define UF2_BOARD_ID "nRF52840-Feather-revE" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" + +#endif // _FEATHER_NRF52840_H diff --git a/src/boards/feather_nrf52840_sense/board.h b/src/boards/feather_nrf52840_sense/board.h index fbaf9bc..4c9b250 100644 --- a/src/boards/feather_nrf52840_sense/board.h +++ b/src/boards/feather_nrf52840_sense/board.h @@ -42,7 +42,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 02) #define BUTTON_2 _PINNUM(0, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/feather_nrf52840_sense_tft/board.h b/src/boards/feather_nrf52840_sense_tft/board.h index 1fa03bd..f46c14b 100644 --- a/src/boards/feather_nrf52840_sense_tft/board.h +++ b/src/boards/feather_nrf52840_sense_tft/board.h @@ -42,7 +42,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 6) #define BUTTON_2 _PINNUM(1, 10) // DFU pin #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/ikigaisense_vita/board.h b/src/boards/ikigaisense_vita/board.h index dab28e3..afb1958 100644 --- a/src/boards/ikigaisense_vita/board.h +++ b/src/boards/ikigaisense_vita/board.h @@ -1,69 +1,68 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _IKIGAISENSE_VITA_NRF52840_H -#define _IKIGAISENSE_VITA_NRF52840_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "IkigaiSense Technologies" -#define BLEDIS_MODEL "Vita nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0093 -#define USB_DESC_CDC_ONLY_PID 0x0093 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "IkigaiSense Vita nRF52840" -#define UF2_VOLUME_LABEL "ISVITABoot" -#define UF2_BOARD_ID "nRF52840-isVITA-revA" -#define UF2_INDEX_URL "https://github.com/ikigaisense/vita" - -#endif // _IKIGAISENSE_VITA_NRF52840_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _IKIGAISENSE_VITA_NRF52840_H +#define _IKIGAISENSE_VITA_NRF52840_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN _PINNUM(1, 15) +#define LED_SECONDARY_PIN _PINNUM(1, 10) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL _PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(1, 02) +#define BUTTON_2 _PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "IkigaiSense Technologies" +#define BLEDIS_MODEL "Vita nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0093 +#define USB_DESC_CDC_ONLY_PID 0x0093 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "IkigaiSense Vita nRF52840" +#define UF2_VOLUME_LABEL "ISVITABoot" +#define UF2_BOARD_ID "nRF52840-isVITA-revA" +#define UF2_INDEX_URL "https://github.com/ikigaisense/vita" + +#endif // _IKIGAISENSE_VITA_NRF52840_H diff --git a/src/boards/itsybitsy_nrf52840_express/board.h b/src/boards/itsybitsy_nrf52840_express/board.h index a3b6c08..a9372d1 100644 --- a/src/boards/itsybitsy_nrf52840_express/board.h +++ b/src/boards/itsybitsy_nrf52840_express/board.h @@ -46,7 +46,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 29) // user switch #define BUTTON_2 _PINNUM(1, 02) // D2 breakout #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/ledglasses_nrf52840/board.h b/src/boards/ledglasses_nrf52840/board.h index dd676d7..e2ea2f0 100644 --- a/src/boards/ledglasses_nrf52840/board.h +++ b/src/boards/ledglasses_nrf52840/board.h @@ -41,7 +41,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 30) // user switch #define BUTTON_2 _PINNUM(0, 28) // NC #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/m60_keyboard/board.h b/src/boards/m60_keyboard/board.h index 77371b1..20822b5 100644 --- a/src/boards/m60_keyboard/board.h +++ b/src/boards/m60_keyboard/board.h @@ -41,7 +41,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 27) #define BUTTON_2 _PINNUM(0, 19) // ESC #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/mbn52832dk/board.h b/src/boards/mbn52832dk/board.h index c9fda30..b731d68 100644 --- a/src/boards/mbn52832dk/board.h +++ b/src/boards/mbn52832dk/board.h @@ -1,63 +1,62 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _MBN52832DK_H -#define _MBN52832DK_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // LED1 -#define LED_SECONDARY_PIN 18 // LED2 -#define LED_STATE_ON 1 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 13 -#define BUTTON_2 14 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -/*------------------------------------------------------------------*/ -/* UART (only used by nRF52832) - *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Murata" -#define BLEDIS_MODEL "MBN52832DK" - -#define UF2_BOARD_ID "nRF52832-MBN52832DK-v1" -#define UF2_PRODUCT_NAME "Murata MBN52832DK" -#define UF2_INDEX_URL "https://www.murata.com/ja-jp/products/connectivitymodule/bluetooth/overview/lineup/mbn52832" - -#endif // _MBN52832DK_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _MBN52832DK_H +#define _MBN52832DK_H + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // LED1 +#define LED_SECONDARY_PIN 18 // LED2 +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 13 +#define BUTTON_2 14 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +/*------------------------------------------------------------------*/ +/* UART (only used by nRF52832) + *------------------------------------------------------------------*/ +#define RX_PIN_NUMBER 8 +#define TX_PIN_NUMBER 6 +#define CTS_PIN_NUMBER 0 +#define RTS_PIN_NUMBER 0 +#define HWFC false + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Murata" +#define BLEDIS_MODEL "MBN52832DK" + +#define UF2_BOARD_ID "nRF52832-MBN52832DK-v1" +#define UF2_PRODUCT_NAME "Murata MBN52832DK" +#define UF2_INDEX_URL "https://www.murata.com/ja-jp/products/connectivitymodule/bluetooth/overview/lineup/mbn52832" + +#endif // _MBN52832DK_H diff --git a/src/boards/mdk_nrf52840_dongle/board.h b/src/boards/mdk_nrf52840_dongle/board.h index 6528451..066c66b 100644 --- a/src/boards/mdk_nrf52840_dongle/board.h +++ b/src/boards/mdk_nrf52840_dongle/board.h @@ -44,7 +44,6 @@ /* BUTTON *------------------------------------------------------------------*/ // TODO(gpshead): simplify, have code support 0. double reset only. -#define BUTTONS_NUMBER 2 // none connected at all #define BUTTON_1 _PINNUM(0, 18) // unusable: RESET #define BUTTON_2 _PINNUM(0, 19) // no connection #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/metro_nrf52840_express/board.h b/src/boards/metro_nrf52840_express/board.h index 0b47a1c..53519ed 100644 --- a/src/boards/metro_nrf52840_express/board.h +++ b/src/boards/metro_nrf52840_express/board.h @@ -42,7 +42,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 0) #define BUTTON_2 _PINNUM(2, 2) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/mikoto/board.h b/src/boards/mikoto/board.h index 6431f67..f46ef52 100644 --- a/src/boards/mikoto/board.h +++ b/src/boards/mikoto/board.h @@ -39,7 +39,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all #define BUTTON_1 _PINNUM(0, 18) // unusable: RESET #define BUTTON_2 _PINNUM(0, 19) // no connection #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/nRF52840_connect_kit/board.h b/src/boards/nRF52840_connect_kit/board.h index 3740928..2cdaa24 100644 --- a/src/boards/nRF52840_connect_kit/board.h +++ b/src/boards/nRF52840_connect_kit/board.h @@ -41,7 +41,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 0) // P1.00: User Button #define BUTTON_2 _PINNUM(1, 7) // P1.07: NC #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/nice_nano/board.h b/src/boards/nice_nano/board.h index 0ec4cde..c082518 100644 --- a/src/boards/nice_nano/board.h +++ b/src/boards/nice_nano/board.h @@ -39,7 +39,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all #define BUTTON_1 _PINNUM(0, 18) // unusable: RESET #define BUTTON_2 _PINNUM(0, 19) // no connection #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/nrf52840_bboard/board.h b/src/boards/nrf52840_bboard/board.h index 515201d..4384475 100644 --- a/src/boards/nrf52840_bboard/board.h +++ b/src/boards/nrf52840_bboard/board.h @@ -41,7 +41,6 @@ // App can trigger OTA bootloader by writing DFU_MAGIC_OTA_APPJUM to // GPREGRET register if softdevice is not initialized; or by // writing DFU_MAGIC_OTA_RESET in case softdevice is initialized. -#define BUTTONS_NUMBER 2 #define BUTTON_1 18 // RESET also by default #define BUTTON_2 1 // P0.1 not exposed anywhere, FRST n/a #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/nrf52840_m2/board.h b/src/boards/nrf52840_m2/board.h index 57265ab..27fc760 100644 --- a/src/boards/nrf52840_m2/board.h +++ b/src/boards/nrf52840_m2/board.h @@ -42,7 +42,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 19) #define BUTTON_2 _PINNUM(1, 7) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/nrfmicro/board.h b/src/boards/nrfmicro/board.h index c6b2528..f3bdb4e 100644 --- a/src/boards/nrfmicro/board.h +++ b/src/boards/nrfmicro/board.h @@ -1,66 +1,65 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _NRFMICRO_NRF52840 -#define _NRFMICRO_NRF52840 - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 // State when LED is lit (active HIGH) - -#define NEOPIXELS_NUMBER 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 2) // DFU -#define BUTTON_2 _PINNUM(0, 12) // FRST -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "nRFMicro" -#define BLEDIS_MODEL "nRFMicro nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x5284 -#define USB_DESC_CDC_ONLY_PID 0x5284 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "nRFMicro" -#define UF2_VOLUME_LABEL "NRFMICRO" -#define UF2_BOARD_ID "nRF52840-nRFMicro-v0" -#define UF2_INDEX_URL "https://github.com/joric/nrfmicro/wiki" - -#endif // _NRFMICRO_NRF52840 +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _NRFMICRO_NRF52840 +#define _NRFMICRO_NRF52840 + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(1, 10) +#define LED_STATE_ON 1 // State when LED is lit (active HIGH) + +#define NEOPIXELS_NUMBER 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(1, 2) // DFU +#define BUTTON_2 _PINNUM(0, 12) // FRST +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "nRFMicro" +#define BLEDIS_MODEL "nRFMicro nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x5284 +#define USB_DESC_CDC_ONLY_PID 0x5284 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "nRFMicro" +#define UF2_VOLUME_LABEL "NRFMICRO" +#define UF2_BOARD_ID "nRF52840-nRFMicro-v0" +#define UF2_INDEX_URL "https://github.com/joric/nrfmicro/wiki" + +#endif // _NRFMICRO_NRF52840 diff --git a/src/boards/ohs2020_badge/board.h b/src/boards/ohs2020_badge/board.h index 1a62811..0172e6d 100644 --- a/src/boards/ohs2020_badge/board.h +++ b/src/boards/ohs2020_badge/board.h @@ -38,7 +38,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 29) // SW2 #define BUTTON_2 _PINNUM(0, 03) // SW1 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/omnimo_nrf52840/board.h b/src/boards/omnimo_nrf52840/board.h index 0a3b710..f591a55 100644 --- a/src/boards/omnimo_nrf52840/board.h +++ b/src/boards/omnimo_nrf52840/board.h @@ -1,72 +1,71 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _OMNIMO_NRF52840_H -#define _OMNIMO_NRF52840_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL _PINNUM(0, 16) - -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(1, 07) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "eAFAQ" -#define BLEDIS_MODEL "OMNIMO nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ - -//Shared VID/PID with pca10056 -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0xCECE -#define USB_DESC_CDC_ONLY_PID 0xCECE - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Omnimo nRF52840" -#define UF2_VOLUME_LABEL "OMNIn52BOOT" -#define UF2_BOARD_ID "nRF52840-Omnimo" -#define UF2_INDEX_URL "https://www.crowdsupply.com/eafaq/omnimo-nrf52840" - -#endif // _OMNIMO_NRF52840_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _OMNIMO_NRF52840_H +#define _OMNIMO_NRF52840_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN _PINNUM(1, 15) +#define LED_SECONDARY_PIN _PINNUM(1, 10) +#define LED_STATE_ON 1 + +#define LED_NEOPIXEL _PINNUM(0, 16) + +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(1, 02) +#define BUTTON_2 _PINNUM(1, 07) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "eAFAQ" +#define BLEDIS_MODEL "OMNIMO nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +//Shared VID/PID with pca10056 +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0xCECE +#define USB_DESC_CDC_ONLY_PID 0xCECE + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Omnimo nRF52840" +#define UF2_VOLUME_LABEL "OMNIn52BOOT" +#define UF2_BOARD_ID "nRF52840-Omnimo" +#define UF2_INDEX_URL "https://www.crowdsupply.com/eafaq/omnimo-nrf52840" + +#endif // _OMNIMO_NRF52840_H diff --git a/src/boards/particle_argon/board.h b/src/boards/particle_argon/board.h index 1f31d93..c8ce5d6 100644 --- a/src/boards/particle_argon/board.h +++ b/src/boards/particle_argon/board.h @@ -1,70 +1,69 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * 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. - */ - -#ifndef _PARTICLE_ARGON_H -#define _PARTICLE_ARGON_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 12) -#define LED_STATE_ON 1 - -#define LED_RGB_RED_PIN _PINNUM(0, 13) -#define LED_RGB_GREEN_PIN _PINNUM(0, 14) -#define LED_RGB_BLUE_PIN _PINNUM(0, 15) -#define BOARD_RGB_BRIGHTNESS 0x202020 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Particle Industries" -#define BLEDIS_MODEL "Argon" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ - -// Shared VID/PID with pca10056 -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA - -#define UF2_PRODUCT_NAME "Particle Argon" -#define UF2_VOLUME_LABEL "ARGONBOOT " -#define UF2_BOARD_ID "nRF52840-Argon-v1" -#define UF2_INDEX_URL "https://www.particle.io/mesh/" - -#endif // _PARTICLE_ARGON_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +#ifndef _PARTICLE_ARGON_H +#define _PARTICLE_ARGON_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(1, 12) +#define LED_STATE_ON 1 + +#define LED_RGB_RED_PIN _PINNUM(0, 13) +#define LED_RGB_GREEN_PIN _PINNUM(0, 14) +#define LED_RGB_BLUE_PIN _PINNUM(0, 15) +#define BOARD_RGB_BRIGHTNESS 0x202020 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU _PINNUM(0, 11) +#define BUTTON_FRESET _PINNUM(0, 03) // A0 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Particle Industries" +#define BLEDIS_MODEL "Argon" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +// Shared VID/PID with pca10056 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA + +#define UF2_PRODUCT_NAME "Particle Argon" +#define UF2_VOLUME_LABEL "ARGONBOOT " +#define UF2_BOARD_ID "nRF52840-Argon-v1" +#define UF2_INDEX_URL "https://www.particle.io/mesh/" + +#endif // _PARTICLE_ARGON_H diff --git a/src/boards/particle_boron/board.h b/src/boards/particle_boron/board.h index ee5236a..a4fa749 100644 --- a/src/boards/particle_boron/board.h +++ b/src/boards/particle_boron/board.h @@ -1,70 +1,69 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * 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. - */ - -#ifndef _PARTICLE_BORON_H -#define _PARTICLE_BORON_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 12) -#define LED_STATE_ON 1 - -#define LED_RGB_RED_PIN _PINNUM(0, 13) -#define LED_RGB_GREEN_PIN _PINNUM(0, 14) -#define LED_RGB_BLUE_PIN _PINNUM(0, 15) -#define BOARD_RGB_BRIGHTNESS 0x202020 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Particle Industries" -#define BLEDIS_MODEL "Boron" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ - -// Shared VID/PID with pca10056 -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA - -#define UF2_PRODUCT_NAME "Particle Boron" -#define UF2_VOLUME_LABEL "BORONBOOT " -#define UF2_BOARD_ID "nRF52840-Boron-v1" -#define UF2_INDEX_URL "https://www.particle.io/mesh/" - -#endif // _PARTICLE_BORON_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +#ifndef _PARTICLE_BORON_H +#define _PARTICLE_BORON_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(1, 12) +#define LED_STATE_ON 1 + +#define LED_RGB_RED_PIN _PINNUM(0, 13) +#define LED_RGB_GREEN_PIN _PINNUM(0, 14) +#define LED_RGB_BLUE_PIN _PINNUM(0, 15) +#define BOARD_RGB_BRIGHTNESS 0x202020 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU _PINNUM(0, 11) +#define BUTTON_FRESET _PINNUM(0, 03) // A0 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Particle Industries" +#define BLEDIS_MODEL "Boron" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +// Shared VID/PID with pca10056 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA + +#define UF2_PRODUCT_NAME "Particle Boron" +#define UF2_VOLUME_LABEL "BORONBOOT " +#define UF2_BOARD_ID "nRF52840-Boron-v1" +#define UF2_INDEX_URL "https://www.particle.io/mesh/" + +#endif // _PARTICLE_BORON_H diff --git a/src/boards/particle_xenon/board.h b/src/boards/particle_xenon/board.h index 3c77828..01da00a 100644 --- a/src/boards/particle_xenon/board.h +++ b/src/boards/particle_xenon/board.h @@ -1,70 +1,69 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries - * - * 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. - */ - -#ifndef _PARTICLE_XENON_H -#define _PARTICLE_XENON_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 12) -#define LED_STATE_ON 1 - -#define LED_RGB_RED_PIN _PINNUM(0, 13) -#define LED_RGB_GREEN_PIN _PINNUM(0, 14) -#define LED_RGB_BLUE_PIN _PINNUM(0, 15) -#define BOARD_RGB_BRIGHTNESS 0x202020 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Particle Industries" -#define BLEDIS_MODEL "Xenon" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ - -// Shared VID/PID with pca10056 -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA - -#define UF2_PRODUCT_NAME "Particle Xenon" -#define UF2_VOLUME_LABEL "XENONBOOT " -#define UF2_BOARD_ID "nRF52840-Xenon-v1" -#define UF2_INDEX_URL "https://www.particle.io/mesh/" - -#endif // _PARTICLE_XENON_H +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +#ifndef _PARTICLE_XENON_H +#define _PARTICLE_XENON_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(1, 12) +#define LED_STATE_ON 1 + +#define LED_RGB_RED_PIN _PINNUM(0, 13) +#define LED_RGB_GREEN_PIN _PINNUM(0, 14) +#define LED_RGB_BLUE_PIN _PINNUM(0, 15) +#define BOARD_RGB_BRIGHTNESS 0x202020 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_DFU _PINNUM(0, 11) +#define BUTTON_FRESET _PINNUM(0, 03) // A0 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Particle Industries" +#define BLEDIS_MODEL "Xenon" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ + +// Shared VID/PID with pca10056 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA + +#define UF2_PRODUCT_NAME "Particle Xenon" +#define UF2_VOLUME_LABEL "XENONBOOT " +#define UF2_BOARD_ID "nRF52840-Xenon-v1" +#define UF2_INDEX_URL "https://www.particle.io/mesh/" + +#endif // _PARTICLE_XENON_H diff --git a/src/boards/pca10056/board.h b/src/boards/pca10056/board.h index 51dc2fb..0fea16d 100644 --- a/src/boards/pca10056/board.h +++ b/src/boards/pca10056/board.h @@ -36,7 +36,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 11 #define BUTTON_2 12 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/pca10059/board.h b/src/boards/pca10059/board.h index 8b2d89d..47e6bc2 100644 --- a/src/boards/pca10059/board.h +++ b/src/boards/pca10059/board.h @@ -38,7 +38,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 6) #define BUTTON_2 _PINNUM(1, 10) diff --git a/src/boards/pca10100/board.h b/src/boards/pca10100/board.h index e96b11c..1df0200 100644 --- a/src/boards/pca10100/board.h +++ b/src/boards/pca10100/board.h @@ -36,7 +36,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 11 #define BUTTON_2 12 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/pillbug/board.h b/src/boards/pillbug/board.h index 7acb62c..8c50985 100644 --- a/src/boards/pillbug/board.h +++ b/src/boards/pillbug/board.h @@ -39,7 +39,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all #define BUTTON_1 _PINNUM(0, 18) // unusable: RESET #define BUTTON_2 _PINNUM(0, 21) // no connection #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/pitaya_go/board.h b/src/boards/pitaya_go/board.h index 9480a93..8daf1f1 100644 --- a/src/boards/pitaya_go/board.h +++ b/src/boards/pitaya_go/board.h @@ -41,7 +41,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(1, 0) // P1.00: User Button #define BUTTON_2 _PINNUM(1, 7) // P1.07: NC #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/raytac_mdbt50q_db_40/board.h b/src/boards/raytac_mdbt50q_db_40/board.h index 81e07db..86763e3 100644 --- a/src/boards/raytac_mdbt50q_db_40/board.h +++ b/src/boards/raytac_mdbt50q_db_40/board.h @@ -44,7 +44,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 4 #define BUTTON_1 _PINNUM(0, 11) #define BUTTON_2 _PINNUM(0, 12) diff --git a/src/boards/raytac_mdbt50q_rx/board.h b/src/boards/raytac_mdbt50q_rx/board.h index 1436d8b..ac3f771 100644 --- a/src/boards/raytac_mdbt50q_rx/board.h +++ b/src/boards/raytac_mdbt50q_rx/board.h @@ -37,7 +37,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 15) #define BUTTON_2 _PINNUM(0, 10) diff --git a/src/boards/sparkfun_nrf52840_micromod/board.h b/src/boards/sparkfun_nrf52840_micromod/board.h index bf43912..c889354 100644 --- a/src/boards/sparkfun_nrf52840_micromod/board.h +++ b/src/boards/sparkfun_nrf52840_micromod/board.h @@ -38,7 +38,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 7) #define BUTTON_2 _PINNUM(0, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/t1000_e/board.h b/src/boards/t1000_e/board.h index 1a08741..a8eae88 100644 --- a/src/boards/t1000_e/board.h +++ b/src/boards/t1000_e/board.h @@ -37,7 +37,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 #define BUTTON_1 _PINNUM(0, 6) // Primary Button #define BUTTON_2 _PINNUM(0, 18) // unusable: RESET #define BUTTON_PULL NRF_GPIO_PIN_PULLUP diff --git a/src/boards/waveshare_nrf52840_eval/board.h b/src/boards/waveshare_nrf52840_eval/board.h index 27991df..81a5fc1 100644 --- a/src/boards/waveshare_nrf52840_eval/board.h +++ b/src/boards/waveshare_nrf52840_eval/board.h @@ -40,7 +40,6 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 /* This is the 'KEY1' in top left of the board under RESET key. * It is used to remain in bootloader mode after reset. */ #define BUTTON_1 _PINNUM(0, 11) diff --git a/src/boards/xiao_nrf52840_ble/board.h b/src/boards/xiao_nrf52840_ble/board.h index 9f4c45e..1543189 100644 --- a/src/boards/xiao_nrf52840_ble/board.h +++ b/src/boards/xiao_nrf52840_ble/board.h @@ -1,68 +1,67 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _XIAO_BLE -#define _XIAO_BLE - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -// The board has 3 leds, but changing the number here causes OTA issues. -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 26) -#define LED_STATE_ON 0 - -#define NEOPIXELS_NUMBER 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 18) -// Button 2 is defined as D1 from expansion board. -#define BUTTON_2 _PINNUM(0, 3) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Seeed" -#define BLEDIS_MODEL "XIAO nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0x0044 -#define USB_DESC_CDC_ONLY_PID 0x0044 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" -#define UF2_VOLUME_LABEL "XIAO-BOOT" -#define UF2_BOARD_ID "nRF52840-SeeedXiao-v1" -#define UF2_INDEX_URL "https://www.seeedstudio.com/" - -#endif // _XIAO_BLE +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _XIAO_BLE +#define _XIAO_BLE + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +// The board has 3 leds, but changing the number here causes OTA issues. +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(0, 26) +#define LED_STATE_ON 0 + +#define NEOPIXELS_NUMBER 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(0, 18) +// Button 2 is defined as D1 from expansion board. +#define BUTTON_2 _PINNUM(0, 3) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Seeed" +#define BLEDIS_MODEL "XIAO nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0x0044 +#define USB_DESC_CDC_ONLY_PID 0x0044 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" +#define UF2_VOLUME_LABEL "XIAO-BOOT" +#define UF2_BOARD_ID "nRF52840-SeeedXiao-v1" +#define UF2_INDEX_URL "https://www.seeedstudio.com/" + +#endif // _XIAO_BLE diff --git a/src/boards/xiao_nrf52840_ble_sense/board.h b/src/boards/xiao_nrf52840_ble_sense/board.h index e512c1b..fd30e14 100644 --- a/src/boards/xiao_nrf52840_ble_sense/board.h +++ b/src/boards/xiao_nrf52840_ble_sense/board.h @@ -1,68 +1,67 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _XIAO_BLE_SENSE -#define _XIAO_BLE_SENSE - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -// The board has 3 leds, but changing the number here causes OTA issues. -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 26) -#define LED_STATE_ON 0 - -#define NEOPIXELS_NUMBER 0 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 18) -// Button 2 is defined as D1 from expansion board. -#define BUTTON_2 _PINNUM(0, 3) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Seeed" -#define BLEDIS_MODEL "XIAO nRF52840 Sense" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0x0045 -#define USB_DESC_CDC_ONLY_PID 0x0045 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" -#define UF2_VOLUME_LABEL "XIAO-SENSE" -#define UF2_BOARD_ID "nRF52840-SeeedXiaoSense-v1" -#define UF2_INDEX_URL "https://www.seeedstudio.com/" - -#endif // _XIAO_BLE_SENSE +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * + * 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. + */ + +#ifndef _XIAO_BLE_SENSE +#define _XIAO_BLE_SENSE + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +// The board has 3 leds, but changing the number here causes OTA issues. +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(0, 26) +#define LED_STATE_ON 0 + +#define NEOPIXELS_NUMBER 0 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTON_1 _PINNUM(0, 18) +// Button 2 is defined as D1 from expansion board. +#define BUTTON_2 _PINNUM(0, 3) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "Seeed" +#define BLEDIS_MODEL "XIAO nRF52840 Sense" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0x0045 +#define USB_DESC_CDC_ONLY_PID 0x0045 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" +#define UF2_VOLUME_LABEL "XIAO-SENSE" +#define UF2_BOARD_ID "nRF52840-SeeedXiaoSense-v1" +#define UF2_INDEX_URL "https://www.seeedstudio.com/" + +#endif // _XIAO_BLE_SENSE From da75a5443f545e57bb1a5b9d00c1125d131ef88d Mon Sep 17 00:00:00 2001 From: ambraglow Date: Tue, 27 Jan 2026 17:08:45 +0100 Subject: [PATCH 26/40] Add support for Syldra development board --- src/boards/syldra/board.cmake | 1 + src/boards/syldra/board.h | 66 +++++++++++++++++++++++++++++++++++ src/boards/syldra/board.mk | 2 ++ src/boards/syldra/pinconfig.c | 19 ++++++++++ 4 files changed, 88 insertions(+) create mode 100644 src/boards/syldra/board.cmake create mode 100644 src/boards/syldra/board.h create mode 100644 src/boards/syldra/board.mk create mode 100644 src/boards/syldra/pinconfig.c diff --git a/src/boards/syldra/board.cmake b/src/boards/syldra/board.cmake new file mode 100644 index 0000000..25daf71 --- /dev/null +++ b/src/boards/syldra/board.cmake @@ -0,0 +1 @@ +set(MCU_VARIANT nrf52840) diff --git a/src/boards/syldra/board.h b/src/boards/syldra/board.h new file mode 100644 index 0000000..4afa78d --- /dev/null +++ b/src/boards/syldra/board.h @@ -0,0 +1,66 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2026 Ambraglow + * + * 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. + */ + +#ifndef _SYLDRA_H +#define _SYLDRA_H + +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +//------------------------------------------------------------------// +// LED +//------------------------------------------------------------------// +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(0, 17) // AD10 LED +#define LED_STATE_ON 1 + +//------------------------------------------------------------------// +// BUTTON +//------------------------------------------------------------------// +#define BUTTONS_NUMBER 2 +#define BUTTON_1 _PINNUM(0, 24) // AD20 -- DFU +#define BUTTON_2 _PINNUM(1, 00) // AD22 -- FRST + +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + + +//-------------------------------------------------------------------// +// BLE OTA +//-------------------------------------------------------------------// +#define BLEDIS_MANUFACTURER "Ambraglow-&-localcc" +#define BLEDIS_MODEL "Syldra_dev_r1" + + +//--------------------------------------------------------------------+ +// USB - using test PIDs +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x0001 +#define USB_DESC_CDC_ONLY_PID 0x7A01 + +#define UF2_PRODUCT_NAME "Syldra nrf52840 Development Board" +#define UF2_VOLUME_LABEL "Syldra-boot" +#define UF2_BOARD_ID "Syldra-dev-v1" +#define UF2_INDEX_URL "https://github.com/ambraglow/nonorf" + +#endif \ No newline at end of file diff --git a/src/boards/syldra/board.mk b/src/boards/syldra/board.mk new file mode 100644 index 0000000..befd7cb --- /dev/null +++ b/src/boards/syldra/board.mk @@ -0,0 +1,2 @@ +MCU_SUB_VARIANT = nrf52840 +SD_NAME = s140 \ No newline at end of file diff --git a/src/boards/syldra/pinconfig.c b/src/boards/syldra/pinconfig.c new file mode 100644 index 0000000..2a592df --- /dev/null +++ b/src/boards/syldra/pinconfig.c @@ -0,0 +1,19 @@ +#include "boards.h" +#include "uf2/configkeys.h" + +__attribute__((used, section(".bootloaderConfig"))) +const uint32_t bootloaderConfig[] = +{ + /* CF2 START */ + CFG_MAGIC0, CFG_MAGIC1, // magic + 5, 100, // used entries, total entries + + 204, 0x100000, // FLASH_BYTES = 0x100000 + 205, 0x40000, // RAM_BYTES = 0x40000 + 208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 + 209, 0xada52840, // UF2_FAMILY = 0xada52840 + 210, 0x20, // PINS_PORT_SIZE = PA_32 + + 0, 0, 0, 0, 0, 0, 0, 0 + /* CF2 END */ +}; \ No newline at end of file From 3249f41dd965d366a71b769ab42aa8ee76ebd9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Tue, 27 Jan 2026 22:41:20 -0300 Subject: [PATCH 27/40] In case a RESET command is received in the middle of a OTA DFU, reboot to bootloader to allow the DFU app to recover previously interrupted transfers, instead of reverting to the last working firmware and launching it --- .../libraries/bootloader_dfu/bootloader.c | 14 ++++++++--- .../libraries/bootloader_dfu/bootloader.h | 7 ++++++ .../libraries/bootloader_dfu/dfu_dual_bank.c | 9 ++++++++ .../bootloader_dfu/dfu_single_bank.c | 8 +++++++ .../libraries/bootloader_dfu/dfu_types.h | 2 ++ src/main.c | 23 +++++++++++++++---- src/usb/msc_uf2.c | 4 +++- src/usb/uf2/uf2cfg.h | 2 +- 8 files changed, 60 insertions(+), 9 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 7955790..9a8e55e 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -44,7 +44,8 @@ typedef enum BOOTLOADER_SETTINGS_SAVING, /**< Bootloader status for indicating that saving of bootloader settings is in progress. */ BOOTLOADER_COMPLETE, /**< Bootloader status for indicating that all operations for the update procedure has completed and it is safe to reset the system. */ BOOTLOADER_TIMEOUT, /**< Bootloader status field for indicating that a timeout has occured and current update process should be aborted. */ - BOOTLOADER_RESET, /**< Bootloader status field for indicating that a reset has been requested and current update process should be aborted. */ + BOOTLOADER_SYS_RESET, /**< Bootloader status field for indicating that a reset has been requested and current update process should be aborted. */ + BOOTLOADER_RESET_TO_SELF, /**< Bootloader status field for indicating that a reset has been requested and current update process should be aborted and the bootloader must be reentered. */ } bootloader_status_t; static pstorage_handle_t m_bootsettings_handle; /**< Pstorage handle to use for registration and identifying the bootloader module on subsequent calls to the pstorage module for load and store of bootloader setting in flash. */ @@ -136,7 +137,8 @@ static void wait_for_events(void) if ((m_update_status == BOOTLOADER_COMPLETE) || (m_update_status == BOOTLOADER_TIMEOUT) || - (m_update_status == BOOTLOADER_RESET) ) + (m_update_status == BOOTLOADER_SYS_RESET) || + (m_update_status == BOOTLOADER_RESET_TO_SELF)) { // When update has completed or a timeout/reset occured we will return. return; @@ -320,7 +322,9 @@ void bootloader_dfu_update_process(dfu_update_status_t update_status) } else if (update_status.status_code == DFU_RESET) { - m_update_status = BOOTLOADER_RESET; + m_update_status = update_status.restart_into_bootloader == false + ? BOOTLOADER_SYS_RESET + : BOOTLOADER_RESET_TO_SELF; } else { @@ -328,6 +332,10 @@ void bootloader_dfu_update_process(dfu_update_status_t update_status) } } +bool bootloader_must_reset_to_self(void) +{ + return m_update_status == BOOTLOADER_RESET_TO_SELF; +} uint32_t bootloader_init(void) { diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h index 5f94e7b..9b6f754 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.h @@ -32,6 +32,13 @@ */ uint32_t bootloader_init(void); +/**@brief Function to check if bootloader must be reentered after a reset + * @details: This function can only be called after bootloader_dfu_start returns + * @retval true If device must reboot to the bootloader + * @retval false If device must reboot to the application, if possible + */ +bool bootloader_must_reset_to_self(void); + /**@brief Function for validating application region in flash. * @retval true If Application region is valid. * @retval false If Application region is not valid. diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c index cba833d..32cc71a 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_dual_bank.c @@ -82,6 +82,7 @@ static void pstorage_callback_handler(pstorage_handle_t * p_handle, APP_ERROR_CHECK(result); } + /**@brief Function for handling the DFU timeout. * * @param[in] p_context The timeout context. @@ -710,6 +711,14 @@ void dfu_reset(void) update_status.status_code = DFU_RESET; + // If we are still receiving packets, and we are expecting more of them, + // and we receive the RESET command, this means the DFU app is trying + // to interrupt and recover a failed previous attempt of FLASHing a new + // application. Make sure to reboot into DFU mode instead of starting + // a previously stored application (specially valid for double bank + // bootloaders + update_status.restart_into_bootloader = (m_dfu_state == DFU_STATE_RX_DATA_PKT && m_data_received != m_image_size); + bootloader_dfu_update_process(update_status); } diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index af25970..b53bf95 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -607,6 +607,14 @@ void dfu_reset(void) update_status.status_code = DFU_RESET; + // If we are still receiving packets, and we are expecting more of them, + // and we receive the RESET command, this means the DFU app is trying + // to interrupt and recover a failed previous attempt of FLASHing a new + // application. Make sure to reboot into DFU mode instead of starting + // a previously stored application (specially valid for double bank + // bootloaders + update_status.restart_into_bootloader = (m_dfu_state == DFU_STATE_RX_DATA_PKT && m_data_received != m_image_size); + bootloader_dfu_update_process(update_status); } diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h index f86a684..e186e05 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_types.h @@ -24,6 +24,7 @@ #define DFU_TYPES_H__ #include +#include #include "nrf_sdm.h" #include "nrf_mbr.h" #include "nrf.h" @@ -154,6 +155,7 @@ typedef struct uint32_t bl_size; /**< Size of the recieved BootLoader. */ uint32_t app_size; /**< Size of the recieved Application. */ uint32_t sd_image_start; /**< Location in flash where the received SoftDevice image is stored. */ + bool restart_into_bootloader; /**< If the chip must be reset and must reenter bootloader mode. */ } dfu_update_status_t; /**@brief Update complete handler type. */ diff --git a/src/main.c b/src/main.c index 2e2fc0c..819b9e2 100644 --- a/src/main.c +++ b/src/main.c @@ -134,6 +134,7 @@ uint32_t* dbl_reset_mem = ((uint32_t*) DFU_DBL_RESET_MEM); // true if ble, false if serial bool _ota_dfu = false; bool _ota_connected = false; +bool _ota_was_active = false; bool _sd_inited = false; bool is_ota(void) { @@ -192,6 +193,10 @@ int main(void) { // Return when DFU process is complete (or not entered at all) check_dfu_mode(); + // Check if we must reenter the bootloader after reset, instead of + // launching the user application + bool bootloader_must_be_reentered = bootloader_must_reset_to_self(); + // Reset peripherals board_teardown(); @@ -202,7 +207,9 @@ int main(void) { * - sd_softdevice_vector_table_base_set(APP_ADDR) * - jump to App reset */ - if (bootloader_app_is_valid() && !bootloader_dfu_sd_in_progress()) { + if (!bootloader_must_be_reentered && + bootloader_app_is_valid() && + !bootloader_dfu_sd_in_progress()) { PRINTF("App is valid\r\n"); if (is_sd_existed()) { // MBR forward IRQ to SD (if not already) @@ -220,9 +227,14 @@ int main(void) { bootloader_app_start(); } - // No application was loaded, reset the system with the OTA DFU update - NRF_POWER->GPREGRET = DFU_MAGIC_OTA_RESET; - + // No application was loaded or we need to reenter the bootloader + + // Reset the system with the OTA DFU update in case we were in it, + // to allow completion of FLASHING, otherwise, default to normal reset + if (_ota_was_active) { + NRF_POWER->GPREGRET = DFU_MAGIC_OTA_RESET; + } + NVIC_SystemReset(); } @@ -440,6 +452,9 @@ uint32_t proc_ble(void) { sd_ble_gap_phy_update(evt->evt.gap_evt.conn_handle, &phys); _ota_connected = true; + + // Remember someone connected to BLE + _ota_was_active = true; led_state(STATE_BLE_CONNECTED); break; } diff --git a/src/usb/msc_uf2.c b/src/usb/msc_uf2.c index 4b6817f..96d705b 100644 --- a/src/usb/msc_uf2.c +++ b/src/usb/msc_uf2.c @@ -171,6 +171,7 @@ void tud_msc_write10_complete_cb(uint8_t lun) dfu_update_status_t update_status; memset(&update_status, 0, sizeof(dfu_update_status_t )); update_status.status_code = DFU_RESET; + update_status.restart_into_bootloader = false; bootloader_dfu_update_process(update_status); @@ -195,9 +196,10 @@ void tud_msc_write10_complete_cb(uint8_t lun) { // update bootloader always end with reset update_status.status_code = DFU_RESET; + update_status.restart_into_bootloader = false; // Location of current stored new bootloader - uint32_t * new_bootloader = (uint32_t *) BOOTLOADER_ADDR_NEW_RECIEVED; + uint32_t * new_bootloader = (uint32_t *) BOOTLOADER_ADDR_NEW_RECEIVED; PRINT_HEX(new_bootloader); diff --git a/src/usb/uf2/uf2cfg.h b/src/usb/uf2/uf2cfg.h index e5a6398..c23a12e 100644 --- a/src/usb/uf2/uf2cfg.h +++ b/src/usb/uf2/uf2cfg.h @@ -32,4 +32,4 @@ #define BOOTLOADER_ADDR_END BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS // Address where new bootloader is written before activation (skip application data) -#define BOOTLOADER_ADDR_NEW_RECIEVED (USER_FLASH_END-DFU_BL_IMAGE_MAX_SIZE) +#define BOOTLOADER_ADDR_NEW_RECEIVED (USER_FLASH_END-DFU_BL_IMAGE_MAX_SIZE) From d435d66921203b2194da372f339bc468938db574 Mon Sep 17 00:00:00 2001 From: Willow Herring <31960031+ReFil@users.noreply.github.com> Date: Wed, 28 Jan 2026 18:55:22 +0000 Subject: [PATCH 28/40] fix: Fix build errors on GCC15 --- Makefile | 4 ++-- src/usb/uf2/ghostfat.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0c9ccd6..9d2d4df 100644 --- a/Makefile +++ b/Makefile @@ -393,8 +393,8 @@ endif CFLAGS += -DDFU_APP_DATA_RESERVED=$(DFU_APP_DATA_RESERVED) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 -# Fixes for gcc version 12, 13 and 14. -ifneq (,$(filter 12.% 13.% 14.%,$(shell $(CC) -dumpversion 2>$(NULL_DEVICE)))) +# Fixes for gcc version 12, 13, 14 and 15. +ifneq (,$(filter 12.% 13.% 14.% 15.%,$(shell $(CC) -dumpversion 2>$(NULL_DEVICE)))) CFLAGS += --param=min-pagesize=0 endif diff --git a/src/usb/uf2/ghostfat.c b/src/usb/uf2/ghostfat.c index d748904..0564182 100644 --- a/src/usb/uf2/ghostfat.c +++ b/src/usb/uf2/ghostfat.c @@ -40,9 +40,16 @@ // //--------------------------------------------------------------------+ +// Add nonstring attribute if supported to avoid errors in GCC 15 +#ifdef __has_attribute + #define __NONSTRING__ __attribute__((nonstring)) +#else + #define __NONSTRING__ +#endif + typedef struct { uint8_t JumpInstruction[3]; - uint8_t OEMInfo[8]; + uint8_t OEMInfo[8] __NONSTRING__; uint16_t SectorSize; uint8_t SectorsPerCluster; uint16_t ReservedSectors; @@ -59,8 +66,8 @@ typedef struct { uint8_t Reserved; uint8_t ExtendedBootSig; uint32_t VolumeSerialNumber; - uint8_t VolumeLabel[11]; - uint8_t FilesystemIdentifier[8]; + uint8_t VolumeLabel[11] __NONSTRING__; + uint8_t FilesystemIdentifier[8] __NONSTRING__; } __attribute__((packed)) FAT_BootBlock; typedef struct { @@ -81,7 +88,7 @@ typedef struct { STATIC_ASSERT(sizeof(DirEntry) == 32); struct TextFile { - char const name[11]; + char const name[11] __NONSTRING__; char const *content; }; From 87b8354d1fbc19e5a91b63cb62645ab459a00b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Fri, 30 Jan 2026 13:09:24 -0300 Subject: [PATCH 29/40] Allow defaulting to OTA DFU instead of Serial/UF2 DFU (turned off by default) --- CMakeLists.txt | 5 +++++ Makefile | 21 +++++++++++++-------- src/main.c | 10 ++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b50cfd..1e17d10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ set(MBR_HEX ${SOFTDEVICE_DIR}/mbr/hex/mbr_nrf52_2.4.1_mbr.hex) set(TINYUSB_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/tinyusb/src) set(TCRYPT_DIR ${CMAKE_CURRENT_LIST_DIR}/lib/tinycrypt/lib) +option(DEFAULT_TO_OTA_DFU "Default to OTA DFU instead of Serial DFU" OFF) option(SIGNED_FW "Enable signed firmware verification" OFF) option(DUALBANK_FW "Enable dual bank DFU support" OFF) option(FORCE_UF2 "Force UF2 support even with SIGNED_FW" OFF) @@ -196,6 +197,10 @@ if (FORCE_UF2) target_compile_definitions(bootloader PUBLIC FORCE_UF2) endif () +if (DEFAULT_TO_OTA_DFU) + target_compile_definitions(bootloader PUBLIC DEFAULT_TO_OTA_DFU) +endif () + if (TRACE_ETM STREQUAL "1") # ENABLE_TRACE will cause system_nrf5x.c to set up ETM trace target_compile_definitions(bootloader PUBLIC ENABLE_TRACE) diff --git a/Makefile b/Makefile index 0c9ccd6..5b9b2e5 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,15 @@ # CONFIGURE # - SDK_PATH : path to SDK directory # -# - SD_NAME : e.g s132, s140 -# - SD_VERSION : SoftDevice version e.g 6.0.0 -# - SD_HEX : to bootloader hex binary -# - SIGNED_FW : if bootloader will ONLY accept signed firmware -# - SIGNED_FW_QX : Qx for signed firmware verification -# - SIGNED_FW_QY : Qy for signed firmware verification -# - DUALBANK_FW : If bootloader will implement a dual bank feature to allow autorecover from failed -# - FORCE_UF2 : if SIGNED_FW is 1, will force to include UF2 support (UNSECURE, UF2 does NOT validate signature!) +# - SD_NAME : e.g s132, s140 +# - SD_VERSION : SoftDevice version e.g 6.0.0 +# - SD_HEX : to bootloader hex binary +# - SIGNED_FW : if bootloader will ONLY accept signed firmware +# - SIGNED_FW_QX : Qx for signed firmware verification +# - SIGNED_FW_QY : Qy for signed firmware verification +# - DUALBANK_FW : If bootloader will implement a dual bank feature to allow autorecover from failed +# - FORCE_UF2 : if SIGNED_FW is 1, will force to include UF2 support (UNSECURE, UF2 does NOT validate signature!) +# - DEFAULT_TO_OTA_DFU : if entering DFU, by default enter OTA DFU instead of Serial DFU #------------------------------------------------------------------------------ PYTHON = python @@ -371,6 +372,10 @@ ifeq ($(FORCE_UF2), 1) CFLAGS += -DFORCE_UF2 endif +ifeq ($(DEFAULT_TO_OTA_DFU), 1) +CFLAGS += -DEFAULT_TO_OTA_DFU +endif + _VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION)))) CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)) << 8) + $(word 3,$(_VER))' diff --git a/src/main.c b/src/main.c index 819b9e2..5beedec 100644 --- a/src/main.c +++ b/src/main.c @@ -286,6 +286,16 @@ static void check_dfu_mode(void) { dfu_start = 1; } +#ifdef DEFAULT_TO_OTA_DFU + // Default to OTA DFU mode, instead of Serial DFU mode, if there is no app present, + // because otherwise, if there is no application, it will restart in Serial DFU mode, + // making it IMPOSSIBLE to recover devices in the field if there are no user + // accessible USB ports + if (!valid_app || dfu_start) { + _ota_dfu = 1; + } +#endif + // App mode: Double Reset detection or DFU startup for nrf52832 if (!(just_start_app || dfu_start || !valid_app)) { #ifdef NRF52832_XXAA From cb30e6f172aaf22566346f6275aaee7eb99a471f Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 31 Jan 2026 11:52:15 +0700 Subject: [PATCH 30/40] update board and supported_boards.md --- README.md | 3 +- .../feather_nrf52833_express/board.cmake | 1 - src/boards/feather_nrf52833_express/board.h | 68 ---------- src/boards/feather_nrf52833_express/board.mk | 1 - .../feather_nrf52833_express/pinconfig.c | 19 --- src/boards/itsybitsy_nrf52840_express/board.h | 5 +- supported_boards.md | 60 +++++++++ tools/gen_boards.py | 117 ++++++++++++++++++ 8 files changed, 181 insertions(+), 93 deletions(-) delete mode 100644 src/boards/feather_nrf52833_express/board.cmake delete mode 100644 src/boards/feather_nrf52833_express/board.h delete mode 100644 src/boards/feather_nrf52833_express/board.mk delete mode 100644 src/boards/feather_nrf52833_express/pinconfig.c create mode 100644 supported_boards.md create mode 100644 tools/gen_boards.py diff --git a/README.md b/README.md index 8d16b37..e66eb64 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ Officially supported boards are: - Adafruit Metro nRF52840 Express - [Raytac MDBT50Q-RX Dongle](https://www.adafruit.com/product/5199) -In addition, there is also lots of other 3rd-party boards which are added by other makers, users and community. Check out the [complete list of all boards here](/src/boards). +In addition, there is also lots of other 3rd-party boards which are added by other makers, users and community. Check +out the [complete list of all boards here](/supported_boards.md). ## Features diff --git a/src/boards/feather_nrf52833_express/board.cmake b/src/boards/feather_nrf52833_express/board.cmake deleted file mode 100644 index cb4f2f9..0000000 --- a/src/boards/feather_nrf52833_express/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(MCU_VARIANT nrf52833) diff --git a/src/boards/feather_nrf52833_express/board.h b/src/boards/feather_nrf52833_express/board.h deleted file mode 100644 index e52dc86..0000000 --- a/src/boards/feather_nrf52833_express/board.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _FEATHER_NRF52833_H -#define _FEATHER_NRF52833_H - -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52833 Express" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 // TODO change later -#define USB_DESC_CDC_ONLY_PID 0x002A // TODO change later - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52833 Express" -#define UF2_VOLUME_LABEL "FTHR833BOOT" -#define UF2_BOARD_ID "nRF52833-Feather-revD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" // TODO change later - -#endif diff --git a/src/boards/feather_nrf52833_express/board.mk b/src/boards/feather_nrf52833_express/board.mk deleted file mode 100644 index d60ac48..0000000 --- a/src/boards/feather_nrf52833_express/board.mk +++ /dev/null @@ -1 +0,0 @@ -MCU_SUB_VARIANT = nrf52833 diff --git a/src/boards/feather_nrf52833_express/pinconfig.c b/src/boards/feather_nrf52833_express/pinconfig.c deleted file mode 100644 index 72308c4..0000000 --- a/src/boards/feather_nrf52833_express/pinconfig.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "boards.h" -#include "uf2/configkeys.h" - -__attribute__((used, section(".bootloaderConfig"))) -const uint32_t bootloaderConfig[] = -{ - /* CF2 START */ - CFG_MAGIC0, CFG_MAGIC1, // magic - 5, 100, // used entries, total entries - - 204, 0x80000, // FLASH_BYTES - 205, 0x20000, // RAM_BYTES - 208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 - 209, 0x621e937a, // UF2_FAMILY - 210, 0x20, // PINS_PORT_SIZE = PA_32 - - 0, 0, 0, 0, 0, 0, 0, 0 - /* CF2 END */ -}; diff --git a/src/boards/itsybitsy_nrf52840_express/board.h b/src/boards/itsybitsy_nrf52840_express/board.h index a9372d1..efa92ac 100644 --- a/src/boards/itsybitsy_nrf52840_express/board.h +++ b/src/boards/itsybitsy_nrf52840_express/board.h @@ -42,7 +42,6 @@ // For dotstart set to max for colour information is not masked off #define BOARD_RGB_BRIGHTNESS 0xffffffff - /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ @@ -67,6 +66,6 @@ #define UF2_PRODUCT_NAME "Adafruit ItsyBitsy nRF52840 Express" #define UF2_VOLUME_LABEL "ITSY840BOOT" #define UF2_BOARD_ID "nRF52840-ItsyBitsy-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4481" -#endif // _ITSY_NRF52840_H +#endif diff --git a/supported_boards.md b/supported_boards.md new file mode 100644 index 0000000..f733ac3 --- /dev/null +++ b/supported_boards.md @@ -0,0 +1,60 @@ +# Supported Boards + +## Adafruit Boards + +| Board | Name | VID PID | URL | +| --- | --- | --- | --- | +| arcade_feather_nrf52840_express | Adafruit Feather nRF52840 Express | 0x239A:0x0029 | https://www.adafruit.com/product/4062 | +| circuitplayground_nrf52840 | Adafruit Circuit Playground nRF52840 | 0x239A:0x0045 | https://www.adafruit.com/product/4333 | +| clue_nrf52840 | Adafruit CLUE nRF52840 | 0x239A:0x0071 | https://www.adafruit.com/product/4500 | +| feather_nrf52832 | Adafruit Feather nRF52832 | N/A | https://www.adafruit.com/product/3406 | +| feather_nrf52840_express | Adafruit Feather nRF52840 Express | 0x239A:0x0029 | https://www.adafruit.com/product/4062 | +| feather_nrf52840_sense | Adafruit Feather nRF52840 Sense | 0x239A:0x0087 | https://www.adafruit.com/product/4516 | +| feather_nrf52840_sense_tft | Adafruit Feather nRF52840 Sense TFT | 0x239A:0x0087 | https://www.adafruit.com/product/ | +| itsybitsy_nrf52840_express | Adafruit ItsyBitsy nRF52840 Express | 0x239A:0x0051 | https://www.adafruit.com/product/4481 | +| ledglasses_nrf52840 | Adafruit LED Glasses Driver nRF52840 | 0x239A:0x010D | https://www.adafruit.com/product/5217 | +| metro_nrf52840_express | Adafruit Metro nRF52840 Express | 0x239A:0x003F | https://www.adafruit.com/ | + +## 3rd Party Boards + +| Board | Name | VID PID | URL | +| --- | --- | --- | --- | +| adm_b_nrf52840_1 | AtelierDuMaker NRF52840 Breakout | 0x239A:0x009F | https://github.com/Atelier-Du-Maker/HolyIoT_NRF52840 | +| ae_bl652_bo | N/A | N/A | N/A | +| aramcon2_badge | ARAMCON2 Badge | 0x239A:0x007B | https://github.com/aramcon-badge | +| aramcon_badge_2019 | ARAMCON Badge 2019 | 0x239A:0x0079 | https://github.com/aramcon-badge | +| arduino_nano_33_ble | Arduino Nano 33 BLE | 0x239A:0x0063 | https://www.arduino.cc/ | +| bast_ble | Bast BLE | 0x1209:0x805A | https://www.electroniccats.com | +| bluemicro_nrf52833 | BlueMicro | 0x1D50:0x616F | http://bluemicro.jpconstantineau.com/ | +| bluemicro_nrf52840 | BlueMicro | 0x1D50:0x6160 | http://bluemicro.jpconstantineau.com/ | +| challenger_840_ble | ILabs Challenger 840 | 0x1209:0x7380 | https://www.ilabs.se | +| ebyte_e104_bt5032a | Ebyte E104-BT5032A nRF52832 | N/A | https://www.ebyte.com/en/product-view-news.html?id=756 | +| ebyte_e73_tbb | Ebyte E73-TBB nRF52832 | N/A | https://www.ebyte.com/en/product-view-news.aspx?id=889 | +| electronut_labs_papyr | Electronut Labs Papyr | 0x239A:0x003B | https://docs.electronut.in/papyr | +| ikigaisense_vita | IkigaiSense Vita nRF52840 | 0x239A:0x0093 | https://github.com/ikigaisense/vita | +| m60_keyboard | MakerDiary M60 Mechanical Keyboard | 0x2886:0xF00F | https://wiki.makerdiary.com/m60/ | +| mbn52832dk | Murata MBN52832DK | N/A | https://www.murata.com/ja-jp/products/connectivitymodule/bluetooth/overview/lineup/mbn52832 | +| mdk_nrf52840_dongle | MDK nRF52840 USB Dongle | 0x239A:0x0029 | https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/ | +| mikoto | Mikoto nRF52840 | 0x1209:0x7A01 | https://github.com/zhiayang/mikoto | +| nice_nano | nice!nano | 0x239A:0x00B3 | https://nicekeyboards.com/docs/nice-nano | +| nrf52840_bboard | nRF52840 BBoard | 0x1D50:0x6157 | https://github.com/ddB0515/nRF52840-BBoard | +| nRF52840_connect_kit | nRF52840 Connect Kit | 0x2886:0xF00F | https://wiki.makerdiary.com/nrf52840-connectkit/ | +| nrf52840_m2 | MakerDiary nRF52840 M.2 Module | 0x2886:0xF00F | https://wiki.makerdiary.com/nrf52840-m2 | +| nrfmicro | nRFMicro | 0x1209:0x5284 | https://github.com/joric/nrfmicro/wiki | +| ohs2020_badge | OHS2020 Badge | 0x239A:0x007F | https://2020.oshwa.org/ | +| omnimo_nrf52840 | Omnimo nRF52840 | 0x1209:0xCECE | https://www.crowdsupply.com/eafaq/omnimo-nrf52840 | +| particle_argon | Particle Argon | 0x239A:0x00DA | https://www.particle.io/mesh/ | +| particle_boron | Particle Boron | 0x239A:0x00DA | https://www.particle.io/mesh/ | +| particle_xenon | Particle Xenon | 0x239A:0x00DA | https://www.particle.io/mesh/ | +| pca10056 | Nordic nRF52840 DK | 0x239A:0x00DA | https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK | +| pca10059 | Nordic nRF52840 Dongle | 0x239A:0x0029 | https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle | +| pca10100 | Nordic nRF52833 DK | 0x239A:0x00D8 | https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52833-DK | +| pillbug | PillBug | 0x16D0:0x10ED | https://mechwild.com | +| pitaya_go | Pitaya Go | 0x2886:0xF00E | https://wiki.makerdiary.com/pitaya-go | +| raytac_mdbt50q_db_40 | Raytac MDBT50Q Demo Board 40 | 0x239A:0x00BB | https://www.raytac.com/product/ins.php?index_id=81 | +| raytac_mdbt50q_rx | Raytac MDBT50Q-RX | 0x239A:0x010B | https://www.adafruit.com/product/5199 | +| sparkfun_nrf52840_micromod | SparkFun MicroMod nRF52840 | 0x1B4F:0x0022 | https://www.sparkfun.com/products/16984 | +| t1000_e | Seeed T1000-E for Meshtastic | 0x2886:0x0057 | https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-E-for-Meshtastic-p-5913.html | +| waveshare_nrf52840_eval | Waveshare nRF52840 Eval | 0x239A:0x0029 | https://www.waveshare.com/wiki/NRF52840_Eval_Kit | +| xiao_nrf52840_ble | Seeed XIAO nRF52840 | 0x2886:0x0044 | https://www.seeedstudio.com/ | +| xiao_nrf52840_ble_sense | Seeed XIAO nRF52840 | 0x2886:0x0045 | https://www.seeedstudio.com/ | diff --git a/tools/gen_boards.py b/tools/gen_boards.py new file mode 100644 index 0000000..140a0dd --- /dev/null +++ b/tools/gen_boards.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import argparse +import re +from pathlib import Path + + +BOARD_H_GLOB = "src/boards/*/board.h" + + +def _first_match(pattern: str, text: str) -> str | None: + match = re.search(pattern, text, flags=re.MULTILINE) + return match.group(1).strip() if match else None + + +def _parse_int(value: str | None) -> int | None: + if value is None: + return None + value = value.strip() + if value.lower().startswith("0x"): + try: + return int(value, 16) + except ValueError: + return None + try: + return int(value, 10) + except ValueError: + return None + + +def _fmt_vid_pid(vid: int | None, pid: int | None) -> str: + if vid is None or pid is None: + return "N/A" + return f"0x{vid:04X}:0x{pid:04X}" + + +def _escape_md(value: str) -> str: + return value.replace("|", "\\|") + + +def _load_board(board_h: Path, repo_root: Path) -> dict[str, str]: + text = board_h.read_text(errors="ignore") + board = board_h.parent.name + name = _first_match(r'^\s*#define\s+UF2_PRODUCT_NAME\s+"([^"]+)"', text) + url = _first_match(r'^\s*#define\s+UF2_INDEX_URL\s+"([^"]+)"', text) + vid = _parse_int(_first_match(r"^\s*#define\s+USB_DESC_VID\s+([0-9A-Fa-fxX]+)", text)) + pid = _parse_int( + _first_match(r"^\s*#define\s+USB_DESC_UF2_PID\s+([0-9A-Fa-fxX]+)", text) + ) + + return { + "board": board, + "name": name or "N/A", + "vid_pid": _fmt_vid_pid(vid, pid), + "url": url or "N/A", + } + + +def generate(repo_root: Path, output: Path) -> None: + boards: list[dict[str, str]] = [] + for board_h in sorted(repo_root.glob(BOARD_H_GLOB)): + boards.append(_load_board(board_h, repo_root)) + + lines: list[str] = [] + lines.append("# Supported Boards") + lines.append("") + def _is_adafruit(entry: dict[str, str]) -> bool: + name = entry["name"].lower() + board = entry["board"].lower() + return name.startswith("adafruit") or board.startswith("adafruit") + + def _render_table(entries: list[dict[str, str]]) -> None: + lines.append("| Board | Name | VID PID | URL |") + lines.append("| --- | --- | --- | --- |") + for entry in sorted(entries, key=lambda e: e["board"].lower()): + lines.append( + f"| {_escape_md(entry['board'])} | {_escape_md(entry['name'])} | " + f"{_escape_md(entry['vid_pid'])} | {_escape_md(entry['url'])} |" + ) + lines.append("") + + adafruit = [entry for entry in boards if _is_adafruit(entry)] + third_party = [entry for entry in boards if not _is_adafruit(entry)] + + lines.append("## Adafruit Boards") + lines.append("") + _render_table(adafruit) + + lines.append("## 3rd Party Boards") + lines.append("") + _render_table(third_party) + + output.write_text("\n".join(lines)) + + +def main() -> None: + parser = argparse.ArgumentParser( + description="Generate supported_boards.md from src/boards/*/board.h" + ) + parser.add_argument( + "--output", + default="supported_boards.md", + help="Output markdown file (default: supported_boards.md)", + ) + args = parser.parse_args() + + repo_root = Path(__file__).resolve().parents[1] + output = Path(args.output) + if not output.is_absolute(): + output = repo_root / output + + generate(repo_root, output) + + +if __name__ == "__main__": + main() From d0f13ea1fed2a78c3272209a0bdf10a2a836f269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Sat, 31 Jan 2026 16:17:22 -0300 Subject: [PATCH 31/40] Made sure to clear pending interrupts and exceptions before jumping to the user application. Was rarely causing locks --- .../bootloader_dfu/bootloader_util.c | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_util.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_util.c index f6c2bcc..62cb285 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_util.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_util.c @@ -32,6 +32,12 @@ #if defined ( __CC_ARM ) __asm static void bootloader_util_reset(uint32_t start_addr) { + MOVS R5, #0x00 ; R5 = 0 + MSR CONTROL, R5 ; Clear CONTROL + MSR PRIMASK, R5 ; Clear PRIMASK + MSR BASEPRI, R5 ; Clear BASEPRI + MSR FAULTMASK, R5 ; Clear FAULTMASK + LDR R5, [R0] ; Get App initial MSP for bootloader. MSR MSP, R5 ; Set the main stack pointer to the applications MSP. LDR R0, [R0, #0x04] ; Load Reset handler into R0. This will be first argument to branch instruction (BX). @@ -69,6 +75,12 @@ static inline void bootloader_util_reset (uint32_t start_addr) __attribute__ ((o static inline void bootloader_util_reset(uint32_t start_addr) { __asm volatile( + "movs r5, #0x00\t\n" // R5 = 0 + "msr control, r5\t\n" // Clear CONTROL + "msr primask, r5\t\n" // Clear PRIMASK + "msr basepri, r5\t\n" // Clear BASEPRI + "msr faultmask, r5\t\n" // Clear FAULTMASK + "ldr r0, [%0]\t\n" // Get App initial MSP for bootloader. "msr msp, r0\t\n" // Set the main stack pointer to the applications MSP. "ldr r0, [%0, #0x04]\t\n" // Load Reset handler into R0. @@ -108,7 +120,13 @@ static inline void bootloader_util_reset(uint32_t start_addr) #elif defined ( __ICCARM__ ) static inline void bootloader_util_reset(uint32_t start_addr) { - asm("ldr r5, [%0]\n" // Get App initial MSP for bootloader. + asm("movs r5, #0x00\n" // R5 = 0 + "msr control, r5\n" // Clear CONTROL + "msr primask, r5\n" // Clear PRIMASK + "msr basepri, r5\n" // Clear BASEPRI + "msr faultmask, r5\n" // Clear FAULTMASK + + "ldr r5, [%0]\n" // Get App initial MSP for bootloader. "msr msp, r5\n" // Set the main stack pointer to the applications MSP. "ldr r0, [%0, #0x04]\n" // Load Reset handler into R0. From e8ffbd019a963815e1ca5edb067b327868aac4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Sat, 31 Jan 2026 16:19:57 -0300 Subject: [PATCH 32/40] Allow using an external LNA/PA to increase BLE range --- src/main.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 5beedec..cccb097 100644 --- a/src/main.c +++ b/src/main.c @@ -422,13 +422,76 @@ static uint32_t ble_stack_init(void) { // Note: Interrupt state (enabled, forwarding) is not work properly if not enable ble sd_ble_enable(&ram_start); -#if BLEGATT_ATT_MTU_MAX > 23 +#if BLEGATT_ATT_MTU_MAX > 23 || defined(GPIO_PA_PIN) || defined(GPIO_LNA_PIN) ble_opt_t opt; +#endif + +#if BLEGATT_ATT_MTU_MAX > 23 varclr(&opt); opt.common_opt.conn_evt_ext.enable = 1; // enable Data Length Extension sd_ble_opt_set(BLE_COMMON_OPT_CONN_EVT_EXT, &opt); #endif +#if defined(GPIO_PA_LNA_MODE_PIN) + // Set PA / LNA Mode Pin: Low for Normal operation + nrf_gpio_cfg_output(GPIO_PA_LNA_MODE_PIN); + nrf_gpio_pin_clear(GPIO_PA_LNA_MODE_PIN); +#endif + +#if defined(GPIO_PA_LNA_SELECT_PIN) + // Set PA / LNA Select Pin: low for u.FL + nrf_gpio_cfg_output(GPIO_PA_LNA_SELECT_PIN); + nrf_gpio_pin_clear(GPIO_PA_LNA_SELECT_PIN); +#endif + + // Configure SoftDevice PA / LNA assist if required +#if defined(GPIO_PA_PIN) || defined(GPIO_LNA_PIN) + + static const uint32_t gpio_toggle_ch = 0; + static const uint32_t ppi_set_ch = 0; + static const uint32_t ppi_clr_ch = 1; + + varclr(&opt); + + // Common PA / LNA config + // GPIOTE channel + opt.common_opt.pa_lna.gpiote_ch_id = gpio_toggle_ch; + // PPI channel for pin learing + opt.common_opt.pa_lna.ppi_ch_id_clr = ppi_clr_ch; + // PPI channel for pin setting + opt.common_opt.pa_lna.ppi_ch_id_set = ppi_set_ch; + +# if defined(GPIO_PA_PIN) + // -- PA config -- + // Set the pin to be active high + opt.common_opt.pa_lna.pa_cfg.active_high = GPIO_PA_PIN_ACTIVE_STATE; + // Enable toggling + opt.common_opt.pa_lna.pa_cfg.enable = 1; + // The GPIO pin to toggle + opt.common_opt.pa_lna.pa_cfg.gpio_pin = GPIO_PA_PIN; +# endif + +# if defined(GPIO_LNA_PIN) + // -- LNA config -- + // Set the pin to be active high + opt.common_opt.pa_lna.lna_cfg.active_high = GPIO_LNA_PIN_ACTIVE_STATE; + // Enable toggling + opt.common_opt.pa_lna.lna_cfg.enable = 1; + + // The GPIO pin to toggle + opt.common_opt.pa_lna.lna_cfg.gpio_pin = GPIO_LNA_PIN; + sd_ble_opt_set(BLE_COMMON_OPT_PA_LNA, &opt); +# endif + + // Set TX power for scan responses + sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT, 0, RADIO_TXPOWER_TXPOWER_Neg8dBm); + + // Set TX power for advertisements + sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, 0, RADIO_TXPOWER_TXPOWER_Neg8dBm); + // (Tx power setting for connections inherit the scan or advertising power setting) + +#endif + return NRF_SUCCESS; } From 4d1ca56d0a3b054edb7cdc37031363857e22b717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Sat, 31 Jan 2026 16:20:36 -0300 Subject: [PATCH 33/40] nice!nano board has no buttons --- src/boards/nice_nano/board.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/boards/nice_nano/board.h b/src/boards/nice_nano/board.h index 0ec4cde..d70dc53 100644 --- a/src/boards/nice_nano/board.h +++ b/src/boards/nice_nano/board.h @@ -39,9 +39,7 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 // none connected at all -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 19) // no connection +#define BUTTONS_NUMBER 0 // none connected at all #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ From e6da12ab45c1707c54e6e169c85fc31afe6919b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Jos=C3=A9=20Tagle?= Date: Sat, 31 Jan 2026 16:23:36 -0300 Subject: [PATCH 34/40] Update Makefile Yes, the '-D' was missing Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5b9b2e5..108ae15 100644 --- a/Makefile +++ b/Makefile @@ -373,7 +373,7 @@ CFLAGS += -DFORCE_UF2 endif ifeq ($(DEFAULT_TO_OTA_DFU), 1) -CFLAGS += -DEFAULT_TO_OTA_DFU +CFLAGS += -DDEFAULT_TO_OTA_DFU endif _VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION)))) From a76d419c34fb9b7478af58623f2b3f590148988b Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 2 Feb 2026 14:30:32 +0700 Subject: [PATCH 35/40] minor clean up --- .../libraries/bootloader_dfu/bootloader.c | 13 +++++++------ .../libraries/bootloader_dfu/dfu_single_bank.c | 5 +++-- src/main.c | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c index 9a8e55e..bd9b8cc 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader.c @@ -140,7 +140,7 @@ static void wait_for_events(void) (m_update_status == BOOTLOADER_SYS_RESET) || (m_update_status == BOOTLOADER_RESET_TO_SELF)) { - // When update has completed or a timeout/reset occured we will return. + // When update has completed or a timeout/reset occurred we will return. return; } } @@ -191,8 +191,9 @@ static void bootloader_settings_save(bootloader_settings_t * p_settings) uint32_t err_code; while(1) { err_code = pstorage_clear(&m_bootsettings_handle, sizeof(bootloader_settings_t)); - if (err_code != NRF_ERROR_NO_MEM) + if (err_code != NRF_ERROR_NO_MEM) { break; + } // This means the write/erase queue of commands was completely full - Should not // happen, but better safe than sorry, wait until space becomes available - // the pstorage event handler is only run from the main loop, and we are also @@ -209,8 +210,9 @@ static void bootloader_settings_save(bootloader_settings_t * p_settings) while(1) { err_code = pstorage_store(&m_bootsettings_handle, (uint8_t *) p_settings, sizeof(bootloader_settings_t), 0); - if (err_code != NRF_ERROR_NO_MEM) + if (err_code != NRF_ERROR_NO_MEM) { break; + } // No space, wait until an entry in the queue is freed while (NRF_ERROR_NOT_FOUND != proc_soc()) { // nothing @@ -322,9 +324,8 @@ void bootloader_dfu_update_process(dfu_update_status_t update_status) } else if (update_status.status_code == DFU_RESET) { - m_update_status = update_status.restart_into_bootloader == false - ? BOOTLOADER_SYS_RESET - : BOOTLOADER_RESET_TO_SELF; + m_update_status = + (update_status.restart_into_bootloader == false ? BOOTLOADER_SYS_RESET : BOOTLOADER_RESET_TO_SELF); } else { diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c index b53bf95..114a57c 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c @@ -789,8 +789,9 @@ uint32_t dfu_bl_image_validate(void) sd_mbr_cmd_1.params.compare.len = bootloader_settings.bl_image_size / sizeof(uint32_t); uint32_t err_code = sd_mbr_command(&sd_mbr_cmd_1); - if (err_code == NRF_SUCCESS) - return NRF_SUCCESS; + if (err_code == NRF_SUCCESS) { + return NRF_SUCCESS; + } uint32_t bl_image_start_2 = (bootloader_settings.sd_image_size == 0) ? DFU_BANK_1_REGION_START : diff --git a/src/main.c b/src/main.c index cccb097..f9a95d8 100644 --- a/src/main.c +++ b/src/main.c @@ -134,7 +134,7 @@ uint32_t* dbl_reset_mem = ((uint32_t*) DFU_DBL_RESET_MEM); // true if ble, false if serial bool _ota_dfu = false; bool _ota_connected = false; -bool _ota_was_active = false; +bool _ota_was_connected = false; bool _sd_inited = false; bool is_ota(void) { @@ -231,7 +231,7 @@ int main(void) { // Reset the system with the OTA DFU update in case we were in it, // to allow completion of FLASHING, otherwise, default to normal reset - if (_ota_was_active) { + if (_ota_was_connected) { NRF_POWER->GPREGRET = DFU_MAGIC_OTA_RESET; } @@ -526,8 +526,8 @@ uint32_t proc_ble(void) { _ota_connected = true; - // Remember someone connected to BLE - _ota_was_active = true; + // Remember someone connected to BLE + _ota_was_connected = true; led_state(STATE_BLE_CONNECTED); break; } From 29173a4de126f68aea29ca44047faf82a3c70398 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 2 Feb 2026 16:49:26 +0700 Subject: [PATCH 36/40] rename BUTTON_FRESET to BUTTON_DFU_OTA change board.d BUTTON_1/2 directly to BUTTON_DFU and BUTTON_DFU_OTA --- src/boards/adm_b_nrf52840_1/board.h | 32 ++++----- src/boards/ae_bl652_bo/board.h | 24 +++---- src/boards/aramcon2_badge/board.h | 36 +++++----- src/boards/aramcon_badge_2019/board.h | 36 +++++----- .../arcade_feather_nrf52840_express/board.h | 41 +++++------ src/boards/arduino_nano_33_ble/board.h | 32 ++++----- src/boards/bast_ble/board.h | 32 ++++----- src/boards/bluemicro_nrf52833/board.h | 40 +++++------ src/boards/bluemicro_nrf52840/board.h | 34 +++++---- src/boards/boards.c | 6 +- src/boards/boards.h | 11 ++- src/boards/challenger_840_ble/board.h | 40 +++++------ src/boards/circuitplayground_nrf52840/board.h | 38 +++++----- src/boards/clue_nrf52840/board.h | 66 +++++++++-------- src/boards/ebyte_e104_bt5032a/board.h | 33 ++++----- src/boards/ebyte_e73_tbb/board.h | 35 ++++----- src/boards/electronut_labs_papyr/board.h | 30 ++++---- src/boards/feather_nrf52832/board.h | 24 +++---- src/boards/feather_nrf52840_express/board.h | 13 ++-- src/boards/feather_nrf52840_sense/board.h | 40 +++++------ src/boards/feather_nrf52840_sense_tft/board.h | 72 +++++++++---------- src/boards/ikigaisense_vita/board.h | 40 +++++------ src/boards/itsybitsy_nrf52840_express/board.h | 12 ++-- src/boards/ledglasses_nrf52840/board.h | 38 +++++----- src/boards/m60_keyboard/board.h | 42 ++++++----- src/boards/m60_keyboard/pinconfig.c | 62 ++++++++-------- src/boards/mbn52832dk/board.h | 24 +++---- src/boards/mdk_nrf52840_dongle/board.h | 42 ++++++----- src/boards/metro_nrf52840_express/board.h | 40 +++++------ src/boards/mikoto/board.h | 32 ++++----- src/boards/nRF52840_connect_kit/board.h | 40 +++++------ src/boards/nice_nano/board.h | 32 ++++----- src/boards/nrf52840_bboard/board.h | 32 ++++----- src/boards/nrf52840_m2/board.h | 42 ++++++----- src/boards/nrfmicro/board.h | 34 +++++---- src/boards/ohs2020_badge/board.h | 32 ++++----- src/boards/omnimo_nrf52840/board.h | 42 ++++++----- src/boards/particle_argon/board.h | 14 ++-- src/boards/particle_boron/board.h | 36 +++++----- src/boards/particle_xenon/board.h | 36 +++++----- src/boards/pca10056/board.h | 30 ++++---- src/boards/pca10059/board.h | 24 +++---- src/boards/pca10100/board.h | 32 ++++----- src/boards/pillbug/board.h | 32 ++++----- src/boards/pitaya_go/board.h | 40 +++++------ src/boards/raytac_mdbt50q_db_40/board.h | 16 ++--- src/boards/raytac_mdbt50q_rx/board.h | 32 ++++----- src/boards/sparkfun_nrf52840_micromod/board.h | 32 ++++----- src/boards/t1000_e/board.h | 32 ++++----- src/boards/waveshare_nrf52840_eval/board.h | 34 +++++---- src/boards/xiao_nrf52840_ble/board.h | 34 +++++---- src/boards/xiao_nrf52840_ble_sense/board.h | 34 +++++---- src/main.c | 4 +- 53 files changed, 844 insertions(+), 919 deletions(-) diff --git a/src/boards/adm_b_nrf52840_1/board.h b/src/boards/adm_b_nrf52840_1/board.h index 11c041a..34dfa54 100644 --- a/src/boards/adm_b_nrf52840_1/board.h +++ b/src/boards/adm_b_nrf52840_1/board.h @@ -25,42 +25,40 @@ #ifndef ADM_B_NRF52840_1_H #define ADM_B_NRF52840_1_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 19) // Red -//#define LED_SECONDARY_PIN 12 // Blue -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 19) // Red +// #define LED_SECONDARY_PIN 12 // Blue +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 11) -#define BUTTON_2 _PINNUM(0, 12) +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 12) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Atelier-Du-Maker" -#define BLEDIS_MODEL "ADM_B_NRF52840_1" +#define BLEDIS_MANUFACTURER "Atelier-Du-Maker" +#define BLEDIS_MODEL "ADM_B_NRF52840_1" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x009F -#define USB_DESC_CDC_ONLY_PID 0x009F +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x009F +#define USB_DESC_CDC_ONLY_PID 0x009F //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "AtelierDuMaker NRF52840 Breakout" -#define UF2_VOLUME_LABEL "ADM840BOOT" -#define UF2_BOARD_ID "ADM_B_NRF52840_1" -#define UF2_INDEX_URL "https://github.com/Atelier-Du-Maker/HolyIoT_NRF52840" +#define UF2_PRODUCT_NAME "AtelierDuMaker NRF52840 Breakout" +#define UF2_VOLUME_LABEL "ADM840BOOT" +#define UF2_BOARD_ID "ADM_B_NRF52840_1" +#define UF2_INDEX_URL "https://github.com/Atelier-Du-Maker/HolyIoT_NRF52840" #endif // ADM_B_NRF52840_1_H diff --git a/src/boards/ae_bl652_bo/board.h b/src/boards/ae_bl652_bo/board.h index 1636ccf..77232d8 100644 --- a/src/boards/ae_bl652_bo/board.h +++ b/src/boards/ae_bl652_bo/board.h @@ -28,26 +28,26 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // LED1 -#define LED_SECONDARY_PIN 19 // LED2 -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // LED1 +#define LED_SECONDARY_PIN 19 // LED2 +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 11 // BTN1 -#define BUTTON_2 15 // BTN2 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 11 // BTN1 +#define BUTTON_DFU_OTA 15 // BTN2 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* UART (only used by nRF52832) *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false +#define RX_PIN_NUMBER 8 +#define TX_PIN_NUMBER 6 +#define CTS_PIN_NUMBER 0 +#define RTS_PIN_NUMBER 0 +#define HWFC false //--------------------------------------------------------------------+ // BLE OTA diff --git a/src/boards/aramcon2_badge/board.h b/src/boards/aramcon2_badge/board.h index 788fa3b..cf61be9 100644 --- a/src/boards/aramcon2_badge/board.h +++ b/src/boards/aramcon2_badge/board.h @@ -25,40 +25,38 @@ #ifndef _ARAMCON2_BADGE_H #define _ARAMCON2_BADGE_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 11) // Red +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 11) // Red -#define LED_NEOPIXEL _PINNUM(0, 8) -#define NEOPIXELS_NUMBER 2 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 8) +#define NEOPIXELS_NUMBER 2 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 2) // left Button -#define BUTTON_2 _PINNUM(0, 29) // middle button -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 2) // left Button +#define BUTTON_DFU_OTA PINNUM(0, 29) // middle button +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP // Used as model string in OTA mode -#define BLEDIS_MANUFACTURER "ARAMCON Badge Team" -#define BLEDIS_MODEL "ARAMCON2 Badge" +#define BLEDIS_MANUFACTURER "ARAMCON Badge Team" +#define BLEDIS_MODEL "ARAMCON2 Badge" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x007B -#define USB_DESC_CDC_ONLY_PID 0x007B +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x007B +#define USB_DESC_CDC_ONLY_PID 0x007B //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "ARAMCON2 Badge" -#define UF2_VOLUME_LABEL "ARAMBOOT" -#define UF2_BOARD_ID "nrf52840-ARAMCON2-Badge" -#define UF2_INDEX_URL "https://github.com/aramcon-badge" +#define UF2_PRODUCT_NAME "ARAMCON2 Badge" +#define UF2_VOLUME_LABEL "ARAMBOOT" +#define UF2_BOARD_ID "nrf52840-ARAMCON2-Badge" +#define UF2_INDEX_URL "https://github.com/aramcon-badge" #endif // _ARAMCON2_BADGE_H diff --git a/src/boards/aramcon_badge_2019/board.h b/src/boards/aramcon_badge_2019/board.h index c545880..b81fdbd 100644 --- a/src/boards/aramcon_badge_2019/board.h +++ b/src/boards/aramcon_badge_2019/board.h @@ -26,42 +26,40 @@ #ifndef _ARAMCON_BADGE_2019_H #define _ARAMCON_BADGE_2019_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 11) // Red +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 11) // Red -#define LED_NEOPIXEL _PINNUM(0, 8) -#define NEOPIXELS_NUMBER 4 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 8) +#define NEOPIXELS_NUMBER 4 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 2) // left Button -#define BUTTON_2 _PINNUM(0, 29) // middle button -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 2) // left Button +#define BUTTON_DFU_OTA PINNUM(0, 29) // middle button +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "ARAMCON Badge Team" -#define BLEDIS_MODEL "ARAMCON Badge 2019" +#define BLEDIS_MANUFACTURER "ARAMCON Badge Team" +#define BLEDIS_MODEL "ARAMCON Badge 2019" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0079 -#define USB_DESC_CDC_ONLY_PID 0x0079 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0079 +#define USB_DESC_CDC_ONLY_PID 0x0079 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "ARAMCON Badge 2019" -#define UF2_VOLUME_LABEL "ARAMBOOT" -#define UF2_BOARD_ID "nrf52840-ARAMCON-Badge-2019" -#define UF2_INDEX_URL "https://github.com/aramcon-badge" +#define UF2_PRODUCT_NAME "ARAMCON Badge 2019" +#define UF2_VOLUME_LABEL "ARAMBOOT" +#define UF2_BOARD_ID "nrf52840-ARAMCON-Badge-2019" +#define UF2_INDEX_URL "https://github.com/aramcon-badge" #endif // _ARAMCON_BADGE_2019_H diff --git a/src/boards/arcade_feather_nrf52840_express/board.h b/src/boards/arcade_feather_nrf52840_express/board.h index b8b91f5..c33b644 100644 --- a/src/boards/arcade_feather_nrf52840_express/board.h +++ b/src/boards/arcade_feather_nrf52840_express/board.h @@ -25,45 +25,42 @@ #ifndef _ARCARDE_FEATHER_NRF52840_H #define _ARCARDE_FEATHER_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 15) +#define LED_SECONDARY_PIN PINNUM(1, 10) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52840 Express" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52840 Express" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x002A +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x002A //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" -#define UF2_VOLUME_LABEL "ARCADE-N4" -#define UF2_BOARD_ID "nRF52840-Feather-revD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" +#define UF2_VOLUME_LABEL "ARCADE-N4" +#define UF2_BOARD_ID "nRF52840-Feather-revD" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" #endif // _ARCARDE_FEATHER_NRF52840_H - diff --git a/src/boards/arduino_nano_33_ble/board.h b/src/boards/arduino_nano_33_ble/board.h index d29fc36..79e32fc 100644 --- a/src/boards/arduino_nano_33_ble/board.h +++ b/src/boards/arduino_nano_33_ble/board.h @@ -25,39 +25,37 @@ #ifndef _ARDUINOBLE33_NRF52840_H #define _ARDUINOBLE33_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 // red LED -#define LED_PRIMARY_PIN _PINNUM(0, 24) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 // red LED +#define LED_PRIMARY_PIN PINNUM(0, 24) +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 11) // D2 switch -#define BUTTON_2 _PINNUM(1, 12) // D3 switch -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 11) // D2 switch +#define BUTTON_DFU_OTA PINNUM(1, 12) // D3 switch +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Arduino" -#define BLEDIS_MODEL "Nano 33 BLE" +#define BLEDIS_MANUFACTURER "Arduino" +#define BLEDIS_MODEL "Nano 33 BLE" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0063 -#define USB_DESC_CDC_ONLY_PID 0x0064 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0063 +#define USB_DESC_CDC_ONLY_PID 0x0064 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Arduino Nano 33 BLE" -#define UF2_VOLUME_LABEL "NANO33BOOT" -#define UF2_BOARD_ID "nRF52840-Nano-33" -#define UF2_INDEX_URL "https://www.arduino.cc/" +#define UF2_PRODUCT_NAME "Arduino Nano 33 BLE" +#define UF2_VOLUME_LABEL "NANO33BOOT" +#define UF2_BOARD_ID "nRF52840-Nano-33" +#define UF2_INDEX_URL "https://www.arduino.cc/" #endif // _ITSY_NRF52840_H diff --git a/src/boards/bast_ble/board.h b/src/boards/bast_ble/board.h index 93a0eb6..598d2dd 100644 --- a/src/boards/bast_ble/board.h +++ b/src/boards/bast_ble/board.h @@ -25,39 +25,39 @@ #ifndef _BASTBLE_NRF52840_H #define _BASTBLE_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) +#define PINNUM(port, pin) ((port) * 32 + (pin)) /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 // red LED -#define LED_PRIMARY_PIN _PINNUM(0, 24) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 // red LED +#define LED_PRIMARY_PIN PINNUM(0, 24) +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 05) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 05) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "ElectronicCats" -#define BLEDIS_MODEL "BastBLE" +#define BLEDIS_MANUFACTURER "ElectronicCats" +#define BLEDIS_MODEL "BastBLE" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with Feather nRF52840, will be disabled for building in the future -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x805A -#define USB_DESC_CDC_ONLY_PID 0x805A +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x805A +#define USB_DESC_CDC_ONLY_PID 0x805A -#define UF2_PRODUCT_NAME "Bast BLE" -#define UF2_VOLUME_LABEL "BASTBLE" -#define UF2_BOARD_ID "Bast-ble-v1" -#define UF2_INDEX_URL "https://www.electroniccats.com" +#define UF2_PRODUCT_NAME "Bast BLE" +#define UF2_VOLUME_LABEL "BASTBLE" +#define UF2_BOARD_ID "Bast-ble-v1" +#define UF2_INDEX_URL "https://www.electroniccats.com" #endif // _BASTBLE_NRF52840_H diff --git a/src/boards/bluemicro_nrf52833/board.h b/src/boards/bluemicro_nrf52833/board.h index 763a0f4..454d340 100644 --- a/src/boards/bluemicro_nrf52833/board.h +++ b/src/boards/bluemicro_nrf52833/board.h @@ -25,44 +25,42 @@ #ifndef _BLUEMICRO_NRF52833_H #define _BLUEMICRO_NRF52833_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 4) -#define LED_SECONDARY_PIN _PINNUM(0, 25) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 4) +#define LED_SECONDARY_PIN PINNUM(0, 25) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 7) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 7) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(1, 1) // no connection on E73-2G4M08S1E Module -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(1, 1) // no connection on E73-2G4M08S1E Module +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "BlueMicro" -#define BLEDIS_MODEL "BlueMicro 833" +#define BLEDIS_MANUFACTURER "BlueMicro" +#define BLEDIS_MODEL "BlueMicro 833" //--------------------------------------------------------------------+ // USB PID from openmoko: // PR https://github.com/openmoko/openmoko-usb-oui/pull/34 //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1d50 -#define USB_DESC_UF2_PID 0x616f -#define USB_DESC_CDC_ONLY_PID 0x616f +#define USB_DESC_VID 0x1d50 +#define USB_DESC_UF2_PID 0x616f +#define USB_DESC_CDC_ONLY_PID 0x616f -#define UF2_PRODUCT_NAME "BlueMicro" -#define UF2_VOLUME_LABEL "BLUEMICRO" -#define UF2_BOARD_ID "nRF52833-BlueMicro-v1" -#define UF2_INDEX_URL "http://bluemicro.jpconstantineau.com/" +#define UF2_PRODUCT_NAME "BlueMicro" +#define UF2_VOLUME_LABEL "BLUEMICRO" +#define UF2_BOARD_ID "nRF52833-BlueMicro-v1" +#define UF2_INDEX_URL "http://bluemicro.jpconstantineau.com/" #endif // _BLUEMICRO_H diff --git a/src/boards/bluemicro_nrf52840/board.h b/src/boards/bluemicro_nrf52840/board.h index f590dfe..46a2ef0 100644 --- a/src/boards/bluemicro_nrf52840/board.h +++ b/src/boards/bluemicro_nrf52840/board.h @@ -25,40 +25,38 @@ #ifndef _BLUEMICRO_NRF52840_H #define _BLUEMICRO_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 4) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 4) +#define LED_SECONDARY_PIN PINNUM(1, 10) +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(1, 1) // no connection on E73-2G4M08S1C Module -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(1, 1) // no connection on E73-2G4M08S1C Module +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "BlueMicro" -#define BLEDIS_MODEL "BlueMicro 840" +#define BLEDIS_MANUFACTURER "BlueMicro" +#define BLEDIS_MODEL "BlueMicro 840" //--------------------------------------------------------------------+ // USB PID from openmoko: // Approved PR https://github.com/openmoko/openmoko-usb-oui/pull/20 //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1d50 -#define USB_DESC_UF2_PID 0x6160 -#define USB_DESC_CDC_ONLY_PID 0x6160 +#define USB_DESC_VID 0x1d50 +#define USB_DESC_UF2_PID 0x6160 +#define USB_DESC_CDC_ONLY_PID 0x6160 -#define UF2_PRODUCT_NAME "BlueMicro" -#define UF2_VOLUME_LABEL "BLUEMICRO" -#define UF2_BOARD_ID "nRF52840-BlueMicro-v1" -#define UF2_INDEX_URL "http://bluemicro.jpconstantineau.com/" +#define UF2_PRODUCT_NAME "BlueMicro" +#define UF2_VOLUME_LABEL "BLUEMICRO" +#define UF2_BOARD_ID "nRF52840-BlueMicro-v1" +#define UF2_INDEX_URL "http://bluemicro.jpconstantineau.com/" #endif // _BLUEMICRO_H diff --git a/src/boards/boards.c b/src/boards/boards.c index 9f98632..c02a278 100644 --- a/src/boards/boards.c +++ b/src/boards/boards.c @@ -50,7 +50,7 @@ void SysTick_Handler(void) { led_tick(); } -#if defined(BUTTON_DFU) || defined(BUTTON_FRESET) +#if defined(BUTTON_DFU) || defined(BUTTON_DFU_OTA) void button_init(uint32_t pin) { if (BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN) { nrf_gpio_cfg_sense_input(pin, BUTTON_PULL, NRF_GPIO_PIN_SENSE_HIGH); @@ -79,8 +79,8 @@ void board_init(void) { #ifdef BUTTON_DFU button_init(BUTTON_DFU); #endif -#ifdef BUTTON_FRESET - button_init(BUTTON_FRESET); +#ifdef BUTTON_DFU_OTA + button_init(BUTTON_DFU_OTA); #endif NRFX_DELAY_US(100); // wait for the pin state is stable diff --git a/src/boards/boards.h b/src/boards/boards.h index 583e044..87b14b1 100644 --- a/src/boards/boards.h +++ b/src/boards/boards.h @@ -31,18 +31,15 @@ #include "nrf.h" #include "nrf_gpio.h" +#define PINNUM(port, pin) ((port) * 32 + (pin)) #include "board.h" #ifndef UF2_VOLUME_LABEL #define UF2_VOLUME_LABEL "NRF52BOOT " #endif -#if !defined(BUTTON_DFU) && defined(BUTTON_1) -#define BUTTON_DFU BUTTON_1 -#endif - -#if !defined(BUTTON_FRESET) && defined(BUTTON_2) -#define BUTTON_FRESET BUTTON_2 +#if !defined(BUTTON_DFU_OTA) && defined(BUTTON_DFU_OTA) + #define BUTTON_DFU_OTA BUTTON_DFU_OTA #endif // The primary LED is usually Red but not in all cases. @@ -104,7 +101,7 @@ void led_tick(void); //--------------------------------------------------------------------+ // BUTTONS //--------------------------------------------------------------------+ -#if defined(BUTTON_DFU) || defined(BUTTON_FRESET) +#if defined(BUTTON_DFU) || defined(BUTTON_DFU_OTA) void button_init(uint32_t pin); bool button_pressed(uint32_t pin); #endif diff --git a/src/boards/challenger_840_ble/board.h b/src/boards/challenger_840_ble/board.h index 25d4c6e..7be348c 100644 --- a/src/boards/challenger_840_ble/board.h +++ b/src/boards/challenger_840_ble/board.h @@ -25,48 +25,46 @@ #ifndef _CHALLENGER_840_BLE_H #define _CHALLENGER_840_BLE_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 12) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 12) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(1, 8) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(1, 8) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 19) -#define BUTTON_2 _PINNUM(0, 8) // Pulls flash cs high -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 19) +#define BUTTON_DFU_OTA PINNUM(0, 8) // Pulls flash cs high +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* On board LDO control *------------------------------------------------------------------*/ -#define LDO_CONTROL_PIN _PINNUM(1, 9) // Enables external pwr +#define LDO_CONTROL_PIN PINNUM(1, 9) // Enables external pwr //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Invector Labs" -#define BLEDIS_MODEL "Challenger 840 BLE" +#define BLEDIS_MANUFACTURER "Invector Labs" +#define BLEDIS_MODEL "Challenger 840 BLE" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x7380 -#define USB_DESC_CDC_ONLY_PID 0x7381 +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x7380 +#define USB_DESC_CDC_ONLY_PID 0x7381 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "ILabs Challenger 840" -#define UF2_VOLUME_LABEL "CH840BOOT" -#define UF2_BOARD_ID "nRF52840-Challenger-840" -#define UF2_INDEX_URL "https://www.ilabs.se" +#define UF2_PRODUCT_NAME "ILabs Challenger 840" +#define UF2_VOLUME_LABEL "CH840BOOT" +#define UF2_BOARD_ID "nRF52840-Challenger-840" +#define UF2_INDEX_URL "https://www.ilabs.se" #endif // _CHALLENGER_840_BLE_H diff --git a/src/boards/circuitplayground_nrf52840/board.h b/src/boards/circuitplayground_nrf52840/board.h index 62a537e..82a9bbf 100644 --- a/src/boards/circuitplayground_nrf52840/board.h +++ b/src/boards/circuitplayground_nrf52840/board.h @@ -25,43 +25,41 @@ #ifndef _CPLAY_NRF52840_H #define _CPLAY_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 14) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 14) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 13) -#define NEOPIXELS_NUMBER 10 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 13) +#define NEOPIXELS_NUMBER 10 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 02) // left button -#define BUTTON_2 _PINNUM(1, 15) // right button -#define BUTTON_PULL NRF_GPIO_PIN_PULLDOWN +#define BUTTON_DFU PINNUM(1, 02) // left button +#define BUTTON_DFU_OTA PINNUM(1, 15) // right button +#define BUTTON_PULL NRF_GPIO_PIN_PULLDOWN //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Circuit Playground nRF52840" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Circuit Playground nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0045 -#define USB_DESC_CDC_ONLY_PID 0x0045 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0045 +#define USB_DESC_CDC_ONLY_PID 0x0045 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Circuit Playground nRF52840" -#define UF2_VOLUME_LABEL "CPLAYBTBOOT" -#define UF2_BOARD_ID "nRF52840-CircuitPlayground-revD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4333" +#define UF2_PRODUCT_NAME "Adafruit Circuit Playground nRF52840" +#define UF2_VOLUME_LABEL "CPLAYBTBOOT" +#define UF2_BOARD_ID "nRF52840-CircuitPlayground-revD" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4333" #endif // _CPLAY_NRF52840_H diff --git a/src/boards/clue_nrf52840/board.h b/src/boards/clue_nrf52840/board.h index 61466e3..91b8f56 100644 --- a/src/boards/clue_nrf52840/board.h +++ b/src/boards/clue_nrf52840/board.h @@ -25,69 +25,67 @@ #ifndef _CLUE_NRF52840_H #define _CLUE_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 01) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 01) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 02) // left button -#define BUTTON_2 _PINNUM(1, 10) // right button -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 02) // left button +#define BUTTON_DFU_OTA PINNUM(1, 10) // right button +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // Display //--------------------------------------------------------------------+ #define DISPLAY_CONTROLLER_ST7789 -#define DISPLAY_PIN_SCK _PINNUM(0, 14) -#define DISPLAY_PIN_MOSI _PINNUM(0, 15) +#define DISPLAY_PIN_SCK PINNUM(0, 14) +#define DISPLAY_PIN_MOSI PINNUM(0, 15) -#define DISPLAY_PIN_CS _PINNUM(0, 12) -#define DISPLAY_PIN_DC _PINNUM(0, 13) -#define DISPLAY_PIN_RST _PINNUM(1, 3) -#define DISPLAY_PIN_BL _PINNUM(1, 5) -#define DISPLAY_BL_ON 1 // GPIO state to enable back light +#define DISPLAY_PIN_CS PINNUM(0, 12) +#define DISPLAY_PIN_DC PINNUM(0, 13) +#define DISPLAY_PIN_RST PINNUM(1, 3) +#define DISPLAY_PIN_BL PINNUM(1, 5) +#define DISPLAY_BL_ON 1 // GPIO state to enable back light -#define DISPLAY_WIDTH 240 -#define DISPLAY_HEIGHT 240 +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 240 -#define DISPLAY_COL_OFFSET 0 -#define DISPLAY_ROW_OFFSET 80 +#define DISPLAY_COL_OFFSET 0 +#define DISPLAY_ROW_OFFSET 80 // Memory Data Access Control & // Vertical Scroll Start Address -#define DISPLAY_MADCTL (TFT_MADCTL_MY) -#define DISPLAY_VSCSAD 0 +#define DISPLAY_MADCTL (TFT_MADCTL_MY) +#define DISPLAY_VSCSAD 0 -#define DISPLAY_TITLE "CLUE" +#define DISPLAY_TITLE "CLUE" //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "CLUE nRF52840" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "CLUE nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0071 -#define USB_DESC_CDC_ONLY_PID 0x0071 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0071 +#define USB_DESC_CDC_ONLY_PID 0x0071 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit CLUE nRF52840" -#define UF2_VOLUME_LABEL "CLUEBOOT" -#define UF2_BOARD_ID "nRF52840-CLUE-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4500" +#define UF2_PRODUCT_NAME "Adafruit CLUE nRF52840" +#define UF2_VOLUME_LABEL "CLUEBOOT" +#define UF2_BOARD_ID "nRF52840-CLUE-revA" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4500" #endif // _CLUE_NRF52840_H diff --git a/src/boards/ebyte_e104_bt5032a/board.h b/src/boards/ebyte_e104_bt5032a/board.h index 3cc675d..983f5ff 100644 --- a/src/boards/ebyte_e104_bt5032a/board.h +++ b/src/boards/ebyte_e104_bt5032a/board.h @@ -28,30 +28,31 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 31 // Red - named "Data" -#define LED_SECONDARY_PIN 30 // Blue - named "Link" (also a red one on the Test Board) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 31 // Red - named "Data" +#define LED_SECONDARY_PIN 30 // Blue - named "Link" (also a red one on the Test Board) +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 29 // DISC Button on E104-BT5032A-TB Test Board - // BUTTON_1 is DFU. The module does not have reset circuitry. - // The Test Board from Ebyte (E104-BT5032A-TB) also does not have reset circuitry - // To be able to upload using the Arduino IDE, (To enter DFU mode) - // Press "DISC", press and release "RST", then release "DISC" -#define BUTTON_2 28 // No button - WKP pin -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU \ + 29 // DISC Button on E104-BT5032A-TB Test Board + // BUTTON_DFU is DFU. The module does not have reset circuitry. + // The Test Board from Ebyte (E104-BT5032A-TB) also does not have reset circuitry + // To be able to upload using the Arduino IDE, (To enter DFU mode) + // Press "DISC", press and release "RST", then release "DISC" +#define BUTTON_DFU_OTA 28 // No button - WKP pin +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* UART (only used by nRF52832) *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 14 -#define TX_PIN_NUMBER 18 -#define CTS_PIN_NUMBER 20 -#define RTS_PIN_NUMBER 19 -#define HWFC false // leaving it false to make GPIO available +#define RX_PIN_NUMBER 14 +#define TX_PIN_NUMBER 18 +#define CTS_PIN_NUMBER 20 +#define RTS_PIN_NUMBER 19 +#define HWFC false // leaving it false to make GPIO available //--------------------------------------------------------------------+ // BLE OTA diff --git a/src/boards/ebyte_e73_tbb/board.h b/src/boards/ebyte_e73_tbb/board.h index f6f4c90..bd522c5 100644 --- a/src/boards/ebyte_e73_tbb/board.h +++ b/src/boards/ebyte_e73_tbb/board.h @@ -28,31 +28,32 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // Red - named "LED1" -#define LED_SECONDARY_PIN 18 // Blue - named "LED2" (also a red one on the Test Board) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // Red - named "LED1" +#define LED_SECONDARY_PIN 18 // Blue - named "LED2" (also a red one on the Test Board) +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 14 // BUTTON_1 is DFU. SW1 on E73-TBB Test Board. - // This Test board uses the E73-2G4M04S1B module which contains a nrf52832. - // The module does not have reset circuitry. - // The Test Board from Ebyte (E73-TBB) also does not have reset circuitry - // To be able to upload using the Arduino IDE, (To enter DFU mode) - // Press "SW1", momentarily ground "RST/P0.21", then release "SW1" -#define BUTTON_2 13 // SW2 on board -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU \ + 14 // BUTTON_DFU is DFU. SW1 on E73-TBB Test Board. + // This Test board uses the E73-2G4M04S1B module which contains a nrf52832. + // The module does not have reset circuitry. + // The Test Board from Ebyte (E73-TBB) also does not have reset circuitry + // To be able to upload using the Arduino IDE, (To enter DFU mode) + // Press "SW1", momentarily ground "RST/P0.21", then release "SW1" +#define BUTTON_DFU_OTA 13 // SW2 on board +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* UART (only used by nRF52832) *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 5 -#define RTS_PIN_NUMBER 7 -#define HWFC false // leaving it false to make GPIO available +#define RX_PIN_NUMBER 8 +#define TX_PIN_NUMBER 6 +#define CTS_PIN_NUMBER 5 +#define RTS_PIN_NUMBER 7 +#define HWFC false // leaving it false to make GPIO available //--------------------------------------------------------------------+ // BLE OTA diff --git a/src/boards/electronut_labs_papyr/board.h b/src/boards/electronut_labs_papyr/board.h index 70fa231..69ce72f 100644 --- a/src/boards/electronut_labs_papyr/board.h +++ b/src/boards/electronut_labs_papyr/board.h @@ -30,10 +30,10 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 13 -#define LED_SECONDARY_PIN 14 -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 13 +#define LED_SECONDARY_PIN 14 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON @@ -42,25 +42,25 @@ // App can trigger OTA bootloader by writing DFU_MAGIC_OTA_APPJUM to // GPREGRET register if softdevice is not initialized; or by // writing DFU_MAGIC_OTA_RESET in case softdevice is initialized. -#define BUTTON_1 18 // RESET also by default -#define BUTTON_2 1 // P0.1 not exposed anywhere, FRST n/a -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 18 // RESET also by default +#define BUTTON_DFU_OTA 1 // P0.1 not exposed anywhere, FRST n/a +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Electronut Labs" -#define BLEDIS_MODEL "Papyr" +#define BLEDIS_MANUFACTURER "Electronut Labs" +#define BLEDIS_MODEL "Papyr" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "Electronut Labs Papyr" -#define UF2_BOARD_ID "nRF52840-Papyr-v1" -#define UF2_INDEX_URL "https://docs.electronut.in/papyr" +#define UF2_PRODUCT_NAME "Electronut Labs Papyr" +#define UF2_BOARD_ID "nRF52840-Papyr-v1" +#define UF2_INDEX_URL "https://docs.electronut.in/papyr" -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x003B -#define USB_DESC_CDC_ONLY_PID 0x003B +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x003B +#define USB_DESC_CDC_ONLY_PID 0x003B #endif // PPAPYR_H diff --git a/src/boards/feather_nrf52832/board.h b/src/boards/feather_nrf52832/board.h index dfb6175..5e280a1 100644 --- a/src/boards/feather_nrf52832/board.h +++ b/src/boards/feather_nrf52832/board.h @@ -28,26 +28,26 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // Red -#define LED_SECONDARY_PIN 19 // Blue -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // Red +#define LED_SECONDARY_PIN 19 // Blue +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 20 -#define BUTTON_2 22 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 20 +#define BUTTON_DFU_OTA 22 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* UART (only used by nRF52832) *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false +#define RX_PIN_NUMBER 8 +#define TX_PIN_NUMBER 6 +#define CTS_PIN_NUMBER 0 +#define RTS_PIN_NUMBER 0 +#define HWFC false //--------------------------------------------------------------------+ // BLE OTA diff --git a/src/boards/feather_nrf52840_express/board.h b/src/boards/feather_nrf52840_express/board.h index cec7e68..4fa7c98 100644 --- a/src/boards/feather_nrf52840_express/board.h +++ b/src/boards/feather_nrf52840_express/board.h @@ -25,26 +25,25 @@ #ifndef _FEATHER_NRF52840_H #define _FEATHER_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) +#define LED_PRIMARY_PIN PINNUM(1, 15) +#define LED_SECONDARY_PIN PINNUM(1, 10) #define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXEL_POWER_PIN _PINNUM(1, 14) +#define LED_NEOPIXEL PINNUM(0, 16) +#define NEOPIXEL_POWER_PIN PINNUM(1, 14) #define NEOPIXELS_NUMBER 1 #define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) +#define BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(0, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ diff --git a/src/boards/feather_nrf52840_sense/board.h b/src/boards/feather_nrf52840_sense/board.h index 4c9b250..e0740fd 100644 --- a/src/boards/feather_nrf52840_sense/board.h +++ b/src/boards/feather_nrf52840_sense/board.h @@ -25,44 +25,42 @@ #ifndef _FEATHER_NRF52840_SENSE_H #define _FEATHER_NRF52840_SENSE_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 9) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 9) +#define LED_SECONDARY_PIN PINNUM(1, 10) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52840 Sense" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52840 Sense" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0087 -#define USB_DESC_CDC_ONLY_PID 0x0088 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0087 +#define USB_DESC_CDC_ONLY_PID 0x0088 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense" -#define UF2_VOLUME_LABEL "FTHRSNSBOOT" -#define UF2_BOARD_ID "nRF52840-Feather-Sense" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4516" +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense" +#define UF2_VOLUME_LABEL "FTHRSNSBOOT" +#define UF2_BOARD_ID "nRF52840-Feather-Sense" +#define UF2_INDEX_URL "https://www.adafruit.com/product/4516" #endif // _FEATHER_NRF52840_SENSE_H diff --git a/src/boards/feather_nrf52840_sense_tft/board.h b/src/boards/feather_nrf52840_sense_tft/board.h index f46c14b..2e97e02 100644 --- a/src/boards/feather_nrf52840_sense_tft/board.h +++ b/src/boards/feather_nrf52840_sense_tft/board.h @@ -25,75 +25,73 @@ #ifndef _FEATHER_NRF52840_SENSE_TFT_H #define _FEATHER_NRF52840_SENSE_TFT_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 11) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 11) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(1, 8) -#define NEOPIXEL_POWER_PIN _PINNUM(1, 2) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(1, 8) +#define NEOPIXEL_POWER_PIN PINNUM(1, 2) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 6) -#define BUTTON_2 _PINNUM(1, 10) // DFU pin -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 6) +#define BUTTON_DFU_OTA PINNUM(1, 10) // DFU pin +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // Display //--------------------------------------------------------------------+ // VSensor required to power the display -#define DISPLAY_VSENSOR_PIN _PINNUM(1, 7) -#define DISPLAY_VSENSOR_ON 1 +#define DISPLAY_VSENSOR_PIN PINNUM(1, 7) +#define DISPLAY_VSENSOR_ON 1 #define DISPLAY_CONTROLLER_ST7789 -#define DISPLAY_PIN_SCK _PINNUM(0, 26) -#define DISPLAY_PIN_MOSI _PINNUM(0, 5) +#define DISPLAY_PIN_SCK PINNUM(0, 26) +#define DISPLAY_PIN_MOSI PINNUM(0, 5) -#define DISPLAY_PIN_CS _PINNUM(1, 5) -#define DISPLAY_PIN_DC _PINNUM(1, 1) -#define DISPLAY_PIN_RST _PINNUM(1, 3) -#define DISPLAY_PIN_BL _PINNUM(0, 27) -#define DISPLAY_BL_ON 1 // GPIO state to enable back light +#define DISPLAY_PIN_CS PINNUM(1, 5) +#define DISPLAY_PIN_DC PINNUM(1, 1) +#define DISPLAY_PIN_RST PINNUM(1, 3) +#define DISPLAY_PIN_BL PINNUM(0, 27) +#define DISPLAY_BL_ON 1 // GPIO state to enable back light -#define DISPLAY_WIDTH 240 -#define DISPLAY_HEIGHT 135 +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 135 -#define DISPLAY_COL_OFFSET 53 -#define DISPLAY_ROW_OFFSET 40 +#define DISPLAY_COL_OFFSET 53 +#define DISPLAY_ROW_OFFSET 40 // Memory Data Access Control & // Vertical Scroll Start Address -#define DISPLAY_MADCTL (TFT_MADCTL_MX) -#define DISPLAY_VSCSAD 0 +#define DISPLAY_MADCTL (TFT_MADCTL_MX) +#define DISPLAY_VSCSAD 0 -#define DISPLAY_TITLE "Sense TFT" +#define DISPLAY_TITLE "Sense TFT" //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52840 Sense TFT" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Feather nRF52840 Sense TFT" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0087 -#define USB_DESC_CDC_ONLY_PID 0x0088 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0087 +#define USB_DESC_CDC_ONLY_PID 0x0088 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense TFT" -#define UF2_VOLUME_LABEL "SENSTFTBOOT" -#define UF2_BOARD_ID "nRF52840-FeatherSenseTFT-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/product/" +#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Sense TFT" +#define UF2_VOLUME_LABEL "SENSTFTBOOT" +#define UF2_BOARD_ID "nRF52840-FeatherSenseTFT-revA" +#define UF2_INDEX_URL "https://www.adafruit.com/product/" #endif diff --git a/src/boards/ikigaisense_vita/board.h b/src/boards/ikigaisense_vita/board.h index afb1958..1c95347 100644 --- a/src/boards/ikigaisense_vita/board.h +++ b/src/boards/ikigaisense_vita/board.h @@ -25,44 +25,42 @@ #ifndef _IKIGAISENSE_VITA_NRF52840_H #define _IKIGAISENSE_VITA_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 15) +#define LED_SECONDARY_PIN PINNUM(1, 10) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 16) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "IkigaiSense Technologies" -#define BLEDIS_MODEL "Vita nRF52840" +#define BLEDIS_MANUFACTURER "IkigaiSense Technologies" +#define BLEDIS_MODEL "Vita nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0093 -#define USB_DESC_CDC_ONLY_PID 0x0093 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0093 +#define USB_DESC_CDC_ONLY_PID 0x0093 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "IkigaiSense Vita nRF52840" -#define UF2_VOLUME_LABEL "ISVITABoot" -#define UF2_BOARD_ID "nRF52840-isVITA-revA" -#define UF2_INDEX_URL "https://github.com/ikigaisense/vita" +#define UF2_PRODUCT_NAME "IkigaiSense Vita nRF52840" +#define UF2_VOLUME_LABEL "ISVITABoot" +#define UF2_BOARD_ID "nRF52840-isVITA-revA" +#define UF2_INDEX_URL "https://github.com/ikigaisense/vita" #endif // _IKIGAISENSE_VITA_NRF52840_H diff --git a/src/boards/itsybitsy_nrf52840_express/board.h b/src/boards/itsybitsy_nrf52840_express/board.h index efa92ac..563d5d5 100644 --- a/src/boards/itsybitsy_nrf52840_express/board.h +++ b/src/boards/itsybitsy_nrf52840_express/board.h @@ -25,17 +25,15 @@ #ifndef _ITSYBITSY_NRF52840_H #define _ITSYBITSY_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 6) +#define LED_PRIMARY_PIN PINNUM(0, 6) #define LED_STATE_ON 1 -#define LED_APA102_CLK _PINNUM(1, 9) -#define LED_APA102_DATA _PINNUM(0, 8) +#define LED_APA102_CLK PINNUM(1, 9) +#define LED_APA102_DATA PINNUM(0, 8) #define LED_APA102_BRIGHTNESS 0x1 #define APA102_NUMBER 1 @@ -45,8 +43,8 @@ /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 29) // user switch -#define BUTTON_2 _PINNUM(1, 02) // D2 breakout +#define BUTTON_DFU PINNUM(0, 29) // user switch +#define BUTTON_DFU_OTA PINNUM(1, 02) // D2 breakout #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ diff --git a/src/boards/ledglasses_nrf52840/board.h b/src/boards/ledglasses_nrf52840/board.h index e2ea2f0..714fe94 100644 --- a/src/boards/ledglasses_nrf52840/board.h +++ b/src/boards/ledglasses_nrf52840/board.h @@ -25,43 +25,41 @@ #ifndef _LEDGLASSES_NRF52840_H #define _LEDGLASSES_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 31) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 31) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(1, 15) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(1, 15) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 30) // user switch -#define BUTTON_2 _PINNUM(0, 28) // NC -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 30) // user switch +#define BUTTON_DFU_OTA PINNUM(0, 28) // NC +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "LED Glasses Driver nRF52840" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "LED Glasses Driver nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x010D -#define USB_DESC_CDC_ONLY_PID 0x010E +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x010D +#define USB_DESC_CDC_ONLY_PID 0x010E //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit LED Glasses Driver nRF52840" -#define UF2_VOLUME_LABEL "GLASSESBOOT" -#define UF2_BOARD_ID "nRF52840-LedGlasses-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/product/5217" +#define UF2_PRODUCT_NAME "Adafruit LED Glasses Driver nRF52840" +#define UF2_VOLUME_LABEL "GLASSESBOOT" +#define UF2_BOARD_ID "nRF52840-LedGlasses-revA" +#define UF2_INDEX_URL "https://www.adafruit.com/product/5217" #endif // _LEDGLASSES_NRF52840_H diff --git a/src/boards/m60_keyboard/board.h b/src/boards/m60_keyboard/board.h index 20822b5..057f1e3 100644 --- a/src/boards/m60_keyboard/board.h +++ b/src/boards/m60_keyboard/board.h @@ -25,51 +25,49 @@ #ifndef _MAKERDIARY_M60_KEYBOARD_H_ #define _MAKERDIARY_M60_KEYBOARD_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 30) // Red -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 30) // Red +#define LED_STATE_ON 0 -#define LED_RGB_RED_PIN _PINNUM(0, 30) -#define LED_RGB_GREEN_PIN _PINNUM(0, 29) -#define LED_RGB_BLUE_PIN _PINNUM(0, 31) -#define BOARD_RGB_BRIGHTNESS 0x404040 +#define LED_RGB_RED_PIN PINNUM(0, 30) +#define LED_RGB_GREEN_PIN PINNUM(0, 29) +#define LED_RGB_BLUE_PIN PINNUM(0, 31) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 27) -#define BUTTON_2 _PINNUM(0, 19) // ESC -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 27) +#define BUTTON_DFU_OTA PINNUM(0, 19) // ESC +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* On board regulator control *------------------------------------------------------------------*/ -#define LDO_CONTROL_PIN _PINNUM(0, 28) // Enables external pwr +#define LDO_CONTROL_PIN PINNUM(0, 28) // Enables external pwr //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Makerdiary" -#define BLEDIS_MODEL "M60 Mechanical Keyboard" +#define BLEDIS_MANUFACTURER "Makerdiary" +#define BLEDIS_MODEL "M60 Mechanical Keyboard" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0xF00F -#define USB_DESC_CDC_ONLY_PID 0xF00F +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0xF00F +#define USB_DESC_CDC_ONLY_PID 0xF00F //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "MakerDiary M60 Mechanical Keyboard" -#define UF2_VOLUME_LABEL "M60KEYBOARD" -#define UF2_BOARD_ID "M60KEYBOARD" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/m60/" +#define UF2_PRODUCT_NAME "MakerDiary M60 Mechanical Keyboard" +#define UF2_VOLUME_LABEL "M60KEYBOARD" +#define UF2_BOARD_ID "M60KEYBOARD" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/m60/" #endif /* _MAKERDIARY_M60_KEYBOARD_H_ */ diff --git a/src/boards/m60_keyboard/pinconfig.c b/src/boards/m60_keyboard/pinconfig.c index 1df7a6f..d831386 100644 --- a/src/boards/m60_keyboard/pinconfig.c +++ b/src/boards/m60_keyboard/pinconfig.c @@ -2,56 +2,60 @@ #include "board.h" #include "uf2/configkeys.h" -__attribute__((used, section(".bootloaderConfig"))) -const uint32_t bootloaderConfig[] = -{ +__attribute__((used, section(".bootloaderConfig"))) const uint32_t bootloaderConfig[] = { /* CF2 START */ - CFG_MAGIC0, CFG_MAGIC1, // magic - 5, 100, // used entries, total entries + CFG_MAGIC0, + CFG_MAGIC1, // magic + 5, + 100, // used entries, total entries - 204, 0x100000, // FLASH_BYTES = 0x100000 - 205, 0x40000, // RAM_BYTES = 0x40000 - 208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 - 209, 0xada52840, // UF2_FAMILY = 0xada52840 - 210, 0x20, // PINS_PORT_SIZE = PA_32 + 204, + 0x100000, // FLASH_BYTES = 0x100000 + 205, + 0x40000, // RAM_BYTES = 0x40000 + 208, + (USB_DESC_VID << 16) | + USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2 + 209, + 0xada52840, // UF2_FAMILY = 0xada52840 + 210, + 0x20, // PINS_PORT_SIZE = PA_32 - 0, 0, 0, 0, 0, 0, 0, 0 + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 /* CF2 END */ }; -static void power_on(void) -{ +static void power_on(void) { // Turn on the regulator nrf_gpio_cfg_output(LDO_CONTROL_PIN); nrf_gpio_pin_write(LDO_CONTROL_PIN, 1); } -void board_init2(void) -{ +void board_init2(void) { power_on(); - // configure P0.05 for ESC/BUTTON_2 + // configure P0.05 for ESC/BUTTON_DFU_OTA // P0.05 --- |<- --- / --- P0.19 // diode sw(esc) // mode: output, push-pull, low - nrf_gpio_cfg( - _PINNUM(0, 5), - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_H0D1, - NRF_GPIO_PIN_NOSENSE - ); - nrf_gpio_pin_write(_PINNUM(0, 5), 0); + nrf_gpio_cfg(PINNUM(0, 5), NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_H0D1, NRF_GPIO_PIN_NOSENSE); + nrf_gpio_pin_write(PINNUM(0, 5), 0); // Wait the buttons stable. // This is mandatory, or the keyboard will enter bootloader whenever - // booted by pressing the button at back (same with BUTTON_1) + // booted by pressing the button at back (same with BUTTON_DFU) NRFX_DELAY_MS(300); } -void board_teardown2(void) -{ +void board_teardown2(void) { // re-enable the battery power_on(); -} \ No newline at end of file +} diff --git a/src/boards/mbn52832dk/board.h b/src/boards/mbn52832dk/board.h index b731d68..0e38c19 100644 --- a/src/boards/mbn52832dk/board.h +++ b/src/boards/mbn52832dk/board.h @@ -28,26 +28,26 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 17 // LED1 -#define LED_SECONDARY_PIN 18 // LED2 -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 17 // LED1 +#define LED_SECONDARY_PIN 18 // LED2 +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 13 -#define BUTTON_2 14 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 13 +#define BUTTON_DFU_OTA 14 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP /*------------------------------------------------------------------*/ /* UART (only used by nRF52832) *------------------------------------------------------------------*/ -#define RX_PIN_NUMBER 8 -#define TX_PIN_NUMBER 6 -#define CTS_PIN_NUMBER 0 -#define RTS_PIN_NUMBER 0 -#define HWFC false +#define RX_PIN_NUMBER 8 +#define TX_PIN_NUMBER 6 +#define CTS_PIN_NUMBER 0 +#define RTS_PIN_NUMBER 0 +#define HWFC false //--------------------------------------------------------------------+ // BLE OTA diff --git a/src/boards/mdk_nrf52840_dongle/board.h b/src/boards/mdk_nrf52840_dongle/board.h index 066c66b..ab5d0e1 100644 --- a/src/boards/mdk_nrf52840_dongle/board.h +++ b/src/boards/mdk_nrf52840_dongle/board.h @@ -25,47 +25,45 @@ #ifndef _MDK_NRF52840_DONGLE_H_ #define _MDK_NRF52840_DONGLE_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 // TODO(gpshead): support 0. -#define LED_PRIMARY_PIN _PINNUM(0, 23) // Red -#define LED_SECONDARY_PIN _PINNUM(0, 24) // Blue -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 // TODO(gpshead): support 0. +#define LED_PRIMARY_PIN PINNUM(0, 23) // Red +#define LED_SECONDARY_PIN PINNUM(0, 24) // Blue +#define LED_STATE_ON 0 -//#define LED_RGB_RED_PIN _PINNUM(0, 23) -//#define LED_RGB_GREEN_PIN _PINNUM(0, 22) -//#define LED_RGB_BLUE_PIN _PINNUM(0, 24) -#define BOARD_RGB_BRIGHTNESS 0x404040 +// #define LED_RGB_RED_PIN PINNUM(0, 23) +// #define LED_RGB_GREEN_PIN PINNUM(0, 22) +// #define LED_RGB_BLUE_PIN PINNUM(0, 24) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ // TODO(gpshead): simplify, have code support 0. double reset only. -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 19) // no connection -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(0, 19) // no connection +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "MakerDiary" -#define BLEDIS_MODEL "nRF52840 Micro Dev Kit USB Dongle" +#define BLEDIS_MANUFACTURER "MakerDiary" +#define BLEDIS_MODEL "nRF52840 Micro Dev Kit USB Dongle" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with Feather nRF52840, will be disabled for building in the future -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x0029 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x0029 -#define UF2_PRODUCT_NAME "MDK nRF52840 USB Dongle" -#define UF2_VOLUME_LABEL "MDK840DONGL" -#define UF2_BOARD_ID "nRF52840-Dongle-v1" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/" +#define UF2_PRODUCT_NAME "MDK nRF52840 USB Dongle" +#define UF2_VOLUME_LABEL "MDK840DONGL" +#define UF2_BOARD_ID "nRF52840-Dongle-v1" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/" #endif /* _MDK_NRF52840_DONGLE_H_ */ diff --git a/src/boards/metro_nrf52840_express/board.h b/src/boards/metro_nrf52840_express/board.h index 53519ed..0c05838 100644 --- a/src/boards/metro_nrf52840_express/board.h +++ b/src/boards/metro_nrf52840_express/board.h @@ -25,45 +25,43 @@ #ifndef _METRO_NRF52840_H_ #define _METRO_NRF52840_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 13) -#define LED_SECONDARY_PIN _PINNUM(1, 15) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 13) +#define LED_SECONDARY_PIN PINNUM(1, 15) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 13) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define LED_NEOPIXEL PINNUM(0, 13) +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 0) -#define BUTTON_2 _PINNUM(2, 2) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 0) +#define BUTTON_DFU_OTA PINNUM(2, 2) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Metro nRF52840 Express" +#define BLEDIS_MANUFACTURER "Adafruit Industries" +#define BLEDIS_MODEL "Metro nRF52840 Express" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x003F -#define USB_DESC_CDC_ONLY_PID 0x0040 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x003F +#define USB_DESC_CDC_ONLY_PID 0x0040 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Metro nRF52840 Express" -#define UF2_VOLUME_LABEL "METR840BOOT" -#define UF2_BOARD_ID "nRF52840-Metro-revA" +#define UF2_PRODUCT_NAME "Adafruit Metro nRF52840 Express" +#define UF2_VOLUME_LABEL "METR840BOOT" +#define UF2_BOARD_ID "nRF52840-Metro-revA" -#define UF2_INDEX_URL "https://www.adafruit.com/" +#define UF2_INDEX_URL "https://www.adafruit.com/" #endif /* _METRO_NRF52840_H_ */ diff --git a/src/boards/mikoto/board.h b/src/boards/mikoto/board.h index f46ef52..9882893 100644 --- a/src/boards/mikoto/board.h +++ b/src/boards/mikoto/board.h @@ -25,40 +25,38 @@ #ifndef _MIKOTO_H #define _MIKOTO_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - #define UICR_REGOUT0_VALUE UICR_REGOUT0_VOUT_3V3 /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 15) // Blue -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 15) // Blue +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 19) // no connection -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(0, 19) // no connection +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "zhiayang" -#define BLEDIS_MODEL "mikoto" +#define BLEDIS_MANUFACTURER "zhiayang" +#define BLEDIS_MODEL "mikoto" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x7A01 -#define USB_DESC_CDC_ONLY_PID 0x7A01 +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x7A01 +#define USB_DESC_CDC_ONLY_PID 0x7A01 -#define UF2_PRODUCT_NAME "Mikoto nRF52840" -#define UF2_VOLUME_LABEL "MIKOTO-BOOT" -#define UF2_BOARD_ID "nRF52840-mikoto-rev520" -#define UF2_INDEX_URL "https://github.com/zhiayang/mikoto" +#define UF2_PRODUCT_NAME "Mikoto nRF52840" +#define UF2_VOLUME_LABEL "MIKOTO-BOOT" +#define UF2_BOARD_ID "nRF52840-mikoto-rev520" +#define UF2_INDEX_URL "https://github.com/zhiayang/mikoto" #endif // _MIKOTO_H diff --git a/src/boards/nRF52840_connect_kit/board.h b/src/boards/nRF52840_connect_kit/board.h index 2cdaa24..9bb02ab 100644 --- a/src/boards/nRF52840_connect_kit/board.h +++ b/src/boards/nRF52840_connect_kit/board.h @@ -25,46 +25,44 @@ #ifndef _MAKERDIARY_NRF82540_CONNECT_KIT_H_ #define _MAKERDIARY_NRF82540_CONNECT_KIT_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 15) // Green -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 15) // Green +#define LED_STATE_ON 0 -#define LED_RGB_RED_PIN _PINNUM(1, 10) -#define LED_RGB_GREEN_PIN _PINNUM(1, 11) -#define LED_RGB_BLUE_PIN _PINNUM(1, 12) -#define BOARD_RGB_BRIGHTNESS 0x404040 +#define LED_RGB_RED_PIN PINNUM(1, 10) +#define LED_RGB_GREEN_PIN PINNUM(1, 11) +#define LED_RGB_BLUE_PIN PINNUM(1, 12) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 0) // P1.00: User Button -#define BUTTON_2 _PINNUM(1, 7) // P1.07: NC -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 0) // P1.00: User Button +#define BUTTON_DFU_OTA PINNUM(1, 7) // P1.07: NC +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Makerdiary" -#define BLEDIS_MODEL "nRF52840 Connect Kit" +#define BLEDIS_MANUFACTURER "Makerdiary" +#define BLEDIS_MODEL "nRF52840 Connect Kit" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0xF00F -#define USB_DESC_CDC_ONLY_PID 0xF00F +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0xF00F +#define USB_DESC_CDC_ONLY_PID 0xF00F //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "nRF52840 Connect Kit" -#define UF2_VOLUME_LABEL "CONNECTKIT" -#define UF2_BOARD_ID "nRF52840-Connect-Kit" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-connectkit/" +#define UF2_PRODUCT_NAME "nRF52840 Connect Kit" +#define UF2_VOLUME_LABEL "CONNECTKIT" +#define UF2_BOARD_ID "nRF52840-Connect-Kit" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-connectkit/" #endif /* _MAKERDIARY_NRF82540_CONNECT_KIT_H_ */ diff --git a/src/boards/nice_nano/board.h b/src/boards/nice_nano/board.h index c082518..55109c0 100644 --- a/src/boards/nice_nano/board.h +++ b/src/boards/nice_nano/board.h @@ -25,40 +25,38 @@ #ifndef _NICENANO_H #define _NICENANO_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - #define UICR_REGOUT0_VALUE UICR_REGOUT0_VOUT_3V3 /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 15) // Blue -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 15) // Blue +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 19) // no connection -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(0, 19) // no connection +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Nice Keyboards" -#define BLEDIS_MODEL "nice!nano" +#define BLEDIS_MANUFACTURER "Nice Keyboards" +#define BLEDIS_MODEL "nice!nano" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00B3 -#define USB_DESC_CDC_ONLY_PID 0x00B3 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00B3 +#define USB_DESC_CDC_ONLY_PID 0x00B3 -#define UF2_PRODUCT_NAME "nice!nano" -#define UF2_VOLUME_LABEL "NICENANO" -#define UF2_BOARD_ID "nRF52840-nicenano" -#define UF2_INDEX_URL "https://nicekeyboards.com/docs/nice-nano" +#define UF2_PRODUCT_NAME "nice!nano" +#define UF2_VOLUME_LABEL "NICENANO" +#define UF2_BOARD_ID "nRF52840-nicenano" +#define UF2_INDEX_URL "https://nicekeyboards.com/docs/nice-nano" #endif // _NICENANO_H diff --git a/src/boards/nrf52840_bboard/board.h b/src/boards/nrf52840_bboard/board.h index 4384475..2c1977e 100644 --- a/src/boards/nrf52840_bboard/board.h +++ b/src/boards/nrf52840_bboard/board.h @@ -25,14 +25,12 @@ #ifndef _NRF52840_BBOARD_H #define _NRF52840_BBOARD_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 7) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 7) +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON @@ -41,27 +39,27 @@ // App can trigger OTA bootloader by writing DFU_MAGIC_OTA_APPJUM to // GPREGRET register if softdevice is not initialized; or by // writing DFU_MAGIC_OTA_RESET in case softdevice is initialized. -#define BUTTON_1 18 // RESET also by default -#define BUTTON_2 1 // P0.1 not exposed anywhere, FRST n/a -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 18 // RESET also by default +#define BUTTON_DFU_OTA 1 // P0.1 not exposed anywhere, FRST n/a +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "ddB0515" -#define BLEDIS_MODEL "nRF52840 BBoard" +#define BLEDIS_MANUFACTURER "ddB0515" +#define BLEDIS_MODEL "nRF52840 BBoard" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1d50 -#define USB_DESC_UF2_PID 0x6157 -#define USB_DESC_CDC_ONLY_PID 0x6157 +#define USB_DESC_VID 0x1d50 +#define USB_DESC_UF2_PID 0x6157 +#define USB_DESC_CDC_ONLY_PID 0x6157 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "nRF52840 BBoard" -#define UF2_VOLUME_LABEL "BBOARDBOOT" -#define UF2_BOARD_ID "nRF52840-BBoard-rev2" -#define UF2_INDEX_URL "https://github.com/ddB0515/nRF52840-BBoard" +#define UF2_PRODUCT_NAME "nRF52840 BBoard" +#define UF2_VOLUME_LABEL "BBOARDBOOT" +#define UF2_BOARD_ID "nRF52840-BBoard-rev2" +#define UF2_INDEX_URL "https://github.com/ddB0515/nRF52840-BBoard" #endif // _NRF52840_BBOARD_H diff --git a/src/boards/nrf52840_m2/board.h b/src/boards/nrf52840_m2/board.h index 27fc760..c093f5d 100644 --- a/src/boards/nrf52840_m2/board.h +++ b/src/boards/nrf52840_m2/board.h @@ -25,47 +25,45 @@ #ifndef _MAKERDIARY_NRF52840_M2_H_ #define _MAKERDIARY_NRF52840_M2_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 30) // Red -#define LED_DOCK_GREEN_PIN _PINNUM(1, 7) // Only available on the M.2 Dock -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 30) // Red +#define LED_DOCK_GREEN_PIN PINNUM(1, 7) // Only available on the M.2 Dock +#define LED_STATE_ON 0 -#define LED_RGB_RED_PIN _PINNUM(0, 30) -#define LED_RGB_GREEN_PIN _PINNUM(0, 29) -#define LED_RGB_BLUE_PIN _PINNUM(0, 31) -#define BOARD_RGB_BRIGHTNESS 0x404040 +#define LED_RGB_RED_PIN PINNUM(0, 30) +#define LED_RGB_GREEN_PIN PINNUM(0, 29) +#define LED_RGB_BLUE_PIN PINNUM(0, 31) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 19) -#define BUTTON_2 _PINNUM(1, 7) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 19) +#define BUTTON_DFU_OTA PINNUM(1, 7) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Makerdiary" -#define BLEDIS_MODEL "nRF52840 M.2" +#define BLEDIS_MANUFACTURER "Makerdiary" +#define BLEDIS_MODEL "nRF52840 M.2" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0xF00F -#define USB_DESC_CDC_ONLY_PID 0xF00F +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0xF00F +#define USB_DESC_CDC_ONLY_PID 0xF00F //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "MakerDiary nRF52840 M.2 Module" -#define UF2_VOLUME_LABEL "nRF52840M2" -#define UF2_BOARD_ID "nRF52840M2" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-m2" +#define UF2_PRODUCT_NAME "MakerDiary nRF52840 M.2 Module" +#define UF2_VOLUME_LABEL "nRF52840M2" +#define UF2_BOARD_ID "nRF52840M2" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/nrf52840-m2" #endif /* _MAKERDIARY_NRF52840_M2_H_ */ diff --git a/src/boards/nrfmicro/board.h b/src/boards/nrfmicro/board.h index f3bdb4e..78507e3 100644 --- a/src/boards/nrfmicro/board.h +++ b/src/boards/nrfmicro/board.h @@ -25,41 +25,39 @@ #ifndef _NRFMICRO_NRF52840 #define _NRFMICRO_NRF52840 -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 // State when LED is lit (active HIGH) +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 10) +#define LED_STATE_ON 1 // State when LED is lit (active HIGH) -#define NEOPIXELS_NUMBER 0 +#define NEOPIXELS_NUMBER 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 2) // DFU -#define BUTTON_2 _PINNUM(0, 12) // FRST -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 2) // DFU +#define BUTTON_DFU_OTA PINNUM(0, 12) // FRST +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "nRFMicro" -#define BLEDIS_MODEL "nRFMicro nRF52840" +#define BLEDIS_MANUFACTURER "nRFMicro" +#define BLEDIS_MODEL "nRFMicro nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0x5284 -#define USB_DESC_CDC_ONLY_PID 0x5284 +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0x5284 +#define USB_DESC_CDC_ONLY_PID 0x5284 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "nRFMicro" -#define UF2_VOLUME_LABEL "NRFMICRO" -#define UF2_BOARD_ID "nRF52840-nRFMicro-v0" -#define UF2_INDEX_URL "https://github.com/joric/nrfmicro/wiki" +#define UF2_PRODUCT_NAME "nRFMicro" +#define UF2_VOLUME_LABEL "NRFMICRO" +#define UF2_BOARD_ID "nRF52840-nRFMicro-v0" +#define UF2_INDEX_URL "https://github.com/joric/nrfmicro/wiki" #endif // _NRFMICRO_NRF52840 diff --git a/src/boards/ohs2020_badge/board.h b/src/boards/ohs2020_badge/board.h index 0172e6d..a6cc943 100644 --- a/src/boards/ohs2020_badge/board.h +++ b/src/boards/ohs2020_badge/board.h @@ -26,39 +26,37 @@ #ifndef _OHS2020_BADGE_H #define _OHS2020_BADGE_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 04) // fake LED since we have none -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 04) // fake LED since we have none +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 29) // SW2 -#define BUTTON_2 _PINNUM(0, 03) // SW1 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 29) // SW2 +#define BUTTON_DFU_OTA PINNUM(0, 03) // SW1 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "OSHWA" -#define BLEDIS_MODEL "OHS2020 Badge" +#define BLEDIS_MANUFACTURER "OSHWA" +#define BLEDIS_MODEL "OHS2020 Badge" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x007F -#define USB_DESC_CDC_ONLY_PID 0x007F +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x007F +#define USB_DESC_CDC_ONLY_PID 0x007F //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "OHS2020 Badge" -#define UF2_VOLUME_LABEL "BADGEBOOT" -#define UF2_BOARD_ID "OHS2020-Badge-revA" -#define UF2_INDEX_URL "https://2020.oshwa.org/" +#define UF2_PRODUCT_NAME "OHS2020 Badge" +#define UF2_VOLUME_LABEL "BADGEBOOT" +#define UF2_BOARD_ID "OHS2020-Badge-revA" +#define UF2_INDEX_URL "https://2020.oshwa.org/" #endif // _OHS2020_BADGE_H diff --git a/src/boards/omnimo_nrf52840/board.h b/src/boards/omnimo_nrf52840/board.h index f591a55..c26c811 100644 --- a/src/boards/omnimo_nrf52840/board.h +++ b/src/boards/omnimo_nrf52840/board.h @@ -25,47 +25,45 @@ #ifndef _OMNIMO_NRF52840_H #define _OMNIMO_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN _PINNUM(1, 15) -#define LED_SECONDARY_PIN _PINNUM(1, 10) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN PINNUM(1, 15) +#define LED_SECONDARY_PIN PINNUM(1, 10) +#define LED_STATE_ON 1 -#define LED_NEOPIXEL _PINNUM(0, 16) +#define LED_NEOPIXEL PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 +#define NEOPIXELS_NUMBER 1 +#define BOARD_RGB_BRIGHTNESS 0x040404 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 02) -#define BUTTON_2 _PINNUM(1, 07) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 02) +#define BUTTON_DFU_OTA PINNUM(1, 07) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "eAFAQ" -#define BLEDIS_MODEL "OMNIMO nRF52840" +#define BLEDIS_MANUFACTURER "eAFAQ" +#define BLEDIS_MODEL "OMNIMO nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -//Shared VID/PID with pca10056 -#define USB_DESC_VID 0x1209 -#define USB_DESC_UF2_PID 0xCECE -#define USB_DESC_CDC_ONLY_PID 0xCECE +// Shared VID/PID with pca10056 +#define USB_DESC_VID 0x1209 +#define USB_DESC_UF2_PID 0xCECE +#define USB_DESC_CDC_ONLY_PID 0xCECE //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Omnimo nRF52840" -#define UF2_VOLUME_LABEL "OMNIn52BOOT" -#define UF2_BOARD_ID "nRF52840-Omnimo" -#define UF2_INDEX_URL "https://www.crowdsupply.com/eafaq/omnimo-nrf52840" +#define UF2_PRODUCT_NAME "Omnimo nRF52840" +#define UF2_VOLUME_LABEL "OMNIn52BOOT" +#define UF2_BOARD_ID "nRF52840-Omnimo" +#define UF2_INDEX_URL "https://www.crowdsupply.com/eafaq/omnimo-nrf52840" #endif // _OMNIMO_NRF52840_H diff --git a/src/boards/particle_argon/board.h b/src/boards/particle_argon/board.h index c8ce5d6..b210606 100644 --- a/src/boards/particle_argon/board.h +++ b/src/boards/particle_argon/board.h @@ -25,25 +25,23 @@ #ifndef _PARTICLE_ARGON_H #define _PARTICLE_ARGON_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 12) +#define LED_PRIMARY_PIN PINNUM(1, 12) #define LED_STATE_ON 1 -#define LED_RGB_RED_PIN _PINNUM(0, 13) -#define LED_RGB_GREEN_PIN _PINNUM(0, 14) -#define LED_RGB_BLUE_PIN _PINNUM(0, 15) +#define LED_RGB_RED_PIN PINNUM(0, 13) +#define LED_RGB_GREEN_PIN PINNUM(0, 14) +#define LED_RGB_BLUE_PIN PINNUM(0, 15) #define BOARD_RGB_BRIGHTNESS 0x202020 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 03) // A0 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ diff --git a/src/boards/particle_boron/board.h b/src/boards/particle_boron/board.h index a4fa749..49cc6d5 100644 --- a/src/boards/particle_boron/board.h +++ b/src/boards/particle_boron/board.h @@ -25,45 +25,43 @@ #ifndef _PARTICLE_BORON_H #define _PARTICLE_BORON_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 12) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 12) +#define LED_STATE_ON 1 -#define LED_RGB_RED_PIN _PINNUM(0, 13) -#define LED_RGB_GREEN_PIN _PINNUM(0, 14) -#define LED_RGB_BLUE_PIN _PINNUM(0, 15) +#define LED_RGB_RED_PIN PINNUM(0, 13) +#define LED_RGB_GREEN_PIN PINNUM(0, 14) +#define LED_RGB_BLUE_PIN PINNUM(0, 15) #define BOARD_RGB_BRIGHTNESS 0x202020 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 03) // A0 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Particle Industries" -#define BLEDIS_MODEL "Boron" +#define BLEDIS_MANUFACTURER "Particle Industries" +#define BLEDIS_MODEL "Boron" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with pca10056 -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA -#define UF2_PRODUCT_NAME "Particle Boron" -#define UF2_VOLUME_LABEL "BORONBOOT " -#define UF2_BOARD_ID "nRF52840-Boron-v1" -#define UF2_INDEX_URL "https://www.particle.io/mesh/" +#define UF2_PRODUCT_NAME "Particle Boron" +#define UF2_VOLUME_LABEL "BORONBOOT " +#define UF2_BOARD_ID "nRF52840-Boron-v1" +#define UF2_INDEX_URL "https://www.particle.io/mesh/" #endif // _PARTICLE_BORON_H diff --git a/src/boards/particle_xenon/board.h b/src/boards/particle_xenon/board.h index 01da00a..5584bad 100644 --- a/src/boards/particle_xenon/board.h +++ b/src/boards/particle_xenon/board.h @@ -25,45 +25,43 @@ #ifndef _PARTICLE_XENON_H #define _PARTICLE_XENON_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 12) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 12) +#define LED_STATE_ON 1 -#define LED_RGB_RED_PIN _PINNUM(0, 13) -#define LED_RGB_GREEN_PIN _PINNUM(0, 14) -#define LED_RGB_BLUE_PIN _PINNUM(0, 15) +#define LED_RGB_RED_PIN PINNUM(0, 13) +#define LED_RGB_GREEN_PIN PINNUM(0, 14) +#define LED_RGB_BLUE_PIN PINNUM(0, 15) #define BOARD_RGB_BRIGHTNESS 0x202020 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_DFU _PINNUM(0, 11) -#define BUTTON_FRESET _PINNUM(0, 03) // A0 +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 03) // A0 #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Particle Industries" -#define BLEDIS_MODEL "Xenon" +#define BLEDIS_MANUFACTURER "Particle Industries" +#define BLEDIS_MODEL "Xenon" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with pca10056 -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA -#define UF2_PRODUCT_NAME "Particle Xenon" -#define UF2_VOLUME_LABEL "XENONBOOT " -#define UF2_BOARD_ID "nRF52840-Xenon-v1" -#define UF2_INDEX_URL "https://www.particle.io/mesh/" +#define UF2_PRODUCT_NAME "Particle Xenon" +#define UF2_VOLUME_LABEL "XENONBOOT " +#define UF2_BOARD_ID "nRF52840-Xenon-v1" +#define UF2_INDEX_URL "https://www.particle.io/mesh/" #endif // _PARTICLE_XENON_H diff --git a/src/boards/pca10056/board.h b/src/boards/pca10056/board.h index 0fea16d..08269bf 100644 --- a/src/boards/pca10056/board.h +++ b/src/boards/pca10056/board.h @@ -28,35 +28,35 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 13 -#define LED_SECONDARY_PIN 14 -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 13 +#define LED_SECONDARY_PIN 14 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 11 -#define BUTTON_2 12 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 11 +#define BUTTON_DFU_OTA 12 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Nordic" -#define BLEDIS_MODEL "PCA10056" +#define BLEDIS_MANUFACTURER "Nordic" +#define BLEDIS_MODEL "PCA10056" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with Feather nRF52840, will be disabled for building in the future -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00DA -#define USB_DESC_CDC_ONLY_PID 0x00DA +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00DA +#define USB_DESC_CDC_ONLY_PID 0x00DA -#define UF2_PRODUCT_NAME "Nordic nRF52840 DK" -#define UF2_BOARD_ID "nRF52840-pca10056-v1" -#define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK" +#define UF2_PRODUCT_NAME "Nordic nRF52840 DK" +#define UF2_BOARD_ID "nRF52840-pca10056-v1" +#define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK" #endif // PCA10056_H diff --git a/src/boards/pca10059/board.h b/src/boards/pca10059/board.h index 47e6bc2..88c2f41 100644 --- a/src/boards/pca10059/board.h +++ b/src/boards/pca10059/board.h @@ -25,13 +25,11 @@ #ifndef PCA10059_H #define PCA10059_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 6 // Red +#define LED_PRIMARY_PIN 6 // Red #define LED_SECONDARY_PIN 12 // Blue #define LED_STATE_ON 0 @@ -39,27 +37,27 @@ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 6) -#define BUTTON_2 _PINNUM(1, 10) +#define BUTTON_DFU PINNUM(1, 6) +#define BUTTON_DFU_OTA PINNUM(1, 10) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Nordic" -#define BLEDIS_MODEL "PCA10059" +#define BLEDIS_MANUFACTURER "Nordic" +#define BLEDIS_MODEL "PCA10059" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ // Shared VID/PID with Feather nRF52840, will be disabled for building in the future -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x0029 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x0029 -#define UF2_PRODUCT_NAME "Nordic nRF52840 Dongle" -#define UF2_BOARD_ID "nRF52840-pca10059-v1" -#define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle" +#define UF2_PRODUCT_NAME "Nordic nRF52840 Dongle" +#define UF2_BOARD_ID "nRF52840-pca10059-v1" +#define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle" #endif // PCA10059_H diff --git a/src/boards/pca10100/board.h b/src/boards/pca10100/board.h index 1df0200..5be1366 100644 --- a/src/boards/pca10100/board.h +++ b/src/boards/pca10100/board.h @@ -28,34 +28,34 @@ /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN 13 -#define LED_SECONDARY_PIN 14 -#define LED_STATE_ON 0 +#define LEDS_NUMBER 2 +#define LED_PRIMARY_PIN 13 +#define LED_SECONDARY_PIN 14 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 11 -#define BUTTON_2 12 -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU 11 +#define BUTTON_DFU_OTA 12 +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Nordic" -#define BLEDIS_MODEL "PCA10100" +#define BLEDIS_MANUFACTURER "Nordic" +#define BLEDIS_MODEL "PCA10100" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x00D8 -#define USB_DESC_CDC_ONLY_PID 0x00D8 +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x00D8 +#define USB_DESC_CDC_ONLY_PID 0x00D8 -#define UF2_PRODUCT_NAME "Nordic nRF52833 DK" -#define UF2_VOLUME_LABEL "NRF833BOOT" -#define UF2_BOARD_ID "nRF52833-pca10100-v1" -#define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52833-DK" +#define UF2_PRODUCT_NAME "Nordic nRF52833 DK" +#define UF2_VOLUME_LABEL "NRF833BOOT" +#define UF2_BOARD_ID "nRF52833-pca10100-v1" +#define UF2_INDEX_URL "https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52833-DK" #endif // PCA10100_H diff --git a/src/boards/pillbug/board.h b/src/boards/pillbug/board.h index 8c50985..1d442c5 100644 --- a/src/boards/pillbug/board.h +++ b/src/boards/pillbug/board.h @@ -25,40 +25,38 @@ #ifndef _PillBug_H #define _PillBug_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - #define UICR_REGOUT0_VALUE UICR_REGOUT0_VOUT_3V3 /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 20) // Blue -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 20) // Blue +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_2 _PINNUM(0, 21) // no connection -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 18) // unusable: RESET +#define BUTTON_DFU_OTA PINNUM(0, 21) // no connection +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "MechWild" -#define BLEDIS_MODEL "PillBug" +#define BLEDIS_MANUFACTURER "MechWild" +#define BLEDIS_MODEL "PillBug" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x16D0 -#define USB_DESC_UF2_PID 0x10ED -#define USB_DESC_CDC_ONLY_PID 0x10ED +#define USB_DESC_VID 0x16D0 +#define USB_DESC_UF2_PID 0x10ED +#define USB_DESC_CDC_ONLY_PID 0x10ED -#define UF2_PRODUCT_NAME "PillBug" -#define UF2_VOLUME_LABEL "PillBug" -#define UF2_BOARD_ID "nRF52840-PillBug" -#define UF2_INDEX_URL "https://mechwild.com" +#define UF2_PRODUCT_NAME "PillBug" +#define UF2_VOLUME_LABEL "PillBug" +#define UF2_BOARD_ID "nRF52840-PillBug" +#define UF2_INDEX_URL "https://mechwild.com" #endif // _PillBug_H diff --git a/src/boards/pitaya_go/board.h b/src/boards/pitaya_go/board.h index 8daf1f1..fd0b994 100644 --- a/src/boards/pitaya_go/board.h +++ b/src/boards/pitaya_go/board.h @@ -25,46 +25,44 @@ #ifndef _MAKERDIARY_PITAYA_GO_H_ #define _MAKERDIARY_PITAYA_GO_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 10) // Red -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 10) // Red +#define LED_STATE_ON 0 -#define LED_RGB_RED_PIN _PINNUM(1, 10) -#define LED_RGB_GREEN_PIN _PINNUM(1, 11) -#define LED_RGB_BLUE_PIN _PINNUM(1, 12) -#define BOARD_RGB_BRIGHTNESS 0x404040 +#define LED_RGB_RED_PIN PINNUM(1, 10) +#define LED_RGB_GREEN_PIN PINNUM(1, 11) +#define LED_RGB_BLUE_PIN PINNUM(1, 12) +#define BOARD_RGB_BRIGHTNESS 0x404040 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(1, 0) // P1.00: User Button -#define BUTTON_2 _PINNUM(1, 7) // P1.07: NC -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(1, 0) // P1.00: User Button +#define BUTTON_DFU_OTA PINNUM(1, 7) // P1.07: NC +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Makerdiary" -#define BLEDIS_MODEL "Pitaya Go" +#define BLEDIS_MANUFACTURER "Makerdiary" +#define BLEDIS_MODEL "Pitaya Go" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0xF00E -#define USB_DESC_CDC_ONLY_PID 0xF00E +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0xF00E +#define USB_DESC_CDC_ONLY_PID 0xF00E //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "Pitaya Go" -#define UF2_VOLUME_LABEL "PITAYAGO" -#define UF2_BOARD_ID "PITAYAGO" -#define UF2_INDEX_URL "https://wiki.makerdiary.com/pitaya-go" +#define UF2_PRODUCT_NAME "Pitaya Go" +#define UF2_VOLUME_LABEL "PITAYAGO" +#define UF2_BOARD_ID "PITAYAGO" +#define UF2_INDEX_URL "https://wiki.makerdiary.com/pitaya-go" #endif /* _MAKERDIARY_PITAYA_GO_H_ */ diff --git a/src/boards/raytac_mdbt50q_db_40/board.h b/src/boards/raytac_mdbt50q_db_40/board.h index 86763e3..838c90e 100644 --- a/src/boards/raytac_mdbt50q_db_40/board.h +++ b/src/boards/raytac_mdbt50q_db_40/board.h @@ -25,18 +25,18 @@ #ifndef RAYTAC_MDBT50Q_DB_40_H #define RAYTAC_MDBT50Q_DB_40_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) +#define PINNUM(port, pin) ((port) * 32 + (pin)) /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 3 /* This is the Green led marked D1 on the board */ -#define LED_PRIMARY_PIN _PINNUM(1, 13) +#define LED_PRIMARY_PIN PINNUM(1, 13) /* This is the Red led marked D2 on the board */ -#define LED_SECONDARY_PIN _PINNUM(1, 14) +#define LED_SECONDARY_PIN PINNUM(1, 14) /* This is the Blue led marked D3 on the board */ -#define LED_TERTIARY_PIN _PINNUM(1, 15) +#define LED_TERTIARY_PIN PINNUM(1, 15) /* There are one more unpopulated LEDs, but for the purposes of bootloader that * doesn't matter. */ #define LED_STATE_ON 0 @@ -45,10 +45,10 @@ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 11) -#define BUTTON_2 _PINNUM(0, 12) -#define BUTTON_3 _PINNUM(0, 24) -#define BUTTON_4 _PINNUM(0, 25) +#define BUTTON_DFU PINNUM(0, 11) +#define BUTTON_DFU_OTA PINNUM(0, 12) +#define BUTTON_3 PINNUM(0, 24) +#define BUTTON_4 PINNUM(0, 25) #define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ diff --git a/src/boards/raytac_mdbt50q_rx/board.h b/src/boards/raytac_mdbt50q_rx/board.h index ac3f771..76a178b 100644 --- a/src/boards/raytac_mdbt50q_rx/board.h +++ b/src/boards/raytac_mdbt50q_rx/board.h @@ -25,41 +25,39 @@ #ifndef RAYTAC_MDBT50Q_RX_H #define RAYTAC_MDBT50Q_RX_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(1, 13) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(1, 13) +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 15) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 15) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Raytac" -#define BLEDIS_MODEL "MDBT50Q-RX" +#define BLEDIS_MANUFACTURER "Raytac" +#define BLEDIS_MODEL "MDBT50Q-RX" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x010B -#define USB_DESC_CDC_ONLY_PID 0x010B +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x010B +#define USB_DESC_CDC_ONLY_PID 0x010B //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Raytac MDBT50Q-RX" -#define UF2_VOLUME_LABEL "MDBT50QBOOT" -#define UF2_BOARD_ID "nRF52840-MDBT50Q_RX-verD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/5199" +#define UF2_PRODUCT_NAME "Raytac MDBT50Q-RX" +#define UF2_VOLUME_LABEL "MDBT50QBOOT" +#define UF2_BOARD_ID "nRF52840-MDBT50Q_RX-verD" +#define UF2_INDEX_URL "https://www.adafruit.com/product/5199" #endif // RAYTAC_MDBT50Q_RX_H diff --git a/src/boards/sparkfun_nrf52840_micromod/board.h b/src/boards/sparkfun_nrf52840_micromod/board.h index c889354..11692a4 100644 --- a/src/boards/sparkfun_nrf52840_micromod/board.h +++ b/src/boards/sparkfun_nrf52840_micromod/board.h @@ -26,40 +26,38 @@ #ifndef _SPARKFUN_NRF52840_MICROMOD_H_ #define _SPARKFUN_NRF52840_MICROMOD_H_ -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 13) -#define LED_STATE_ON 1 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 13) +#define LED_STATE_ON 1 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 7) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 7) +#define BUTTON_DFU_OTA PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "SparkFun" -#define BLEDIS_MODEL "MicroMod nRF52840" +#define BLEDIS_MANUFACTURER "SparkFun" +#define BLEDIS_MODEL "MicroMod nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1B4F -#define USB_DESC_UF2_PID 0x0022 -#define USB_DESC_CDC_ONLY_PID 0x0023 +#define USB_DESC_VID 0x1B4F +#define USB_DESC_UF2_PID 0x0022 +#define USB_DESC_CDC_ONLY_PID 0x0023 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "SparkFun MicroMod nRF52840" -#define UF2_VOLUME_LABEL "SFMM852BOOT" -#define UF2_BOARD_ID "nRF52840-micromod-v10" +#define UF2_PRODUCT_NAME "SparkFun MicroMod nRF52840" +#define UF2_VOLUME_LABEL "SFMM852BOOT" +#define UF2_BOARD_ID "nRF52840-micromod-v10" -#define UF2_INDEX_URL "https://www.sparkfun.com/products/16984" +#define UF2_INDEX_URL "https://www.sparkfun.com/products/16984" #endif /* _SPARKFUN_NRF52840_MICROMOD_H_ */ diff --git a/src/boards/t1000_e/board.h b/src/boards/t1000_e/board.h index a8eae88..58a52c9 100644 --- a/src/boards/t1000_e/board.h +++ b/src/boards/t1000_e/board.h @@ -25,42 +25,40 @@ #ifndef _T1000_E_H #define _T1000_E_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 24) // Green -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 24) // Green +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 6) // Primary Button -#define BUTTON_2 _PINNUM(0, 18) // unusable: RESET -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU PINNUM(0, 6) // Primary Button +#define BUTTON_DFU_OTA PINNUM(0, 18) // unusable: RESET +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Seeed Studio" -#define BLEDIS_MODEL "T1000-E" +#define BLEDIS_MANUFACTURER "Seeed Studio" +#define BLEDIS_MODEL "T1000-E" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0x0057 -#define USB_DESC_CDC_ONLY_PID 0x0057 +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0x0057 +#define USB_DESC_CDC_ONLY_PID 0x0057 //--------------------------------------------------------------------+ // UF2 //--------------------------------------------------------------------+ -#define UF2_PRODUCT_NAME "Seeed T1000-E for Meshtastic" -#define UF2_VOLUME_LABEL "T1000-E" -#define UF2_BOARD_ID "nRF52840-T1000-E-v1" -#define UF2_INDEX_URL "https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-E-for-Meshtastic-p-5913.html" +#define UF2_PRODUCT_NAME "Seeed T1000-E for Meshtastic" +#define UF2_VOLUME_LABEL "T1000-E" +#define UF2_BOARD_ID "nRF52840-T1000-E-v1" +#define UF2_INDEX_URL "https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-E-for-Meshtastic-p-5913.html" #endif /* _T1000_E_H */ diff --git a/src/boards/waveshare_nrf52840_eval/board.h b/src/boards/waveshare_nrf52840_eval/board.h index 81a5fc1..d66a785 100644 --- a/src/boards/waveshare_nrf52840_eval/board.h +++ b/src/boards/waveshare_nrf52840_eval/board.h @@ -23,49 +23,47 @@ #ifndef _WAVESHARE_NRF52840_H #define _WAVESHARE_NRF52840_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 +#define LEDS_NUMBER 2 /* This is led marked LED1 on the board */ -#define LED_PRIMARY_PIN _PINNUM(0, 13) +#define LED_PRIMARY_PIN PINNUM(0, 13) /* This is led marked LED2 on the board */ -#define LED_SECONDARY_PIN _PINNUM(0, 14) +#define LED_SECONDARY_PIN PINNUM(0, 14) /* There are two more LEDs, but for the purposes of bootloader that * doesn't matter. */ -#define LED_STATE_ON 0 +#define LED_STATE_ON 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ /* This is the 'KEY1' in top left of the board under RESET key. * It is used to remain in bootloader mode after reset. */ -#define BUTTON_1 _PINNUM(0, 11) +#define BUTTON_DFU PINNUM(0, 11) /* Pin below is in the bottom left of PCB, and can be shorted to GND * with a regular 2.54mm jumper or tweezers. This pin is used to * clear user firmware and remain in bootloader mode. */ -#define BUTTON_2 _PINNUM(0, 29) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU_OTA PINNUM(0, 29) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Waveshare" -#define BLEDIS_MODEL "nRF52840 Eval" +#define BLEDIS_MANUFACTURER "Waveshare" +#define BLEDIS_MODEL "nRF52840 Eval" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x002A +#define USB_DESC_VID 0x239A +#define USB_DESC_UF2_PID 0x0029 +#define USB_DESC_CDC_ONLY_PID 0x002A //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Waveshare nRF52840 Eval" -#define UF2_VOLUME_LABEL "WS52840EVK" -#define UF2_BOARD_ID "WS-nRF52840-EVK" -#define UF2_INDEX_URL "https://www.waveshare.com/wiki/NRF52840_Eval_Kit" +#define UF2_PRODUCT_NAME "Waveshare nRF52840 Eval" +#define UF2_VOLUME_LABEL "WS52840EVK" +#define UF2_BOARD_ID "WS-nRF52840-EVK" +#define UF2_INDEX_URL "https://www.waveshare.com/wiki/NRF52840_Eval_Kit" #endif // _WAVESHARE_NRF52840_H diff --git a/src/boards/xiao_nrf52840_ble/board.h b/src/boards/xiao_nrf52840_ble/board.h index 1543189..eacabd2 100644 --- a/src/boards/xiao_nrf52840_ble/board.h +++ b/src/boards/xiao_nrf52840_ble/board.h @@ -25,43 +25,41 @@ #ifndef _XIAO_BLE #define _XIAO_BLE -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ // The board has 3 leds, but changing the number here causes OTA issues. -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 26) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 26) +#define LED_STATE_ON 0 -#define NEOPIXELS_NUMBER 0 +#define NEOPIXELS_NUMBER 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 18) +#define BUTTON_DFU PINNUM(0, 18) // Button 2 is defined as D1 from expansion board. -#define BUTTON_2 _PINNUM(0, 3) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU_OTA PINNUM(0, 3) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Seeed" -#define BLEDIS_MODEL "XIAO nRF52840" +#define BLEDIS_MANUFACTURER "Seeed" +#define BLEDIS_MODEL "XIAO nRF52840" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0x0044 -#define USB_DESC_CDC_ONLY_PID 0x0044 +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0x0044 +#define USB_DESC_CDC_ONLY_PID 0x0044 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" -#define UF2_VOLUME_LABEL "XIAO-BOOT" -#define UF2_BOARD_ID "nRF52840-SeeedXiao-v1" -#define UF2_INDEX_URL "https://www.seeedstudio.com/" +#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" +#define UF2_VOLUME_LABEL "XIAO-BOOT" +#define UF2_BOARD_ID "nRF52840-SeeedXiao-v1" +#define UF2_INDEX_URL "https://www.seeedstudio.com/" #endif // _XIAO_BLE diff --git a/src/boards/xiao_nrf52840_ble_sense/board.h b/src/boards/xiao_nrf52840_ble_sense/board.h index fd30e14..ff0c204 100644 --- a/src/boards/xiao_nrf52840_ble_sense/board.h +++ b/src/boards/xiao_nrf52840_ble_sense/board.h @@ -25,43 +25,41 @@ #ifndef _XIAO_BLE_SENSE #define _XIAO_BLE_SENSE -#define _PINNUM(port, pin) ((port)*32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ // The board has 3 leds, but changing the number here causes OTA issues. -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 26) -#define LED_STATE_ON 0 +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN PINNUM(0, 26) +#define LED_STATE_ON 0 -#define NEOPIXELS_NUMBER 0 +#define NEOPIXELS_NUMBER 0 /*------------------------------------------------------------------*/ /* BUTTON *------------------------------------------------------------------*/ -#define BUTTON_1 _PINNUM(0, 18) +#define BUTTON_DFU PINNUM(0, 18) // Button 2 is defined as D1 from expansion board. -#define BUTTON_2 _PINNUM(0, 3) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP +#define BUTTON_DFU_OTA PINNUM(0, 3) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP //--------------------------------------------------------------------+ // BLE OTA //--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Seeed" -#define BLEDIS_MODEL "XIAO nRF52840 Sense" +#define BLEDIS_MANUFACTURER "Seeed" +#define BLEDIS_MODEL "XIAO nRF52840 Sense" //--------------------------------------------------------------------+ // USB //--------------------------------------------------------------------+ -#define USB_DESC_VID 0x2886 -#define USB_DESC_UF2_PID 0x0045 -#define USB_DESC_CDC_ONLY_PID 0x0045 +#define USB_DESC_VID 0x2886 +#define USB_DESC_UF2_PID 0x0045 +#define USB_DESC_CDC_ONLY_PID 0x0045 //------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" -#define UF2_VOLUME_LABEL "XIAO-SENSE" -#define UF2_BOARD_ID "nRF52840-SeeedXiaoSense-v1" -#define UF2_INDEX_URL "https://www.seeedstudio.com/" +#define UF2_PRODUCT_NAME "Seeed XIAO nRF52840" +#define UF2_VOLUME_LABEL "XIAO-SENSE" +#define UF2_BOARD_ID "nRF52840-SeeedXiaoSense-v1" +#define UF2_INDEX_URL "https://www.seeedstudio.com/" #endif // _XIAO_BLE_SENSE diff --git a/src/main.c b/src/main.c index 2e2fc0c..703bdb8 100644 --- a/src/main.c +++ b/src/main.c @@ -263,8 +263,8 @@ static void check_dfu_mode(void) { #endif // DFU + FRESET are pressed --> OTA -#if defined(BUTTON_DFU) && defined(BUTTON_FRESET) - _ota_dfu = _ota_dfu || (button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET)); +#if defined(BUTTON_DFU) && defined(BUTTON_DFU_OTA) + _ota_dfu = _ota_dfu || (button_pressed(BUTTON_DFU) && button_pressed(BUTTON_DFU_OTA)); #endif bool const valid_app = bootloader_app_is_valid(); From a6f668ece4cdab8e3b3733c9921f829ed08a6636 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 2 Feb 2026 17:16:03 +0700 Subject: [PATCH 37/40] clean up --- .../board.cmake | 1 - .../arcade_feather_nrf52840_express/board.h | 66 ------------------- .../arcade_feather_nrf52840_express/board.mk | 1 - .../pinconfig.c | 62 ----------------- src/boards/bast_ble/board.h | 1 - src/boards/boards.h | 4 -- src/boards/raytac_mdbt50q_db_40/board.h | 15 ++--- supported_boards.md | 1 - 8 files changed, 5 insertions(+), 146 deletions(-) delete mode 100644 src/boards/arcade_feather_nrf52840_express/board.cmake delete mode 100644 src/boards/arcade_feather_nrf52840_express/board.h delete mode 100644 src/boards/arcade_feather_nrf52840_express/board.mk delete mode 100644 src/boards/arcade_feather_nrf52840_express/pinconfig.c diff --git a/src/boards/arcade_feather_nrf52840_express/board.cmake b/src/boards/arcade_feather_nrf52840_express/board.cmake deleted file mode 100644 index 25daf71..0000000 --- a/src/boards/arcade_feather_nrf52840_express/board.cmake +++ /dev/null @@ -1 +0,0 @@ -set(MCU_VARIANT nrf52840) diff --git a/src/boards/arcade_feather_nrf52840_express/board.h b/src/boards/arcade_feather_nrf52840_express/board.h deleted file mode 100644 index c33b644..0000000 --- a/src/boards/arcade_feather_nrf52840_express/board.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * - * 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. - */ - -#ifndef _ARCARDE_FEATHER_NRF52840_H -#define _ARCARDE_FEATHER_NRF52840_H - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 2 -#define LED_PRIMARY_PIN PINNUM(1, 15) -#define LED_SECONDARY_PIN PINNUM(1, 10) -#define LED_STATE_ON 1 - -#define LED_NEOPIXEL PINNUM(0, 16) -#define NEOPIXELS_NUMBER 1 -#define BOARD_RGB_BRIGHTNESS 0x040404 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTON_DFU PINNUM(1, 02) -#define BUTTON_DFU_OTA PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "Adafruit Industries" -#define BLEDIS_MODEL "Feather nRF52840 Express" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x239A -#define USB_DESC_UF2_PID 0x0029 -#define USB_DESC_CDC_ONLY_PID 0x002A - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "Adafruit Feather nRF52840 Express" -#define UF2_VOLUME_LABEL "ARCADE-N4" -#define UF2_BOARD_ID "nRF52840-Feather-revD" -#define UF2_INDEX_URL "https://www.adafruit.com/product/4062" - -#endif // _ARCARDE_FEATHER_NRF52840_H diff --git a/src/boards/arcade_feather_nrf52840_express/board.mk b/src/boards/arcade_feather_nrf52840_express/board.mk deleted file mode 100644 index 9d29ac6..0000000 --- a/src/boards/arcade_feather_nrf52840_express/board.mk +++ /dev/null @@ -1 +0,0 @@ -MCU_SUB_VARIANT = nrf52840 diff --git a/src/boards/arcade_feather_nrf52840_express/pinconfig.c b/src/boards/arcade_feather_nrf52840_express/pinconfig.c deleted file mode 100644 index 5424d86..0000000 --- a/src/boards/arcade_feather_nrf52840_express/pinconfig.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "boards.h" - -__attribute__((used, section(".bootloaderConfig"))) -const uint32_t bootloaderConfig[] = { - /* CF2 START */ - 513675505, 539130489, // magic - 49, 100, // used entries, total entries - 4, 0x18, // PIN_BTN_A = PIN_RX - 5, 0xa, // PIN_BTN_B = PIN_D2 - 13, 0x29, // PIN_LED = PIN_D13 - 18, 0xf, // PIN_MISO = PA15 - 19, 0xd, // PIN_MOSI = PA13 - 20, 0x23, // PIN_NEOPIXEL = PB03 - 21, 0x18, // PIN_RX = PA24 - 23, 0xe, // PIN_SCK = PA14 - 24, 0xb, // PIN_SCL = PA11 - 25, 0xc, // PIN_SDA = PA12 - 28, 0x19, // PIN_TX = PA25 - 32, 0xe, // PIN_DISPLAY_SCK = PIN_SCK - 34, 0xd, // PIN_DISPLAY_MOSI = PIN_MOSI - 35, 0x1e, // PIN_DISPLAY_CS = PIN_A2 - 36, 0x1c, // PIN_DISPLAY_DC = PIN_A3 - 37, 0xa0, // DISPLAY_WIDTH = 160 - 38, 0x80, // DISPLAY_HEIGHT = 128 - 39, 0x80, // DISPLAY_CFG0 = 0x80 - 40, 0x603, // DISPLAY_CFG1 = 0x603 - 41, 0x20, // DISPLAY_CFG2 = 0x20 - 43, 0x2, // PIN_DISPLAY_RST = PIN_A4 - 44, 0x3, // PIN_DISPLAY_BL = PIN_A5 - 47, 0x6, // PIN_BTN_LEFT = PIN_D11 - 48, 0x1a, // PIN_BTN_RIGHT = PIN_D9 - 49, 0x1b, // PIN_BTN_UP = PIN_D10 - 50, 0x7, // PIN_BTN_DOWN = PIN_D6 - 51, 0x8, // PIN_BTN_MENU = PIN_D12 - 56, 0x2a, // PIN_LED2 = PB10 - 60, 0x19, // PIN_JACK_TX = PIN_TX - 100, 0x4, // PIN_A0 = PA04 - 101, 0x5, // PIN_A1 = PA05 - 102, 0x1e, // PIN_A2 = PA30 - 103, 0x1c, // PIN_A3 = PA28 - 104, 0x2, // PIN_A4 = PA02 - 105, 0x3, // PIN_A5 = PA03 - 152, 0xa, // PIN_D2 = PA10 - 155, 0x28, // PIN_D5 = PB08 - 156, 0x7, // PIN_D6 = PA07 - 159, 0x1a, // PIN_D9 = PA26 - 160, 0x1b, // PIN_D10 = PA27 - 161, 0x6, // PIN_D11 = PA06 - 162, 0x8, // PIN_D12 = PA08 - 163, 0x29, // PIN_D13 = PB09 - 200, 0x1, // NUM_NEOPIXELS = 1 - 204, 0x100000, // FLASH_BYTES = 0x100000 - 205, 0x40000, // RAM_BYTES = 0x40000 - 208, 0xd7688ea1, // BOOTLOADER_BOARD_ID = 0xd7688ea1 - 209, 0xada52840, // UF2_FAMILY = 0xada52840 - 210, 0x20, // PINS_PORT_SIZE = PA_32 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - /* CF2 END */ -}; diff --git a/src/boards/bast_ble/board.h b/src/boards/bast_ble/board.h index 598d2dd..68a1ea7 100644 --- a/src/boards/bast_ble/board.h +++ b/src/boards/bast_ble/board.h @@ -25,7 +25,6 @@ #ifndef _BASTBLE_NRF52840_H #define _BASTBLE_NRF52840_H -#define PINNUM(port, pin) ((port) * 32 + (pin)) /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ diff --git a/src/boards/boards.h b/src/boards/boards.h index 87b14b1..8600119 100644 --- a/src/boards/boards.h +++ b/src/boards/boards.h @@ -38,10 +38,6 @@ #define UF2_VOLUME_LABEL "NRF52BOOT " #endif -#if !defined(BUTTON_DFU_OTA) && defined(BUTTON_DFU_OTA) - #define BUTTON_DFU_OTA BUTTON_DFU_OTA -#endif - // The primary LED is usually Red but not in all cases. #define LED_PRIMARY 0 // The secondary LED, when available, is usually blue. diff --git a/src/boards/raytac_mdbt50q_db_40/board.h b/src/boards/raytac_mdbt50q_db_40/board.h index 838c90e..2d26a3c 100644 --- a/src/boards/raytac_mdbt50q_db_40/board.h +++ b/src/boards/raytac_mdbt50q_db_40/board.h @@ -25,20 +25,15 @@ #ifndef RAYTAC_MDBT50Q_DB_40_H #define RAYTAC_MDBT50Q_DB_40_H -#define PINNUM(port, pin) ((port) * 32 + (pin)) - /*------------------------------------------------------------------*/ /* LED *------------------------------------------------------------------*/ #define LEDS_NUMBER 3 -/* This is the Green led marked D1 on the board */ -#define LED_PRIMARY_PIN PINNUM(1, 13) -/* This is the Red led marked D2 on the board */ -#define LED_SECONDARY_PIN PINNUM(1, 14) -/* This is the Blue led marked D3 on the board */ -#define LED_TERTIARY_PIN PINNUM(1, 15) -/* There are one more unpopulated LEDs, but for the purposes of bootloader that - * doesn't matter. */ +#define LED_PRIMARY_PIN PINNUM(1, 13) /* Green led marked D1 on the board */ +#define LED_SECONDARY_PIN PINNUM(1, 14) /* Red led marked D2 on the board */ +#define LED_TERTIARY_PIN PINNUM(1, 15) /* Blue led marked D3 on the board */ + +/* There are one more unpopulated LEDs, but for the purposes of bootloader that doesn't matter. */ #define LED_STATE_ON 0 /*------------------------------------------------------------------*/ diff --git a/supported_boards.md b/supported_boards.md index f733ac3..82484fd 100644 --- a/supported_boards.md +++ b/supported_boards.md @@ -4,7 +4,6 @@ | Board | Name | VID PID | URL | | --- | --- | --- | --- | -| arcade_feather_nrf52840_express | Adafruit Feather nRF52840 Express | 0x239A:0x0029 | https://www.adafruit.com/product/4062 | | circuitplayground_nrf52840 | Adafruit Circuit Playground nRF52840 | 0x239A:0x0045 | https://www.adafruit.com/product/4333 | | clue_nrf52840 | Adafruit CLUE nRF52840 | 0x239A:0x0071 | https://www.adafruit.com/product/4500 | | feather_nrf52832 | Adafruit Feather nRF52832 | N/A | https://www.adafruit.com/product/3406 | From 5bb68e612548690de7204fc4308b4bf736fe8579 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 2 Feb 2026 19:12:21 +0700 Subject: [PATCH 38/40] sync master --- src/boards/syldra/board.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/boards/syldra/board.h b/src/boards/syldra/board.h index 4afa78d..b48024a 100644 --- a/src/boards/syldra/board.h +++ b/src/boards/syldra/board.h @@ -25,32 +25,27 @@ #ifndef _SYLDRA_H #define _SYLDRA_H -#define _PINNUM(port, pin) ((port)*32 + (pin)) - //------------------------------------------------------------------// // LED //------------------------------------------------------------------// #define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 17) // AD10 LED +#define LED_PRIMARY_PIN PINNUM(0, 17) // AD10 LED #define LED_STATE_ON 1 //------------------------------------------------------------------// // BUTTON //------------------------------------------------------------------// -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 24) // AD20 -- DFU -#define BUTTON_2 _PINNUM(1, 00) // AD22 -- FRST +#define BUTTON_DFU PINNUM(0, 24) // AD20 -- DFU +#define BUTTON_DFU_OTA PINNUM(1, 00) // AD22 -- OTA #define BUTTON_PULL NRF_GPIO_PIN_PULLUP - //-------------------------------------------------------------------// // BLE OTA //-------------------------------------------------------------------// #define BLEDIS_MANUFACTURER "Ambraglow-&-localcc" #define BLEDIS_MODEL "Syldra_dev_r1" - //--------------------------------------------------------------------+ // USB - using test PIDs //--------------------------------------------------------------------+ From cef2651b0d08cdf7ec86d7eeb53ac03d88f201a7 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 2 Feb 2026 19:14:56 +0700 Subject: [PATCH 39/40] correct uf2 board id --- src/boards/syldra/board.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boards/syldra/board.h b/src/boards/syldra/board.h index b48024a..61539f8 100644 --- a/src/boards/syldra/board.h +++ b/src/boards/syldra/board.h @@ -55,7 +55,7 @@ #define UF2_PRODUCT_NAME "Syldra nrf52840 Development Board" #define UF2_VOLUME_LABEL "Syldra-boot" -#define UF2_BOARD_ID "Syldra-dev-v1" +#define UF2_BOARD_ID "nRF52840-Syldra-dev-v1" #define UF2_INDEX_URL "https://github.com/ambraglow/nonorf" #endif \ No newline at end of file From 6b24be5f69e03a25aacc41f06e2364a1576c8141 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 3 Feb 2026 14:14:08 +0700 Subject: [PATCH 40/40] - add GCC diagnostic ignored "-Warray-bounds" to affected code - correct usage of __has_attribute(nonstring) and rename to ATTR_NOSTRING --- Makefile | 6 ---- .../bootloader_dfu/bootloader_settings.c | 31 ++++++++++++------- src/usb/uf2/ghostfat.c | 22 ++++++------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 9d2d4df..f1fb137 100644 --- a/Makefile +++ b/Makefile @@ -392,12 +392,6 @@ endif CFLAGS += -DDFU_APP_DATA_RESERVED=$(DFU_APP_DATA_RESERVED) -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 -# Fixes for gcc version 12, 13, 14 and 15. -ifneq (,$(filter 12.% 13.% 14.% 15.%,$(shell $(CC) -dumpversion 2>$(NULL_DEVICE)))) - CFLAGS += --param=min-pagesize=0 -endif - #------------------------------------------------------------------------------ # Linker Flags #------------------------------------------------------------------------------ diff --git a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c index c071020..1febf3f 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/bootloader_settings.c @@ -40,15 +40,22 @@ void bootloader_util_settings_get(const bootloader_settings_t ** pp_bootloader_s *pp_bootloader_settings = p_bootloader_settings; } -void bootloader_mbr_addrs_populate(void) -{ - if (*(const uint32_t *)MBR_BOOTLOADER_ADDR == 0xFFFFFFFF) - { - nrfx_nvmc_word_write(MBR_BOOTLOADER_ADDR, BOOTLOADER_REGION_START); - } - - if (*(const uint32_t *)MBR_PARAM_PAGE_ADDR == 0xFFFFFFFF) - { - nrfx_nvmc_word_write(MBR_PARAM_PAGE_ADDR, BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS); - } -} +void bootloader_mbr_addrs_populate(void) +{ +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + if (*(const uint32_t *)MBR_BOOTLOADER_ADDR == 0xFFFFFFFF) + { + nrfx_nvmc_word_write(MBR_BOOTLOADER_ADDR, BOOTLOADER_REGION_START); + } + + if (*(const uint32_t *)MBR_PARAM_PAGE_ADDR == 0xFFFFFFFF) + { + nrfx_nvmc_word_write(MBR_PARAM_PAGE_ADDR, BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS); + } +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#endif +} diff --git a/src/usb/uf2/ghostfat.c b/src/usb/uf2/ghostfat.c index 0564182..97753ef 100644 --- a/src/usb/uf2/ghostfat.c +++ b/src/usb/uf2/ghostfat.c @@ -41,18 +41,18 @@ //--------------------------------------------------------------------+ // Add nonstring attribute if supported to avoid errors in GCC 15 -#ifdef __has_attribute - #define __NONSTRING__ __attribute__((nonstring)) +#if defined(__has_attribute) && __has_attribute(nonstring) + #define ATTR_NONSTRING __attribute__((nonstring)) #else - #define __NONSTRING__ + #define ATTR_NONSTRING #endif typedef struct { uint8_t JumpInstruction[3]; - uint8_t OEMInfo[8] __NONSTRING__; - uint16_t SectorSize; - uint8_t SectorsPerCluster; - uint16_t ReservedSectors; + uint8_t OEMInfo[8] ATTR_NONSTRING; + uint16_t SectorSize; + uint8_t SectorsPerCluster; + uint16_t ReservedSectors; uint8_t FATCopies; uint16_t RootDirectoryEntries; uint16_t TotalSectors16; @@ -66,8 +66,8 @@ typedef struct { uint8_t Reserved; uint8_t ExtendedBootSig; uint32_t VolumeSerialNumber; - uint8_t VolumeLabel[11] __NONSTRING__; - uint8_t FilesystemIdentifier[8] __NONSTRING__; + uint8_t VolumeLabel[11] ATTR_NONSTRING; + uint8_t FilesystemIdentifier[8] ATTR_NONSTRING; } __attribute__((packed)) FAT_BootBlock; typedef struct { @@ -88,8 +88,8 @@ typedef struct { STATIC_ASSERT(sizeof(DirEntry) == 32); struct TextFile { - char const name[11] __NONSTRING__; - char const *content; + const char name[11] ATTR_NONSTRING; + const char *content; };