Skip to content

Commit f68c789

Browse files
committed
Use new QSPI GPIO support in SDK
Removes the extra QSPI GPIO functions from the example, now just uses stdio
1 parent 56f5ca9 commit f68c789

2 files changed

Lines changed: 12 additions & 45 deletions

File tree

‎bootloaders/uart/CMakeLists.txt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ add_executable(uart_binary
2626
# pull in common dependencies
2727
target_link_libraries(uart_binary pico_stdlib)
2828

29+
# use the QSPI SD2 and SD3 pins as the default UART TX and RX (UART0), which are the same pins as the ROM UART bootloader
30+
target_compile_definitions(uart_binary PRIVATE
31+
PICO_SUPPORT_QSPI_GPIOS=1
32+
PICO_DEFAULT_UART=0
33+
PICO_DEFAULT_UART_TX_PIN=QSPI_GPIO_SD2
34+
PICO_DEFAULT_UART_RX_PIN=QSPI_GPIO_SD3
35+
PICO_DEFAULT_UART_BAUD_RATE=1000000
36+
)
37+
2938
pico_set_binary_type(uart_binary no_flash)
3039

3140
# package uf2 in flash

‎bootloaders/uart/uart_binary.c‎

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

7+
#include <stdio.h>
78
#include "pico/stdlib.h"
8-
#include "hardware/uart.h"
9-
#include "hardware/structs/pads_qspi.h"
10-
#include "hardware/structs/io_qspi.h"
119

1210
#ifndef LED_DELAY_MS
1311
#define LED_DELAY_MS 500
@@ -31,53 +29,13 @@ void pico_set_led(bool led_on) {
3129
#endif
3230
}
3331

34-
enum qspi_gpio {
35-
// arbitrarily choose PAD register bank to set the order
36-
QSPI_GPIO_SCLK = 0,
37-
QSPI_GPIO_SD0 = 1,
38-
QSPI_GPIO_SD1 = 2,
39-
QSPI_GPIO_SD2 = 3,
40-
QSPI_GPIO_SD3 = 4,
41-
QSPI_GPIO_SS = 5,
42-
};
43-
44-
// curiously the IO and PAD register banks for the QSPI GPIOs are not in the same order
45-
// This look up table will map the PAD offset to the IO offset for the same pin
46-
const uint QSPI_GPIO_PAD_TO_IO_OFFSET[] = {
47-
0, // SCLK
48-
2, // SD0
49-
3, // SD1
50-
4, // SD2
51-
5, // SD3
52-
1, // SS
53-
};
54-
55-
// Set function for QSPI GPIO pin
56-
void qspi_gpio_set_function(enum qspi_gpio gpio, gpio_function1_t fn) {
57-
// Set input enable on, output disable off
58-
hw_write_masked(&pads_qspi_hw->io[gpio],
59-
PADS_QSPI_GPIO_QSPI_SD2_IE_BITS,
60-
PADS_QSPI_GPIO_QSPI_SD2_IE_BITS | PADS_QSPI_GPIO_QSPI_SD2_OD_BITS
61-
);
62-
// Zero all fields apart from fsel; we want this IO to do what the peripheral tells it.
63-
// This doesn't affect e.g. pullup/pulldown, as these are in pad controls.
64-
io_qspi_hw->io[QSPI_GPIO_PAD_TO_IO_OFFSET[gpio]].ctrl = fn << IO_QSPI_GPIO_QSPI_SD2_CTRL_FUNCSEL_LSB;
65-
66-
// Remove pad isolation now that the correct peripheral is in control of the pad
67-
hw_clear_bits(&pads_qspi_hw->io[gpio], PADS_QSPI_GPIO_QSPI_SD2_ISO_BITS);
68-
}
69-
7032
int main() {
7133
pico_led_init();
7234

73-
// SD2 is UART0 TX, SD3 is UART0 RX (same as the ROM UART bootloader)
74-
qspi_gpio_set_function(QSPI_GPIO_SD2, GPIO_FUNC1_UART_AUX);
75-
qspi_gpio_set_function(QSPI_GPIO_SD3, GPIO_FUNC1_UART_AUX);
76-
77-
uart_init(uart0, 1000000);
35+
stdio_init_all();
7836

7937
while (true) {
80-
uart_puts(uart0, "Hello, world\n");
38+
printf("Hello, world\n");
8139
pico_set_led(true);
8240
sleep_ms(LED_DELAY_MS);
8341
pico_set_led(false);

0 commit comments

Comments
 (0)