Skip to content

Commit

Permalink
[nrfconnect] Support nRF52840 Dongle in all-clusters-app (project-chi…
Browse files Browse the repository at this point in the history
…p#17215)

* [nrfconnect] Support nRF52840 Dongle in all-clusters-app

The dongle doesn't have external flash, so only build
configurations without the DFU are supported. Also, due
to flash size limitations (nR52840 dongle reserves some
flash for an immutable bootloader), shell commands
must have been disabled, too.

By the way, make fixes in lighting-app which in theory
already had the support for the nRF52840 Dongle, but it
didn't work due to various issues.

Signed-off-by: Damian Krolik <[email protected]>

* Add new targets to build_examples.py

* Fix build

* Revert accidentally committed change
  • Loading branch information
Damian-Nordic authored and andrei-menzopol committed Apr 14, 2022
1 parent fd26ea2 commit 54ae0c0
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 30 deletions.
4 changes: 4 additions & 0 deletions examples/all-clusters-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ chip_configure_data_model(app
if(CONFIG_CHIP_OTA_REQUESTOR)
target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp)
endif()

if (CONFIG_SHELL AND BOARD STREQUAL "nrf52840dongle_nrf52840")
target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUTrigger.cpp)
endif()
41 changes: 35 additions & 6 deletions examples/all-clusters-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ into an existing Matter network and can be controlled by this network.
- [Configuring the example](#configuring-the-example)
- [Example build types](#example-build-types)
- [Flashing and debugging](#flashing-and-debugging)
- [Flashing on the development kits](#nrfdks_flashing)
- [Flashing on the nRF52840 Dongle](#nrf52840dongle_flashing)
- [Testing the example](#testing-the-example)
- [Testing using CHIPTool](#testing-using-chiptool)

Expand Down Expand Up @@ -98,10 +100,11 @@ more information.

The example supports building and running on the following devices:

| Hardware platform | Build target | Platform image |
| ----------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [nRF52840 DK](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK) | `nrf52840dk_nrf52840` | <details><summary>nRF52840 DK</summary><img src="../../platform/nrfconnect/doc/images/nRF52840_DK_info-medium.jpg" alt="nRF52840 DK"/></details> |
| [nRF5340 DK](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF5340-DK) | `nrf5340dk_nrf5340_cpuapp` | <details><summary>nRF5340 DK</summary><img src="../../platform/nrfconnect/doc/images/nRF5340_DK_info-medium.jpg" alt="nRF5340 DK"/></details> |
| Hardware platform | Build target | Platform image |
| ------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [nRF52840 DK](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK) | `nrf52840dk_nrf52840` | <details><summary>nRF52840 DK</summary><img src="../../platform/nrfconnect/doc/images/nRF52840_DK_info-medium.jpg" alt="nRF52840 DK"/></details> |
| [nRF5340 DK](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF5340-DK) | `nrf5340dk_nrf5340_cpuapp` | <details><summary>nRF5340 DK</summary><img src="../../platform/nrfconnect/doc/images/nRF5340_DK_info-medium.jpg" alt="nRF5340 DK"/></details> |
| [nRF52840 Dongle](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle) | `nrf52840dongle_nrf52840` | <details><summary>nRF52840 Dongle</summary><img src="../../platform/nrfconnect/doc/images/nRF52840_Dongle-medium.jpg" alt="nRF52840 Dongle"/></details> |

<hr>

Expand All @@ -113,6 +116,15 @@ This section lists the User Interface elements that you can use to control and
monitor the state of the device. These correspond to PCB components on the
platform image.

> **Note**:
>
> The following Device UI elements are missing on the nRF52840 Dongle: **Button
> 2**, **Button 3**, **Button 4**, **SEGGER J-Link USB port**, and **NFC port
> with antenna attached**. You can collect logs from the nRF52840 Dongle using
> the **nRF USB port** instead of the **SEGGER J-Link USB port**.
> Functionalities associated with the remaining missing elements are
> inaccessible.
**LED 1** shows the overall state of the device and its connectivity. The
following states are possible:

Expand Down Expand Up @@ -381,9 +393,11 @@ depending on the selected board:
command-line shell.
- release -- Release version of the application - can be used to enable only
the necessary application functionalities to optimize its performance. It
has Device Firmware Upgrade feature enabled.
has Device Firmware Upgrade feature enabled. It can be used only for the
nRF52840 DK and nRF5340 DK, as only those platforms support the DFU.
- dfu -- Debug version of the application with Device Firmware Upgrade feature
support.
support. It can be used only for the nRF52840 DK and nRF5340 DK, as only
those platforms support the DFU.

For more information, see the
[Configuring nRF Connect SDK examples](../../../docs/guides/nrfconnect_examples_configuration.md)
Expand All @@ -395,6 +409,13 @@ page.

## Flashing and debugging

The flashing and debugging procedure is different for the development kits and
the nRF52840 Dongle.

<a name="nrfdks_flashing"></a>

### Flashing on the development kits

To flash the application to the device, use the west tool and run the following
command from the example directory:

Expand All @@ -408,6 +429,14 @@ directory:

$ west debug

<a name="nrf52840dongle_flashing"></a>

### Flashing on the nRF52840 Dongle

Visit
[Programming and Debugging nRF52840 Dongle](https://docs.zephyrproject.org/latest/boards/arm/nrf52840dongle_nrf52840/doc/index.html#programming-and-debugging)
to read more about flashing on the nRF52840 Dongle.

<hr>

## Testing the example
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Configure logging over USB
# - do enable shell to reduce flash usage
# - disable CDC ACM logs as it may lead to infinite loop when CDC ACM is used as the log backend
CONFIG_USB_DEVICE_STACK=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_SHELL_LOG_BACKEND=n
CONFIG_UART_LINE_CTRL=y
CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y

# The minimal logging mode does not work properly with the USB CDC device, so use the deferred mode
CONFIG_LOG_MODE_MINIMAL=n
CONFIG_LOG2_MODE_DEFERRED=y
CONFIG_LOG_BUFFER_SIZE=8192

# Reduce the code size as the dongle reserves some space for MBR and Open Bootloader
CONFIG_ASSERT_VERBOSE=n
CONFIG_SHELL=n
CONFIG_OPENTHREAD_SHELL=n
CONFIG_MATTER_LOG_LEVEL_INF=y

# Use partition manager to configure the settings partition not to overlap with Open Bootloader
CONFIG_PM_SINGLE_IMAGE=y

# Enable CHIP pairing automatically on application start.
CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http: //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/ {
chosen {
zephyr,console = &cdc_acm_uart0;
};
};

&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
label = "CDC_ACM_0";
};
};
40 changes: 39 additions & 1 deletion examples/all-clusters-app/nrfconnect/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,51 @@

#include <logging/log.h>

#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
#include <drivers/uart.h>
#include <usb/usb_device.h>
#endif

LOG_MODULE_REGISTER(app, CONFIG_MATTER_LOG_LEVEL);

using namespace ::chip;

#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
static int InitUSB()
{
int err = usb_enable(nullptr);

if (err)
{
LOG_ERR("Failed to initialize USB device");
return err;
}

const struct device * dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
uint32_t dtr = 0;

while (!dtr)
{
uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
k_sleep(K_MSEC(100));
}

return 0;
}
#endif

int main()
{
CHIP_ERROR err = AppTask::Instance().StartApp();
CHIP_ERROR err = CHIP_NO_ERROR;

#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
err = System::MapErrorZephyr(InitUSB());
#endif

if (err == CHIP_NO_ERROR)
{
err = AppTask::Instance().StartApp();
}

LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format());
return err == CHIP_NO_ERROR ? EXIT_SUCCESS : EXIT_FAILURE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
settings_storage:
address: 0xd8000
size: 0x8000
region: flash_primary
open_bootloader:
address: 0xe0000
size: 0x20000
region: flash_primary
2 changes: 1 addition & 1 deletion examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if(CONFIG_MCUMGR_SMP_BT)
target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp)
endif()

if (BOARD STREQUAL "nrf52840dongle_nrf52840")
if (CONFIG_SHELL AND BOARD STREQUAL "nrf52840dongle_nrf52840")
target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUTrigger.cpp)
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http: //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,9 +14,9 @@
* limitations under the License.
*/

/ {
chosen {
zephyr,shell-uart = &cdc_acm_uart0;
/ {
chosen {
zephyr,console = &cdc_acm_uart0;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@
# limitations under the License.
#

# Configure shell and logging over USB
# Configure logging over USB
# - do enable shell to reduce flash usage
# - disable CDC ACM logs as it may lead to infinite loop when CDC ACM is used as the log backend
CONFIG_USB_DEVICE_STACK=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_SHELL_LOG_BACKEND=n
CONFIG_UART_LINE_CTRL=y
CONFIG_SHELL_BACKEND_SERIAL_INIT_PRIORITY=51
CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y

# The minimal logging mode does not work properly with the USB CDC device, so use the deferred mode
CONFIG_LOG_MODE_MINIMAL=n
CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_STRDUP_MAX_STRING=128
CONFIG_LOG_STRDUP_BUF_COUNT=24
CONFIG_LOG2_MODE_DEFERRED=y
CONFIG_LOG_BUFFER_SIZE=8192

# Reduce the code size as the dongle reserves some space for MBR and Open Bootloader
CONFIG_ASSERT_VERBOSE=n
CONFIG_SHELL=n
CONFIG_OPENTHREAD_SHELL=n

# Use partition manager to configure the settings partition not to overlap with Open Bootloader
CONFIG_PM_SINGLE_IMAGE=y
35 changes: 28 additions & 7 deletions examples/lighting-app/nrfconnect/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,39 @@
#include "Rpc.h"
#endif

#ifdef CONFIG_USB_DEVICE_STACK
#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
#include <drivers/uart.h>
#include <usb/usb_device.h>
#endif

LOG_MODULE_REGISTER(app, CONFIG_MATTER_LOG_LEVEL);

using namespace ::chip;

#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
static int InitUSB()
{
int err = usb_enable(nullptr);

if (err)
{
LOG_ERR("Failed to initialize USB device");
return err;
}

const struct device * dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
uint32_t dtr = 0;

while (!dtr)
{
uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
k_sleep(K_MSEC(100));
}

return 0;
}
#endif

int main()
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand All @@ -42,12 +67,8 @@ int main()
rpc::Init();
#endif

#ifdef CONFIG_USB_DEVICE_STACK
err = System::MapErrorZephyr(usb_enable(nullptr));
if (err != CHIP_NO_ERROR)
{
LOG_ERR("Failed to initialize USB device");
}
#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
err = System::MapErrorZephyr(InitUSB());
#endif

if (err == CHIP_NO_ERROR)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
settings_storage:
address: 0xd8000
size: 0x8000
region: flash_primary
open_bootloader:
address: 0xe0000
size: 0x20000
region: flash_primary
4 changes: 3 additions & 1 deletion scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,12 @@ def NrfTargets():
target.Extend('nrf52840dk', board=NrfBoard.NRF52840DK),
]

# Enable nrf52840dongle for lighting app only
# Enable nrf52840dongle for all-clusters and lighting app only
yield target.Extend('nrf52840dongle-all-clusters', board=NrfBoard.NRF52840DONGLE, app=NrfApp.ALL_CLUSTERS)
yield target.Extend('nrf52840dongle-light', board=NrfBoard.NRF52840DONGLE, app=NrfApp.LIGHT)

for target in targets:
yield target.Extend('all-clusters', app=NrfApp.ALL_CLUSTERS)
yield target.Extend('lock', app=NrfApp.LOCK)
yield target.Extend('light', app=NrfApp.LIGHT)
yield target.Extend('shell', app=NrfApp.SHELL)
Expand Down
Loading

0 comments on commit 54ae0c0

Please sign in to comment.