Giter VIP home page Giter VIP logo

arduino_nano_ble_write_flash's Introduction

Arduino Nano BLE Write Flash

An example of modifying flash memory on the Arduino Nano BLE Sense 33 from a sketch, using Mbed.

Overview

I couldn't find complete examples that showed me how to initialize, modify, and write flash memory on the Arduino Nano BLE boards, so I've put this together to capture what I came up with, and hopefully help other people who need to do this. The main difference between this and other examples I've found is that I've persuaded the compiler to initialize the area of memory once during upload. The example itself simply increments a counter variable once every time the board is reset. It reserves an area of 64KB to hold the data it's modifying, which is overkill for this application, but is what I need for some other use cases.

Trying it out

To give this a try yourself:

  • Attach an Arduino Nano BLE Sense 33 board to your development machine.
  • Load the arduino_nano_ble_write_flash.ino sketch into the Arduino IDE.
  • Open the Serial Monitor.
  • Build and upload the sketch.

The first time the sketch runs, you should see Counter=0 in the Serial Monitor. If you then reset the board with a single short press of its button, you should see Counter=1, with the number increasing by one every time its reset.

How it works

There are comments inline in the code which should help explain some of how this is implemented. The most novel part is the use of a const byte array to reserve the memory we need in flash, using alignment and initialization tricks to make sure it's zero on first upload, and accessible by the Mbed flash API.

Warnings

Accessing flash directly is an advanced topic, since it's possible to brick your board if you write to the wrong locations. It's also not advised to write repeatedly to flash (for example in your loop() function) since the memory only has a limited number of erase and program cycles it can support, and writing to flash can be slow and blocks a lot of other interrupts needed by the system.

Related work

I'm grateful to the authors of the other examples I used to learn about flash access on modern Arduinos, including:

Licensing

Available under the Apache 2 License, see LICENSE file for more details.

Pete Warden, [email protected]

arduino_nano_ble_write_flash's People

Contributors

petewarden avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.