Hot answers tagged

8 votes
Accepted

Can I force a function to live in the boot sector without overwriting the bootloader?

The Optiboot version 8 has a do_spm function which can be called from application. The Optiboot repository contains an example for the use of this function. SPM is the AVR CPU instruction to write to ...
  • 17k
7 votes
Accepted

Executing machine code at runtime Uno

The microcontroller is executing one command at a time from..where? Flash memory directly. The AVR core can only execute instructions from Flash memory. It uses a two-bus system known as Harvard ...
  • 104k
7 votes
Accepted

EEPROM.get returns bad data

You are saving a String object in EEPROM, which is useless. A string object does not store the contents of your string. Instead, it just stores: the memory address where the actual contents (the ...
  • 39.2k
6 votes
Accepted

Using PROGMEM to store array of structs

An easy way of accessing any type of data in PROGMEM is to use this small library: PROGMEM_readAnything.h #include <Arduino.h> // for type definitions template <typename T> void ...
  • 35.7k
6 votes

How can a function/method determine if a const array passed in is PROGMEM (flash) or not (RAM)?

I am afraid there is no good solution to this problem. One option I do like is to use the __flash qualifier instead of PROGMEM: const uint8_t ram_array[] = { 1, 2, 3, 4 }; __flash const uint8_t ...
  • 39.2k
6 votes
Accepted

Extend program space by getting rid of bootloader on NANO

It's enforcing this line from the arduino:avr boards.txt nano.menu.cpu.atmega328.upload.maximum_size=30720 To be clear, the board is assumed to have a bootloader, even if you're not using it to get ...
  • 4,611
5 votes

What programming practices should be adopted while coding sketches for Arduino?

Paul covered the most important points. This answer is intended to be a complement to his. First, you should keep in mind the general rules, which are more important than the more specific ones. The ...
  • 39.2k
5 votes

Is it possible to use extra AVR Flash memory as non-volatile EEPROM-like Flash memory storage?

Yes you can. This Arduino IDE add on lets you make calls to code store in the bootload of memory so you can make changes to the flash memory. https://majek.sh/en/writing-to-internal-flash-on-arduino/ ...
  • 2,368
5 votes
Accepted

Is it possible to use extra AVR Flash memory as non-volatile EEPROM-like Flash memory storage?

The answer is "yes, you can use extra AVR Flash memory as non-volatile EEPROM-like Flash memory storage, very similar to an STM32 microcontroller." One of these days I'm going to write an Arduino ...
4 votes
Accepted

Store floats in and reading them from flash

There is a helper macro in avr-libc that is designed just for this purpose: #define pgm_read_float_near(address_short) __LPM_float((uint16_t)(address_short)) Read a float from the program space with ...
  • 104k
4 votes
Accepted

Set EEPROM from PC before program

The simplest way would be to have two sketches. One that will store all the strings into EEPROM. After that you can upload the second actual sketch that uses the values stored in EEPROM. You ...
  • 11.2k
4 votes
Accepted

Writing your own Arduino flashing tool

This application already exists. It's called AVRDUDE: http://www.nongnu.org/avrdude/ You can download it compiled for Windows at the link above. This is the very flashing tool that the Arduino IDE ...
  • 3,906
4 votes

How can a function/method determine if a const array passed in is PROGMEM (flash) or not (RAM)?

There is also an OO solution possible, using the strategy design pattern, but this comes with some (slight) memory and performance penalties. You need to use C++ for this. Put each array you want to ...
4 votes

How can a function/method determine if a const array passed in is PROGMEM (flash) or not (RAM)?

I will expand on KIIV's comment here. This is a known issue to the people who wrote the Arduino framework. Essentially, the pointers to PROGMEM and RAM are both data pointers (think of a pointer like ...
4 votes
Accepted

How do I get the size of my program at runtime?

Just to warn you, I minimally tested this, but it seems to work. In the Due's linker script there are these relevant lines, containing the named rom section. MEMORY { rom (rx) : ORIGIN = ...
  • 4,611
3 votes

Set EEPROM from PC before program

I think here is a confusion about the three types of memory. EEPROM, FLASH and SRAM are completely separate. EEPROM is like your file storage. FLASH contains you program and static values. SRAM is the ...
  • 1,485
3 votes

What programming practices should be adopted while coding sketches for Arduino?

Keep in mind that RAM is even less. 32KB is a fair lot of code, since C/C++ is highly efficient. "Don't save **** in RAM." If you need to load images into a display, save the images on an SD card. ...
  • 2,702
3 votes
Accepted

What protocols and tools does Arduino Due use for flashing and debugging?

The Due (more specifically the SAM3X) uses its own proprietary protocol. It's all embedded in the bootloader, which is hard wired in the ROM and can never be changed (idiotic if you ask me). I know ...
  • 104k
3 votes

How to save a hex file into Arduino Flash to send it via Serial?

If I understand your question correctly, you need to integrate this data into a .ino script. Probably as a byte array. Then the script can read the array and Serial.write its content. You could ...
  • 1,551
3 votes
Accepted

Flashing ESP8266 over WiFi whith samrtphone?

ESP8266 OTA can be performed through a web browser as detailed in the ESP8266 OTA information page. Since a smartphone has a web browser I can see no reason why you can't use that.
  • 104k
3 votes

Trying to flash ESP8266 with Arduino UNO

You do not need the level shifter. The input pins of the ESP8266 contain over-voltage (though not over-current) protection. All you need to do is limit the current that can flow through the over-...
  • 104k
3 votes
Accepted

Flashing an ATtiny85 with a NodeMCU?

It can be done. Your Digispark has SPI pins, which are ISP pins. For the esp8266 there is an ESP8266AVRISP library for OTA upload to AVR. You can use the example of the library. You must wire the SPI ...
  • 17k
3 votes
Accepted

AVR-GCC can't call function located on fixed address

I've tried this code with arduino and it worked (i taught, of course, i can't add the "-Wl,--section-start=.app_start=0xFA0" flag to the compilation process so the function not gonna be moved to other ...
3 votes

Can't flash ESP8266 anymore (NodeMCU)

The fix ended up being to use a 220ohm resistor between D3 and GND (It has been pointed out, though I haven't tested it, that just wiring D3 to ground on startup should have the same effect). Then ...
  • 147
3 votes
Accepted

Reading contents of ESP8266 Flash from inside sketch

I think you're reading of flash is slightly wrong while ESP.flashRead takes a unit32_t pointer for output data, the read "count" argument is in bytes - looking at Updater.cpp code it does this ...
3 votes

EEPROM.get returns bad data

Just to have the full working code, I ended up with this: #include <EEPROM.h> char serial_characters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"}; // 7 chars for serial and one for string end '...
  • 242
3 votes
Accepted

ESP8266 OTA update with different flash size settings?

The basic problem is that when you upload over OTA you don't upload the partition structure. The ESP32's flash is split into a number of "partitions" or areas. It might look something like: ...
  • 104k
3 votes
Accepted

ESP32: best way to embed certificates

I don't know what you need that Preferences thing for, but I would use SPIFFS/FAT anyway. Simply store the certificate in a file in flash and read that file when you need it. The required space is no ...
  • 1,799
3 votes

D1 mini esp8266 error: esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

I'm not sure if this will help EVERYONE, but I hope it at least helps someone. I had the same issue with several different boards (3 Nano's, 2 NodeMCU ESP8266's, and 1 Uno). I searched and searched ...
2 votes

PROGMEM: do I have to copy data from flash to RAM for reading?

Arduino documentation says, it is possible to keep constants like strings or whatever I don't want to change during runtime in program memory. All constants are initially in program memory. Where ...
  • 35.7k

Only top scored, non community-wiki answers of a minimum length are eligible