Commit f061dcf8 authored by Dmitry Frank's avatar Dmitry Frank Committed by Cesanta Bot

Make nRF5 example fit better in nRF ecosystem

By making dir hierarchy replicate that of examples provided with the nRF
IoT SDK.

Also, example for Keil uVision IDE is added.

PUBLISHED_FROM=1a3d9a54d15eb1acfb1b5d162138576a387ed21c
parent 99377bdd
This diff is collapsed.
# nRF52 example project This is a Mongoose "Hello, world" that can be compiled under nRF IoT SDK.
This example shows how to use mongoose on nRF52 boards.
To run it you will need:
- [nRF52 DK](https://www.nordicsemi.com/Products/Getting-started-with-the-nRF52-Development-Kit) dev board
- Linux machine with 6lowpan module enabled. There are a few tutorials out there,
e.g [this one](https://devzone.nordicsemi.com/blogs/972/setting-up-ipv6-over-ble-using-nrf52-series-and-co/)
- [Docker](https://docs.docker.com/engine/installation/linux/)
## Building firmware and cleaning
Nothing special: `make` and `make clean`.
## Flashing
`make flash`
## Watch debug output
This is a two-step process:
- In a separate terminal, invoke `make jlinkexe`. It will run `JLinkExe`
utility, in which you'll need to type `connect`. You can actually do a lot of
things there, including halting and stopping the target, flashing firmware,
etc. You can type `?` to get the list of all available commands.
- Now, in another terminal, invoke `make rtt`. It will start RTT client which
will connect to the running `JLinkExe` and will show logs from the device.
## Debug with GDB
This is a two-step process:
- In a separate terminal, invoke `make gdbserver`. Note that `make jlinkexe`
and `make gdbserver`, unfortunately, cannot run sumultaneously.
- Now, in another terminal, invoke `make gdb`. It will start GDB session which
will connect to the running GDB server.
To make it work, you should download [nRF5 IoT SDK](http://developer.nordicsemi.com/nRF5_IoT_SDK/) and unpack it in current directory as `nrf5_iot_sdk`.
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#if !defined(COMMISSIONING_ENABLED) /* ifdef-ok */
# define COMMISSIONING_ENABLED 0
#endif
This diff is collapsed.
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
/* clang-format off */ /* clang-format off */
...@@ -35,12 +31,11 @@ ...@@ -35,12 +31,11 @@
#include "ipv6_medium.h" #include "ipv6_medium.h"
#include "SEGGER_RTT.h" #include "SEGGER_RTT.h"
#include "myboard.h" #include "myboard.h"
#include "app_cfg.h"
#define SCHED_MAX_EVENT_DATA_SIZE 128 /**< Maximum size of scheduler events. */ #define SCHED_MAX_EVENT_DATA_SIZE 128 /**< Maximum size of scheduler events. */
#define SCHED_QUEUE_SIZE 12 /**< Maximum number of events in the scheduler queue. */ #define SCHED_QUEUE_SIZE 12 /**< Maximum number of events in the scheduler queue. */
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
#define ERASE_BUTTON_PIN_NO BSP_BUTTON_3 /**< Button used to erase commissioning settings. */ #define ERASE_BUTTON_PIN_NO BSP_BUTTON_3 /**< Button used to erase commissioning settings. */
#endif // COMMISSIONING_ENABLED #endif // COMMISSIONING_ENABLED
...@@ -71,7 +66,7 @@ static ipv6_medium_instance_t m_ipv6_medium; ...@@ -71,7 +66,7 @@ static ipv6_medium_instance_t m_ipv6_medium;
static struct tcp_pcb * mp_tcp_port; /**< TCP Port to listen on. */ static struct tcp_pcb * mp_tcp_port; /**< TCP Port to listen on. */
static tcp_state_t m_tcp_state; /**< TCP State information. */ static tcp_state_t m_tcp_state; /**< TCP State information. */
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
static bool m_power_off_on_failure = false; static bool m_power_off_on_failure = false;
static bool m_identity_mode_active; static bool m_identity_mode_active;
#endif // COMMISSIONING_ENABLED #endif // COMMISSIONING_ENABLED
...@@ -79,7 +74,7 @@ static bool m_identity_mode_active; ...@@ -79,7 +74,7 @@ static bool m_identity_mode_active;
/**@brief Function to handle interface up event. */ /**@brief Function to handle interface up event. */
void nrf_driver_interface_up(void) void nrf_driver_interface_up(void)
{ {
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
commissioning_joining_mode_timer_ctrl(JOINING_MODE_TIMER_STOP_RESET); commissioning_joining_mode_timer_ctrl(JOINING_MODE_TIMER_STOP_RESET);
#endif // COMMISSIONING_ENABLED #endif // COMMISSIONING_ENABLED
...@@ -97,7 +92,7 @@ void nrf_driver_interface_up(void) ...@@ -97,7 +92,7 @@ void nrf_driver_interface_up(void)
/**@brief Function to handle interface down event. */ /**@brief Function to handle interface down event. */
void nrf_driver_interface_down(void) void nrf_driver_interface_down(void)
{ {
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
commissioning_joining_mode_timer_ctrl(JOINING_MODE_TIMER_START); commissioning_joining_mode_timer_ctrl(JOINING_MODE_TIMER_START);
#endif // COMMISSIONING_ENABLED #endif // COMMISSIONING_ENABLED
...@@ -156,7 +151,7 @@ static void leds_init(void) ...@@ -156,7 +151,7 @@ static void leds_init(void)
LEDS_OFF(ALL_APP_LED); LEDS_OFF(ALL_APP_LED);
} }
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
/**@brief Timer callback used for controlling board LEDs to represent application state. /**@brief Timer callback used for controlling board LEDs to represent application state.
* *
*/ */
...@@ -211,7 +206,7 @@ static void iot_timer_init(void) ...@@ -211,7 +206,7 @@ static void iot_timer_init(void)
static const iot_timer_client_t list_of_clients[] = static const iot_timer_client_t list_of_clients[] =
{ {
{system_timer_callback, LWIP_SYS_TICK_MS}, {system_timer_callback, LWIP_SYS_TICK_MS},
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
{blink_timeout_handler, LED_BLINK_INTERVAL_MS}, {blink_timeout_handler, LED_BLINK_INTERVAL_MS},
{commissioning_time_tick, SEC_TO_MILLISEC(COMMISSIONING_TICK_INTERVAL_SEC)} {commissioning_time_tick, SEC_TO_MILLISEC(COMMISSIONING_TICK_INTERVAL_SEC)}
#endif // COMMISSIONING_ENABLED #endif // COMMISSIONING_ENABLED
...@@ -258,7 +253,7 @@ static void ip_stack_init(void) ...@@ -258,7 +253,7 @@ static void ip_stack_init(void)
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
} }
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
/**@brief Function for handling button events. /**@brief Function for handling button events.
* *
* @param[in] pin_no The pin number of the button pressed. * @param[in] pin_no The pin number of the button pressed.
...@@ -286,7 +281,7 @@ static void buttons_init(void) ...@@ -286,7 +281,7 @@ static void buttons_init(void)
static app_button_cfg_t buttons[] = static app_button_cfg_t buttons[] =
{ {
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
{ERASE_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler} {ERASE_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler}
#endif // COMMISSIONING_ENABLED #endif // COMMISSIONING_ENABLED
}; };
...@@ -340,7 +335,7 @@ static void on_ipv6_medium_error(ipv6_medium_error_t * p_ipv6_medium_error) ...@@ -340,7 +335,7 @@ static void on_ipv6_medium_error(ipv6_medium_error_t * p_ipv6_medium_error)
// Do something. // Do something.
} }
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
void commissioning_id_mode_cb(mode_control_cmd_t control_command) void commissioning_id_mode_cb(mode_control_cmd_t control_command)
{ {
switch (control_command) switch (control_command)
...@@ -386,7 +381,7 @@ void bleconfig_init(void) { ...@@ -386,7 +381,7 @@ void bleconfig_init(void) {
timers_init(); timers_init();
iot_timer_init(); iot_timer_init();
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
err_code = pstorage_init(); err_code = pstorage_init();
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
...@@ -398,7 +393,7 @@ void bleconfig_init(void) { ...@@ -398,7 +393,7 @@ void bleconfig_init(void) {
ipv6_medium_init_params.ipv6_medium_evt_handler = on_ipv6_medium_evt; ipv6_medium_init_params.ipv6_medium_evt_handler = on_ipv6_medium_evt;
ipv6_medium_init_params.ipv6_medium_error_handler = on_ipv6_medium_error; ipv6_medium_init_params.ipv6_medium_error_handler = on_ipv6_medium_error;
ipv6_medium_init_params.use_scheduler = true; ipv6_medium_init_params.use_scheduler = true;
#if COMMISSIONING_ENABLED #ifdef COMMISSIONING_ENABLED
ipv6_medium_init_params.commissioning_id_mode_cb = commissioning_id_mode_cb; ipv6_medium_init_params.commissioning_id_mode_cb = commissioning_id_mode_cb;
ipv6_medium_init_params.commissioning_power_off_cb = commissioning_power_off_cb; ipv6_medium_init_params.commissioning_power_off_cb = commissioning_power_off_cb;
#endif // COMMISSIONING_ENABLED #endif // COMMISSIONING_ENABLED
......
target extended-remote localhost:2331 target extended-remote localhost:2331
file out/example.out file _build/nrf52832_xxaa_s1xx_iot.out
This diff is collapsed.
SDK ?= $(shell cat sdk.version) SDK ?= $(shell cat sdk.version)
SRC_DIR ?= $(realpath ../../..) SRC_DIR ?= $(realpath ../../../../../../..)
.PHONY: all clean flash gdbserver gdb jlinkexe rtt .PHONY: all clean flash gdbserver gdb jlinkexe rtt
...@@ -22,5 +22,6 @@ all clean flash gdbserver gdb jlinkexe rtt: ...@@ -22,5 +22,6 @@ all clean flash gdbserver gdb jlinkexe rtt:
$(V)docker run --rm -it $(ADD_DOCKER_ARGS) -v $(SRC_DIR):/src $(SDK) \ $(V)docker run --rm -it $(ADD_DOCKER_ARGS) -v $(SRC_DIR):/src $(SDK) \
/bin/bash -c "\ /bin/bash -c "\
make -C /src/mongoose mongoose.c mongoose.h && \ make -C /src/mongoose mongoose.c mongoose.h && \
make -C /src/mongoose/examples/nRF52 -f Makefile.build $@ -$(MAKEFLAGS) \ if [ ! -e /src/mongoose/examples/nRF52/nrf5_iot_sdk ]; then ln -s /opt/nrf5_iot_sdk /src/mongoose/examples/nRF52/nrf5_iot_sdk; fi && \
make -C /src/mongoose/examples/nRF52/http/boards/pca10040/armgcc $@ -$(MAKEFLAGS) \
" "
`Makefile` is intended to be used under nRF IoT SDK (see
../../../../README.md); `Makefile.docker` is intended to be used under Cesanta
repository.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "bleconfig.h" #include "bleconfig.h"
#include "myboard.h" #include "myboard.h"
#include "../../mongoose.h" #include "mongoose.h"
/* /*
* This is a callback invoked by Mongoose to signal that a poll is needed soon. * This is a callback invoked by Mongoose to signal that a poll is needed soon.
...@@ -72,9 +72,11 @@ int main(void) ...@@ -72,9 +72,11 @@ int main(void)
// Note that many connections can be added to a single event manager // Note that many connections can be added to a single event manager
// Connections can be created at any point, e.g. in event handler function // Connections can be created at any point, e.g. in event handler function
const char *err; const char *err;
struct mg_bind_opts opts = {}; struct mg_bind_opts opts;
struct mg_connection *nc = NULL;
memset(&opts, 0x00, sizeof(opts));
opts.error_string = &err; opts.error_string = &err;
struct mg_connection *nc = mg_bind_opt(&mgr, "80", ev_handler, opts); // Create listening connection and add it to the event manager nc = mg_bind_opt(&mgr, "80", ev_handler, opts); // Create listening connection and add it to the event manager
if (nc == NULL) { if (nc == NULL) {
printf("Failed to create listener: %s\n", err); printf("Failed to create listener: %s\n", err);
return 1; return 1;
......
...@@ -27,7 +27,7 @@ Purpose : Implementation of SEGGER real-time terminal which allows ...@@ -27,7 +27,7 @@ Purpose : Implementation of SEGGER real-time terminal which allows
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (2) // Max. number of up-buffers (T->H) available on this target (Default: 2) #define SEGGER_RTT_MAX_NUM_UP_BUFFERS (2) // Max. number of up-buffers (T->H) available on this target (Default: 2)
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (2) // Max. number of down-buffers (H->T) available on this target (Default: 2) #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (2) // Max. number of down-buffers (H->T) available on this target (Default: 2)
#define BUFFER_SIZE_UP (512) // Size of the buffer for terminal output of target, up to host (Default: 1k) #define BUFFER_SIZE_UP (2048) // Size of the buffer for terminal output of target, up to host (Default: 1k)
#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16) #define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64) #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
......
/* Linker script for Nordic Semiconductor nRF5 devices
*
* Version: Sourcery G++ 4.5-1
* Support: https://support.codesourcery.com/GNUToolchain/
*
* Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
/* Linker script to place sections and symbol values. Should be used together
* with other linker script that defines memory regions FLASH and RAM.
* It references following symbols, which must be defined in code:
* Reset_Handler : Entry of reset handler
*
* It defines following symbols, which code can use without definition:
* __exidx_start
* __exidx_end
* __etext
* __data_start__
* __preinit_array_start
* __preinit_array_end
* __init_array_start
* __init_array_end
* __fini_array_start
* __fini_array_end
* __data_end__
* __bss_start__
* __bss_end__
* __end__
* end
* __HeapLimit
* __StackLimit
* __StackTop
* __stack
*/
ENTRY(Reset_Handler)
SECTIONS
{
.text :
{
KEEP(*(.Vectors))
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
/* .ctors */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.rodata*)
*(.eh_frame*)
. = ALIGN(4);
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(4);
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
. = ALIGN(4);
} > FLASH
__exidx_end = .;
__etext = .;
.data : AT (__etext)
{
__data_start__ = .;
*(vtable)
*(.data*)
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
*(SORT(.init_array.*))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
*(SORT(.fini_array.*))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
*(.jcr)
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > RAM
.bss :
{
. = ALIGN(4);
__bss_start__ = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > RAM
.heap (COPY):
{
__end__ = .;
end = __end__;
*(.heap*)
__HeapLimit = .;
} > RAM
/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy (COPY):
{
*(.stack*)
} > RAM
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment