Using uart in custom application

Support for creating custom user applications on the VESC.
zimon
Posts: 3
Joined: 28 Mar 2017, 10:37

Using uart in custom application

Postby zimon » 28 Mar 2017, 11:33

Hello, maybe someone can help me there.
I want to use the Serial to connect to my Vesc Application, for sending some commands and receiving values.
I connected the RX, TX of UART6 via FTDI to my Laptop, switched on the UART in halconf.h with

Code: Select all

HAL_USE_UART                TRUE

I'm sending strings in this line

Code: Select all

static const uint8_t message[] = "0123456789ABCDEF";
uartStartSend(&UARTD6, 16, message); 


I'm connecting with my terminal on Baudrate 38400, but I don't receive any data. Do I need to initialize the Uart?
Someone having a idea?

rew
Posts: 898
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Using uart in custom application

Postby rew » 29 Mar 2017, 07:22

There are two drivers for serial hardware in Chibios. One is the "serial" and the other is the "uart".

The serial does what you expect from a serial driver: print strings, receive characters etc.

The uart is more geared to a packet format where you know the packet size in advance. Possibly very high speeds (i.e. it uses DMA).

I'm not yet sure if you want to use the UART driver.

For the serial driver you need to initialize with:

Code: Select all

sdStart(&SD1, &mainserial);

zimon
Posts: 3
Joined: 28 Mar 2017, 10:37

Re: Using uart in custom application

Postby zimon » 30 Mar 2017, 10:19

sounds like what I want, cool.
So I switched on the Serial

Code: Select all

#define STM32_SERIAL_USE_USART6             TRUE

and tried to start the serial by

Code: Select all

sdStart(&SD6, &mainserial);

in &mainserial I need to tell cr1,cr2,cr3. Do you have any idea?

Code: Select all

typedef struct {
  /**
   * @brief Bit rate.
   */
  uint32_t                  speed;
  /* End of the mandatory fields.*/
  /**
   * @brief Initialization value for the CR1 register.
   */
  uint16_t                  cr1;
  /**
   * @brief Initialization value for the CR2 register.
   */
  uint16_t                  cr2;
  /**
   * @brief Initialization value for the CR3 register.
   */
  uint16_t                  cr3;
} SerialConfig;


Also I'm looking for the output function. I found a tutorial telling

Code: Select all

 char data[] = "Hello World ! \n \r";
    sdWrite(&SD6, (uint8_t *) data, strlen(data)); // Writes "Hello World in the UART output



So if you have a short Tutorial for me, or a full code sample. It would be wounderful. So far I'm trying, the following. I need the cr1,cr2,cr2 values and the output/input function.

Code: Select all

    static SerialConfig uartCfg =
{
9600,0,0,0 // bit rate
};
    sdStart(&SD6, SerialConfig);
   
    char data[] = "Hello World ! \n \r";
    sdWrite(&SD6, (uint8_t *) data, strlen(data)); // Writes "Hello World in the UART output


Thanks for help!

rew
Posts: 898
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Using uart in custom application

Postby rew » 01 Apr 2017, 12:15

The CR1, -2, and -3 values depend on the hardware, as in: you have to read the reference manual for the chip involved.

[rant mode on]
This is one of the bad design decisions in Chibios. (IMHO). I would want a driver to work with identical code across different CPUs and even architectures as long as you're not doing anything specific to the hardware.

So "blink a led" should require exactly the same code on STM32F103, STM32F205, STM32F405 and atmel. Similarly something simple with the uart should be identical across different CPUs. That's why you have drivers / HAL. Alas, you have to specify the control registers specific for the CPU, and their number changes between CPUs.

I would have preferred something along the lines of Serial_set_options that would be generic enough that you can access all the CPU-specific options that would otherwise be hidden....
[rant mode off]

Anyway, on my STM32F072 my "mainserial" has:

Code: Select all

static SerialConfig mainserial = {
  115200, // the baud rate;
  0,0,0
};
As in: Try with all zeros first. Could very well work. :-)

zimon
Posts: 3
Joined: 28 Mar 2017, 10:37

Re: Using uart in custom application

Postby zimon » 04 Apr 2017, 09:43

hey, thanks for help rew.

Maybe you have a idea about this error?

Code: Select all

.../ChibiOS_3.0.2/os/hal/ports/STM32/LLD/USARTv1/uart_lld.c:444: multiple definition of `Vector15C'
build/obj/serial_lld.o:.../ChibiOS_3.0.2/os/hal/ports/STM32/LLD/USARTv1/serial_lld.c:363: first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [ChibiOS_3.0.2/os/common/ports/ARMCMx/compilers/GCC/rules.mk:236: build/BLDC_4_ChibiOS.elf] Error 1


Is it maybe about the cr1,cr2,cr3 values?

rew
Posts: 898
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

Re: Using uart in custom application

Postby rew » 05 Apr 2017, 03:14

No. It seems you cannot have both the uart and serial drivers enabled at the same time.


Return to “Custom Applications”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest