Skip to content

Commit

Permalink
RT1020 and RT1060 OTA
Browse files Browse the repository at this point in the history
  • Loading branch information
robert committed Jan 12, 2024
1 parent 124ab99 commit f750cf3
Show file tree
Hide file tree
Showing 16 changed files with 716 additions and 72 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,4 @@ clean: clean_examples clean_embedded
#find examples -maxdepth 3 -name zephyr -prune -o -name Makefile -print | xargs dirname | xargs -n1 make clean -C

clean_embedded:
for X in $(EXAMPLES_EMBEDDED); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done

for X in $(EXAMPLES_EMBEDDED); do test -f $$X/Makefile || continue; $(MAKE) -C $$X clean || exit 1; done
13 changes: 4 additions & 9 deletions examples/nxp/rt1020-evk-make-baremetal-builtin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ CFLAGS += -Wformat-truncation -fno-common -Wconversion -Wno-sign-conversion
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_mcu/devices/MIMXRT1021 #-DCPU_MIMXRT1021DAG5A
CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 $(CFLAGS_EXTRA)
LDSCRIPT = link_ram.ld
LDFLAGS ?= -T$(LDSCRIPT) -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map
LDSCRIPT = link.ld
LDFLAGS ?= -T$(LDSCRIPT) -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map

SOURCES = main.c syscalls.c sysinit.c
SOURCES += cmsis_mcu/devices/MIMXRT1021/gcc/startup_MIMXRT1021.S # NXP startup file. Compiler-dependent!
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS # Make startup code work as expected

# Mongoose options are defined in mongoose_custom.h
SOURCES += mongoose.c
SOURCES += mongoose.c flash_image.c net.c packed_fs.c

# Example specific build options. See README.md
CFLAGS += -DHTTP_URL=\"http://0.0.0.0/\" -DHTTPS_URL=\"https://0.0.0.0/\"
Expand All @@ -24,11 +24,6 @@ endif

all build example: firmware.bin

image: LDSCRIPT = link.ld
image: SOURCES += flash_image.c net.c packed_fs.c # no room to run dashboard in RAM w/ default config
image: CFLAGS += -DRUNINFLASH
image: firmware.bin

firmware.bin: firmware.elf
arm-none-eabi-objcopy -O binary $< $@

Expand Down Expand Up @@ -71,7 +66,7 @@ test: update
curl --fail-with-body -su :$(VCON_API_KEY) $(DEVICE_URL)/tx?t=5 | tee /tmp/output.txt
grep 'READY, IP:' /tmp/output.txt # Check for network init

testimage: image
testimage: firmware.bin

clean:
$(RM) firmware.* *.su cmsis_core cmsis_mcu mbedtls *.zip
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "dcd.h" // pin settings for MIMXRT1020-EVK board
#include "flexspi.h" // peripheral structures
#include "hal.h"
#include "flexspi.h" // peripheral structures

extern uint32_t __isr_vector[];

Expand Down
6 changes: 3 additions & 3 deletions examples/nxp/rt1020-evk-make-baremetal-builtin/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ENTRY(Reset_Handler);
MEMORY {
flash_hdr(rx) : ORIGIN = 0x60000000, LENGTH = 8k
flash_irq(rx) : ORIGIN = 0x60002000, LENGTH = 1k
flash_code(rx) : ORIGIN = 0x60002400, LENGTH = 8183k
flash_code(rx) : ORIGIN = 0x60002400, LENGTH = 8179k

itcram(rx) : ORIGIN = 0x00000000, LENGTH = 64k
dtcram(rw) : ORIGIN = 0x20000000, LENGTH = 64k
Expand All @@ -15,8 +15,8 @@ SECTIONS {
KEEP(*(.dat)) . = 0x1030 ; KEEP(*(.dcd)) . = 0x2000 ;} >flash_hdr
.irq : { KEEP(*(.isr_vector)) } > flash_irq
.text : { *(.text* .text.*) *(.rodata*) ; } > flash_code
.data : { __data_start__ = .; *(.data SORT(.data.*)) __data_end__ = .; } > dtcram AT > flash_code
.data : { __data_start__ = .; *(.data SORT(.data.*)) *(.iram) __data_end__ = .; } > itcram AT > flash_code
__etext = LOADADDR(.data);
.bss : { __bss_start__ = .; *(.bss SORT(.bss.*) COMMON) __bss_end__ = .; } > dtcram
.bss : { __bss_start__ = .; *(.bss SORT(.bss.*) COMMON) __bss_end__ = .; } > itcram
_end = .;
}
64 changes: 38 additions & 26 deletions examples/nxp/rt1020-evk-make-baremetal-builtin/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,57 @@ static void timer_fn(void *arg) {
ifp->ndrop, ifp->nerr));
}

