Skip to content

Commit

Permalink
pico build, linux host
Browse files Browse the repository at this point in the history
  • Loading branch information
mkellner committed Feb 19, 2021
1 parent 66b0804 commit 21ab119
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 9 deletions.
5 changes: 3 additions & 2 deletions build/devices/pico/base/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@
//---------
void setupDebugger()
{
#if mxDebug
int i;

for (i=1; i<=5; i++) {
for (i=1; i<=10; i++) {
printf("pico-usb-start %d\r\n", i);
delay(1000);
}

#endif
}

void debuggerTask()
Expand Down
13 changes: 13 additions & 0 deletions build/devices/pico/config/connectToXsbugLinux
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

port=$(findUSBLinux $1 $2 cdc_acm)
while [ "" == "${port}" ]; do
sleep 0.1
port=$(findUSBLinux $1 $2 cdc_acm)
done

sleep 2

${MODDABLE}/build/bin/lin/release/serial2xsbug ${port} 921600 8N1 $3

# -dtr $3
Binary file added build/devices/pico/config/elf2uf2_lin
Binary file not shown.
File renamed without changes.
21 changes: 21 additions & 0 deletions build/devices/pico/config/findUSBLinux
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
if [ "$#" -lt 2 ] ; then
echo "Usage: $0 <vid> <pid> [<driver>]"
echo " returns path of USB device matching <vid> and <pid>"
echo " <driver> is cdc_acm or usb-storage"
exit 1
fi

for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && exit
# echo "$(udevadm info -q property --export -p $syspath)"
eval "$(udevadm info -q property --export -p $syspath)"
[[ "$ID_VENDOR_ID" != "$1" || "$ID_MODEL_ID" != "$2" ]] && exit
[[ "$3" != "" && "$ID_USB_DRIVER" != "$3" ]] && exit
echo "/dev/$devname"
)
done

36 changes: 36 additions & 0 deletions build/devices/pico/config/programmingModeLinux
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

vid=$1
pid=$2
name=$3
volumefile=$4
serial=$( findUSBLinux $vid $pid cdc_acm )

rm "$volumefile" 2> /dev/null

volume=$( df -P | grep "$name" | awk '{print($6)}' )
if [ -d "$volume" ];
then
echo "Already in programming mode."
else
if [ -z "$serial" ];
then
echo "If led is not blinking, please double-tap the reset button to enter programming mode."
else
echo "Triggering serial port $serial."
serial2xsbug $serial 921600 8N1 -programming
fi

echo -n "Waiting for $name."
# echo -n "Double-tap the reset button to enter programming mode."
set -o pipefail
volume=$( df -P | grep "$name" | awk '{print($6)}' )
while [ -z "$volume" ]; do
echo -n "."
sleep 1
volume=$( df -P | grep "$name" | awk '{print($6)}' )
done
echo
fi

echo $volume >> "$volumefile"
51 changes: 51 additions & 0 deletions build/devices/pico/config/waitForVolumeLinux
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

MISSING=0

while [[ "$#" -gt 2 ]]
do
case "$1" in
-x|--missing)
MISSING=1
shift;
;;
*)
;;
esac
done

name=$1
volumefile=$2

if [[ -f "$volumefile" ]]
then
rm "$volumefile" 2> /dev/null
fi

volume=$( df -P | grep "$name" | awk '{print($6)}' )
set -o pipefail

if [[ $MISSING == 0 ]]
then
echo "Waiting for $name."
echo -n "Double-tap the reset button to enter programming mode."
while [ -z "$volume" ]; do
echo -n "."
sleep .1
volume=$( df -P | grep "$name" | awk '{print($6)}' )
done
else
echo -n "Waiting for copy to complete."
while [ ! -z "$volume" ]; do
echo -n "."
sleep .1
volume=$( df -P | grep "$name" | awk '{print($6)}' )
done
fi
echo

if [[ -f "$volumefile" ]]
then
echo $volume >> "$volumefile"
fi

25 changes: 19 additions & 6 deletions tools/mcconfig/make.pico.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ UF2_VOLUME_NAME ?= RPI-RP2
PICO_VID ?= 2e8a
PICO_PID ?= 000a


ifeq ($(HOST_OS),Darwin)
DO_COPY = cp $(BIN_DIR)/xs_pico.uf2 $(UF2_VOLUME_PATH)
MODDABLE_TOOLS_DIR = $(BUILD_DIR)/bin/mac/release
UF2_VOLUME_PATH = /Volumes/$(UF2_VOLUME_NAME)
UF2CONV = $(MODDABLE)/build/devices/pico/config/elf2uf2_mac

