Skip to content

Commit ac6a5f1

Browse files
Merge branch 'master' into master
2 parents 664f83a + 0cb4082 commit ac6a5f1

File tree

20 files changed

+288
-65
lines changed

20 files changed

+288
-65
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Compile Examples
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/compile-examples.yml"
7+
- "cores/**"
8+
- "libraries/**"
9+
- "variants/**"
10+
- "boards.txt"
11+
- "platform.txt"
12+
push:
13+
paths:
14+
- ".github/workflows/compile-examples.yml"
15+
- "cores/**"
16+
- "libraries/**"
17+
- "variants/**"
18+
- "boards.txt"
19+
- "platform.txt"
20+
21+
jobs:
22+
compile-examples:
23+
runs-on: ubuntu-latest
24+
25+
env:
26+
# sketch paths to compile (recursive) compatible with all boards
27+
UNIVERSAL_SKETCH_PATHS: '"libraries/Scheduler"'
28+
29+
strategy:
30+
fail-fast: false
31+
32+
matrix:
33+
board:
34+
- fqbn: arduino-beta:mbed:nano33ble
35+
- fqbn: arduino-beta:mbed:envie_m4
36+
- fqbn: arduino-beta:mbed:envie_m7
37+
38+
# compile only the examples compatible with each board
39+
include:
40+
- board:
41+
fqbn: arduino-beta:mbed:nano33ble
42+
additional-sketch-paths: '"libraries/PDM" "libraries/ThreadDebug"'
43+
- board:
44+
fqbn: arduino-beta:mbed:envie_m4
45+
additional-sketch-paths: '"libraries/doom" "libraries/KernelDebug" "libraries/Portenta_SDCARD" "libraries/Portenta_System" "libraries/Portenta_Video" '
46+
- board:
47+
fqbn: arduino-beta:mbed:envie_m7
48+
additional-sketch-paths: '"libraries/doom" "libraries/KernelDebug" "libraries/Portenta_Audio" "libraries/Portenta_SDCARD" "libraries/Portenta_System" "libraries/Portenta_Video" "libraries/ThreadDebug" "libraries/USBHOST"'
49+
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v2
53+
54+
# The source files are in a subfolder of the ArduinoCore-API repository, so it's not possible to clone it directly to the final destination in the core
55+
- name: Checkout ArduinoCore-API
56+
uses: actions/checkout@v2
57+
with:
58+
repository: arduino/ArduinoCore-API
59+
ref: namespace_arduino
60+
path: ArduinoCore-API
61+
62+
- name: Remove old symlink to api
63+
run: rm "$GITHUB_WORKSPACE/cores/arduino/api"
64+
65+
- name: Install ArduinoCore-API
66+
run: mv "$GITHUB_WORKSPACE/ArduinoCore-API/api" "$GITHUB_WORKSPACE/cores/arduino"
67+
68+
- name: Compile examples
69+
uses: arduino/actions/libraries/compile-examples@master
70+
with:
71+
fqbn: ${{ matrix.board.fqbn }}
72+
platforms: |
73+
# Use Board Manager to install the latest release of Arduino mbed Boards to get the toolchain
74+
- name: "arduino-beta:mbed"
75+
# Overwrite the Board Manager installation with the local platform
76+
- source-path: "./"
77+
name: "arduino-beta:mbed"
78+
sketch-paths: "${{ env.UNIVERSAL_SKETCH_PATHS }} ${{ matrix.additional-sketch-paths }}"
79+
verbose: 'false'
80+
enable-size-deltas-report: true
81+
82+
- name: Save memory usage change report as artifact
83+
if: github.event_name == 'pull_request'
84+
uses: actions/upload-artifact@v1
85+
with:
86+
name: size-deltas-reports
87+
path: size-deltas-reports
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
on:
2+
schedule:
3+
- cron: '*/5 * * * *'
4+
5+
jobs:
6+
report:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Comment size deltas reports to PRs
11+
uses: arduino/actions/libraries/report-size-deltas@master

