Skip to content

Commit 1ccfe90

Browse files
authored
Merge branch 'develop' into patch-3
2 parents 65e1be7 + c8befdf commit 1ccfe90

File tree

24 files changed

+1058
-17
lines changed

24 files changed

+1058
-17
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# Raspberry Pi Pico SDK Examples
22

3-
By default, the Pico SDK targets builds for RP2040 (PICO_PLATFORM=rp2040). To build for RP2350 instead, pass
4-
`-DPICO_PLATFORM=rp2350` to CMake (or `-DPICO_PLATFORM=rp2350-riscv` for RISC-V). Alternatively, in many cases, you can rely
5-
on the board configuration to set the platform for you. For example, passing `-DPICO_BOARD=pico2` will automatically select RP2350.
3+
## Getting started
64

7-
Most, but not all examples, currently work on RP2350 however you should be able to do a full build with any of the above platforms (PICO_PLATFORM=host however currently fails on some examples)
5+
See [Getting Started with the Raspberry Pi Pico](https://rptl.io/pico-get-started) and the README in the [pico-sdk](https://github.com/raspberrypi/pico-sdk) for information
6+
on getting up and running.
87

9-
For RISC-V compilation, you should take a compiler from here: https://www.embecosm.com/resources/tool-chain-downloads/#riscv-stable
8+
##### Notes on different boards and platforms (RP2040 / RP2350)
109

10+
The majority of examples are applicable to both RP2040 and RP2350 based boards,
11+
however certain examples that use chip-specific functionality will only build on that platform.
12+
Similarly, Wi-Fi and Bluetooth examples will only build on a board that includes Wi-Fi and Bluetooth support.
1113

12-
## Getting started
14+
Platform and board information are passed to the CMake build via the `PICO_PLATFORM` and `PICO_BOARD` variables.
15+
For more information see the "Platform and Board Configuration" chapter of
16+
the [Raspberry Pi Pico-series C/C++ SDK](https://rptl.io/pico-c-sdk) book
1317

14-
See [Getting Started with the Raspberry Pi Pico](https://rptl.io/pico-get-started) and the README in the [pico-sdk](https://github.com/raspberrypi/pico-sdk) for information
15-
on getting up and running.
18+
Information on which examples are not being built is output during the CMake configuration step.
1619

1720
### First Examples
1821

@@ -187,6 +190,7 @@ App|Description
187190
[picow_httpd](pico_w/wifi/httpd) | Runs a LWIP HTTP server test app
188191
[picow_http_client](pico_w/wifi/http_client) | Demonstrates how to make http and https requests
189192
[picow_http_client_verify](pico_w/wifi/http_client) | Demonstrates how to make a https request with server authentication
193+
[picow_mqtt_client](pico_w/wifi/mqtt) | Demonstrates how to implement an MQTT client application
190194

191195
#### FreeRTOS examples
192196

@@ -426,6 +430,14 @@ App|Description
426430
---|---
427431
[dev_lowlevel](usb/device/dev_lowlevel) | A USB Bulk loopback implemented with direct access to the USB hardware (no TinyUSB)
428432

433+
#### Custom CDC with SDK stdio
434+
435+
This example demonstrates how to use the TinyUSB CDC device library to create two USB serial ports, and assign one of them to the SDK for stdio.
436+
437+
App|Description
438+
---|---
439+
[dev_cdc](usb/device/dev_cdc) | A USB CDC device example with two serial ports, one of which is used for stdio. The example exposes two serial ports over USB to the host. The first port is used for stdio, and the second port is used for a simple echo loopback. You can connect to the second port and send some characters, and they will be echoed back on the first port while you will receive a "OK\r\n" message on the second port indicating that the data was received.
440+
429441
### USB Host
430442

431443
All the USB host examples come directly from the TinyUSB host examples directory [here](https://github.com/hathach/tinyusb/tree/master/examples/host).

blink_simple/blink_simple.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#define LED_DELAY_MS 250
1111
#endif
1212

13+
#ifndef PICO_DEFAULT_LED_PIN
14+
#warning blink_simple example requires a board with a regular LED
15+
#endif
16+
1317
// Initialize the GPIO for the LED
1418
void pico_led_init(void) {
1519
#ifdef PICO_DEFAULT_LED_PIN

i2c/lis3dh_i2c/lis3dh_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
const int ADDRESS = 0x18;
2828
const uint8_t CTRL_REG_1 = 0x20;
2929
const uint8_t CTRL_REG_4 = 0x23;
30-
const uint8_t TEMP_CFG_REG = 0xC0;
30+
const uint8_t TEMP_CFG_REG = 0x1F;
3131

3232
#ifdef i2c_default
3333

interp/hello_interp/hello_interp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void texture_mapping_setup(uint8_t *texture, uint texture_width_bits, uint textu
215215
uint uv_fractional_bits) {
216216
interp_config cfg = interp_default_config();
217217
// set add_raw flag to use raw (un-shifted and un-masked) lane accumulator value when adding
218-
// it to the the lane base to make the lane result
218+
// it to the lane base to make the lane result
219219
interp_config_set_add_raw(&cfg, true);
220220
interp_config_set_shift(&cfg, uv_fractional_bits);
221221
interp_config_set_mask(&cfg, 0, texture_width_bits - 1);
@@ -288,4 +288,4 @@ int main() {
288288
texture_mapping();
289289

290290
return 0;
291-
}
291+
}

multicore/multicore_runner/multicore_runner.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212

1313
#define FLAG_VALUE 123
1414

15+
typedef int32_t (*func_ptr_t)(int32_t);
16+
1517
void core1_entry() {
1618
while (1) {
1719
// Function pointer is passed to us via the FIFO
1820
// We have one incoming int32_t as a parameter, and will provide an
1921
// int32_t return value by simply pushing it back on the FIFO
2022
// which also indicates the result is ready.
21-
int32_t (*func)() = (int32_t(*)()) multicore_fifo_pop_blocking();
23+
func_ptr_t func = (func_ptr_t) multicore_fifo_pop_blocking();
2224
int32_t p = multicore_fifo_pop_blocking();
23-
int32_t result = (*func)(p);
25+
int32_t result = func(p);
2426
multicore_fifo_push_blocking(result);
2527
}
2628
}

pico_w/wifi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ else()
1818
add_subdirectory_exclude_platforms(tcp_server)
1919
add_subdirectory_exclude_platforms(udp_beacon)
2020
add_subdirectory_exclude_platforms(http_client)
21+
add_subdirectory_exclude_platforms(mqtt)
2122

2223
if (NOT PICO_MBEDTLS_PATH)
2324
message("Skipping tls examples as PICO_MBEDTLS_PATH is not defined")

pico_w/wifi/access_point/picow_access_point.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,17 @@ int main() {
306306

307307
cyw43_arch_enable_ap_mode(ap_name, password, CYW43_AUTH_WPA2_AES_PSK);
308308

309+
#if LWIP_IPV6
310+
#define IP(x) ((x).u_addr.ip4)
311+
#else
312+
#define IP(x) (x)
313+
#endif
314+
309315
ip4_addr_t mask;
310-
IP4_ADDR(ip_2_ip4(&state->gw), 192, 168, 4, 1);
311-
IP4_ADDR(ip_2_ip4(&mask), 255, 255, 255, 0);
316+
IP(state->gw).addr = PP_HTONL(CYW43_DEFAULT_IP_AP_ADDRESS);
317+
IP(mask).addr = PP_HTONL(CYW43_DEFAULT_IP_MASK);
318+
319+
#undef IP
312320

313321
// Start the dhcp server
314322
dhcp_server_t dhcp_server;

pico_w/wifi/lwipopts_examples_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#define MEM_LIBC_MALLOC 0
2121
#endif
2222
#define MEM_ALIGNMENT 4
23+
#ifndef MEM_SIZE
2324
#define MEM_SIZE 4000
25+
#endif
2426
#define MEMP_NUM_TCP_SEG 32
2527
#define MEMP_NUM_ARP_QUEUE 10
2628
#define PBUF_POOL_SIZE 24

pico_w/wifi/mbedtls_config_examples_common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,7 @@
6868
#define MBEDTLS_PEM_PARSE_C
6969
#define MBEDTLS_BASE64_C
7070

71-
#endif
71+
// The following significantly speeds up mbedtls due to NIST optimizations.
72+
#define MBEDTLS_ECP_NIST_OPTIM
73+
74+
#endif

pico_w/wifi/mqtt/CMakeLists.txt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Define the host name of the MQTT server in an environment variable or pass it to cmake,
2+
# e.g. cmake -DMQTT_SERVER=myserver ..
3+
4+
if (DEFINED ENV{MQTT_SERVER} AND (NOT MQTT_SERVER))
5+
set(MQTT_SERVER $ENV{MQTT_SERVER})
6+
message("Using MQTT_SERVER from environment ('${MQTT_SERVER}')")
7+
endif()
8+
if (NOT MQTT_SERVER)
9+
message("Skipping MQTT example as MQTT_SERVER is not defined")
10+
return()
11+
endif()
12+
# Define the name of an MQTT broker/server to enable this example
13+
set(MQTT_SERVER "${MQTT_SERVER}" CACHE INTERNAL "MQTT server for examples")
14+
15+
if (DEFINED ENV{MQTT_USERNAME} AND (NOT MQTT_USERNAME))
16+
set(MQTT_USERNAME $ENV{MQTT_USERNAME})
17+
message("Using MQTT_USERNAME from environment ('${MQTT_USERNAME}')")
18+
endif()
19+
set(MQTT_USERNAME "${MQTT_USERNAME}" CACHE INTERNAL "MQTT user name for examples")
20+
if (DEFINED ENV{MQTT_PASSWORD} AND (NOT MQTT_PASSWORD))
21+
set(MQTT_PASSWORD $ENV{MQTT_PASSWORD})
22+
message("Using MQTT_PASSWORD from environment")
23+
endif()
24+
set(MQTT_PASSWORD "${MQTT_PASSWORD}" CACHE INTERNAL "MQTT password for examples")
25+
26+
# Set path to the certificate include file
27+
if (NOT MQTT_CERT_PATH)
28+
set(MQTT_CERT_PATH ${CMAKE_CURRENT_LIST_DIR}/certs/${MQTT_SERVER})
29+
endif()
30+
31+
# Set the name of the certificate include file
32+
if (NOT MQTT_CERT_INC)
33+
set(MQTT_CERT_INC mqtt_client.inc)
34+
endif()
35+
36+
set(TARGET_NAME picow_mqtt_client)
37+
add_executable(${TARGET_NAME}
38+
mqtt_client.c
39+
)
40+
target_link_libraries(${TARGET_NAME}
41+
pico_stdlib
42+
hardware_adc
43+
pico_cyw43_arch_lwip_threadsafe_background
44+
pico_lwip_mqtt
45+
pico_mbedtls
46+
pico_lwip_mbedtls
47+
)
48+
target_include_directories(${TARGET_NAME} PRIVATE
49+
${CMAKE_CURRENT_LIST_DIR}
50+
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
51+
)
52+
target_compile_definitions(${TARGET_NAME} PRIVATE
53+
WIFI_SSID=\"${WIFI_SSID}\"
54+
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
55+
MQTT_SERVER=\"${MQTT_SERVER}\"
56+
)
57+
if (EXISTS "${MQTT_CERT_PATH}/${MQTT_CERT_INC}")
58+
target_compile_definitions(${TARGET_NAME} PRIVATE
59+
MQTT_CERT_INC=\"${MQTT_CERT_INC}\" # contains the tls certificates for MQTT_SERVER needed by the client
60+
ALTCP_MBEDTLS_AUTHMODE=MBEDTLS_SSL_VERIFY_REQUIRED
61+
)
62+
target_include_directories(${TARGET_NAME} PRIVATE
63+
${MQTT_CERT_PATH}
64+
)
65+
endif()
66+
if (MQTT_USERNAME AND MQTT_PASSWORD)
67+
target_compile_definitions(${TARGET_NAME} PRIVATE
68+
MQTT_USERNAME=\"${MQTT_USERNAME}\"
69+
MQTT_PASSWORD=\"${MQTT_PASSWORD}\"
70+
)
71+
endif()
72+
pico_add_extra_outputs(${TARGET_NAME})
73+
74+
# Ignore warnings from lwip code
75+
set_source_files_properties(
76+
${PICO_LWIP_PATH}/src/apps/altcp_tls/altcp_tls_mbedtls.c
77+
PROPERTIES
78+
COMPILE_OPTIONS "-Wno-unused-result"
79+
)

0 commit comments

Comments
 (0)