Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a6da573

Browse files
committed
nano_nora: add Arduino Nano ESP32 board support
1 parent 7df98db commit a6da573

File tree

8 files changed

+587
-0
lines changed

8 files changed

+587
-0
lines changed

boards.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24112,3 +24112,54 @@ nebulas3.menu.EraseFlash.all=Enabled
2411224112
nebulas3.menu.EraseFlash.all.upload.erase_cmd=-e
2411324113

2411424114
##############################################################
24115+
24116+
nano_nora.name=Arduino Nano ESP32
24117+
nano_nora.vid.0=0x2341
24118+
nano_nora.pid.0=0x0070
24119+
nano_nora.upload_port.0.vid=0x2341
24120+
nano_nora.upload_port.0.pid=0x0070
24121+
24122+
nano_nora.bootloader.tool=esptool_py
24123+
nano_nora.bootloader.tool.default=esptool_py
24124+
24125+
nano_nora.upload.tool=dfu-util
24126+
nano_nora.upload.tool.default=dfu-util
24127+
nano_nora.upload.tool.network=esp_ota
24128+
nano_nora.upload.protocol=serial
24129+
nano_nora.upload.maximum_size=3145728
24130+
nano_nora.upload.maximum_data_size=327680
24131+
nano_nora.upload.use_1200bps_touch=false
24132+
nano_nora.upload.wait_for_upload_port=false
24133+
24134+
nano_nora.serial.disableDTR=false
24135+
nano_nora.serial.disableRTS=false
24136+
24137+
nano_nora.build.tarch=xtensa
24138+
nano_nora.build.bootloader_addr=0x0
24139+
nano_nora.build.target=esp32s3
24140+
nano_nora.build.mcu=esp32s3
24141+
nano_nora.build.core=esp32
24142+
nano_nora.build.variant=arduino_nano_nora
24143+
nano_nora.build.board=ARDUINO_NANO_NORA
24144+
nano_nora.build.code_debug=0
24145+
24146+
nano_nora.build.usb_mode=0
24147+
nano_nora.build.cdc_on_boot=1
24148+
nano_nora.build.msc_on_boot=0
24149+
nano_nora.build.dfu_on_boot=1
24150+
nano_nora.build.f_cpu=240000000L
24151+
nano_nora.build.flash_size=16MB
24152+
nano_nora.build.flash_freq=80m
24153+
nano_nora.build.flash_mode=dio
24154+
nano_nora.build.boot=qio
24155+
nano_nora.build.boot_freq=80m
24156+
nano_nora.build.partitions=app3M_fat9M_fact512k_16MB
24157+
nano_nora.build.defines=-DBOARD_HAS_PSRAM
24158+
nano_nora.build.loop_core=-DARDUINO_RUNNING_CORE=1
24159+
nano_nora.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1
24160+
nano_nora.build.psram_type=opi
24161+
nano_nora.build.memory_type={build.boot}_{build.psram_type}
24162+
24163+
nano_nora.tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0xf70000 "{build.variant.path}/extra/nora_recovery/nora_recovery.ino.bin" 0x10000 "{build.path}/{build.project_name}.bin"
24164+
24165+
##############################################################