PROGRAMMING_MODE = $(PLATFORM_DIR)/config/waitForVolume $(UF2_VOLUME_PATH)
# PROGRAMMING_MODE = $(PLATFORM_DIR)/config/programmingMode $(M4_VID) $(M4_PID) $(UF2_VOLUME_PATH)
# PROGRAMMING_MODE = $(PLATFORM_DIR)/config/programmingMode $(PICO_VID) $(PICO_PID) $(UF2_VOLUME_PATH)
KILL_SERIAL_2_XSBUG = $(shell pkill serial2xsbug)

ifeq ($(DEBUG),1)
Expand All @@ -55,15 +58,22 @@ ifeq ($(HOST_OS),Darwin)
WAIT_FOR_COPY_COMPLETE = $(PLATFORM_DIR)/config/waitForVolume -x $(UF2_VOLUME_PATH)
endif
else
PLATFORM_OTHER = \
$(MODDABLE_TOOLS_DIR)/findUSBLinux
DO_COPY = DESTINATION=$$(cat $(TMP_DIR)/volumename); cp $(BIN_DIR)/xs_pico.uf2 $$DESTINATION
MODDABLE_TOOLS_DIR = $(BUILD_DIR)/bin/lin/release
PROGRAMMING_MODE = $(PLATFORM_DIR)/config/programmingModeLinux $(M4_VID) $(M4_PID) $(UF2_VOLUME_NAME) $(TMP_DIR)/volumename
UF2CONV = $(MODDABLE)/build/devices/pico/config/elf2uf2_lin

# PROGRAMMING_MODE = $(PLATFORM_DIR)/config/waitForVolumeLinux $(UF2_VOLUME_PATH)
PROGRAMMING_MODE = $(PLATFORM_DIR)/config/programmingModeLinux $(PICO_VID) $(PICO_PID) $(UF2_VOLUME_NAME) $(TMP_DIR)/volumename
KILL_SERIAL_2_XSBUG = $(shell pkill serial2xsbug)
WAIT_FOR_COPY_COMPLETE = $(PLATFORM_DIR)/config/waitForVolumeLinux -x $(UF2_VOLUME_NAME) $(TMP_DIR)/volumename

ifeq ($(DEBUG),1)
DO_XSBUG = $(shell nohup $(MODDABLE_TOOLS_DIR)/xsbug > /dev/null 2>&1 &)
CONNECT_XSBUG = $(PLATFORM_DIR)/config/connectToXsbugLinux $(M4_VID) $(M4_PID)
CONNECT_XSBUG = $(PLATFORM_DIR)/config/connectToXsbugLinux $(PICO_VID) $(PICO_PID)
# CONNECT_XSBUG = PATH=$(PLATFORM_DIR)/config:$(PATH) ; $(PLATFORM_DIR)/config/connectToXsbugLinux $(PICO_VID) $(PICO_PID)
# CONNECT_XSBUG=@echo "Connect to xsbug @ $(PICO_VID):$(PICO_PID)." ; serial2xsbug $(PICO_VID):$(PICO_PID) $(DEBUGGER_SPEED) 8N1
NORESTART=-norestart
else
DO_XSBUG =
Expand Down Expand Up @@ -498,7 +508,9 @@ OBJECTS += \
$(PICO_OBJ)

OTHER_STUFF += \
env_vars
env_vars \
$(PLATFORM_OTHER)


TOOLS_BIN = $(PICO_GCC_ROOT)/bin
TOOLS_PREFIX = arm-none-eabi-
Expand Down Expand Up @@ -687,6 +699,9 @@ ifndef PICO_SDK_DIR
$(error PICO_SDK_DIR environment variable must be defined! See https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/devices/ for details.)
endif

$(MODDABLE_TOOLS_DIR)/findUSBLinux: $(PLATFORM_DIR)/config/findUSBLinux
cp $(PLATFORM_DIR)/config/findUSBLinux $(MODDABLE_TOOLS_DIR)

clean:
echo "# Clean project"
-rm -rf $(BIN_DIR) 2>/dev/null
Expand All @@ -700,8 +715,6 @@ allclean:
@echo "# rm $(MODDABLE)/build/tmp/pico"
-rm -rf $(MODDABLE)/build/tmp/pico

UF2CONV = $(MODDABLE)/build/devices/pico/config/elf2uf2

$(BIN_DIR)/xs_pico.uf2: $(BIN_DIR)/xs_pico.elf
@echo Making: $(BIN_DIR)/xs_pico.uf2 from xs_pico.elf
$(UF2CONV) $(BIN_DIR)/xs_pico.elf $(BIN_DIR)/xs_pico.uf2
Expand Down
2 changes: 1 addition & 1 deletion tools/serial2xsbug/serial2xsbug.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#define mxNetworkBufferSize 1024
#define mxSerialBufferSize 1024
#define mxTagSize 17
#define mxTrace 0
#define mxTrace 1
#define mxTraceCommands 0

typedef struct txSerialMachineStruct txSerialMachineRecord, *txSerialMachine;
Expand Down

0 comments on commit 21ab119

Please sign in to comment.