Skip to content

Commit 4aa4719

Browse files
authored
Merge pull request #101 from arduino/esp-idf-4.4
Build nina firmware using esp idf v4.4.8
2 parents 331d584 + 36b0383 commit 4aa4719

File tree

14 files changed

+1269
-435
lines changed

14 files changed

+1269
-435
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ This firmware uses [Espressif's IDF](https://github.com/espressif/esp-idf)
1616
1. Load the `Tools -> SerialNINAPassthrough` example sketch on to the board
1717
1. Use `esptool` to flash the compiled firmware
1818

19+
### Building with docker
20+
21+
As an alternative for building we can use the docker image from espressif idf, we can do that as follows:
22+
23+
```
24+
docker run -v $PWD:/data espressif/idf:v4.4.8 -- sh -c 'cd /data && make'
25+
```
26+
27+
You can also flash the firmware with the following snippet:
28+
29+
```
30+
DEVICE=/dev/ttyACM0
31+
docker run --device=$DEVICE -v $PWD:/data espressif/idf:v4.4.8 -- sh -c 'cd /data && make flash ESPPORT=$DEVICE'
32+
```
33+
1934
## Notes
2035
If updating the NINA firmware for an **Arduino UNO WiFi Rev. 2** or **Arduino Nano RP2040** board via [SerialNINAPassthrough](https://github.com/arduino-libraries/WiFiNINA/blob/master/examples/Tools/SerialNINAPassthrough/SerialNINAPassthrough.ino) sketch, then the `esptool` invocation needs to be changed slightly:
2136
```diff

arduino/cores/esp32/WString.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ void String::remove(unsigned int index, unsigned int count){
638638
if (count > len - index) { count = len - index; }
639639
char *writeTo = buffer + index;
640640
len = len - count;
641-
strncpy(writeTo, buffer + index + count,len - index);
641+
memmove(writeTo, buffer + index + count, len - index);
642642
buffer[len] = 0;
643643
}
644644

arduino/cores/esp32/itoa.c

-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
extern "C" {
2424
#endif
2525

26-
extern char* utoa( unsigned long value, char *string, int radix )
27-
{
28-
return ultoa( value, string, radix ) ;
29-
}
30-
3126
extern char* ultoa( unsigned long value, char *string, int radix )
3227
{
3328
char tmp[33];

arduino/cores/esp32/wiring_digital.c

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <driver/gpio.h>
2121

2222
#include "wiring_digital.h"
23+
#include "soc/gpio_periph.h"
2324

2425
void pinMode(uint32_t pin, uint32_t mode)
2526
{

arduino/libraries/ArduinoBearSSL/src/SHA1.h

-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,4 @@ class SHA1Class: public SHAClass {
4747
br_sha1_context _ctx;
4848
};
4949

50-
extern SHA1Class SHA1;
51-
5250
#endif

arduino/libraries/WiFi/src/WiFi.cpp

+17-21
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <esp_wifi.h>
2323
#include <esp_wpa2.h>
24-
#include <tcpip_adapter.h>
24+
#include <esp_netif.h>
2525

2626
#include <lwip/apps/sntp.h>
2727
#include <lwip/dns.h>
@@ -38,7 +38,7 @@ WiFiClass::WiFiClass() :
3838
_initialized(false),
3939
_status(WL_NO_SHIELD),
4040
_reasonCode(0),
41-
_interface(ESP_IF_WIFI_STA),
41+
_interface(WIFI_IF_STA),
4242
_onReceiveCallback(NULL),
4343
_onDisconnectCallback(NULL),
4444
_wpa2Cert(NULL),
@@ -195,15 +195,15 @@ uint8_t WiFiClass::begin(const char* ssid, const char* key)
195195
wifiConfig.sta.scan_method = WIFI_FAST_SCAN;
196196
_status = WL_NO_SSID_AVAIL;
197197

198-
_interface = ESP_IF_WIFI_STA;
198+
_interface = WIFI_IF_STA;
199199

200200
xEventGroupClearBits(_eventGroup, BIT0);
201201
esp_wifi_stop();
202202
esp_wifi_set_mode(WIFI_MODE_STA);
203203
esp_wifi_start();
204204
xEventGroupWaitBits(_eventGroup, BIT0, false, true, portMAX_DELAY);
205205

206-
if (esp_wifi_set_config(ESP_IF_WIFI_STA, &wifiConfig) != ESP_OK) {
206+
if (esp_wifi_set_config(WIFI_IF_STA, &wifiConfig) != ESP_OK) {
207207
_status = WL_CONNECT_FAILED;
208208
}
209209

@@ -229,13 +229,13 @@ uint8_t WiFiClass::beginAP(const char *ssid, uint8_t channel)
229229

230230
_status = WL_NO_SSID_AVAIL;
231231

232-
_interface = ESP_IF_WIFI_AP;
232+
_interface = WIFI_IF_AP;
233233

234234
xEventGroupClearBits(_eventGroup, BIT1);
235235
esp_wifi_stop();
236236
esp_wifi_set_mode(WIFI_MODE_AP);
237237

238-
if (esp_wifi_set_config(ESP_IF_WIFI_AP, &wifiConfig) != ESP_OK) {
238+
if (esp_wifi_set_config(WIFI_IF_AP, &wifiConfig) != ESP_OK) {
239239
_status = WL_AP_FAILED;
240240
} else {
241241
esp_wifi_start();
@@ -258,13 +258,13 @@ uint8_t WiFiClass::beginAP(const char *ssid, uint8_t key_idx, const char* key, u
258258

259259
_status = WL_NO_SSID_AVAIL;
260260

261-
_interface = ESP_IF_WIFI_AP;
261+
_interface = WIFI_IF_AP;
262262

263263
xEventGroupClearBits(_eventGroup, BIT1);
264264
esp_wifi_stop();
265265
esp_wifi_set_mode(WIFI_MODE_AP);
266266

267-
if (esp_wifi_set_config(ESP_IF_WIFI_AP, &wifiConfig) != ESP_OK) {
267+
if (esp_wifi_set_config(WIFI_IF_AP, &wifiConfig) != ESP_OK) {
268268
_status = WL_AP_FAILED;
269269
} else {
270270
esp_wifi_start();
@@ -287,13 +287,13 @@ uint8_t WiFiClass::beginAP(const char *ssid, const char* key, uint8_t channel)
287287

288288
_status = WL_NO_SSID_AVAIL;
289289

290-
_interface = ESP_IF_WIFI_AP;
290+
_interface = WIFI_IF_AP;
291291

292292
xEventGroupClearBits(_eventGroup, BIT1);
293293
esp_wifi_stop();
294294
esp_wifi_set_mode(WIFI_MODE_AP);
295295

296-
if (esp_wifi_set_config(ESP_IF_WIFI_AP, &wifiConfig) != ESP_OK) {
296+
if (esp_wifi_set_config(WIFI_IF_AP, &wifiConfig) != ESP_OK) {
297297
_status = WL_AP_FAILED;
298298
} else {
299299
esp_wifi_start();
@@ -311,9 +311,7 @@ uint8_t WiFiClass::beginEnterprise(const char* ssid, const char* username, const
311311
esp_wifi_sta_wpa2_ent_clear_ca_cert();
312312
esp_wifi_sta_wpa2_ent_clear_cert_key();
313313

314-
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
315-
316-
esp_wifi_sta_wpa2_ent_enable(&config);
314+
esp_wifi_sta_wpa2_ent_enable();
317315

318316
int usernameLen = strlen(username);
319317
if (usernameLen) {
@@ -349,9 +347,7 @@ uint8_t WiFiClass::beginEnterpriseTLS(const char* ssid, const char* cert, const
349347
esp_wifi_sta_wpa2_ent_clear_ca_cert();
350348
esp_wifi_sta_wpa2_ent_clear_cert_key();
351349

352-
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
353-
354-
esp_wifi_sta_wpa2_ent_enable(&config);
350+
esp_wifi_sta_wpa2_ent_enable();
355351

356352
int certLen = strlen(cert);
357353
int keyLen = strlen(key);
@@ -388,7 +384,7 @@ void WiFiClass::config(/*IPAddress*/uint32_t local_ip, /*IPAddress*/uint32_t gat
388384
_ipInfo.gw.addr = gateway;
389385
_ipInfo.netmask.addr = subnet;
390386

391-
if (_interface == ESP_IF_WIFI_AP) {
387+
if (_interface == WIFI_IF_AP) {
392388
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP);
393389
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &_ipInfo);
394390
tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP);
@@ -466,7 +462,7 @@ uint32_t WiFiClass::gatewayIP()
466462

467463
uint32_t WiFiClass::dnsIP(int n)
468464
{
469-
return dns_getserver(n).u_addr.ip4.addr;
465+
return dns_getserver(n)->u_addr.ip4.addr;
470466
}
471467

472468
char* WiFiClass::SSID()
@@ -626,7 +622,7 @@ unsigned long WiFiClass::getTime()
626622

627623
void WiFiClass::lowPowerMode()
628624
{
629-
esp_wifi_set_ps(WIFI_PS_MODEM);
625+
esp_wifi_set_ps(WIFI_PS_MIN_MODEM);
630626
}
631627

632628
void WiFiClass::noLowPowerMode()
@@ -711,7 +707,7 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
711707
struct netif* staNetif;
712708
if (strlen(_hostname) == 0) {
713709
uint8_t mac[6];
714-
esp_wifi_get_mac(ESP_IF_WIFI_STA, mac);
710+
esp_wifi_get_mac(WIFI_IF_STA, mac);
715711
sprintf(_hostname, "arduino-%.2x%.2x", mac[4], mac[5]);
716712
}
717713
tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, _hostname);
@@ -792,7 +788,7 @@ void WiFiClass::handleSystemEvent(system_event_t* event)
792788

793789
wifi_config_t config;
794790

795-
esp_wifi_get_config(ESP_IF_WIFI_AP, &config);
791+
esp_wifi_get_config(WIFI_IF_AP, &config);
796792
memcpy(_apRecord.ssid, config.ap.ssid, sizeof(config.ap.ssid));
797793
_apRecord.authmode = config.ap.authmode;
798794

arduino/libraries/WiFi/src/WiFi.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef WIFI_H
2121
#define WIFI_H
2222

23-
#include <esp_event_loop.h>
23+
#include <esp_event.h>
2424

2525
#include <freertos/FreeRTOS.h>
2626
#include <freertos/event_groups.h>
@@ -119,7 +119,7 @@ class WiFiClass
119119
volatile uint8_t _status;
120120
volatile uint8_t _reasonCode;
121121
EventGroupHandle_t _eventGroup;
122-
esp_interface_t _interface;
122+
wifi_interface_t _interface;
123123

124124
wifi_ap_record_t _scanResults[MAX_SCAN_RESULTS];
125125
wifi_ap_record_t _apRecord;

arduino/libraries/WiFi/src/WiFiClient.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
6464
addr.sin_addr.s_addr = (uint32_t)ip;
6565
addr.sin_port = htons(port);
6666

67-
if (lwip_connect_r(_socket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
68-
lwip_close_r(_socket);
67+
if (lwip_connect(_socket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
68+
lwip_close(_socket);
6969
_socket = -1;
7070
return 0;
7171
}
7272

7373
int nonBlocking = 1;
74-
lwip_ioctl_r(_socket, FIONBIO, &nonBlocking);
74+
lwip_ioctl(_socket, FIONBIO, &nonBlocking);
7575

7676
return 1;
7777
}
@@ -87,7 +87,7 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
8787
return 0;
8888
}
8989

90-
int result = lwip_send_r(_socket, (void*)buf, size, MSG_PEEK);
90+
int result = lwip_send(_socket, (void*)buf, size, MSG_PEEK);
9191

9292
if (result < 0) {
9393
return 0;
@@ -106,8 +106,8 @@ int WiFiClient::available()
106106
int result = 0;
107107

108108
//This function returns the number of bytes of pending data already received in the socket’s network.
109-
if (lwip_ioctl_r(_socket, FIONREAD, &result) < 0) {
110-
lwip_close_r(_socket);
109+
if (lwip_ioctl(_socket, FIONREAD, &result) < 0) {
110+
lwip_close(_socket);
111111
_socket = -1;
112112
return 0;
113113
}
@@ -132,10 +132,10 @@ int WiFiClient::read(uint8_t* buf, size_t size)
132132
return -1;
133133
}
134134

135-
int result = lwip_recv_r(_socket, buf, size, MSG_DONTWAIT);
135+
int result = lwip_recv(_socket, buf, size, MSG_DONTWAIT);
136136

137137
if (result <= 0 && errno != EWOULDBLOCK) {
138-
lwip_close_r(_socket);
138+
lwip_close(_socket);
139139
_socket = -1;
140140
return 0;
141141
}
@@ -152,9 +152,9 @@ int WiFiClient::peek()
152152
uint8_t b;
153153

154154
//This function tries to receive data from the network and can return an error if the connection when down.
155-
if (lwip_recv_r(_socket, &b, sizeof(b), MSG_PEEK | MSG_DONTWAIT) <= 0) {
155+
if (lwip_recv(_socket, &b, sizeof(b), MSG_PEEK | MSG_DONTWAIT) <= 0) {
156156
if (errno != EWOULDBLOCK) {
157-
lwip_close_r(_socket);
157+
lwip_close(_socket);
158158
_socket = -1;
159159
}
160160

@@ -171,7 +171,7 @@ void WiFiClient::flush()
171171
void WiFiClient::stop()
172172
{
173173
if (_socket != -1) {
174-
lwip_close_r(_socket);
174+
lwip_close(_socket);
175175
_socket = -1;
176176
}
177177
}

arduino/libraries/WiFi/src/WiFiServer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ uint8_t WiFiServer::begin(uint16_t port)
5050
addr.sin_port = htons(port);
5151

5252
if (lwip_bind(_socket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
53-
lwip_close_r(_socket);
53+
lwip_close(_socket);
5454
_socket = -1;
5555
return 0;
5656
}
5757

5858
if (lwip_listen(_socket, 1) < 0) {
59-
lwip_close_r(_socket);
59+
lwip_close(_socket);
6060
_socket = -1;
6161
return 0;
6262
}
6363

6464
int nonBlocking = 1;
65-
lwip_ioctl_r(_socket, FIONBIO, &nonBlocking);
65+
lwip_ioctl(_socket, FIONBIO, &nonBlocking);
6666

6767
// Set port.
6868
_port = port;

arduino/libraries/WiFi/src/WiFiUdp.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ uint8_t WiFiUDP::begin(uint16_t port)
5252
addr.sin_port = htons(port);
5353

5454
if (lwip_bind(_socket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
55-
lwip_close_r(_socket);
55+
lwip_close(_socket);
5656
_socket = -1;
5757
return 0;
5858
}
5959

6060
int nonBlocking = 1;
61-
lwip_ioctl_r(_socket, FIONBIO, &nonBlocking);
61+
lwip_ioctl(_socket, FIONBIO, &nonBlocking);
6262

6363
return 1;
6464
}
@@ -74,7 +74,7 @@ uint8_t WiFiUDP::beginMulticast(/*IPAddress*/uint32_t ip, uint16_t port)
7474
multi.imr_multiaddr.s_addr = (uint32_t)ip;
7575
multi.imr_interface.s_addr = (uint32_t)0;
7676

77-
lwip_setsockopt_r(_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &multi, sizeof(multi));
77+
lwip_setsockopt(_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &multi, sizeof(multi));
7878

7979
return 1;
8080
}
@@ -89,7 +89,7 @@ int WiFiUDP::available()
8989
/* Release any resources being used by this WiFiUDP instance */
9090
void WiFiUDP::stop()
9191
{
92-
lwip_close_r(_socket);
92+
lwip_close(_socket);
9393
_socket = -1;
9494
}
9595

@@ -158,7 +158,7 @@ int WiFiUDP::parsePacket()
158158
_rcvIndex = 0;
159159
_rcvSize = 0;
160160

161-
int result = lwip_recvfrom_r(_socket, _rcvBuffer, sizeof(_rcvBuffer), MSG_DONTWAIT, (struct sockaddr*)&addr, &addrLen);
161+
int result = lwip_recvfrom(_socket, _rcvBuffer, sizeof(_rcvBuffer), MSG_DONTWAIT, (struct sockaddr*)&addr, &addrLen);
162162

163163
if (result <= 0) {
164164
return 0;

arduino/libraries/Wire/src/Wire.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ extern "C" {
2121
#include <string.h>
2222

2323
#include <driver/gpio.h>
24-
#include <esp_intr.h>
25-
#include <rom/ets_sys.h>
24+
#include <esp_intr_alloc.h>
25+
#include <esp32/rom/ets_sys.h>
2626
#include <soc/gpio_sig_map.h>
27+
#include <freertos/xtensa_api.h>
2728
}
2829

2930
#include <Arduino.h>

0 commit comments

Comments
 (0)