cores/arduino/Arduino.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20+
#if ARDUINO_LIBRARY_DISCOVERY_PHASE == 1
21+
#define ARDUINO_LIB_DISCOVERY_PHASE
22+
#endif
2023
#if !defined(Arduino_h) && !defined(ARDUINO_LIB_DISCOVERY_PHASE)
2124
#define Arduino_h
2225

cores/arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_PORTENTA_H7/COMPONENT_WHD/interface/cyhal_hw_types.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ typedef struct
8181
void *empty;
8282
} cyhal_spi_t;
8383

84+
85+
#include "whd_debug.h"
86+
87+
#if defined(WPRINT_ENABLE_WHD_ERROR) || defined(WPRINT_ENABLE_WHD_INFO) || defined(WPRINT_ENABLE_WHD_DEBUG)
8488
/** \} group_hal_hw_types_data_structures */
8589
#define PRINTF(...) do { \
8690
(void) printf(__VA_ARGS__); \
8791
} while (0)
88-
92+
#else
93+
#define PRINTF(...)
94+
#endif
8995

9096
#include "whd_config.h"
9197

cores/arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_PORTENTA_H7/COMPONENT_WHD/src/include/whd_debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern "C"
3636
#define WPRINT_ENABLE_WHD_DEBUG
3737

3838
#define WHD_ENABLE_STATS
39-
/*#define WHD_LOGGING_BUFFER_ENABLE*/
39+
#define WHD_LOGGING_BUFFER_ENABLE
4040

4141
#if defined (__GNUC__)
4242
#define WHD_TRIGGER_BREAKPOINT( ) do { __asm__ ("bkpt"); } while (0)

libraries/WiFi/src/WiFi.cpp

Lines changed: 116 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "WiFi.h"
22