#ifndef RUNINFLASH
static void fn(struct mg_connection *c, int ev, void *ev_data) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->fn_data;
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/hello")) { // Request to /api/hello
mg_http_reply(c, 200, "", "{%m:%u,%m:%u,%m:%u,%m:%u,%m:%u}\n",
MG_ESC("eth"), ifp->state, MG_ESC("frames_received"),
ifp->nrecv, MG_ESC("frames_sent"), ifp->nsent,
MG_ESC("frames_dropped"), ifp->ndrop,
MG_ESC("interface_errors"), ifp->nerr);
} else if (mg_http_match_uri(hm, "/")) { // Index page
mg_http_reply(
c, 200, "", "%s",
"<html><head><link rel='icon' href='data:;base64,='></head><body>"
"<h1>Welcome to Mongoose</h1>"
"See <a href=/api/hello>/api/hello</a> for REST example"
"</body></html>");
} else { // All other URIs
mg_http_reply(c, 404, "", "Not Found\n");
}
}
#ifdef MQTT_DASHBOARD
bool hal_gpio_write(int pin, bool status) { // For MQTT dashboard HAL
return (pin != status);
}
bool hal_gpio_read(int pin) { // For MQTT dashboard HAL
return (pin != 0);
}
int hal_led_pin(void) {
return (int) 0;
}
uint64_t mg_now(void) {
return mg_millis();
}
#endif

int main(void) {
gpio_output(LED); // Setup blue LED
uart_init(UART_DEBUG, 115200); // Initialise debug printf
ethernet_init(); // Initialise ethernet pins

MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000));

struct mg_mgr mgr; // Initialise
mg_mgr_init(&mgr); // Mongoose event manager
mg_log_set(MG_LL_DEBUG); // Set log level

mg_ota_boot();

#ifdef MQTT_DASHBOARD
// User can customise the MQTT url, device ID or the root topic below
#define DEVICE_ID "RT1020"
g_url = MQTT_SERVER_URL;
g_device_id = DEVICE_ID;
g_root_topic = MQTT_ROOT_TOPIC;
#endif

#if MG_OTA == MG_OTA_FLASH
// Demonstrate the use of mg_flash_{load/save} functions for keeping device
// configuration data on flash. Increment boot count on every boot.
struct deviceconfig {
uint32_t boot_count;
char some_other_data[40];
};
uint32_t key = 0x12345678; // A unique key, one per data type
struct deviceconfig dc = {}; // Initialise to some default values
mg_flash_load(NULL, key, &dc, sizeof(dc)); // Load from flash
dc.boot_count++; // Increment boot count
mg_flash_save(NULL, key, &dc, sizeof(dc)); // And save back
MG_INFO(("Boot count: %u", dc.boot_count));
#endif

// Initialise Mongoose network stack
struct mg_tcpip_driver_imxrt_data driver_data = {.mdc_cr = 24, .phy_addr = 2};
struct mg_tcpip_if mif = {.mac = GENERATE_LOCALLY_ADMINISTERED_MAC(),
Expand All @@ -84,11 +100,7 @@ int main(void) {
}

MG_INFO(("Initialising application..."));
#ifdef RUNINFLASH
web_init(&mgr);
#else
mg_http_listen(&mgr, "http://0.0.0.0:80", fn, &mif);
#endif

MG_INFO(("Starting event loop"));
for (;;) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// See https://mongoose.ws/documentation/#build-options
#define MG_ARCH MG_ARCH_NEWLIB
#define MG_OTA MG_OTA_FLASH
#define MG_DEVICE MG_DEVICE_RT1020

#define MG_ENABLE_TCPIP 1
#define MG_ENABLE_DRIVER_IMXRT 1
Expand Down
2 changes: 1 addition & 1 deletion examples/nxp/rt1060-evk-make-baremetal-builtin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
CFLAGS += -I. -Icmsis_core/CMSIS/Core/Include -Icmsis_mcu/devices/MIMXRT1062 #-DCPU_MIMXRT1062DVL6B
CFLAGS += -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 $(CFLAGS_EXTRA)
LDSCRIPT = link.ld
LDFLAGS ?= -T$(LDSCRIPT) -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map
LDFLAGS ?= -T$(LDSCRIPT) -nostdlib -nostartfiles --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map

SOURCES = main.c syscalls.c sysinit.c
SOURCES += cmsis_mcu/devices/MIMXRT1062/gcc/startup_MIMXRT1062.S # NXP startup file. Compiler-dependent!
Expand Down
6 changes: 3 additions & 3 deletions examples/nxp/rt1060-evk-make-baremetal-builtin/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ENTRY(Reset_Handler);
MEMORY {
flash_hdr(rx) : ORIGIN = 0x60000000, LENGTH = 8k
flash_irq(rx) : ORIGIN = 0x60002000, LENGTH = 1k
flash_code(rx) : ORIGIN = 0x60002400, LENGTH = 8183k
flash_code(rx) : ORIGIN = 0x60002400, LENGTH = 8179k

itcram(rx) : ORIGIN = 0x00000000, LENGTH = 128k
dtcram(rw) : ORIGIN = 0x20000000, LENGTH = 128k
Expand All @@ -15,8 +15,8 @@ SECTIONS {
KEEP(*(.dat)) . = 0x1030 ; KEEP(*(.dcd)) . = 0x2000 ;} >flash_hdr
.irq : { KEEP(*(.isr_vector)) } > flash_irq
.text : { *(.text* .text.*) *(.rodata*) ; } > flash_code
.data : { __data_start__ = .; *(.data SORT(.data.*)) __data_end__ = .; } > dtcram AT > flash_code
.data : { __data_start__ = .; *(.data SORT(.data.*)) *(.iram) __data_end__ = .; } > itcram AT > flash_code
__etext = LOADADDR(.data);
.bss : { __bss_start__ = .; *(.bss SORT(.bss.*) COMMON) __bss_end__ = .; } > dtcram
.bss : { __bss_start__ = .; *(.bss SORT(.bss.*) COMMON) __bss_end__ = .; } > itcram
_end = .;
}
48 changes: 45 additions & 3 deletions examples/nxp/rt1060-evk-make-baremetal-builtin/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG
memcpy((char *) buf + n, &r, n + sizeof(r) > len ? len - n : sizeof(r));
}
}

