Giter Club home page Giter Club logo

pico-examples's People

Contributors

agento2 avatar akhodeir avatar andygpz11 avatar aslampr07 avatar dp111 avatar fivdi avatar hamuelbones avatar hathach avatar henrygab avatar jamesh65 avatar josefwegner avatar julienbernard3383279 avatar kilograham avatar kripton avatar kromych avatar liamfraser avatar lurch avatar michaelstoops avatar mjcross avatar mrgreensworkshop avatar mucahitkurtlar avatar pdaxrom avatar peterharperuk avatar pmarques-dev avatar spegs21 avatar tommessick avatar urish avatar wenzel-hoffman avatar wren6991 avatar yotabits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pico-examples's Issues

Misleading Typo in Code Comment

pio/uart_rx/uart_rx.pio, lines 74-75:

// Shift to right, autopull disabled
sm_config_set_in_shift(&c, true, false, 32);

Maybe this should read "autopush" instead of of "autopull"?

USB stdio Read from host

Hello,

There is an stdio example which shows how to print text to a host using printf; however I can't seem to figure out how to read data is that is being sent by the host to the RP2040?

Perhaps this is unimplemented so far. If it isn't, I think there should be an example showing how to do it.

Python SDK can't import array

I updated my pico to use Micropython from rp2-pico-20210202-v1.14.uf2 (newest release as I'm writing) and after doing so some of my test programs stopped working. Im getting an ImportError: no module named 'array'. At first I thought that it was just removed, but now I also can't use rp2.asm_pio() getting similar error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "rp2.py", line 228, in asm_pio
  File "rp2.py", line 36, in __init__
ImportError: no module named 'array'

bidirectional hello_world communication

Right now I can't see any examples of the Pico accepting input via serial (whether over USB or not). The examples only send information out via calls to printf(). More complex examples (e.g. USB HID device) do exist, but there is nothing in the middle.

Presumably using fgets or fgetc to read from stdin is the way to go but it would nice to have a canonical example (particularly as so far anything I write regarding accepting input over USB serial seems to repeatedly crash the pico after 4288 seconds - regardless of how fast/slow I send information - and I have no idea if it's a bug in the SDK or me doing something stupid!)

Hub75 example flickering on 64x32 matrix

I slightly modified the hub75 example to work on a 64x32 matrix, but I am noticing considerable flickering on the display. Is this expected?

These are the changes I made:

  • Changed ROWSEL_N_PINS to 4 as it is a 1/16nd scan panel (A-D).
  • Modified WITDTH and HEIGHT to 64 and 32.

Besides the flickering, it mostly works. Images and colors are displayed correctly.
Flickering is very prominent tho, turning multiple consecutive rows on and off.

Is this behaviour expected or is there something I am missing making this work for a smaller display?

Thanks for the thorough examples and documentation, they have been very helpful.

PIO for 4MHz Bus interface

How many nanoseconds pass between the reception of a data from the PIO and the core that has to manage the data? I'd like to know if a Rpi Pico can handle a slow (4MHz) bus interface.

pico-example bus_scan hangs when Grove I2C LCD is connected

I am attempting to run the 'bus_scan' pico-example from the i2c/bus_scan folder with a Grove i2c LCD connected to Pins 6,7 (i2c0) but the scan hangs at line '30'
This is the LCD I am using:
https://wiki.seeedstudio.com/Grove-16x2_LCD_Series/

Ex:

I2C Bus Scan
   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
00 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
10 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
20 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
30 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  

I have an OLED Display which the bus_scan code seems to pick up fine:

I2C Bus Scan
   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
00 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
10 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
20 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
30 .  .  .  .  .  .  .  .  .  .  .  .  @  .  .  .
40 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
50 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
60 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
70 .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
Done.

However, I have a Python script which scans the same bus and it seems to pick-up the Grove LCD addresses without issue:

>>> %Run -c $EDITOR_CONTENT
I2C Scan:
[62, 98, 112]

Is there something I have to set differently for the Grove LCD vs another i2c device for the pico-example bus_scan code?

Pico parallel pio

Can PIO state machines read/write 8+ pins at time? If not, is there available any tip to handle this?
Thanks.

PIO / WS2812 / parallel -- documentation?

First, this is a great example, showing how to implement scatter-gather list DMA functionality on this board, for a real-world scenario.

Would pull requests for documentation be accepted, and if so, what is the preferred format?
(e.g., embedded in source, separate README.md, other?)

For example, I think this directory should have at least a few sections documented:

  1. WS2812B signaling (even if pointing to a section of the SDK)
  2. What the parallel version does (up to 32(30) outputs simultaneously!)
  3. How the data for parallel WS2812B sample is massaged into the bitplane format
  4. How two DMA channels are used to implement scatter-gather support

I've given a strawman starting point for the last item below.

DMA Architecture Summary (click to expand)

This sample implements scatter-gather list based transfers, using two chained DMA channels:

  1. The "main" DMA channel, which transfers a eight (8x) 32-bit values to the state machine. Together, these values contain one byte of data for up to 32 output channels.

  2. The "main" DMA channel is configured to only generate an interrupt when a trigger register is written with a nullptr/zero value. Sweet! Only one interrupt should ever generate, at the end of all transfers:

    channel_config_set_irq_quiet(&channel_config, true);

  3. The "cb" (callback?) DMA channel writes a single 32-bit value to the main DMA channel's configuration register. It uses the third alias, so that writing the updated read address also triggers the start of the main DMA channel.

  4. The interrupt is enabled only for the main DMA channel, using DMA_IRQ_0

    irq_set_exclusive_handler(DMA_IRQ_0, dma_complete_handler);
    dma_channel_set_irq0_enabled(DMA_CHANNEL, true);
    irq_set_enabled(DMA_IRQ_0, true);

Add a USB "dev_lowlevel" device example but using tinyusb

There is a "dev_lowlevel" example but it's a little too low level for my taste. Unless i'm blind the tinyusb README states it does support generic devices with simple in and out endpoints ("- Vendor-specific class support with generic In & Out endpoints. Can be used with MS OS 2.0 compatible descriptor to load winUSB driver without INF file.") but there is no example provided (both by this repo and tinyusb itself).

Would be nice if an example could be added that does the same as "dev_lowlevel" but using tinyusb. Thanks.

Problem with pico-examples/i2c/bus_scan/bus_scan.c ??

Hello all when I compile the code to scan devices on bus. Copy the uf2 file Pico, Pico disappears but it's COM port is not detected by neither computer device manager nor serial port utility. During compilation I also observe this warnning:

bus_scan\bus_scan.c:38:2: warning: #warning i2c/bus_scan example requires a board with I2C pins [-Wcpp]
   38 | #warning i2c/bus_scan example requires a board with I2C pins

These are the contents of my CMakeLists.txt file:

add_executable(i2c_bus_scan
        bus_scan.c
        )

# Pull in our (to be renamed) simple get you started dependencies
target_link_libraries(i2c_bus_scan pico_stdlib hardware_i2c)

# enable usb output, disable uart output
pico_enable_stdio_usb(i2c_bus_scan 1)
pico_enable_stdio_uart(i2c_bus_scan 0)

# create map/bin/hex file etc.
pico_add_extra_outputs(i2c_bus_scan)

# add url via pico_set_program_url
example_auto_set_url(i2c_bus_scan)

My computer gives me this message:
USB Device not Recognized.

But when I burn Hello World program, it works and prints text to Serial port or USB without any problem.

Can anybody suggest me what should I do? Do I need to make any changes in bus_scan.c file? I reckon no changes are required.

flash_range_erase does not work when USB stdio is enabled

Hi, I was trying to erase the internal flash following the example, but it seems that flash_range_erase does not work. The whole program just gets stuck after calling flash_range_erase.

I want to erase out about 1MB area right after the first 1MB on the Pico Pi. Therefore the parameters I passed is flash_range_erase(1048576, 1044480). And 1044480 is indeed a multiple of 4096 (i.e., the sector size), 1044480=255*4096.

My pico-sdk version is 2d5789eca89658a7f0a01e2d6010c0f254605d72.

My CMakeLists.txt is,

cmake_minimum_required(VERSION 3.12)

set(PICO_SDK_PATH "/home/ubuntu/src/pico-sdk")
# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)

project(pico_fs C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# initialize the Pico SDK
pico_sdk_init()

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories("${PICO_SDK_PATH}")
add_executable(pico_test_flash main.c)

target_link_libraries(pico_test_flash
    pico_stdlib
    hardware_flash
)

# enable usb output, disable uart output
pico_enable_stdio_usb(pico_test_flash 1)
pico_enable_stdio_uart(pico_test_flash 0)

# create map/bin/hex file etc.
pico_add_extra_outputs(pico_test_flash)

The main.c file is

#include <stdio.h>
#include <stdlib.h>

#include "pico/stdlib.h"
#include "hardware/flash.h"

// We're going to erase and reprogram a region ~1MB from the start of flash.
// Once done, we can access this at XIP_BASE + 1MB.
#define FLASH_TARGET_OFFSET (1024 * 1024)

int main() {
    stdio_init_all();
    getchar();
    printf("Erasing target region...\n");
    flash_range_erase(FLASH_TARGET_OFFSET, 255 * FLASH_SECTOR_SIZE);
    printf("Done.\n");

    while (true) {
        int ret = getchar_timeout_us(1000 * 1000);
        if (ret != PICO_ERROR_TIMEOUT) {
            break;
        }
        printf("Press any key to exit\n");
    }
}

When I connected my Pico Pi using screen and pressed the enter key, the only output was Erasing target region.... I waited for about 15 minutes, there was still no more output. (Although occasionally the program works, most of the time it just hangs there)

MSVSC error building examples: [build] ninja: error: 'pioasm/pioasm.exe', needed by 'dma/channel_irq

Hi,

I've followed the "Getting started with Raspberry Pi Pico" pdf to the step, however attempting to compile the examples within Microsoft Visual Studio Code produces this error:

[main] Building folder: pico-examples 
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/Anonymous/Documents/Hardware/PiPico/pico-examples/build --config Debug --target all -- -j 6
[build] ninja: error: 'pioasm/pioasm.exe', needed by 'dma/channel_irq/CMakeFiles/dma_channel_irq_pio_serialiser_pio_h', missing and no known rule to make it
[build] Build finished with exit code 1

Configuration error when follow the guide of MS Visual Studio Code setup.

When I open the pico-example folder, the configuration process generate following error. How can I get sdk automatically download there?. It seems same for me when using command line instead of vsc, after type nmake

[main] Configuring folder: pico-examples 
[driver] Removing c:/Users/yuxiong/Documents/GitHub/pico-examples/build/CMakeCache.txt
[driver] Removing c:\Users\yuxiong\Documents\GitHub\pico-examples\build\CMakeFiles
[proc] Executing command: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -Hc:/Users/yuxiong/Documents/GitHub/pico-examples -Bc:/Users/yuxiong/Documents/GitHub/pico-examples/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] Using PICO_SDK_PATH from environment (' ..\..\pico-sdk')
[cmake] CMake Error at pico_sdk_import.cmake:54 (message):
[cmake]   Directory 'C:/Users/yuxiong/Documents/GitHub/pico-examples/build/pico-sdk'
[cmake]   not found
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:4 (include)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!

spi slave examples

Does it support spi slave ? How is the speed? Do you have an example?

Example request RS485 rx

I have many skills but I am completely ignorant about hardware interfaces.
I need to read a RS485 data stream. It's sort of a firehose data stream DATA, Pause, DATA... and I currently use a Pi and a RS485 USB dongle for the read. I sample periodically as I can't just sit on the feed and read every byte. I believe, if I could read the stream, I could move all my specialized management of the data to a Pico. I just need to be able to get those bytes and inter record gaps. ;)

This is not an urgent request, just a nice to have feature.

1 microsecond timer intterupt on pico

i am using pico in one of my project and we want timer interrupt of 1microsecond with periodic. As we know pico can run up to 133MHz clock.
i referred some examples but timer value was higher. Is the following example correct?

`
int main() {
stdio_init_all();
printf("Timer lowlevel!\n");

// Set alarm every 1 microsecond
while (1) {
    alarm_fired = false;
    alarm_in_us(1);
    // Wait for alarm to fire
    while (!alarm_fired);
}

}`

pico-examples/pio/logic_analyser not working for some values of CAPTURE_PIN_COUNT

The logic analyser example does not work when CAPTURE_PIN_COUNT does not divide exactly into 32. This is at odds with the comment in the file logic_analyser.c: "// 1 to 32 pins can be captured."

For example: CAPTURE_PIN_COUNT=4 produces the following correct output:

16: ----____________----____________----____________----____________----____________----____________
17: ------------____------------____------------____------------____------------____------------____
18: ________________________________________________________________________________________________
19: ________________________________________________________________________________________________

However, with CAPTURE_PIN_COUNT=3 the output is:

16: -----------____________________------------___________________------------___________________---
17: _______________----__------____-______________----___-----____--_____________----____----____---
18: ---_______-____------___________--____________-------___________-____________--------___________

This is incorrect - the trace for pins 16,17 and 18 should be identical to the previous example.

The comment could be updated to state that "// 1,2,4,8,16 or 32 pins can be captured." Alternatively the attached file contains a fix that works for all values from 1 to 32.

Change summary:

  • The underlying issue is that the PIO discards bits when a sample overruns the available space in the ISR. To prevent this, push_threshold is set to a multiple of pin_count.
  • The capture_buf size calculation has been updated.
  • Calculation of the word and bit offsets in print_capture_buf() updated.

logic_analyser.c.txt

PIO / WS2812 ... Bug on preprocessor debug disable?

int main() {
//set_sys_clock_48();
stdio_init_all();
puts("WS2812 parallel");
#if PIN_TX != 3
gpio_debug_pins_init();
#endif

First, I'm at a loss trying to understand why this is ever disabled, given that the PICO has dedicated SWD pins. This also isn't checking against PICO_DEFAULT_UART_TX_PIN, PICO_DEFAULT_UART_RX_PIN, or PICO_DEFAULT_LED_PIN ... was it leftover from the FPGA days?

Even if it's OK for the non-parallel, however, it's not correct for this file, since it outputs to 2 consecutive GPIO. PIN_TX is only the first GPIO that the state machines will push output through. Therefore, if PIN_TX is defined as 2, then it would still call gpio_debug_pins_init(), even though GPIO2 and GPIO3 would be getting DMA...

Thoughts appreciated?

PIO WS2812 example - bug in `pattern_fade()`

This bug is found at the start of the function, pattern_fade():

  1. Line 96 sets slow_t to a value that depends on the second function parameter. This makes sense.

    uint slow_t = t / 32;

  2. Line 97, however, sets slow_t to a fixed, constant value of 8 (variable level is defined at line 88, never modified).

If I followed it correctly, the current code results in alternately setting all pixels to RGB 0x000000 (black), or setting all pixels to RGB 0x010101. Clearly not the intended behavior.

Most likely, line 97 was intended to be an operator that modified the existing value, such as any of:

    slow_t += level; 
    slow_t -= level; 
    slow_t *= level; 
    slow_t /= level; 
    slow_t <<= level; 
    slow_t >>= level; 

Unfortunately, I am note 100% sure what the intended result was.

My best guess? It's an attempt to add half the potential error, so integer division / masking later makes calculating the error amount easier.

    slow_t += level; // increase provided value by half of (1 << shift)?

@kilograham ... any ideas who would know the intended results here, and might confirm the intended behavior here?

Thanks!

CMake fails to build examples at the command line on Windows

Hi,

Just a heads up. I found that the pico examples weren't building and I needed to add:

set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})

