I tried the last Pico SDK, and tried to make it run the blinky (hello world" example.
In that example, the speed is set to 9600 baud. But it seems to spanw 115.200 nonetheless, over the UART pins. I created the project with the new VSCode plugin.
Build file (generated by the plugin):
# Generated Cmake Pico project file cmake_minimum_required(VERSION 3.13) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Initialise pico_sdk from installed location # (note this can come from environment, CMake cache etc) # == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work == if(WIN32) set(USERHOME $ENV{USERPROFILE}) else() set(USERHOME $ENV{HOME}) endif() set(sdkVersion 2.0.0) set(toolchainVersion 13_2_Rel1) set(picotoolVersion 2.0.0) include(${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) # ==================================================================================== set(PICO_BOARD pico CACHE STRING "Board type") # Pull in Raspberry Pi Pico SDK (must be before project) include(pico_sdk_import.cmake) project(blinky C CXX ASM) # Initialise the Raspberry Pi Pico SDK pico_sdk_init() # Add executable. Default name is the project name, version 0.1 add_executable(blinky blinky.c ) pico_set_program_name(blinky "blinky") pico_set_program_version(blinky "0.1") # Modify the below lines to enable/disable output over UART/USB pico_enable_stdio_uart(blinky 1) pico_enable_stdio_usb(blinky 0) # Add the standard library to the build target_link_libraries(blinky pico_stdlib) # Add the standard include files to the build target_include_directories(blinky PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required ) pico_add_extra_outputs(blinky)
Source file (also generated by the plugin):
#include <stdio.h> #include "pico/stdlib.h" #include "hardware/uart.h" #include "hardware/gpio.h" #include "hardware/divider.h" // UART defines // By default the stdout UART is `uart0`, so we will use the second one #define UART_ID uart1 #define BAUD_RATE 9600 // Use pins 4 and 5 for UART1 // Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments #define UART_TX_PIN 4 #define UART_RX_PIN 5 // GPIO defines // Example uses GPIO 2 #define GPIO 2 int main() { stdio_init_all(); // Set up our UART uart_init(UART_ID, BAUD_RATE); // Set the TX and RX pins by using the function select on the GPIO // Set datasheet for more information on function select gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART); gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART); // For more examples of UART use see https://github.com/raspberrypi/pico-examples/tree/master/uart // GPIO initialisation. // We will make this GPIO an input, and pull it up by default gpio_init(GPIO); gpio_set_dir(GPIO, GPIO_IN); gpio_pull_up(GPIO); // See https://github.com/raspberrypi/pico-examples/tree/master/gpio for other gpio examples, including using interrupts // Example of using the HW divider. The pico_divider library provides a more user friendly set of APIs // over the divider (and support for 64 bit divides), and of course by default regular C language integer // divisions are redirected thru that library, meaning you can just use C level `/` and `%` operators and // gain the benefits of the fast hardware divider. int32_t dividend = 123456; int32_t divisor = -321; // This is the recommended signed fast divider for general use. divmod_result_t result = hw_divider_divmod_s32(dividend, divisor); printf("%d/%d = %d remainder %d\n", dividend, divisor, to_quotient_s32(result), to_remainder_s32(result)); // This is the recommended unsigned fast divider for general use. int32_t udividend = 123456; int32_t udivisor = 321; divmod_result_t uresult = hw_divider_divmod_u32(udividend, udivisor); printf("%d/%d = %d remainder %d\n", udividend, udivisor, to_quotient_u32(uresult), to_remainder_u32(uresult)); // See https://github.com/raspberrypi/pico-examples/tree/master/divider for more complex use while (true) { printf("Hello, world!\n"); sleep_ms(1000); } }
If I use a TTL-to-USB bridge, it generates garble at 9600, readable data at 115200...
115200 baud:
9600 baud:
I'm using a Pico RP2040, SDK 2.0.0, GCC 13.2.1