static void timer_fn(void *arg) {
gpio_toggle(LED); // Blink LED
struct mg_tcpip_if *ifp = arg; // And show
Expand All @@ -31,16 +32,57 @@ static void timer_fn(void *arg) {
ifp->ndrop, ifp->nerr));
}

#ifdef MQTT_DASHBOARD
bool hal_gpio_write(int pin, bool status) { // For MQTT dashboard HAL
return (pin != status);
}
bool hal_gpio_read(int pin) { // For MQTT dashboard HAL
return (pin != 0);
}
int hal_led_pin(void) {
return (int) 0;
}
uint64_t mg_now(void) {
return mg_millis();
}
#endif

int main(void) {
gpio_output(LED); // Setup blue LED
gpio_output(LED); // Setup green LED
uart_init(UART_DEBUG, 115200); // Initialise debug printf
ethernet_init(); // Initialise ethernet pins
MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000));

struct mg_mgr mgr; // Initialise
mg_mgr_init(&mgr); // Mongoose event manager
mg_log_set(MG_LL_DEBUG); // Set log level

MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000));

mg_ota_boot();

#ifdef MQTT_DASHBOARD
// User can customise the MQTT url, device ID or the root topic below
#define DEVICE_ID "RT1060"
g_url = MQTT_SERVER_URL;
g_device_id = DEVICE_ID;
g_root_topic = MQTT_ROOT_TOPIC;
#endif

#if MG_OTA == MG_OTA_FLASH
// Demonstrate the use of mg_flash_{load/save} functions for keeping device
// configuration data on flash. Increment boot count on every boot.
struct deviceconfig {
uint32_t boot_count;
char some_other_data[40];
};
uint32_t key = 0x12345678; // A unique key, one per data type
struct deviceconfig dc = {}; // Initialise to some default values
mg_flash_load(NULL, key, &dc, sizeof(dc)); // Load from flash
dc.boot_count++; // Increment boot count
mg_flash_save(NULL, key, &dc, sizeof(dc)); // And save back
MG_INFO(("Boot count: %u", dc.boot_count));
#endif

// Initialise Mongoose network stack
struct mg_tcpip_driver_imxrt_data driver_data = {.mdc_cr = 24, .phy_addr = 2};
struct mg_tcpip_if mif = {.mac = GENERATE_LOCALLY_ADMINISTERED_MAC(),
Expand All @@ -65,6 +107,6 @@ int main(void) {
for (;;) {
mg_mgr_poll(&mgr, 0);
}

return 0;
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// See https://mongoose.ws/documentation/#build-options
#define MG_ARCH MG_ARCH_NEWLIB
#define MG_OTA MG_OTA_FLASH
#define MG_DEVICE MG_DEVICE_RT1060

#define MG_ENABLE_TCPIP 1
#define MG_ENABLE_DRIVER_IMXRT 1
Expand Down
Loading

0 comments on commit f750cf3

Please sign in to comment.