Crazyflie UART Configuration

Firmware/software/electronics/mechanics
Post Reply
t_walker_21
Beginner
Posts: 17
Joined: Wed Feb 11, 2015 7:39 pm

Crazyflie UART Configuration

Post by t_walker_21 »

Hello Bitcraze Community,

I need to add a GPS to my crazyflie, and I need to know how I can go about setting up a UART interface between the STM MCU and the gps. Where do I put the code to implement the uart, and what exactly do I need to do?

-Tevon
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie UART Configuration

Post by tobias »

Until an easy to use API is in place I would base it of the uart_syslink implementation. All the DMA, NVIC (interrupt) stuff can be dropped and just use the uartSendData function.

The pins to use can be copied from the header file. In the deck pinout:
UART1 would be the UART4
UART2 would be the UART2

It's a bit complected right now but it is at least a start...
t_walker_21
Beginner
Posts: 17
Joined: Wed Feb 11, 2015 7:39 pm

Re: Crazyflie UART Configuration

Post by t_walker_21 »

Okay. Thank you for the information.
t_walker_21
Beginner
Posts: 17
Joined: Wed Feb 11, 2015 7:39 pm

Re: Crazyflie UART Configuration

Post by t_walker_21 »

tobias wrote:Until an easy to use API is in place I would base it of the uart_syslink implementation. All the DMA, NVIC (interrupt) stuff can be dropped and just use the uartSendData function.

The pins to use can be copied from the header file. In the deck pinout:
UART1 would be the UART4
UART2 would be the UART2

It's a bit complected right now but it is at least a start...

So where would I put that "send data" function? Just looking at main, I see a platform/system initialization, and the TaskScheduler being setup. Let us say, for example, I wanted to send the character 't' from uart to perhaps an arduino. WHere would I place uartSendData(1,(uint8_t *)'t'); ? I can't seem to figure out how to append changes to your firmware. Do I make changes to main.c? Or will simply manipulating the header and .c implementation files get the job done? Please clearly explain.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie UART Configuration

Post by tobias »

Yes it is a bit complicated. I'll try to but together the basic driver this week so you can easily use any of the uarts.

Since it is a real-time OS, only the initialization code will be executed from main. After that it is the tasks that executes code. You can find defines of the different tasks in config.h. Depending on what you plan to do, it might be good creating a new task or you can hijack another task such as the stabilizer to execute you code from.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie UART Configuration

Post by tobias »

So I implemented some basic spin loop UART drivers for UART1 and UART2 on the deck port. See this commit. One thing I noticed is that on the deck expansion port image the UART2 TX and RX has been exchanged (TX from the CF2 side should be on pin1).

Enable the drivers by defining ENABLE_UART1 or ENABLE_UART2 in e.g. your config.mk file or e.g. in config.h.
sdiemert
Beginner
Posts: 2
Joined: Tue Dec 13, 2016 6:42 pm

Re: Crazyflie UART Configuration

Post by sdiemert »

Hi,

Jumping on this thread, even though it is a bit old.... It was the closest one to my question that I could find.

I am trying to write my own code on the STM to communicate with the NRF radio to send data back to a host computer. I am creating packets and sending them via UART (sendData function) directly to the NRF, but it doesn't seem to be working....

I have configured the UART (without interrupts) just as in uart_syslink.c and as in uart1.c (your link from above).

Here is the code I am using to send a single char:

Code: Select all

void send_char(char c){
    uint8_t bytes[7] = {0};
    // expected at beginnging of packet
    bytes[0] = 0xBC;
    bytes[1] = 0xCF;
    // radio packet type
    bytes[2] = 0x00;
    // length - one byte
    bytes[3] = 0x01;
    // payload
    bytes[4] = (uint8_t)c;
    uint8_t i;
    for(i = 2; i < 5; i++){
        bytes[5] += bytes[i];
        bytes[6] += bytes[5];
    }
    GPIO_ResetBits(GPIOC, GPIO_Pin_2);
    for(i = 0; i < 7; i++){
        GPIO_ResetBits(GPIOC, GPIO_Pin_0);
        while (!(UART_NAME->SR & USART_FLAG_TXE));
        UART_NAME->DR = (bytes[i] & 0x00FF);
        GPIO_SetBits(GPIOC, GPIO_Pin_0);
    }
    GPIO_SetBits(GPIOC, GPIO_Pin_2);
}
I was using LEDs to debug. Currently, it appears to get stuck in the while loop, i.e. the USART_FLAG_TXE bit is never set.

I suspect I am not doing something that the NRF firmware expects or that I am not clearing a flag, but as far as I can tell, I have correctly crafted a packet and I am sending it correctly.

I am using some python code on my host machine to read the data out of the Crazyflie radio dongle.

Any help appreciated!

Thanks
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie UART Configuration

Post by tobias »

Welcome to the forum sdiemert!

Could you maybe explain a bit more what you want to do? There is already a UART between the STM32 and the NRF51 which carries the syslink. I suspect you want a serial channel through the radio to the computer?
sdiemert
Beginner
Posts: 2
Joined: Tue Dec 13, 2016 6:42 pm

Re: Crazyflie UART Configuration

Post by sdiemert »

Tobias, thanks for the welcome! I am excited to get started with the crazyflie.

In general, I am hoping to write my own custom firmware, I am a college student and am looking to improve my embedded systems skills; writing my own drivers/libraries the Crazyflie platform provides practice and is fun :-). At this point, I am not looking to modify the existing firmware code base, just write my own from scratch.

More specifically, as you suggest, I am hoping to be able to send data from the crazyflie to a host computer (connected via NRF dongle). As you mentioned, the syslink UART is the best way to do this. I am looking to do this without using the libraries from crazyflie-firmware, as I mentioned above, I would like to write them myself for practice.

I am unable to make the code in the above post work, as far as I can tell, it should, but it doesn't, so I am obviously missing something.

Thanks for the prompt reply!
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyflie UART Configuration

Post by arnaud »

Hi sdiemert,

This is an interesting project and you can learn a lot doing that :-).

If you are getting locked in a loop in the STM32 side then you certainly have a problem with the way you are handling the UART peripheral in the STM32. We have two UARTs on the deck expansion port, maybe you can test your driver on one of those to be sure you are setting up the UART correctly.

I guess you have seen the syslink documentation in the wiki: https://wiki.bitcraze.io/doc:crazyflie:syslink:index. The way the radio is implemented, the down-link packets are sent with the radio acknowledgements. This means that you will need to send a packet to the Crazyflie to get the packets back from the Crazyflie.
Post Reply