Lighthouse deck and USB serial port communication

Discussions related to positioning systems where the position is calculated outside the Crazyflie and sent to the device using radio, including MoCap systems
Post Reply
deeyem
Beginner
Posts: 4
Joined: Tue Mar 03, 2020 2:57 pm

Lighthouse deck and USB serial port communication

Post by deeyem »

I am working on a localisation project that will use the Lighthouse-4 deck with custom hardware (not the Crazyflie). As a start, I wanted to test the Lighthouse deck by simply connecting it to a USB serial port on my laptop.

I have set up the USB connector 3.0V RX/TX logic levels, as noted in this post. I am using the 'print_frame.py' script from the lighthouse-fpga repository to test the link, but there does not seem to be any communication happening. I have used an oscilloscope to check the RX & TX lines and nothing is happening on either.

I'd like to know if anyone has been able to use the Lighthouse deck in this way and if so what steps one should follow. For example, is it necessary to first program the deck with the bootloader, does it need to be rebooted, reset or in another way made ready? I have tried using the bootloader, which appeared to run successfully but did not change what I was seeing.

All suggestions are appreciated!
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: Lighthouse deck and USB serial port communication

Post by marcus »

At power-on the deck will stay in the bootloader awaiting commands and the UART will be disabled. From what I can see the script you're referring to does not enable the UART and boot the main configuration. There's some more doc about it here, but you need to first send 0xBC to enable the UART and then send 0x00 which will boot up the main application.

You can have a look at this script that's used for updating the application in the SPI flash.
deeyem
Beginner
Posts: 4
Joined: Tue Mar 03, 2020 2:57 pm

Re: Lighthouse deck and USB serial port communication

Post by deeyem »

Thanks for the suggestion. Unfortunately, I'm still having no luck.

I repurposed the script you linked, uart_bootloader.py, and replaced the code for flashing the deck with the sync check from print_frame.py. So, after finding the bootloader version and chip ID, the following runs:

Code: Select all

boot()
print("Waiting for sync ...")
sync = [b'\xff', b'\xff', b'\xff', b'\xff', b'\xff', b'\xff', b'\xff', b'\xff', b'\xff', b'\xff', b'\xff', b'\xff']
syncBuffer = [b'\x00'] * len(sync)
while sync != syncBuffer:
    b = fpga.read(1)
    if len(b) < 1:
        sys.exit(1)
    syncBuffer.append(b)
    syncBuffer = syncBuffer[1:]
print("Found sync!")
I'm able to get the bootloader version, and I get the chip ID - both the expected values. But the script hangs on fpga.read(1) in the above code block and doesn't seem to read anything. Is there anything more that needs to be done to get the sensor data off the deck?

Side note: after sending the boot command, 0x00, the green LED turns on. Is this correct?
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Lighthouse deck and USB serial port communication

Post by kristoffer »

Hi!

I think the problem might be that we are working on the lighthouse-fpga project to add Lighthouse V2 support, and that the code has changed recently. If your deck has the stock binary it is not compatible with master as the protocol has changed.
You should probably look at the scripts in the V2 tag: https://github.com/bitcraze/lighthouse-fpga/tree/V2

If I remember correctly, you should look for 7 consecutive bytes that are non zero for sync (as opposed to 12 bytes of 0xff).
deeyem
Beginner
Posts: 4
Joined: Tue Mar 03, 2020 2:57 pm

Re: Lighthouse deck and USB serial port communication

Post by deeyem »

Hi! I've given that a try but am still having the same issue.

From what I can see, the problem isn't that it's not syncing, but that the script is simply not receiving any data from the serial connection. In the relevant script from the V2 tag, it gets to the line

Code: Select all

data = port.read(1)
and then proceeds no further. It's as though it's just waiting indefinitely for a signal that's not coming.

In a way, this seems to make sense, since we haven't asked for anything (e.g. the bootloader version). Apart from the boot command 0x00, is there nothing that needs to be done to tell the deck to transmit the sensor measurements?
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Lighthouse deck and USB serial port communication

Post by kristoffer »

Are you sure USB-to-UART is working on your machine?
Which OS are you on? I'm on OSX and I had to install a driver (https://www.silabs.com/products/develop ... cp-drivers), it is apparently not supported out of the box.
deeyem
Beginner
Posts: 4
Joined: Tue Mar 03, 2020 2:57 pm

Re: Lighthouse deck and USB serial port communication

Post by deeyem »

I am also on a Mac (Catalina 10.15.3). I installed the drivers as you suggested and restarted my machine just to be sure. Unfortunately, it's still only working for the SPI exchanges and not receiving any of the UART data.

There are two things bothering me, which may add some context:

1) Is it possible that this behaviour is caused by the FPGA being damaged? Someone before me may have used it with incorrect voltages on RX/TX. It would be strange if this is the case though, seeing as I can still flash the deck and it is responding to SPI commands.

2) Sending a "boot" command [ port.write(b"\0") ] changes the behaviour. If I start without a boot, the red and blue LEDs are on and the SPI commands work. If I start the script with a boot, the red LED turns off and the SPI commands don't work. I then have to cycle the power to "unboot" it.
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Lighthouse deck and USB serial port communication

Post by kristoffer »

I must admit that I'm not completely sure how the bootloader works (it is probably documented in the lighthouse-bootloader repo), but what is working for me is to flash it while booting.

The first time with a new binary I get (running from the lighthouse-fpga repo file tree)

Code: Select all

lighthouse-fpga kristoffer$ ./tools/reboot.py /dev/tty.SLAB_USBtoUART && ../lighthouse-bootloader/scripts/uart_bootloader.py /dev/tty.SLAB_USBtoUART ../crazyflie-firmware/blobs/lighthouse.bin 
Reset command sent!
Bootloader version 2
flash ID: 0xEF 0x40 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
Comparing first and last 256 bytes ...
Different bitstream, flashing the new one ...
Erasing 64K at 0x00020000
Erasing 64K at 0x00030000
Programming ...
Verifying ...
Booting!
While the second time I get:

Code: Select all

Kristoffers-MBP:lighthouse-fpga kristoffer$ ./tools/reboot.py /dev/tty.SLAB_USBtoUART && ../lighthouse-bootloader/scripts/uart_bootloader.py /dev/tty.SLAB_USBtoUART ../crazyflie-firmware/blobs/lighthouse.bin 
Reset command sent!
Bootloader version 2
flash ID: 0xEF 0x40 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
Comparing first and last 256 bytes ...
Identical! Booting ...
Post Reply