... to the start of the CMakeLists.txt file. Just before where it says "include(pico_sdk_import.cmake)".

Without this line, CMake was not using the PICO_SDK_PATH environment variable, as per section 8.2.3 of the Getting Started with Raspberry Pi Pico document.

Cheers.

Problem connecting WebUSB example

Set up

  • PC OS : Ubuntu 20.04.1
  • Board : RPi Pico
  • Firmware: examples/device/webusb_serial/ , pretty much.
  • Compiler: arm-none-eabi-gcc (15:9-2019-q4-0ubuntu1) 9.2.1 20191025 (release)

Describe the bug

When power the device up, the little Chrome notification opens saying "TinyUSB Device detected. Go to www.tinyusb.org to connect.".

When I click on that the device panics with message:

*** PANIC ***

ep %d %s was already available

emitted from the UART. (If CFG_TUSB_DEBUG is set, it instead prints ep 0 in was already available, see below)

To reproduce

I've created a minimal project at https://github.com/nickzoic/rpi-pico-webusb-example.git
Sorry for the slightly complicated build, there's no hw/bsp/raspberry_pi_pico/board.mk file and I'm not sure how to make one.

  1. Check it out (recursively) and build it with make
  2. Upload firmware.uf2 to board
  3. Click on popup to connect Chrome to https://www.tinyusb.org/examples/webusb-serial/
  4. :-( panic message on UART
  5. Chrome shows message "NetworkError: Unable to set device interface."

Same thing happens if I ignore the popup message and use the 'Connect' button on the webusb-serial page to connect.

Interestingly, if I comment out that panic() call in pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c, everything seems to work perfectly.

Screenshots

Here's a wireshark capture of the device, although I've got to admit the details are a bit beyond me: I hope this is the right thing!

webusb.pcapng.gz

Log

debug-uart.txt

/dev/ttyACM0 missing when running I2C examples

I'm running Arch linux, I have installed the SDK then cloned pico-examples, pico-playground and pico-extras and added them to PATH in my .bashrc

I have also added export PICO_SDK_PATH=/usr/share/pico-sdk to my .bashrc

I create the build directory, cd into it, cmake .. then make and the examples compile

flash_program.uf2 compiles without error, and it runs when I drop it into my Pico, and the LED flashes as expected

hello_usb.uf2 also appears to compile without error, and it also runs when I drop it into my Pico. I can see /dev/ttyACM0 and sudo minicom gives me the expected "Hello, world!" when I point it at /dev/ttyACM0

mpu6050_i2c.uf2, lcd_1602_i2c.uf2 and i2c_bus_scan.uf2 compile with the following warnings, /dev/ttyACM0 is not created and nothing appears to work using a known good MPU6050. I have used a different computer (running Arch again), along with a different known good MPU6050 and a different Pico - same results.

What did I miss or forget to do please?

<snip>

Scanning dependencies of target i2c_bus_scan
[ 55%] Building C object i2c/bus_scan/CMakeFiles/i2c_bus_scan.dir/bus_scan.c.obj
/home/user/GitHub/pico-examples/i2c/bus_scan/bus_scan.c: In function 'main':
/home/user/GitHub/pico-examples/i2c/bus_scan/bus_scan.c:38:2: warning: #warning i2c/bus_scan example requires a board with I2C pins [-Wcpp]
   38 | #warning i2c/bus_scan example requires a board with I2C pins
      |  ^~~~~~~

<snip>

[ 58%] Built target i2c_bus_scan
Scanning dependencies of target lcd_1602_i2c
[ 58%] Building C object i2c/lcd_1602_i2c/CMakeFiles/lcd_1602_i2c.dir/lcd_1602_i2c.c.obj
/home/user/GitHub/pico-examples/i2c/lcd_1602_i2c/lcd_1602_i2c.c: In function 'main':
/home/user/GitHub/pico-examples/i2c/lcd_1602_i2c/lcd_1602_i2c.c:134:6: warning: #warning i2c/lcd_1602_i2c example requires a board with I2C pins [-Wcpp]
  134 |     #warning i2c/lcd_1602_i2c example requires a board with I2C pins
      |      ^~~~~~~

<snip>

[ 61%] Built target lcd_1602_i2c
Scanning dependencies of target mpu6050_i2c
[ 61%] Building C object i2c/mpu6050_i2c/CMakeFiles/mpu6050_i2c.dir/mpu6050_i2c.c.obj
/home/user/GitHub/pico-examples/i2c/mpu6050_i2c/mpu6050_i2c.c: In function 'main':
/home/user/GitHub/pico-examples/i2c/mpu6050_i2c/mpu6050_i2c.c:83:6: warning: #warning i2c/mpu6050_i2c example requires a board with I2C pins [-Wcpp]
   83 |     #warning i2c/mpu6050_i2c example requires a board with I2C pins
      |      ^~~~~~~

<snip>

Add PIO SPI slave example

I currently have an Arduino Mega in SPI master mode, and a RPi Pico in slave mode, communicating over SPI. I was using the mega to troubleshoot some issues I was having.

My pinout is:

Arduino MOSI -> Pico GP16 (SPI0 RX)
Arduino SS   -> Pico GP17 (SPI0 CSn)
Arduino GND  -> Pico GND 
Arduino SCLK -> Pico GP18 (SPI0 SCK)

Here is the Pico's code:

#include <stdio.h>
#include <string.h>
#include "pico/stdlib.h"
#include "pico/binary_info.h"
#include "hardware/spi.h"

int main() {
    stdio_init_all();

    printf("Initializing SPI...\n");

    // SPI initialisation. This example will use SPI at 1MHz.
    spi_init(spi_default, 1000*1000);

    spi_set_slave(spi_default, true);
    gpio_set_function(PICO_DEFAULT_SPI_RX_PIN, GPIO_FUNC_SPI);
    gpio_set_function(PICO_DEFAULT_SPI_SCK_PIN, GPIO_FUNC_SPI);
    gpio_set_function(PICO_DEFAULT_SPI_TX_PIN, GPIO_FUNC_SPI);
    gpio_set_function(PICO_DEFAULT_SPI_CSN_PIN, GPIO_FUNC_SPI);

    int bytesread = 0;
    uint8_t buffer[14];

    while(true)
    {
        bytesread = spi_read_blocking(spi_default, 0, buffer, 14);
        for(int i = 0; i < bytesread; i++)
        {
            printf("%02x ", buffer[i]);
        }
        printf("\n");
    }
}

and here is the Arduino's code:

#include <SPI.h>                            

void setup (void)
{
  SPI.begin();                            //Begins the SPI commnuication
  SPI.setClockDivider(SPI_CLOCK_DIV8);    //Sets clock for SPI communication at 1 MHz
  pinMode(SS, OUTPUT);
  digitalWrite(SS, HIGH);                 
}

//Hello, World! in hex
byte buf[14] = {0x48,0x65,0x6c,0x6c,0x6f,0x2c,0x20,0x57,0x6f,0x72,0x6c,0x64,0x21,0x00};

void loop(void)
{
  digitalWrite(SS, LOW);
  for(int i = 0; i < 14; i++){
    SPI.transfer(buf[i]);
  }
  digitalWrite(SS, HIGH);
  delay(100);
}

This code sends the byte array buffer over SPI, setting CS to LOW, completing the transfer, then setting CS back to HIGH, as this is how the SPI protocol is supposed to function. However, in doing so, the Pico only receives the first byte of each transfer, waiting until it recieves 14 bytes and then displaying all the first byte.

Pico serial output:
image

After doing some fiddling around with the code, I realized that if I change the loop to toggle CS on each byte sent, the Pico successfully receives all of the data.

void loop(void)
{
  for(int i = 0; i < 14; i++){
    digitalWrite(SS, LOW);
    SPI.transfer(buf[i]);
    digitalWrite(SS, HIGH);
  }
  delay(100);
}

New Pico serial output:
image

However, this is not how the SPI protocol should operate and makes the Pico incompatible with pretty much every SPI master device, and seems to be an issue in the pico's hardware_spi library, unless this is user error and if that is the case then I will gladly be corrected.

pico-examples/picoboard/blinky/blinky.c

in pico-examples/picoboard/blinky/blinky.c should lines:

57        if (*str >= 'A' && *str < 'Z') {
...
59        } else if (*str >= 'a' && *str < 'z') {

not be str <= 'Z' + str <= 'z'? like so:

57        if (*str >= 'A' && *str <= 'Z') {
...
59        } else if (*str >= 'a' && *str <= 'z') {

ruby

is possible run mruby on pico?

dev_hid_generic_inout Appears to hang when reading

Hi.
I've tried using hid_test.py from the tinyusb examples to test this example, but it seems to hang the Pico when trying to read.

Host system:
Macbook Pro M1
MacOS Big Sur 11.2.3
Connected via USB hub

Example request: DMA ping-pong

Would be nice with an example application of DMA ping-pong (in which the DMA alternates between two buffers so that one can be written to while the other is being processed).

Raspberry Pi install - error: invalid use of non-static data member ‘address_range::type

Following the install process for the Pico on a Raspberry Pi 4 using the pico_setup.sh script, when it got to the building of the pico-examples, a couple of failures were seen:

OS Version: PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"

##Build errors**

make[5]: *** [CMakeFiles/elf2uf2.dir/build.make:63: CMakeFiles/elf2uf2.dir/main.cpp.o] Error 1
make[4]: *** [CMakeFiles/Makefile2:73: CMakeFiles/elf2uf2.dir/all] Error 2
make[3]: *** [Makefile:84: all] Error 2
make[2]: *** [blink/CMakeFiles/ELF2UF2Build.dir/build.make:111: blink/elf2uf2/src/ELF2UF2Build-stamp/ELF2UF2Build-build] Error 2
make[1]: *** [CMakeFiles/Makefile2:1578: blink/CMakeFiles/ELF2UF2Build.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Build Output

Adding PICO_EXAMPLES_PATH to ~/.bashrc
Cloning https://github.com/raspberrypi/pico-extras.git
Cloning into 'pico-extras'...
remote: Enumerating objects: 151, done.
remote: Counting objects: 100% (151/151), done.
remote: Compressing objects: 100% (110/110), done.
remote: Total 151 (delta 12), reused 151 (delta 12), pack-reused 0
Receiving objects: 100% (151/151), 124.12 KiB | 1.88 MiB/s, done.
Resolving deltas: 100% (12/12), done.
Submodule 'lwip' (https://git.savannah.nongnu.org/git/lwip.git) registered for path 'lib/lwip'
Cloning into '/home/pi/development/pico/pico/pico-extras/lib/lwip'...
Submodule path 'lib/lwip': checked out 'c385f31076b27efb8ee37f00cb5568783a58f299'
Adding PICO_EXTRAS_PATH to ~/.bashrc
Cloning https://github.com/raspberrypi/pico-playground.git
Cloning into 'pico-playground'...
remote: Enumerating objects: 140, done.
remote: Counting objects: 100% (140/140), done.
remote: Compressing objects: 100% (117/117), done.
remote: Total 140 (delta 24), reused 128 (delta 17), pack-reused 0
Receiving objects: 100% (140/140), 1.86 MiB | 2.43 MiB/s, done.
Resolving deltas: 100% (24/24), done.
Adding PICO_PLAYGROUND_PATH to ~/.bashrc
Using PICO_SDK_PATH from environment ('/home/pi/development/pico/pico/pico-sdk')
Pico SDK is located at /home/pi/development/pico/pico/pico-sdk
Defaulting PICO_PLATFORM to rp2040 since not specified.
Defaulting PICO platform compiler to pico_arm_gcc since not specified.
PICO compiler is pico_arm_gcc
PICO_GCC_TRIPLE defaulted to arm-none-eabi
-- The C compiler identification is GNU 7.3.1
-- The CXX compiler identification is GNU 7.3.1
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/arm-none-eabi-gcc
Using regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize)
Defaulting PICO target board to pico since not specified.
Using board configuration from /home/pi/development/pico/pico/pico-sdk/src/boards/include/boards/pico.h
-- Found Python3: /usr/bin/python3.7 (found version "3.7.3") found components:  Interpreter
TinyUSB available at /home/pi/development/pico/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; adding USB support.
Compiling TinyUSB with CFG_TUSB_DEBUG=1
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
ELF2UF2 will need to be built
PIOASM will need to be built
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/development/pico/pico/pico-examples/build
Building blink
Scanning dependencies of target ELF2UF2Build
Scanning dependencies of target bs2_default
[  0%] Creating directories for 'ELF2UF2Build'
[  0%] Building ASM object pico_sdk/src/rp2_common/boot_stage2/CMakeFiles/bs2_default.dir/boot2_w25q080.S.obj
[  0%] Linking ASM executable bs2_default.elf
[  0%] Built target bs2_default
Scanning dependencies of target bs2_default_bin
[  0%] No download step for 'ELF2UF2Build'
[  0%] Generating bs2_default.bin
[  0%] Built target bs2_default_bin
[  0%] No patch step for 'ELF2UF2Build'
[  0%] No update step for 'ELF2UF2Build'
Scanning dependencies of target bs2_default_padded_checksummed_asm
[  0%] Generating bs2_default_padded_checksummed.S
[  0%] Performing configure step for 'ELF2UF2Build'
[  0%] Built target bs2_default_padded_checksummed_asm
-- The C compiler identification is GNU 5.5.0
-- The CXX compiler identification is GNU 5.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/development/pico/pico/pico-examples/build/elf2uf2
[  0%] Performing build step for 'ELF2UF2Build'
Scanning dependencies of target elf2uf2
[ 50%] Building CXX object CMakeFiles/elf2uf2.dir/main.cpp.o
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:68:58: error: invalid use of non-static data member ‘address_range::type’
     address_range(FLASH_START, FLASH_END, address_range::type::CONTENTS),
                                                          ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:55:10: note: declared here
     type type;
          ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:69:64: error: invalid use of non-static data member ‘address_range::type’
     address_range(MAIN_RAM_START, MAIN_RAM_END, address_range::type::NO_CONTENT
                                                                ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:55:10: note: declared here
     type type;
          ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:70:1: error: no matching function for call to ‘std::vector<address_range>::vector(<brace-enclosed initializer list>)’
 };
 ^
In file included from /usr/include/c++/5/vector:64:0,
                 from /home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:9:
/usr/include/c++/5/bits/stl_vector.h:401:9: note: candidate: template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&)
         vector(_InputIterator __first, _InputIterator __last,
         ^
/usr/include/c++/5/bits/stl_vector.h:401:9: note:   template argument deduction/substitution failed:
/usr/include/c++/5/bits/stl_vector.h:373:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(initializer_list<value_type> __l,
       ^
/usr/include/c++/5/bits/stl_vector.h:373:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:348:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(vector&& __rv, const allocator_type& __m)
       ^
/usr/include/c++/5/bits/stl_vector.h:348:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:339:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(const vector& __x, const allocator_type& __a)
       ^
/usr/include/c++/5/bits/stl_vector.h:339:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:335:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = address_range; _Alloc = std::allocator<address_range>]
       vector(vector&& __x) noexcept
       ^
/usr/include/c++/5/bits/stl_vector.h:335:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/5/bits/stl_vector.h:318:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = address_range; _Alloc = std::allocator<address_range>]
       vector(const vector& __x)
       ^
/usr/include/c++/5/bits/stl_vector.h:318:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/5/bits/stl_vector.h:289:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::value_type = address_range; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(size_type __n, const value_type& __value,
       ^
/usr/include/c++/5/bits/stl_vector.h:289:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:277:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(size_type __n, const allocator_type& __a = allocator_type())
       ^
/usr/include/c++/5/bits/stl_vector.h:277:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:264:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
       ^
/usr/include/c++/5/bits/stl_vector.h:264:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/5/bits/stl_vector.h:253:7: note: candidate: std::vector<_Tp, _Alloc>::vector() [with _Tp = address_range; _Alloc = std::allocator<address_range>]
       vector()
       ^
/usr/include/c++/5/bits/stl_vector.h:253:7: note:   candidate expects 0 arguments, 2 provided
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:73:64: error: invalid use of non-static data member ‘address_range::type’
     address_range(MAIN_RAM_START, MAIN_RAM_END, address_range::type::CONTENTS),
                                                                ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:55:10: note: declared here
     type type;
          ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:74:60: error: invalid use of non-static data member ‘address_range::type’
     address_range(0x00000000u, 0x00002000u, address_range::type::IGNORE) // for
                                                            ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:55:10: note: declared here
     type type;
          ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:75:1: error: no matching function for call to ‘std::vector<address_range>::vector(<brace-enclosed initializer list>)’
 };
 ^
In file included from /usr/include/c++/5/vector:64:0,
                 from /home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:9:
/usr/include/c++/5/bits/stl_vector.h:401:9: note: candidate: template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&)
         vector(_InputIterator __first, _InputIterator __last,
         ^
/usr/include/c++/5/bits/stl_vector.h:401:9: note:   template argument deduction/substitution failed:
/usr/include/c++/5/bits/stl_vector.h:373:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(initializer_list<value_type> __l,
       ^
/usr/include/c++/5/bits/stl_vector.h:373:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:348:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(vector&& __rv, const allocator_type& __m)
       ^
/usr/include/c++/5/bits/stl_vector.h:348:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:339:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(const vector& __x, const allocator_type& __a)
       ^
/usr/include/c++/5/bits/stl_vector.h:339:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:335:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = address_range; _Alloc = std::allocator<address_range>]
       vector(vector&& __x) noexcept
       ^
/usr/include/c++/5/bits/stl_vector.h:335:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/5/bits/stl_vector.h:318:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = address_range; _Alloc = std::allocator<address_range>]
       vector(const vector& __x)
       ^
/usr/include/c++/5/bits/stl_vector.h:318:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/5/bits/stl_vector.h:289:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::value_type = address_range; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(size_type __n, const value_type& __value,
       ^
/usr/include/c++/5/bits/stl_vector.h:289:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:277:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(size_type __n, const allocator_type& __a = allocator_type())
       ^
/usr/include/c++/5/bits/stl_vector.h:277:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/5/bits/stl_vector.h:264:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = address_range; _Alloc = std::allocator<address_range>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<address_range>]
       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
       ^
/usr/include/c++/5/bits/stl_vector.h:264:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/5/bits/stl_vector.h:253:7: note: candidate: std::vector<_Tp, _Alloc>::vector() [with _Tp = address_range; _Alloc = std::allocator<address_range>]
       vector()
       ^
/usr/include/c++/5/bits/stl_vector.h:253:7: note:   candidate expects 0 arguments, 2 provided
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp: In function ‘int check_address_range(const address_ranges&, uint32_t, uint32_t, uint32_t, bool, address_range&)’:
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:120:46: error: ‘address_range::type’ is not a class, namespace, or enumeration
             if (range.type == address_range::type::NO_CONTENTS && !uninitialize
                                              ^
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp: In function ‘int read_and_check_elf32_ph_entries(FILE*, const elf32_header&, const address_ranges&, std::map<unsigned int, std::vector<page_fragment> >&)’:
/home/pi/development/pico/pico/pico-sdk/tools/elf2uf2/main.cpp:153:51: error: ‘address_range::type’ is not a class, namespace, or enumeration
                     if (ar.type != address_range::type::CONTENTS) {
                                                   ^
make[5]: *** [CMakeFiles/elf2uf2.dir/build.make:63: CMakeFiles/elf2uf2.dir/main.cpp.o] Error 1
make[4]: *** [CMakeFiles/Makefile2:73: CMakeFiles/elf2uf2.dir/all] Error 2
make[3]: *** [Makefile:84: all] Error 2
make[2]: *** [blink/CMakeFiles/ELF2UF2Build.dir/build.make:111: blink/elf2uf2/src/ELF2UF2Build-stamp/ELF2UF2Build-build] Error 2
make[1]: *** [CMakeFiles/Makefile2:1578: blink/CMakeFiles/ELF2UF2Build.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Error building hello_usb example

I am not super comfortable with cmake, and I'm pretty sure this is why I'm having trouble. I am using this as my CMakeLists.txt:

cmake_minimum_required(VERSION 3.13)

include(pico_sdk_import.cmake)

project(hello_usb)

pico_sdk_init()

if (TARGET tinyusb_device)
    add_executable(hello_usb
            hello_usb.c
            )

    # Pull in our pico_stdlib which aggregates commonly used features
    target_link_libraries(hello_usb pico_stdlib)

    # enable usb output, disable uart output
    pico_enable_stdio_usb(hello_usb 1)
    pico_enable_stdio_uart(hello_usb 0)

    # create map/bin/hex/uf2 file etc.
    pico_add_extra_outputs(hello_usb)

    example_auto_set_url(hello_usb)
elseif(PICO_ON_DEVICE)
    message(WARNING "not building hello_usb because TinyUSB submodule is not initialized in the SDK")
endif()

I get the following error when running cmake:

CMake Error at CMakeLists.txt:24 (example_auto_set_url):
  Unknown CMake command "example_auto_set_url".

I'm not sure what function this is trying to call or if this is native to cmake or what. Any guidance would help a lot.

Get an unique device ID

Hello,

is there a way to obtain a unique identifier for each device? Something like MAC address on other device Who has a network card ?

VS Code: Launching of gdb-multiarch not possible

When setting a Raspberry Pi up as described in the Getting Started guide, two problems arise when launching the debugger:

  • Setting "gdbpath" in launch.json is marked as not allowed
  • When launching the setting is ignored, and arm-none-eabi-gdb is used, which is unavailable

It seems that setting "cortex-debug.gdbpath" can only be set in settings.json

Incorrect blink frequency in pio_blink

The formula used in the recent update to use the sys clock is incorrect.

The offending line is the last line in blink.c:

pio->txf[sm] = clock_get_hz(clk_sys) / 2 * freq;

This divides sys clock by 2 and multiplies the result by the frequency desired.

The result is that a frequency of 1 Hz correctly blinks at 1Hz, however, a frequency of 4Hz blinks at 0.25Hz and a frequency of 3Hz at 0.33Hz.

Replacing the multiply with divide corrects this.

Issue with pico_unique_id

Hi all,
I believe I have discovered some issue with pico_unique_id example, but can't for the life of me figure out how to find out what it is....

Firstly, in it's existing form, I feel the example program is not much use to a beginner as it sends the ID out through the UART.....most people won't have a USB serial port plugged into GPIO0 and GPIO1, so I thought I'd build it to use USB for stdout. In my mind most people will have purchased a single Pico to play with and would expect the example to work without having to purhase any additional bits.

As it happens, I do have a 3.3v serial port adapter and when the example is built, running with my external USB-Serial adapter connected, the example runs and emits the expected uniqe serial number string. Great!

When compiled to use USB for stdout, I get nothing and the USB doesn't even initialise properly....so more investigation required.;

Ok, I think to myself, lets run the standard example code under OpenOCD and find out what's going on as I happen to have a spare Pico too !

Here's where it gets interesting....

The standard pico_unique_id example which runs quite happily without the debugger won't run under the debugger using OpenOCD and causes a SIGINT on the line:

inline static void hw_write_masked(io_rw_32 *addr, uint32_t values, uint32_t write_mask) {

which in turn is called from flash_cs_force

The best I can figure out at the moment is that it's something going wrong in the constructor code that's run from the runtime_init.

So I have two (related?) problems with this example, and one request

  1. I can't debug the standard example using openOCD debugger.
  2. When it is built to use USB for stdout it crashes and I can't find out why because I can't debug it (Crashes at the same point with the same fault)

The request is "Can this example be made to work without the need for an external serial port?"

Error in bme280_spi example

The call
read_registers(0x88, buffer, 24);
within read_compensation_parameters() should be changed to
read_registers(0x88, buffer, 26);
as the compensation parameter DIG_H1 resides in 0xA1 according to the BME280 datasheet, so that 26 bytes must be read.

cmake does not respect PICO_SDK_PATH changing

[nix-shell:~/apps/rpi/pico/pico-examples/build]$ cmake .. -DPICO_STDIO_USB=1
CMake Error at pico_sdk_import.cmake:54 (message):
  Directory '/nix/store/iakf0a4wi5al3a6gngf70arkmwcz7il1-source' not found
Call Stack (most recent call first):
  CMakeLists.txt:4 (include)


-- Configuring incomplete, errors occurred!
See also "/home/clever/apps/rpi/pico/pico-examples/build/CMakeFiles/CMakeOutput.log".
See also "/home/clever/apps/rpi/pico/pico-examples/build/CMakeFiles/CMakeError.log".

[nix-shell:~/apps/rpi/pico/pico-examples/build]$ echo $PICO_SDK_PATH
/nix/store/60rlhylazjg06mpzn9qnpjwcs2n1ykh5-source

[nix-shell:~/apps/rpi/pico/pico-examples/build]$ rm CMakeCache.txt

[nix-shell:~/apps/rpi/pico/pico-examples/build]$ cmake .. -DPICO_STDIO_USB=1
Using PICO_SDK_PATH from environment ('/nix/store/60rlhylazjg06mpzn9qnpjwcs2n1ykh5-source')
Pico SDK is located at /nix/store/60rlhylazjg06mpzn9qnpjwcs2n1ykh5-source
Defaulting PICO_PLATFORM to rp2040 since not specified.
Defaulting PICO platform compiler to pico_arm_gcc since not specified.
-- Defaulting build type to 'Release' since not specified.
PICO compiler is pico_arm_gcc
PICO_GCC_TRIPLE defaulted to arm-none-eabi
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- The ASM compiler identification is GNU
-- Found assembler: /nix/store/1nkm42wc9rkpvly02q2vbd6gprjxsxjz-arm-none-eabi-stage-final-gcc-debug-wrapper-9.3.0/bin/arm-none-eabi-gcc
Defaulting PICO target board to pico since not specified.
Using board configuration from /nix/store/60rlhylazjg06mpzn9qnpjwcs2n1ykh5-source/src/boards/include/boards/pico.h
-- Found Python3: /nix/store/bs03sg8b0gq2zr4v252hh9psp780qj5q-python3-3.8.5/bin/python3.8 (found version "3.8.5") found components: Interpreter
TinyUSB available at /nix/store/60rlhylazjg06mpzn9qnpjwcs2n1ykh5-source/lib/tinyusb/src/portable/raspberrypi/rp2040; adding USB support.
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
ELF2UF2 will need to be built
PIOASM will need to be built
-- Configuring done
-- Generating done
-- Build files have been written to: /home/clever/apps/rpi/pico/pico-examples/build

after running a garbage collection (deleting the old $PICO_SDK_PATH) and updating $PICO_SDK_PATH to point to the new directory, cmake refused to respect that, and kept looking in the old path
deleting CMakeCache.txt made it forget and look in the new path, but it would be better if it detected the change automatically

usb/device/dev_audio_headset not working as intended

Any audio received from the device stutters and is distorted. After adding some printfs to the code, I've found that both tud_audio_rx_done_cb and tud_audio_tx_done_pre_load_cb only seem to be called either 333 or 334 times per second, rather than 1000.

PIO WS2812 example - timing problem

I was looking at the WS2812 driver to understand how it worked and came across some problems with the timing. The driver is described in section 3.2.2 of the C/C++ SDK. I understood the logic of the program but couldn't see how it met the timing specifications of the WS2812. That was where I discovered the timings in the code and in the description do not match. In the code the timings are T1=2, T2=5 and T3=3. Reading the description and looking at figure 5 and 6 I get timings of T1=4, T2=3 and T3=3.

There are two times to get right, the short time 400ns and the long time 850ns. Their sum is 1250ns which satisfies the period. Neither the values in the code nor the description seem correct. I calculate T1=8, T2=9 and T3=8 with 50ns clock period. The resolution's finer but still in the range of the delays of the state machine.

		       T3	T1	T2	T short	T long
code		3	2	5	250ns	875ns
description	3	4	3	500ns	875ns
ideal		8	8	9	400ns	850ns

The example code does work so for my sanity I checked with a scope and I do see the calculated timings. Presumably it's working because the WS2812 is forgiving.

I also simplified the state machine code avoiding jumps by putting the shifted out bit onto the output line.

.program ws2812

.define public T0 8
.define public T1 9

.wrap_target
set pins, 0 [T0 - 2] ; start off low
out x, 1 ; get a single bit from the shift register
set pins, 1 [T0 - 1] ; start the high
mov pins, x [T1 - 1] ; continue waveform high or low according to bit
.wrap

Note there are corresponding changes to the C and Python code for state machine configuration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.