Skip to content

Commit

Permalink
write image to flash
Browse files Browse the repository at this point in the history
  • Loading branch information
robert committed Nov 24, 2023
1 parent 2a25e44 commit f01781d
Show file tree
Hide file tree
Showing 10 changed files with 641 additions and 5 deletions.
32 changes: 30 additions & 2 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 @@ -32,15 +33,42 @@ static void timer_fn(void *arg) {
}

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

#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 = DEFAULT_ROOT_TOPIC;
#endif

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(); // Call bootloader: continue to load, or boot another FW

#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
// 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 +93,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_EXTERNAL_FLASH
#define MG_DEVICE MG_DEVICE_RT1060_QUAD_NOR

#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/net.c
2 changes: 1 addition & 1 deletion examples/nxp/rt1060-evk-make-baremetal-builtin/net.h
Loading

0 comments on commit f01781d

Please sign in to comment.