Skip to content

Commit 346fff2

Browse files
committed
cyw43 basic gpio support, hwaddr in boot_out
1 parent 22b04ae commit 346fff2

File tree

35 files changed

+848
-32
lines changed

35 files changed

+848
-32
lines changed

locale/circuitpython.pot

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ msgstr ""
9595
msgid "%q failure: %d"
9696
msgstr ""
9797

98+
#: shared-bindings/digitalio/DigitalInOut.c
9899
#: shared-bindings/microcontroller/Pin.c
99100
msgid "%q in use"
100101
msgstr ""
@@ -916,6 +917,10 @@ msgstr ""
916917
msgid "Expected a %q"
917918
msgstr ""
918919

920+
#: ports/raspberrypi/bindings/cyw43/__init__.c
921+
msgid "Expected a %q or %q"
922+
msgstr ""
923+
919924
#: shared-bindings/alarm/__init__.c
920925
msgid "Expected an %q"
921926
msgstr ""
@@ -1177,7 +1182,7 @@ msgstr ""
11771182
msgid "Internal watchdog timer expired."
11781183
msgstr ""
11791184

1180-
#: py/argcheck.c
1185+
#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c
11811186
msgid "Invalid %q"
11821187
msgstr ""
11831188

main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
784784
mp_printf(&mp_plat_print, "%02X", raw_id[i]);
785785
}
786786
mp_printf(&mp_plat_print, "\n");
787+
port_boot_info();
787788
#endif
788789

789790
bool found_boot = maybe_run_list(boot_py_filenames);

ports/atmel-samd/common-hal/digitalio/DigitalInOut.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
6666
self->pin = NULL;
6767
}
6868

69-
void common_hal_digitalio_digitalinout_switch_to_input(
69+
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
7070
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
7171
self->output = false;
7272
// This also sets direction to input.
7373
common_hal_digitalio_digitalinout_set_pull(self, pull);
74+
return DIGITALINOUT_OK;
7475
}
7576

7677
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@@ -151,7 +152,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
151152
}
152153
}
153154

154-
void common_hal_digitalio_digitalinout_set_pull(
155+
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
155156
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
156157
enum gpio_pull_mode asf_pull = GPIO_PULL_OFF;
157158
switch (pull) {
@@ -168,6 +169,7 @@ void common_hal_digitalio_digitalinout_set_pull(
168169
// Must set pull after setting direction.
169170
gpio_set_pin_direction(self->pin->number, GPIO_DIRECTION_IN);
170171
gpio_set_pin_pull_mode(self->pin->number, asf_pull);
172+
return DIGITALINOUT_OK;
171173
}
172174

173175
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

ports/broadcom/common-hal/digitalio/DigitalInOut.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
6363
self->pin = NULL;
6464
}
6565

66-
void common_hal_digitalio_digitalinout_switch_to_input(
66+
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
6767
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
6868
self->output = false;
6969
// This also sets direction to input.
7070
common_hal_digitalio_digitalinout_set_pull(self, pull);
71+
return DIGITALINOUT_OK;
7172
}
7273

7374
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@@ -134,7 +135,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
134135
}
135136
}
136137

137-
void common_hal_digitalio_digitalinout_set_pull(
138+
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
138139
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
139140
const uint8_t pin = self->pin->number;
140141
BP_PULL_Enum bp_pull = BP_PULL_NONE;
@@ -144,6 +145,7 @@ void common_hal_digitalio_digitalinout_set_pull(
144145
bp_pull = BP_PULL_DOWN;
145146
}
146147
gpio_set_pull(pin, bp_pull);
148+
return DIGITALINOUT_OK;
147149
}
148150

149151
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

ports/cxd56/common-hal/digitalio/DigitalInOut.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *se
6464
return self->pin == NULL;
6565
}
6666

67-
void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
67+
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
6868
self->input = true;
6969
self->pull = pull;
7070
board_gpio_write(self->pin->number, -1);
7171
board_gpio_config(self->pin->number, 0, true, true, pull);
72+
return DIGITALINOUT_OK;
7273
}
7374

7475
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode) {
@@ -124,10 +125,11 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitali
124125
return self->open_drain ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL;
125126
}
126127

127-
void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
128+
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
128129
self->pull = pull;
129130
board_gpio_write(self->pin->number, -1);
130131
board_gpio_config(self->pin->number, 0, true, true, pull);
132+
return DIGITALINOUT_OK;
131133
}
132134

133135
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t *self) {

ports/espressif/common-hal/digitalio/DigitalInOut.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
8282
self->pin = NULL;
8383
}
8484

85-
void common_hal_digitalio_digitalinout_switch_to_input(
85+
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
8686
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
8787
common_hal_digitalio_digitalinout_set_pull(self, pull);
8888
gpio_set_direction(self->pin->number, GPIO_MODE_INPUT);
89+
return DIGITALINOUT_OK;
8990
}
9091

9192
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@@ -140,7 +141,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
140141
return DRIVE_MODE_PUSH_PULL;
141142
}
142143