package/package_esp32_index.template.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
},
3434
{
3535
"name": "ESP32-C3 Dev Board"
36+
},
37+
{
38+
"name": "Arduino Nano ESP32"
3639
}
3740
],
3841
"toolsDependencies": [
@@ -85,6 +88,11 @@
8588
"packager": "esp32",
8689
"name": "mklittlefs",
8790
"version": "3.0.0-gnu12-dc7f933"
91+
},
92+
{
93+
"packager": "arduino",
94+
"name": "dfu-util",
95+
"version": "0.11.0-arduino5"
8896
}
8997
]
9098
}
@@ -683,6 +691,66 @@
683691
]
684692
}
685693
]
694+
},
695+
{
696+
"name": "arduino",
697+
"maintainer": "Arduino",
698+
"websiteURL": "http://www.arduino.cc/",
699+
"email": "[email protected]",
700+
"help": {
701+
"online": "http://www.arduino.cc/en/Reference/HomePage"
702+
},
703+
"platforms": [],
704+
"tools": [
705+
{
706+
"name": "dfu-util",
707+
"version": "0.11.0-arduino5",
708+
"systems": [
709+
{
710+
"host": "i386-apple-darwin",
711+
"url": "http://downloads.arduino.cc/tools/dfu-util-0.11-arduino5-darwin_amd64.tar.gz",
712+
"archiveFileName": "dfu-util-0.11-arduino5-darwin_amd64.tar.gz",
713+
"size": "72429",
714+
"checksum": "SHA-256:9e576c6e44f54b1e921a43ea77bcc08ec99e0e4e0905f4b9acf9ab2c979f0a22"
715+
},
716+
{
717+
"host": "arm-linux-gnueabihf",
718+
"url": "http://downloads.arduino.cc/tools/dfu-util-0.11-arduino5-linux_arm.tar.gz",
719+
"archiveFileName": "dfu-util-0.11-arduino5-linux_arm.tar.gz",
720+
"size": "2512819",
721+
"checksum": "SHA-256:acd4bd283fd408515279a44dd830499ad37b0767e8f2fde5c27e878ded909dc3"
722+
},
723+
{
724+
"host": "aarch64-linux-gnu",
725+
"url": "http://downloads.arduino.cc/tools/dfu-util-0.11-arduino5-linux_arm64.tar.gz",
726+
"archiveFileName": "dfu-util-0.11-arduino5-linux_arm64.tar.gz",
727+
"size": "2607592",
728+
"checksum": "SHA-256:b3f46a65da0c2fed2449dc5a3351c3c74953a868aa7f8d99ba2bb8c418344fe9"
729+
},
730+
{
731+
"host": "x86_64-linux-gnu",
732+
"url": "http://downloads.arduino.cc/tools/dfu-util-0.11-arduino5-linux_amd64.tar.gz",
733+
"archiveFileName": "dfu-util-0.11-arduino5-linux_amd64.tar.gz",
734+
"size": "2283425",
735+
"checksum": "SHA-256:96c64c278561af806b585c123c85748926ad02b1aedc07e5578ca9bee2be0d2a"
736+
},
737+
{
738+
"host": "i686-linux-gnu",
739+
"url": "http://downloads.arduino.cc/tools/dfu-util-0.11-arduino5-linux_386.tar.gz",
740+
"archiveFileName": "dfu-util-0.11-arduino5-linux_386.tar.gz",
741+
"size": "2524406",
742+
"checksum": "SHA-256:9a707692261e5710ed79a6d8a4031ffd0bfe1e585216569934346e9b2d68d0c2"
743+
},
744+
{
745+
"host": "i686-mingw32",
746+
"url": "http://downloads.arduino.cc/tools/dfu-util-0.11-arduino5-windows_386.tar.gz",
747+
"archiveFileName": "dfu-util-0.11-arduino5-windows_386.tar.gz",
748+
"size": "571340",
749+
"checksum": "SHA-256:6451e16bf77600fe2436c8708ab4b75077c49997cf8bedf03221d9d6726bb641"
750+
}
751+
]
752+
}
753+
]
686754
}
687755
]
688756
}

platform.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ recipe.size.regex.data=^(?:\.dram0\.data|\.dram0\.bss|\.noinit)\s+([0-9]+).*
239239
## ---------------------------------
240240
pluggable_discovery.required.0=builtin:serial-discovery
241241
pluggable_discovery.required.1=builtin:mdns-discovery
242+
pluggable_discovery.required.2=builtin:dfu-discovery
242243
pluggable_monitor.required.serial=builtin:serial-monitor
243244

