Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Look at the target datasheet. For example, in the nRF52840, the RAM goes from 0x2000000 to 0x4000000.

  • Look at or configure the GNU linker script. For example, our application sets RAM : ORIGIN = 0x20000000, LENGTH = 64K, meaning that the RAM begins at 0x2000000 (as per the datasheet) and has a total size of 64 kiB.

  • Look at the generated memory map file, and find where are the symbols _stack_start and __sheap. Since the stack grows from top to bottom (e.g. from 0x2000000 to 0x2000000 + 64 kiB), and the heap grows from the bottom, that _stack_start - __sheap is the total size of our allocatable RAM (i.e. discarding . Note that this discards sections such as .bss, .data, .uninit). , which we do not want to paint!

We now know that we want to paint the memory from __sheap up to _stack_start.

Before continuing, remember that we want to write in the RAM before our code starts executing, otherwise we risk overwriting the stack that is already in use. One way of doing that is writing the loop in assembly (using only registers), and another way is doing it in the reset handler or in some pre-initialisation code in your platform. The cortex-m-rt crate provides a pre_init hook that runs before main, which is ideal to put the stack painting code. In the code below, we first obtain the address where the heap starts using the symbol defined by the linker. Next, since our code is already executing, we do not want to overwrite already allocated stack memory, so we get the current value of the stack pointer , (offset by a constant, since we are using the stack while painting it). Finally, we run the loop that writes the pattern to the memory.

...

There are two main approaches to measuring execution time. In one of them, let’s call it internal, we rely on some timer already available in our board, and use it to keep track of certain interesting events that we want to measure. While this approach is simple, it has the downside downsides of consuming some energy , which may impact other concurrent measurementsand an additional peripheral, as well as some extra added code (e.g. a RTC driver). The second approach is the external, where an instrument such as a logical analyser is connected to one or more GPIOs in the board. Then, we want to log an event, we toggle those GPIOs on or off, and have them logged over time by the external instrument software.

...

multimeters, oscilloscopes, power profilers

The way to To measure energy consumption consists in connecting we connect the device to an external instrument, such as a multimeter, an oscilloscope or a power profilersprofiler, that can measure current draw.

Multimeters can be used to read the current consumption at a given point in time, but do not allow automating measurements or taking them over time.

TODO: I don’t know how to set up the hardware part of measuring with an osciloscope?

A more sophisticated and accurate way of measuring energy consumption consists in using a power profiler, such as the nRF Power Profiler Kit and the Otii Arc Pro. One advantage of the latter is that it is designed to be board-agnostic, so we will select it as the instrument for this tutorial.

...