143-
void common_hal_digitalio_digitalinout_set_pull(
144+
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
144145
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
145146
gpio_num_t number = self->pin->number;
146147
gpio_pullup_dis(number);
@@ -150,6 +151,7 @@ void common_hal_digitalio_digitalinout_set_pull(
150151
} else if (pull == PULL_DOWN) {
151152
gpio_pulldown_en(number);
152153
}
154+
return DIGITALINOUT_OK;
153155
}
154156

155157
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

ports/litex/common-hal/digitalio/DigitalInOut.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
5858
self->pin = NULL;
5959
}
6060

61-
void common_hal_digitalio_digitalinout_switch_to_input(
61+
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
6262
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
6363
(void)pull;
6464
touch_oe_write(touch_oe_read() & ~(1 << self->pin->number));
65+
return DIGITALINOUT_OK;
6566
}
6667

6768
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@@ -111,10 +112,11 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
111112
}
112113
}
113114

114-
void common_hal_digitalio_digitalinout_set_pull(
115+
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
115116
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
116117
(void)self;
117118
(void)pull;
119+
return DIGITALINOUT_OK;
118120
}
119121

120122
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
8888
self->pin = NULL;
8989
}
9090

91-
void common_hal_digitalio_digitalinout_switch_to_input(
91+
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
9292
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
9393
self->output = false;
9494

9595
// This also sets direction to input.
9696
common_hal_digitalio_digitalinout_set_pull(self, pull);
97+
return DIGITALINOUT_OK;
9798
}
9899

99100
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@@ -150,14 +151,15 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
150151
}
151152
}
152153

153-
void common_hal_digitalio_digitalinout_set_pull(
154+
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
154155
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
155156
self->pull = pull;
156157

157158
pin_config(self->pin, self->open_drain, self->pull);
158159

159160
const gpio_pin_config_t config = { kGPIO_DigitalInput, 0, kGPIO_NoIntmode };
160161
GPIO_PinInit(self->pin->gpio, self->pin->number, &config);
162+
return DIGITALINOUT_OK;
161163
}
162164

163165
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

ports/nrf/common-hal/digitalio/DigitalInOut.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
5959
self->pin = NULL;
6060
}
6161

62-
void common_hal_digitalio_digitalinout_switch_to_input(
62+
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(
6363
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
6464
nrf_gpio_cfg_input(self->pin->number, NRF_GPIO_PIN_NOPULL);
6565
common_hal_digitalio_digitalinout_set_pull(self, pull);
66+
return DIGITALINOUT_OK;
6667
}
6768

6869
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
@@ -120,7 +121,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
120121
}
121122
}
122123