244245
## ------------------
@@ -305,3 +306,11 @@ tools.esp_ota.upload.protocol=network
305306
tools.esp_ota.upload.field.password=Password
306307
tools.esp_ota.upload.field.password.secret=true
307308
tools.esp_ota.upload.pattern={cmd} -i {upload.port.address} -p {upload.port.properties.port} --auth={upload.field.password} -f "{build.path}/{build.project_name}.bin"
309+
310+
## Upload Sketch Through DFU OTA
311+
## -------------------------------------------
312+
tools.dfu-util.path={runtime.tools.dfu-util-0.11.0-arduino5.path}
313+
tools.dfu-util.cmd=dfu-util
314+
tools.dfu-util.upload.params.verbose=-d
315+
tools.dfu-util.upload.params.quiet=
316+
tools.dfu-util.upload.pattern="{path}/{cmd}" --device {vid.0}:{pid.0} -D "{build.path}/{build.project_name}.bin" -Q
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Name, Type, SubType, Offset, Size, Flags
2+
nvs, data, nvs, 0x9000, 0x5000,
3+
otadata, data, ota, 0xe000, 0x2000,
4+
app0, app, ota_0, 0x10000, 0x300000,
5+
app1, app, ota_1, 0x310000, 0x300000,
6+
ffat, data, fat, 0x610000, 0x960000,
7+
factory, app, factory, 0xF70000, 0x80000,
8+
coredump, data, coredump, 0xFF0000, 0x10000,
9+
# to create/use ffat, see https://github.com/marcmerlin/esp32_fatfsimage
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
# Arduino Nano Nora Recovery Sketch
3+
4+
This sketch implements the DFU recovery mode logic, called by all sketches
5+
when a double tap on the RESET button is detected. It should not be uploaded
6+
as any other sketch; instead, this should be compiled and then flashed in
7+
the module's `factory` partition.
8+
9+
## Compilation
10+
11+
The binary can be compiled with the Arduino 2.x IDE or CLI using the
12+
`nano_nora` variant. In particular, using the CLI the resulting binary
13+
can be exported to the `build` directory with the `-e` switch to
14+
`arduino-cli compile`.
15+
16+
## Automatic installation
17+
18+
By replacing the binary in the current folder, automatic installation
19+
can be performed by running the "Upload with Programmer" action on any
20+
sketch in the Arduino 2.x IDE or CLI. In particular, using the CLI the
21+
binary can be installed via the command:
22+
23+
```
24+
arduino-cli compile -u --programmer esptool
25+
```
26+
27+
## Manual installation
28+
29+
Once compiled, the binary can also be installed on a board using `esptool.py`
30+
with the following command:
31+
32+
```
33+
esptool.py --chip esp32s3 --port "/dev/ttyACM0" --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 16MB 0xF70000 "nora_recovery.ino.bin"
34+
```
35+
36+
where:
37+
- `esptool.py` is located in your core's install path under `tools/esptool_py`;
38+
- `/dev/ttyACM0` is the serial port exposed by the board to be used;
39+
- `0xF70000` is the factory partition address (make sure it matches the
40+
offset in the variant's `{build.partitions}` file);
41+
- `nora_recovery.ino.bin` is the compiled sketch image.
42+
43+
Due to a BSP issue, the first call to `esptool.py` will enter the hardware
44+
bootloader for programming, but fail with an "Input/output error". This is
45+
a known issue; calling the program again with the same arguments will now
46+
work correctly.
47+
48+
Once flashing is complete, a power cycle (or RESET button tap) is required
49+
to leave the `esptool.py` flashing mode and load user sketches.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#define USB_TIMEOUT_MS 15000
2+
#define POLL_DELAY_MS 60
3+
#define FADESTEP 8
4+
5+
void pulse_led() {
6+
static u32_t pulse_width = 0;
7+
static u8_t dir = 0;
8+
9+
if (dir) {
10+
pulse_width -= FADESTEP;
11+
if (pulse_width < FADESTEP) {
12+
dir = 0U;
13+
pulse_width = FADESTEP;
14+
}
15+
} else {
16+
pulse_width += FADESTEP;
17+
if (pulse_width > 255) {
18+
dir = 1U;
19+
pulse_width = 255;
20+
}
21+
}
22+
23+
analogWrite(LED_GREEN, pulse_width);
24+
}
25+
26+
#include <esp_ota_ops.h>
27+
#include <esp_partition.h>
28+
#include <esp_flash_partitions.h>
29+
#include <esp_image_format.h>
30+
bool load_previous_firmware() {
31+
// if user flashed this recovery sketch to an OTA partition, stay here
32+
extern bool _recovery_active;
33+
if (!_recovery_active)
34+
return false;
35+
36+
// booting from factory partition, look for a valid OTA image
37+
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL);
38+
for (; it != NULL; it = esp_partition_next(it)) {
39+
const esp_partition_t *part = esp_partition_get(it);
40+
if (part->subtype != ESP_PARTITION_SUBTYPE_APP_FACTORY) {
41+
esp_partition_pos_t candidate = { part->address, part->size };
42+
esp_image_metadata_t meta;
43+
if (esp_image_verify(ESP_IMAGE_VERIFY_SILENT, &candidate, &meta) == ESP_OK) {
44+
// found, use it
45+
esp_ota_set_boot_partition(part);
46+
return true;
47+
}
48+
}
49+
}
50+
51+
return false;
52+
}
53+
54+
void setup() {
55+
extern bool _recovery_marker_found;
56+
if (!_recovery_marker_found) {
57+
// marker not found, probable cold start
58+
// try starting previous firmware immediately
59+
if (load_previous_firmware())
60+
esp_restart();
61+
}
62+
63+
printf("Recovery firmware started, waiting for USB\r\n");
64+
}
65+
66+
void loop() {
67+
static int elapsed_ms = 0;
68+
69+
pulse_led();
70+
delay(POLL_DELAY_MS);
71+
if (USB) {
72+
// wait indefinitely for DFU to complete
73+
elapsed_ms = 0;
74+
} else {
75+
// wait for USB connection
76+
elapsed_ms += POLL_DELAY_MS;
77+
}
78+
79+
if (elapsed_ms > USB_TIMEOUT_MS) {
80+
elapsed_ms = 0;
81+
// timed out, try loading previous firmware
82+
if (load_previous_firmware()) {
83+
// found a valid FW image, load it
84+
analogWrite(LED_GREEN, 255);
85+
printf("Leaving recovery firmware\r\n");
86+
delay(200);
87+
esp_restart(); // does not return
88+
}
89+
}
90+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#ifndef Pins_Arduino_h
2+
#define Pins_Arduino_h
3+
4+
#include <stdint.h>
5+
#include "soc/soc_caps.h"
6+
7+
#define USB_VID 0x2341
8+
#define USB_PID 0x0070
9+
10+
#define EXTERNAL_NUM_INTERRUPTS 46
11+
#define NUM_DIGITAL_PINS 48
12+
#define NUM_ANALOG_INPUTS 20
13+
14+
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
15+
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
16+
#define digitalPinHasPWM(p) (p < 46)
17+
18+
static const uint8_t TX = 43;
19+
static const uint8_t RX = 44;
20+
static const uint8_t RTS = 45;
21+
static const uint8_t CTS = 6;
22+
static const uint8_t DTR = 1;
23+
static const uint8_t DSR = 7;
24+
25+
static const uint8_t LED_RED = 46;
26+
static const uint8_t LED_GREEN = 0;
27+
static const uint8_t LED_BLUE = 45;
28+
static const uint8_t LED_BUILTIN = 48;
29+
#define LED_BUILTIN LED_BUILTIN
30+
31+
static const uint8_t SS = 21;
32+
static const uint8_t MOSI = 38;
33+
static const uint8_t MISO = 47;
34+
static const uint8_t SCK = 48;
35+
36+
static const uint8_t A0 = 1;
37+
static const uint8_t A1 = 2;
38+
static const uint8_t A2 = 3;
39+
static const uint8_t A3 = 4;
40+
static const uint8_t A4 = 11;
41+
static const uint8_t A5 = 12;
42+
static const uint8_t A6 = 13;
43+
static const uint8_t A7 = 14;
44+
45+
static const uint8_t D0 = 44; // RX0
46+
static const uint8_t D1 = 43; // TX0
47+
static const uint8_t D2 = 5;
48+
static const uint8_t D3 = 6;
49+
static const uint8_t D4 = 7;
50+
static const uint8_t D5 = 8;
51+
static const uint8_t D6 = 9;
52+
static const uint8_t D7 = 10;
53+
54+
static const uint8_t D8 = 17;
55+
static const uint8_t D9 = 18;
56+
static const uint8_t D10 = 21; // SS
57+
static const uint8_t D11 = 38; // MOSI
58+
static const uint8_t D12 = 47; // MISO
59+
static const uint8_t D13 = 48; // SCK
60+
static const uint8_t SDA = 11;
61+
static const uint8_t SCL = 12;
62+
63+
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)