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-
7032int 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