123-
void common_hal_digitalio_digitalinout_set_pull(
124+
digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(
124125
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
125126
nrf_gpio_pin_pull_t hal_pull = NRF_GPIO_PIN_NOPULL;
126127

@@ -137,6 +138,7 @@ void common_hal_digitalio_digitalinout_set_pull(
137138
}
138139

139140
nrf_gpio_cfg_input(self->pin->number, hal_pull);
141+
return DIGITALINOUT_OK;
140142
}
141143

142144
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(

ports/raspberrypi/Makefile

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,71 @@ CROSS_COMPILE = arm-none-eabi-
5757

5858
HAL_DIR=hal/$(MCU_SERIES)
5959

60+
ifeq ($(CIRCUITPY_CYW43),1)
61+
INC_CYW43 := \
62+
-isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \
63+
-isystem sdk/lib/cyw43-driver/src \
64+
-isystem sdk/lib/cyw43-driver/firmware \
65+
66+
CFLAGS_CYW43 := -DCYW43_LWIP=0 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25
67+
SRC_SDK_CYW43 := \
68+
lib/cyw43-driver/src/cyw43_ctrl.c \
69+
lib/cyw43-driver/src/cyw43_ll.c \
70+
lib/cyw43-driver/src/cyw43_lwip.c \
71+
lib/cyw43-driver/src/cyw43_stats.c \
72+
src/common/pico_sync/sem.c \
73+
src/rp2_common/pico_cyw43_arch/cyw43_arch.c \
74+
src/rp2_common/pico_cyw43_arch/cyw43_arch_threadsafe_background.c \
75+
src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c \
76+
77+
SRC_CYW43 := $(wildcard bindings/cyw43/*.c)
78+
79+
PIOASM = $(BUILD)/sdk/pioasm/pioasm
80+
.PHONY: PioasmBuild
81+
PioasmBuild: $(PIOASM)
82+
$(PIOASM):
83+
$(Q)cmake -S sdk -B $(BUILD)/sdk
84+
$(Q)make -C $(BUILD)/sdk PioasmBuild
85+
86+
$(BUILD)/cyw43_bus_pio_spi.pio.h: sdk/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.pio $(PIOASM)
87+
$(Q)$(PIOASM) -o c-sdk $< $@
88+
$(BUILD)/sdk/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.o: $(BUILD)/cyw43_bus_pio_spi.pio.h
89+
90+
CYW43_FIRMWARE_BIN = 43439A0-7.95.49.00.combined
91+
92+
$(BUILD)/cyw43_resource.o: sdk/lib/cyw43-driver/firmware/$(CYW43_FIRMWARE_BIN)
93+
$(Q)$(OBJCOPY) -I binary -O elf32-littlearm -B arm \
94+
--readonly-text \
95+
--rename-section .data=.big_const,contents,alloc,load,readonly,data \
96+
--redefine-sym _binary_sdk_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_start=fw_43439A0_7_95_49_00_start \
97+
--redefine-sym _binary_sdk_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_size=fw_43439A0_7_95_49_00_size \
98+
--redefine-sym _binary_sdk_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_end=fw_43439A0_7_95_49_00_end \
99+
$< $@
100+
OBJ_CYW43 := $(BUILD)/cyw43_resource.o
101+
# need to do the equivalent of this in cmake
102+
### # cyw43_resource.o contains the WiFi and BT firmware as a binary blob
103+
### add_custom_command(
104+
### OUTPUT ${CYW43_FIRMWARE_OBJ}
105+
### DEPENDS ${PICO_CYW43_DRIVER_PATH}/firmware/${CYW43_FIRMWARE_BIN}
106+
### WORKING_DIRECTORY ${PICO_CYW43_DRIVER_PATH}/firmware
107+
### COMMAND ${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm
108+
### --readonly-text
109+
### --rename-section .data=${RESOURCE_SECNAME},${RESOURCE_SECFLAGS}
110+
### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_start=${CYW43_FIRMWARE_PRETTY}_start
111+
### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_end=${CYW43_FIRMWARE_PRETTY}_end
112+
### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_size=${CYW43_FIRMWARE_PRETTY}_size
113+
### ${CYW43_FIRMWARE_BIN} ${CYW43_FIRMWARE_OBJ}
114+
### )
115+
###
116+
else
117+
$(error y u no y fi)
118+
INC_CYW43 :=
119+
CFLAGS_CYW43 :=
120+
SRC_SDK_CYW43 :=
121+
SRC_CYW43 :=
122+
OBJ_CYW43 :=
123+
endif
124+
60125
INC += \
61126
-I. \
62127
-I../.. \
@@ -102,6 +167,7 @@ INC += \
102167
-isystem sdk/src/rp2_common/pico_runtime/printf/include/ \
103168
-isystem sdk/src/rp2_common/pico_bootrom/include/ \
104169
-isystem sdk/src/rp2_common/pico_unique_id/include/ \
170+
$(INC_CYW43) \
105171
-Isdk_config \
106172
-I../../lib/tinyusb/src \
107173
-I../../supervisor/shared/usb \
@@ -116,6 +182,9 @@ CFLAGS += -DTUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX=1 -DCFG_TUSB_MCU=OPT_MCU_R
116182
# option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk
117183
CFLAGS += $(OPTIMIZATION_FLAGS)
118184

185+
# flags specific to wifi / cyw43
186+
187+
CFLAGS += $(CFLAGS_CYW43)
119188
#Debugging/Optimization
120189
ifeq ($(DEBUG), 1)
121190
CFLAGS += -ggdb3 -O3
@@ -133,7 +202,7 @@ endif
133202
# Remove -Wno-stringop-overflow after we can test with CI's GCC 10. Mac's looks weird.
134203
DISABLE_WARNINGS = -Wno-stringop-overflow -Wno-unused-function -Wno-unused-variable -Wno-strict-overflow -Wno-cast-align -Wno-strict-prototypes -Wno-nested-externs -Wno-double-promotion -Wno-sign-compare
135204

136-
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes
205+
CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes -Wno-error=unused-result
137206

138207
CFLAGS += \
139208
-march=armv6-m \
@@ -186,6 +255,7 @@ SRC_SDK := \
186255
src/rp2_common/pico_runtime/runtime.c \
187256
src/rp2_common/pico_stdio/stdio.c \
188257
src/rp2_common/pico_unique_id/unique_id.c \
258+
$(SRC_SDK_CYW43) \
189259

190260
SRC_SDK := $(addprefix sdk/, $(SRC_SDK))
191261
$(patsubst %.c,$(BUILD)/%.o,$(SRC_SDK)): CFLAGS += -Wno-missing-prototypes -Wno-undef
@@ -205,6 +275,7 @@ SRC_C += \
205275
lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c \
206276
lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c \
207277
mphalport.c \
278+
$(SRC_CYW43) \
208279

209280
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
210281
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
@@ -244,6 +315,7 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
244315
OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o))
245316
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
246317
OBJ += $(BUILD)/boot2_padded_checksummed.o
318+
OBJ += $(OBJ_CYW43)
247319

248320
$(BUILD)/boot2_padded_checksummed.o: $(BUILD)/boot2_padded_checksummed.S
249321
$(STEPECHO) "CC $<"

0 commit comments

Comments
 (0)