Work in progress, updated test tool to only read and prototyped firmware to continuously write to the TX buffer. Firmware still needs work, this was only done to understand how the pico usb core works.

This commit is contained in:
Mickey Malone
2021-02-09 07:05:45 -06:00
parent c8e1023366
commit b1eb887656
2 changed files with 66 additions and 40 deletions

View File

@@ -578,10 +578,38 @@ void ep1_out_handler(uint8_t *buf, uint16_t len) {
usb_start_transfer(ep, (char*)new_buf, size); usb_start_transfer(ep, (char*)new_buf, size);
} }
void get_random_data(char *buffer, uint16_t len) {
uint16_t adc_result;
uint8_t size;
int i;
gpio_put(25, 1);
if(len > 64)
{
//TODO handle length error
size = 64;
}
memset(buffer, 0, len);
for(i = 1; i <= len; i=i+1)
{
adc_result = adc_read();
memcpy(&buffer[i-1], (void*)&adc_result, 2);
}
gpio_put(25, 0);
}
void ep2_in_handler(uint8_t *buf, uint16_t len) { void ep2_in_handler(uint8_t *buf, uint16_t len) {
printf("Sent %d bytes to host\n", len); printf("Sent %d bytes to host\n", len);
// Get ready to rx again from host // Get ready to rx again from host
usb_start_transfer(usb_get_endpoint_configuration(EP1_OUT_ADDR), NULL, 64);
char buffer[64];
get_random_data(buffer, 64);
//usb_start_transfer(usb_get_endpoint_configuration(EP1_OUT_ADDR), NULL, 64);
struct usb_endpoint_configuration *ep = usb_get_endpoint_configuration(EP2_IN_ADDR);
usb_start_transfer(ep, buffer, 64);
} }
int main(void) { int main(void) {
@@ -604,8 +632,12 @@ int main(void) {
tight_loop_contents(); tight_loop_contents();
} }
// Get ready to rx from host char buffer[64];
usb_start_transfer(usb_get_endpoint_configuration(EP1_OUT_ADDR), NULL, 64);
// Get ready to tx
get_random_data(buffer, 64);
usb_start_transfer(usb_get_endpoint_configuration(EP2_IN_ADDR), buffer, 64);
//usb_start_transfer(usb_get_endpoint_configuration(EP1_OUT_ADDR), NULL, 64);
// Everything is interrupt driven so just loop here // Everything is interrupt driven so just loop here
while (1) { while (1) {

View File

@@ -1,50 +1,44 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
#
# Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# sudo pip3 install pyusb
import usb.core import usb.core
import usb.util import usb.util
import random import random
import time
import argparse
# find our device # Parser stuff
dev = usb.core.find(idVendor=0x0000, idProduct=0x0004) parser = argparse.ArgumentParser(description="Raspberry Pi Pico Random Number Generator Test Tool")
parser.add_argument("--performance", action="store_true", help="Performance test the RNG.")
args = parser.parse_args()
# was it found? # Get the device
if dev is None: rng = usb.core.find(idVendor=0x0000, idProduct=0x0004)
raise ValueError('Device not found') assert rng is not None
# get an endpoint instance # Get the configuration of the device
cfg = dev.get_active_configuration() cfg = rng.get_active_configuration()
intf = cfg[(0, 0)]
outep = usb.util.find_descriptor( # Get the only interface of our device
intf, intf = cfg.interfaces()[0]
# match the first OUT endpoint
custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
inep = usb.util.find_descriptor( # Get the endpoints
intf, endpts = intf.endpoints()
# match the first IN endpoint
custom_match= \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_IN)
assert inep is not None # Get the IN or Host RCV Device TX endpoint
assert outep is not None endpts_in = endpts[0] if endpts[0].bEndpointAddress == usb.util.ENDPOINT_IN else endpts[1]
num_bytes = random.randint(1,64) # Time tracking for bits/s
count = 0
start_time = (int(time.time()) - 1)
outep.write([num_bytes], 500) if args.performance:
from_device = inep.read(num_bytes, 500) while True:
try:
print(":".join("{:02x}".format(b) for b in from_device)) from_device = endpts_in.read(endpts_in.wMaxPacketSize, 500)
count = count+1
print(":".join("{:02x}".format(b) for b in from_device), end="")
print(" KBps {0:.2f}".format((int((count * 64) / (int(time.time()) - start_time))) / 1024 ))
except KeyboardInterrupt:
exit(0)
else:
print(":".join("{:02x}".format(b) for b in endpts_in.read(endpts_in.wMaxPacketSize, 500)))