daniestevez / galileo-osnma

Galileo OSNMA (Open Service Navigation Message Authentication)
Apache License 2.0
50 stars 8 forks source link

longan-nano not appearing as serial device after firmware flash #4

Closed K4KDR closed 2 years ago

K4KDR commented 2 years ago

After flashing my longan-nano w/ the newly created firmware.bin file and the disconnecting/reconnecting it to the computer, it does not appear as a new /dev/ttyACM or /dev/ttyUSB device for me to attempt to connect to.

I carefully followed the instructions to replace the contents of osnma-longan-nano/pubkey.pem with the authentic key.

The package was then built with:

cargo build --release

... and then:

~/riscv-binutils-gdb/binutils/objcopy -O binary target/riscv32imac-unknown-none-elf/release/osnma-longan-nano firmware.bin

... and the firmware.bin file was created as expected.

After connecting the longan-nano to my computer with the boot0 button depressed, its status was verified with dfu-util:

k4kdr@3010i5:~/galileo-osnma/osnma-longan-nano$ dfu-util -l
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [28e9:0189] ver=0100, devnum=16, cfg=1, intf=0, path="2-1.4", alt=0, name="@Internal Flash  /0x08000000/128*001Kg", serial="??"

... and the default code was uploaded for safekeeping:

k4kdr@3010i5:~/galileo-osnma/osnma-longan-nano$ dfu-util -U longan-nano-orig-code.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Opening DFU capable USB device...
ID 28e9:0189
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
Limiting default upload to 16384 bytes
Upload  [=========================] 100%        16384 bytes
Upload done.

... then, the firmware.bin file was downloaded to the device:

k4kdr@3010i5:~/galileo-osnma/osnma-longan-nano$ dfu-util -a 0 -s 0x08000000:leave -D firmware.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 28e9:0189
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash  "
Downloading to address = 0x08000000, size = 111920
Download    [=========================] 100%       111920 bytes
Download done.
File downloaded successfully
dfu-util: Error during download get_status

... but after disconnecting/reconnecting the longan-nano to the computer, it did NOT present as a /dev/tty device. Also, the solid red 'boot0' LED was illuminated as if I had connected the device while holding in the boot0 button.

Finally, I downloaded the original code to the device and after reboot, the LED's flashed normally as they did new, out-of-the-box.

Any help greatly appreciated as I am not seeing what step I might have made an error on. Thanks very much for your time!

K4KDR commented 2 years ago

Additional info:

Upgraded dfu-util to v0.11 but still the same behavior. However, the output is slightly different:

k4kdr@3010i5:~/galileo-osnma/osnma-longan-nano$ /usr/local/bin/dfu-util -l
dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [28e9:0189] ver=0100, devnum=21, cfg=1, intf=0, path="2-1.4", alt=0, name="@Internal Flash  /0x08000000/128*001Kg", serial="3CBJ"

... and

k4kdr@3010i5:~/galileo-osnma/osnma-longan-nano$ /usr/local/bin/dfu-util -a 0 -s 0x08000000:leave -D firmware.bin
dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Warning: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release
Opening DFU capable USB device...
Device ID 28e9:0189
Device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Interface #0 ...
Determining device status...
DFU state(2) = dfuIDLE, status(0) = No error condition is present
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash  "
Found GD32VF103, which reports a bad page size and count for its internal memory.
Fixed layout based on part number: page size 1024, count 128.
Downloading element to address = 0x08000000, size = 111920
Erase       [=========================] 100%       111920 bytes
Erase    done.
Download    [=========================] 100%       111920 bytes
Download done.
File downloaded successfully
Submitting leave request...
daniestevez commented 2 years ago

Hi Scott,

The osnma-longan-nano demo doesn't use the USB of the Longan Nano board as a serial port (mainly for simplicity, since using the USB would require to implement a USB serial device in the firmware). Instead, the UART port on the board is used. This is on the 8 pin header that is also used for JTAG. See the instructions here. To connect this to the PC, you need a 3V3 UART TTL to USB adapter. There are many inexpensive boards that can be used for this.

Potentially, there are other approaches that may use hardware you already have. If you have a Raspberry Pi or similar board, you can connect the UART of the Raspberry Pi to the UART of the Longan Nano and run the osnma-longan-nano-client on the Raspberry Pi instead of the PC (probably cross build --target armv7-unknown-linux-gnueabihf --release is an easy way to cross-compile the client for the Raspberry Pi using cross, if you have Docker running). It could also be possible to use an Arduino or similar to set up a "UART to USB bridge". For instance, with the Arduino Uno it is possible to remove the Atmega328P and use the UART to TTL converter on the board (but a resistor divider is needed on the UART line from the Arduino to the Longan nano to drop the voltage, since the Arduino Uno uses 5V instead of 3V3).

Regarding the Longan nano LEDs, I believe that the red LED is always on whenever the board is powered. In the schematic it appears across 3V3 and GND (with a 2k resistor). Only the RGB LED is controlled by GPIOs on the GD32V, and osnma-longan-nano doesn't use them, so the RGB LED won't light up (it would be fun to use the LEDs to show what osnma-longan-nano is doing; maybe I'll do that at some point).

K4KDR commented 2 years ago

>>> The osnma-longan-nano demo doesn't use the USB of the Longan Nano board as a serial port ~~ the UART port on the board is used

My mistake! I understood your how-to ref. the Serial Port Connection to be ONE option for flashing the device. Reading more carefully, it is very clear that it is actually THE connection to use for serial comms to the computer.

I have a USB>UART converter on the way, so hopefully I will soon be able to work through that phase of the testing.

Thanks!!

daniestevez commented 2 years ago

I'm trying to clean up the issues by closing what is already solved and moving to a discussion what has background information that could be interesting to others. I think this issue can be closed (you can do it yourself).

K4KDR commented 2 years ago

Will do - please feel free to move to the DISCUSSION section if you wish.