Commit Graph

862 Commits

Author SHA1 Message Date
Bill Sideris 47c373e67e
Use `cyw43_tcpip_link_status` instead 2022-10-17 18:33:32 +03:00
Bill Sideris bce024f59e
Implement async wifi connection on picow 2022-10-17 18:17:14 +03:00
Jeff Epler 47541afc7c
picow: ask at a lower level if the interface is up
Closes: #7072

```
Adafruit CircuitPython 8.0.0-beta.2-9-g5192082e64-dirty on 2022-10-17; Raspberry Pi Pico W with rp2040
>>> import wifi
>>> print(wifi.radio.ipv4_address)
None
>>> import os
>>> wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
>>> print(wifi.radio.ipv4_address)
10.0.2.94
```
2022-10-17 10:08:50 -05:00
Jeff Epler d4b1d4d430
Fix GPIO state when initializing CYW43 pin
Closes: #7063
2022-10-15 13:10:22 -05:00
Dan Halbert 062d63ee3a
Merge pull request #7050 from jepler/picow-wirelsess-off-in-deep-sleep
picow: Turn off wifi co-processor regulator when entering deep sleep
2022-10-14 08:17:16 -04:00
Jeff Epler 3b3fe44174
implement hashlib for picow 2022-10-13 20:42:50 -05:00
Jeff Epler 0c5fd55c16
picow: Turn off wifi co-processor regulator when entering deep sleep
This reduces power consumption during true deep sleep.

In my measurements with ppk2 and a program that _irrevocably_ entered
deep sleep (no time alarm or pin alarm), power usage as measured on a
ppk2 decreased from ~10mA to ~1mA.
2022-10-13 20:10:10 -05:00
Georg Bøe e768b9ebb3 Return correct errno 2022-10-13 21:00:51 +02:00
Jeff Epler 874ddd67bf
Pico W: ssl: factor out do_handshake 2022-10-12 11:38:30 -05:00
Jeff Epler 1641a7c002
Pico W: ssl: Correctly handle errors in send/recv
The prefixed versions raise Python exceptions, the un-prefixed return
negative error values. We don't want to raise an exception from here,
it leaves the SSL stack in an undefined state.
2022-10-12 11:38:30 -05:00
Jeff Epler 7c849fdadb
Pico W: ssl: Raise MemoryError for allocation errors 2022-10-12 11:38:29 -05:00
Jeff Epler b1f7940297
Pico W: Correctly treat empty cadata= as disabling host checking 2022-10-12 11:38:29 -05:00
Jeff Epler ca9523b814
Pico w: socket: Correctly return negative error code from recv_into 2022-10-12 11:38:29 -05:00
Jeff Epler 62cbd3bcd8
Pico w: socket: correctly track sockets generated by accept() 2022-10-12 11:38:26 -05:00
Dan Halbert e19abef57e forgot to add these! 2022-10-11 13:12:43 -04:00
Dan Halbert 851f8a188d Merge remote-tracking branch 'adafruit/main' into HEAD 2022-10-11 12:21:59 -04:00
Jeff Epler 0c8b261ec9
picow: Add support of self-signed certificates.
## Testing self-signed certificates and `load_verify_locations`

Obtain the badssl "self-signed" certificate in the correct form:

```sh
openssl s_client -servername self-signed.badssl.com -connect untrusted-root.badssl.com:443 < /dev/null | openssl x509 > self-signed.pem
```

Copy it and the script to CIRCUITPY:
```python
import os
import wifi
import socketpool
import ssl
import adafruit_requests

TEXT_URL = "https://self-signed.badssl.com/"
if not wifi.radio.ipv4_address:
    wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))

pool = socketpool.SocketPool(wifi.radio)
context = ssl.create_default_context()
requests = adafruit_requests.Session(pool, context)

print(f"Fetching from {TEXT_URL} without certificate (should fail)")
try:
    response = requests.get(TEXT_URL)
except Exception as e:
    print(f"Failed: {e}")
else:
    print(f"{response.status_code=}, should have failed with exception")

print("Loading server certificate")
with open("/self-signed.pem", "rb") as certfile:
    context.load_verify_locations(cadata=certfile.read())
requests = adafruit_requests.Session(pool, context)

print(f"Fetching from {TEXT_URL} with certificate (should succeed)")
try:
    response = requests.get(TEXT_URL)
except Exception as e:
    print(f"Unexpected exception: {e}")
else:
    print(f"{response.status_code=}, should be 200 OK")
```
2022-10-10 15:53:56 -05:00
Jeff Epler c98174eea5
Add support for SSL client certificate (load_cert_chain)
Tested with badssl.com:

 1. Get client certificates from https://badssl.com/download/
 2. Convert public portion with `openssl x509 -in badssl.com-client.pem -out CIRCUITPY/cert.pem`
 3. Convert private portion with `openssl rsa -in badssl.com-client.pem -out CIRCUITPY/privkey.pem` and the password `badssl.com`
 4. Put wifi settings in CIRCUITPY/.env
 5. Run the below Python script:

```py
import os
import wifi
import socketpool
import ssl
import adafruit_requests

TEXT_URL = "https://client.badssl.com/"
wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))

pool = socketpool.SocketPool(wifi.radio)
context = ssl.create_default_context()
requests = adafruit_requests.Session(pool, context)

print(f"Fetching from {TEXT_URL} without certificate (should fail)")
response = requests.get(TEXT_URL)
print(f"{response.status_code=}, should be 400 Bad Request")
input("hit enter to continue\r")

print("Loading client certificate")
context.load_cert_chain("/cert.pem", "privkey.pem")
requests = adafruit_requests.Session(pool, context)

print(f"Fetching from {TEXT_URL} with certificate (should succeed)")
response = requests.get(TEXT_URL)
print(f"{response.status_code=}, should be 200 OK")
```
2022-10-10 15:10:53 -05:00
Dan Halbert de95463deb
Merge pull request #7023 from dhalbert/wifi-scanning-fixes
update esp-idf; allow start/stop channels in wifi scanning
2022-10-10 13:54:54 -04:00
Dan Halbert 747dc7746d handle scan channel bounds but note they do nothing for RP2040 CYW43 2022-10-07 16:22:17 -04:00
Jeff Epler f882571366
pico w: pins improvements
Closes: #7017

 * Remove the 'GP23' alias for CYW1
 * Remove the 'CYW0' alias for CYW0
 * Switch VBUS_SENSE to CYW2, remove 'GP24' alias

Code that wants to use SMPS_MODE, VBUS_SENSE and LED while being
portable to the W and non-W variants should use those names, not alias
names.

 * Remove A3 / VOLTAGE_MONITOR

Right now this cannot be used. The ability to check the voltage monitor
should be added back in some fashion in the future.
2022-10-07 08:48:36 -05:00
Dan Halbert 041885da1b
Merge pull request #7011 from jepler/pico-w-resize-circuitpy-again
switch flash split to leave 512kB for CIRCUITPY
2022-10-07 08:32:18 -04:00
Neradoc 3a6382d1ea cyw43.CywPin should be the class, not a string 2022-10-07 02:11:05 +02:00
Jeff Epler 644d293641
Fix CIRCUITPY drive offset in flash correctly, accounting for NVM
.. and fix nvm to read/right the correct area.

.. putting a comment in link.ld to explain it all

Closes #7012
2022-10-06 12:39:46 -05:00
Jeff Epler 07cd2ff065
restore 4kB gap pending resolution of #7011 2022-10-06 11:20:48 -05:00
Jeff Epler 6e2c24083a
switch flash split to leave 512kB for CIRCUITPY 2022-10-06 10:12:22 -05:00
Jeff Epler 2dc283f578
close underlying socket object when closing ssl socket 2022-10-05 15:10:14 -05:00
Jeff Epler 4a9389d347
remove debug message 2022-10-05 14:57:04 -05:00
Jeff Epler 14f2309b6f
Enable more key exchange methods
This is intended (but not entirely verified) to match our esp32 builds.
It does fix accessing https://circuitpython.org, which failed before with
"MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE".

It still doesn't work on a personal website of mine with valid letsencrypt
certificate but I haven't verified whether it works on esp32s2 with CP.
That site only allows TLS 1.3, while this mbedtls only supports up to
1.2.
The version of mbedtls we adopted based on micropython's use has no
TLS 1.3 support, but the one in espressif esp-idf does.
2022-10-05 14:56:27 -05:00
Jeff Epler fabfdcf6fe
More ssl work 2022-10-05 14:56:26 -05:00
Jeff Epler 944d388158
copy esp_crt_bundle.c from esp-idf@d51f7d8821 2022-10-05 14:56:26 -05:00
Jeff Epler dcb650c513 pico w: add ssl module
Note: at this time, the ssl module on pico_w never verifies the server
certificate. This means it does not actually provide a higher security
level than regular socket / http protocols.
2022-10-05 13:12:43 -04:00
Jeff Epler 2bd50673b6
Finish adapting flash storage size
Before this, CIRCUITPY would start at 1MB anyway. This appeared to work
only because I hadn't checked the actual size of the CIRCUITPY drive,
and because until now the flash hadn't actually crossed that 1MB
boundary into CIRCUITPY storage.

WARNING: on pico_w, upgrading/downgrading CircuitPython across this commit
boundary will erase the CIRCUITPY filesystem. After this commit,
switching between pico and pico_w firmware will erase the CIRCUITPY
filesystem
2022-10-05 10:02:38 -05:00
Dan Halbert ad79f595a5
Merge pull request #6974 from MicroDev1/patch
Couple Minor Fixes
2022-10-01 13:12:01 -04:00
Dan Halbert 7bb90dbf45 remove redundant port/*/.gitignore; cleanup others 2022-10-01 11:52:36 -04:00
Jeff Epler 40c2de833d
doc improvements 2022-10-01 10:09:33 -05:00
Jeff Epler d3e85d165e
Set cyw43 power management as needed, default to disabled
.. the value actually needs to be enforced each time the STA or AP
is enabled, because internally there's a call to cyw43_wifi_pm with the
library's defaut power management value, not ours.

Add a getter, though it only returns our idea of what the power
management register is set to, it doesn't read out from the actual
hardware, sadly.
2022-10-01 08:20:34 -05:00
Jeff Epler 943b992bfc
Improve cyw43.set_power_management documentation
.. and provide 4 preset values
2022-10-01 07:52:08 -05:00
Dan Halbert bced76887e
Merge pull request #6973 from jepler/rp2040-fix-warnings
Rp2040 fix warnings
2022-09-30 16:21:31 -04:00
Jeff Epler c02602ace1
Enable strict-overflow diagnostic 2022-09-30 11:19:23 -05:00
Jeff Epler afc1c0e3bb
Fix unused variable diagnostics, make it a fatal error 2022-09-30 11:19:22 -05:00
Jeff Epler 37620d4eb0
Fix several classes of compiler diagnostic & make fatal
* -Wno-nested-externs
 * -Wno-strict-prototypes
 * -Wno-double-promotion
 * -Wno-sign-compare
2022-09-30 11:19:22 -05:00
Jeff Epler c6eef3931f
Enable warning for unused static functions 2022-09-30 11:19:22 -05:00
Jeff Epler 2c9c6fc80e
Remove unused static functions 2022-09-30 11:19:21 -05:00
Jeff Epler 907c5d387f
Tweak black_bindings
Originally, black_bindings found each contiguous "//|" block and sent
it to black independently. This was slower than it needed to be.

Instead, swap the comment prefix: when running black, take off
"//|" prefixes and put "##|" prefixes on all un-prefixed lines.
Then, after black is run, do the opposite operation

This more than doubles the overall speed of "pre-commit run --all",
from 3m20s to 55s CPU time on my local machine (32.5s to under 10s
"elapsed" time)

It also causes a small amount of churn in the bindings, because
black now sees enough context to know whether one 'def' follows another
or ends the 'def's in a 'class'. In the latter case, it adds an extra
newline, which becomes a "//|" line.

I'm less sure why a trailing comma was omitted before down in
rp2pio/StateMachine.c but let's roll with it.
2022-09-30 11:18:13 -05:00
Jeff Epler 0912889106
raspberrypi: statically allocate storage for hostname 2022-09-30 10:05:11 -05:00
Jeff Epler 84c7ac4a81
Make cyw43.set_power_management() be a function as intended 2022-09-30 07:56:59 -05:00
Jeff Epler 3281e14be1
fix reference to board module 2022-09-29 21:37:34 -05:00
Jeff Epler 4de9487820
It turns out you CAN have too many GPIO 2022-09-29 20:10:33 -05:00
Jeff Epler 510bd11f58
Enable reading back value of cyw43 pin
Now, `led.value = not led.value` works as a way to toggle the LED state.

Closes: #6959
2022-09-29 11:06:11 -05:00
Jeff Epler a3bcfd6911
Add pin_CYW1 for SMPS_MODE 2022-09-29 10:54:06 -05:00
Jeff Epler 72b06021c0
fix doc formatting 2022-09-29 10:27:13 -05:00
Jeff Epler 74cdf42ece
pico w: implement bind, listen, accept
this works with some simple tcp & udp echo service code
2022-09-29 10:02:20 -05:00
Jeff Epler 12ea04ca70
Add cyw43.set_power_management 2022-09-29 10:02:20 -05:00
Jeff Epler 91f1266db5
Document CywPin 2022-09-29 10:02:19 -05:00
Jeff Epler 56f9f0d136
add tx power get/set 2022-09-29 10:02:19 -05:00
Jeff Epler 71a00157ba
Add hostname setting 2022-09-29 10:02:19 -05:00
Jeff Epler c6d3163841
remove comment about something the Makefile does now 2022-09-29 10:02:18 -05:00
Dan Halbert db065a299f
Merge pull request #6933 from jepler/🥧🐮
Implement a useful subset of `wifi` and `socketpool` modules on 🥧🐮
2022-09-28 18:09:24 -04:00
Jeff Epler 2dd6df9d93
better to explain why this file has no useful content 2022-09-28 15:19:06 -05:00
Jeff Epler 3d76aa00f5
implementations not needed 2022-09-28 14:38:13 -05:00
Jeff Epler 09d4fbc557
Remove FIXME
this was verbatim-copied from micropython
2022-09-28 14:38:13 -05:00
Jeff Epler 6189156a0b
Add missing NotImplementedErrors 2022-09-28 14:38:12 -05:00
Jeff Epler edf1efd728
Add CYW43 guards to more things 2022-09-28 14:38:12 -05:00
Jeff Epler e100981d90
revert CFLAGS change 2022-09-28 14:38:12 -05:00
Jeff Epler 4380292848
comment why not actually reset wifi 2022-09-28 14:38:11 -05:00
Jeff Epler ff7731491e
Implement enough of socketpool to do ntp and non-https requests 2022-09-28 10:06:34 -05:00
Jeff Epler a7a1bd7880
Implement DNS resolution
```
>>> s = socketpool.SocketPool(wifi.radio)
>>> s.getaddrinfo("google.com", 80)
[(0, 0, 0, '', ('142.250.81.206', 80))]
```
2022-09-28 10:06:33 -05:00
Jeff Epler 6c3cdceb45
Implement scan, connect, ping
My pings go out, and then they come back

```py
import os
import wifi
import ipaddress

wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
ipv4 = ipaddress.ip_address("8.8.4.4")
print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
```
2022-09-28 10:06:33 -05:00
Jeff Epler 346fff2e7c
cyw43 basic gpio support, hwaddr in boot_out 2022-09-28 10:06:33 -05:00
Jeff Epler 22b04aef22
Reindent a block 2022-09-28 10:05:53 -05:00
Jeff Epler 9caa65cf28
allow a board to override link.ld 2022-09-28 10:05:53 -05:00
Jeff Epler b2cc8d2aad
run black_bindings across all bindings 2022-09-27 15:21:42 -05:00
Jeff Epler 4e96667d50
Manual fix for oddball cases 2022-09-27 15:19:32 -05:00
Dan Halbert de80db681f
Merge pull request #6915 from dhalbert/ringbuf-cleanup
ringbuf cleanup
2022-09-25 17:50:21 -04:00
Neradoc 5346b89b08 don't use @property in docs, just document as a property 2022-09-25 07:18:18 +02:00
Dan Halbert ea15a9118a ringbuf cleanup 2022-09-21 10:03:05 -04:00
Dan Halbert 8a568d18b5
Merge pull request #6757 from latkinso42/adcdma
analogbufio
2022-09-16 08:32:24 -04:00
Dan Halbert 82694b7265 remove extraneous copyrights 2022-09-15 20:31:08 -04:00
Dan Halbert 60f43b1703 allow preserving pin state during deep sleep 2022-09-15 17:35:14 -04:00
Lee Atkinson f279a2dbb2
Merge branch 'adafruit:main' into adcdma 2022-09-08 11:46:01 -04:00
Dan Halbert 58b00467c4
Merge pull request #6878 from dhalbert/weak-board-defs
Use MP_WEAK for default board.c routines
2022-09-08 10:47:08 -04:00
Dan Halbert 4cb69a51d5 Use MP_WEAK for default board.c routines 2022-09-08 07:36:50 -04:00
latkinso42 c1f57c6ceb Pushing for resolution 2022-09-07 18:53:35 -04:00
latkinso42 25078a24a3 Attempt to fix Build-Docs and Pre-Commit 2022-09-06 18:58:57 -04:00
Pontus Oldberg c043c437f7 Merge branch 'main' of https://github.com/PontusO/circuitpython 2022-09-06 09:37:25 +02:00
Pontus Oldberg 9a937e6ea3 Added challenger_rp2040_wifi_ble board. 2022-09-06 09:37:21 +02:00
latkinso42 5498b3ac91 fix to analogbufio BufferedIn.h 2022-09-05 14:22:08 -04:00
Scott Shawcroft a09836eb4a
Merge pull request #6681 from PontusO/main
Adds support for the Challenger RP2040 SubGHz board
2022-09-05 10:01:51 -07:00
latkinso42 a1856ea3e9 Renaming module from adcbuffer to analogbufio 2022-09-05 12:11:49 -04:00
latkinso42 478b40ecf9 Merge branch 'adcdma' of https://github.com/latkinso42/circuitpython into adcdma
Syncing with remote
2022-09-04 16:07:37 -04:00
Lee Atkinson 3cd8259a78
Merge branch 'adafruit:main' into adcdma 2022-09-04 15:59:20 -04:00
latkinso42 d7a1db5b87 Changes per review 2022-09-04 15:57:59 -04:00
Dan Halbert 449b43e5a6
Merge pull request #6863 from jepler/rp2pio-erroneous-mask
rp2pio: fix occasional bug when not using OUT pins
2022-09-04 09:15:35 -04:00
Jeff Epler a3e17189a4
rp2pio: fix occasional bug when not using OUT pins
a NULL first pin object is used to indicate that there are zero
of some kind of pin associated with the StateMachine. However,
mask_and_rotate wasn't checking for zero. It actually read data from
near address 0x0 and (in my case) got a nonzero mask, which then
caused a program with GPIO11 and GPIO12 as input with pull-up and no
out pins to erroneously encounter the error "pull masks conflict with
direction masks"
2022-09-03 20:39:42 -05:00
latkinso42 6fe2ea4513 Merging back with updated main files 2022-09-02 15:51:45 -04:00
Pontus Oldberg 59fb3fbbd6
Merge branch 'adafruit:main' into main 2022-09-01 10:35:13 +02:00
Lee Atkinson 04af01a672 Pin Validation fixed/readmultiple return fixed 2022-08-27 14:47:12 -04:00
Jeff Epler ebd58155f2 bump pico-sdk to 1.4.0 2022-08-26 09:54:16 -05:00
Lee Atkinson 6fd08483e2 Tidying code for PR/ Minor Issues 2022-08-24 17:41:51 -04:00