3-
bool arduino::WiFiClass::isVisible(char* ssid) {
3+
bool arduino::WiFiClass::isVisible(const char* ssid) {
44
for (int i=0; i<10; i++) {
55
if (strncmp(ap_list[i].get_ssid(), ssid, 32) == 0) {
66
connected_ap = i;
@@ -10,7 +10,12 @@ bool arduino::WiFiClass::isVisible(char* ssid) {
1010
return false;
1111
}
1212

13-
int arduino::WiFiClass::begin(char* ssid, const char *passphrase) {
13+
arduino::IPAddress arduino::WiFiClass::ipAddressFromSocketAddress(SocketAddress socketAddress) {
14+
nsapi_addr_t address = socketAddress.get_addr();
15+
return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]);
16+
}
17+
18+
int arduino::WiFiClass::begin(const char* ssid, const char *passphrase) {
1419
if (_ssid) free(_ssid);
1520

1621
_ssid = (char*)malloc(33);
@@ -19,51 +24,109 @@ int arduino::WiFiClass::begin(char* ssid, const char *passphrase) {
1924
return WL_CONNECT_FAILED;
2025
}
2126

22-
if (wifi_if == NULL) {
23-
wifi_if = (WiFiInterface*)cb();
27+
if (wifi_if == nullptr) {
28+
//Q: What is the callback for?
29+
_initializerCallback();
30+
if(wifi_if == nullptr) return WL_CONNECT_FAILED;
2431
}
2532

26-
// too long? break it off
27-
if (strlen(ssid) > 32) ssid[32] = 0;
2833
memcpy(_ssid, ssid, 33);
34+
// too long? break it off
35+
if (strlen(ssid) > 32) _ssid[32] = 0;
2936

3037
scanNetworks();
3138
// use scan result to populate security field
32-
if (!isVisible(ssid)) {
33-
return WL_CONNECT_FAILED;
39+
if (!isVisible(_ssid)) {
40+
_currentNetworkStatus = WL_CONNECT_FAILED;
41+
return _currentNetworkStatus;
3442
}
3543

36-
nsapi_error_t ret = wifi_if->connect(ssid, passphrase, ap_list[connected_ap].get_security());
44+
nsapi_error_t ret = wifi_if->connect(_ssid, passphrase, ap_list[connected_ap].get_security());
3745

38-
return ret == NSAPI_ERROR_OK ? WL_CONNECTED : WL_CONNECT_FAILED;
46+
_currentNetworkStatus = ret == NSAPI_ERROR_OK ? WL_CONNECTED : WL_CONNECT_FAILED;
47+
return _currentNetworkStatus;
3948
}
4049

4150
int arduino::WiFiClass::beginAP(const char* ssid, const char *passphrase, uint8_t channel) {
4251

4352
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
44-
softap = WhdSoftAPInterface::get_default_instance();
53+
_softAP = WhdSoftAPInterface::get_default_instance();
4554
#endif
4655

47-
if (softap == NULL) {
56+
if (_softAP == NULL) {
4857
return WL_CONNECT_FAILED;
4958
}
5059

51-
//Set ap ssid, password and channel
52-
SocketAddress ip("192.168.3.1");
53-
SocketAddress gw("192.168.3.1");
54-
SocketAddress netmask("255.255.255.0");
55-
((WhdSoftAPInterface*)softap)->set_network(ip, gw, netmask);
56-
nsapi_error_t ret = ((WhdSoftAPInterface*)softap)->start(ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */, NULL, true /* cohexistance */);
60+
ensureDefaultAPNetworkConfiguration();
61+
62+
//Set ap ssid, password and channel
63+
static_cast<WhdSoftAPInterface*>(_softAP)->set_network(_ip, _netmask, _gateway);
64+
nsapi_error_t ret = static_cast<WhdSoftAPInterface*>(_softAP)->start(ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */, NULL, true /* cohexistance */);
5765

5866
return ret == NSAPI_ERROR_OK ? WL_AP_LISTENING : WL_CONNECT_FAILED;
5967
}
6068

69+
void arduino::WiFiClass::ensureDefaultAPNetworkConfiguration() {
70+
if(_ip == nullptr){
71+
_ip = SocketAddress(DEFAULT_IP_ADDRESS);
72+
}
73+
if(_gateway == nullptr){
74+
_gateway = _ip;
75+
}
76+
if(_netmask == nullptr){
77+
_netmask = SocketAddress(DEFAULT_NETMASK);
78+
}
79+
}
80+
6181
void arduino::WiFiClass::end() {
62-
if (softap != NULL) {
63-
((WhdSoftAPInterface*)softap)->stop();
82+
disconnect();
83+
}
84+
85+
int arduino::WiFiClass::disconnect() {
86+
if (_softAP != nullptr) {
87+
return static_cast<WhdSoftAPInterface*>(_softAP)->stop();
88+
} else {
89+
return wifi_if->disconnect();
6490
}
6591
}
6692

93+
void arduino::WiFiClass::config(arduino::IPAddress local_ip){
94+
nsapi_addr_t convertedIP = {NSAPI_IPv4, {local_ip[0], local_ip[1], local_ip[2], local_ip[3]}};
95+
_ip = SocketAddress(convertedIP);
96+
}
97+
98+
void arduino::WiFiClass::config(const char *local_ip){
99+
_ip = SocketAddress(local_ip);
100+
}
101+
102+
void arduino::WiFiClass::config(IPAddress local_ip, IPAddress dns_server){
103+
config(local_ip);
104+
setDNS(dns_server);
105+
}
106+
107+
void arduino::WiFiClass::config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway){
108+
config(local_ip, dns_server);
109+
nsapi_addr_t convertedGatewayIP = {NSAPI_IPv4, {gateway[0], gateway[1], gateway[2], gateway[3]}};
110+
_gateway = SocketAddress(convertedGatewayIP);
111+
}
112+
113+
void arduino::WiFiClass::config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet){
114+
config(local_ip, dns_server, gateway);
115+
nsapi_addr_t convertedSubnetMask = {NSAPI_IPv4, {subnet[0], subnet[1], subnet[2], subnet[3]}};
116+
_netmask = SocketAddress(convertedSubnetMask);
117+
}
118+
119+
void arduino::WiFiClass::setDNS(IPAddress dns_server1){
120+
nsapi_addr_t convertedDNSServer = {NSAPI_IPv4, {dns_server1[0], dns_server1[1], dns_server1[2], dns_server1[3]}};
121+
_dnsServer1 = SocketAddress(convertedDNSServer);
122+
}
123+
124+
void arduino::WiFiClass::setDNS(IPAddress dns_server1, IPAddress dns_server2){
125+
setDNS(dns_server1);
126+
nsapi_addr_t convertedDNSServer2 = {NSAPI_IPv4, {dns_server2[0], dns_server2[1], dns_server2[2], dns_server2[3]}};
127+
_dnsServer2 = SocketAddress(convertedDNSServer2);
128+
}
129+
67130
char* arduino::WiFiClass::SSID() {
68131
return _ssid;
69132
}
@@ -108,7 +171,7 @@ static uint8_t sec2enum(nsapi_security_t sec)
108171

109172
int8_t arduino::WiFiClass::scanNetworks() {
110173
uint8_t count = 10;
111-
if (ap_list == NULL) {
174+
if (ap_list == nullptr) {
112175
ap_list = new WiFiAccessPoint[count];
113176
}
114177
return wifi_if->scan(ap_list, count);
@@ -130,9 +193,8 @@ int32_t arduino::WiFiClass::RSSI() {
130193
return wifi_if->get_rssi();
131194
}
132195

133-
uint8_t arduino::WiFiClass::status() {
134-
// @todo: fix
135-
return WL_CONNECTED;
196+
uint8_t arduino::WiFiClass::status() {
197+
return _currentNetworkStatus;
136198
}
137199

138200
uint8_t arduino::WiFiClass::encryptionType() {
@@ -148,7 +210,7 @@ uint8_t* arduino::WiFiClass::BSSID(unsigned char* bssid) {
148210
}
149211

150212
uint8_t* arduino::WiFiClass::macAddress(uint8_t* mac) {
151-
const char *mac_str = wifi_if->get_mac_address();
213+
const char *mac_str = getNetwork()->get_mac_address();
152214
for( int b = 0; b < 6; b++ )
153215
{
154216
uint32_t tmp;
@@ -159,28 +221,46 @@ uint8_t* arduino::WiFiClass::macAddress(uint8_t* mac) {
159221
return mac;
160222
}
161223

162-
arduino::IPAddress arduino::WiFiClass::localIP() {
163-
arduino::IPAddress addr;
224+
arduino::IPAddress arduino::WiFiClass::localIP() {
225+
SocketAddress ip;
226+
NetworkInterface *interface = getNetwork();
227+
interface->get_ip_address(&ip);
228+
return ipAddressFromSocketAddress(ip);
229+
}
230+
231+
arduino::IPAddress arduino::WiFiClass::subnetMask() {
232+
SocketAddress ip;
233+
NetworkInterface *interface = getNetwork();
234+
interface->get_netmask(&ip);
235+
return ipAddressFromSocketAddress(ip);
236+
}
164237

238+
arduino::IPAddress arduino::WiFiClass::gatewayIP() {
165239
SocketAddress ip;
166-
if (softap != NULL) {
167-
softap->get_ip_address(&ip);
168-
} else {
169-
wifi_if->get_ip_address(&ip);
170-
}
171-
addr.fromString(ip.get_ip_address()); // @todo: the IP we get from Mbed is correct, but is parsed incorrectly by Arduino
172-
return addr;
240+
NetworkInterface *interface = getNetwork();
241+
interface->get_gateway(&ip);
242+
return ipAddressFromSocketAddress(ip);
173243
}
174244

175245
NetworkInterface *arduino::WiFiClass::getNetwork() {
176-
if (softap != NULL) {
177-
return softap;
246+
if (_softAP != nullptr) {
247+
return _softAP;
178248
} else {
179249
return wifi_if;
180250
}
181251
}
182252

253+
unsigned long arduino::WiFiClass::getTime() {
254+
return 0;
255+
}
256+
183257
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
258+
259+
#include "whd_version.h"
260+
char* arduino::WiFiClass::firmwareVersion() {
261+
return WHD_VERSION;
262+
}
263+
184264
arduino::WiFiClass WiFi(WiFiInterface::get_default_instance());
185265
#endif
186266

0 commit comments

Comments
 (0)