Skip to content

stm32: serial: Data is not read properly at a certain baud rate #13890

@KwonTae-young

Description

@KwonTae-young

Describe the bug
UART data is not read properly at a certain baud rate.

To Reproduce
Board: stm32f4_disco
Barcode module: EM1399
image

I was conducting a test with EM1399 to read the barcode.
EM1399 is connected to UART1.

west init zephyrproject -m https://github.com/KwonTae-young/zephyr/ --mr code
cd zephyrproject/zephyr
source zephyr-env.sh
mkdir samples/barcode/build
cd samples/barcode/build/
cmake -DBOARD=stm32f4_disco ..
make -j8 flash

Expected behavior
I expected the scanned barcode information to be output.

Impact
At certain baud rate, barcode data is not read properly through UART.

Screenshots or console output
I have tested on a total of two boards.(stm32f4_disco, nrf52840_pca10056)
stm32f4_disco does not read the data properly.
nrf52840_pca10056 reads the data correctly.

  1. UART setup of EM1399
EM1399
baud rate 9600
stop bit 1
data bit 8
parity none
flow control none
  1. stm32f4_disco
    image
  • pin connection
EM1399 stm32f4_disco
VDD(2) 3V
GND(3) GND
TX(5) PB7(UART1_RX)
nTrig(12) custom button
  • console
***** Booting Zephyr OS zephyr-v1.13.0-5106-g5d6c36b85f *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=9600
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 32 (1 bytes)
uart_isr: 37 (1 bytes)
uart_isr: 31 (1 bytes)
uart_isr: 36 (1 bytes)
uart_isr: 0a (1 bytes)
  1. nrf52840_pca10056
    image
  • pin connection
EM1399 nrf52840_pca10056
VDD(2) 3V
GND(3) GND
TX(5) P0.27(UART1_RX)
nTrig(12) custom button
  • console
***** Booting Zephyr OS zephyr-v1.13.0-5105-g7352d2b0c1 *****
Sample app running on: nrf52840_pca10056
uart_init() done
uart_config.baudrate=9600
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 39 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 39 (1 bytes)
uart_isr: 32 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 37 (1 bytes)
uart_isr: 34 (1 bytes)
uart_isr: 31 (1 bytes)
uart_isr: 34 (1 bytes)
uart_isr: 36 (1 bytes)
uart_isr: 0d (1 bytes)

Environment (please complete the following information):

  • OS: Linux(Ubuntu 18.04)
  • Toolchain: Zephyr SDK 0.9.5
  • Commit SHA or Version used: 7352d2b.

Additional context
nrf52840_pca10056 is normal and only stm32f4_disco is read strangely.
So I think it is a bug.
The barcode data tested is shown below.
image

/*
 * Copyright (c) 2015 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <stdio.h>
#include <zephyr/types.h>
#include <string.h>
#include <uart.h>
#include <misc/byteorder.h>

#define BUF_MAXSIZE	256
#define SLEEP_TIME	500

static struct device *uart_dev;
static u8_t rx_buf[BUF_MAXSIZE];

static void msg_dump(const char *s, u8_t *data, unsigned len)
{
	unsigned i;

	printf("%s: ", s);
	for (i = 0U; i < len; i++) {
		printf("%02x ", data[i]);
	}
	printf("(%u bytes)\n", len);
}

static void uart_isr(struct device *x)
{
	int len = uart_fifo_read(uart_dev, rx_buf, BUF_MAXSIZE);

	ARG_UNUSED(x);
	msg_dump(__func__, rx_buf, len);
}

static void uart_init(void)
{
	uart_dev = device_get_binding("UART_1");

	uart_irq_callback_set(uart_dev, uart_isr);
	uart_irq_rx_enable(uart_dev);

	printf("%s() done\n", __func__);
}

void main(void)
{
	struct uart_config uart_cfg;
	int ret;

	printf("Sample app running on: %s\n", CONFIG_BOARD);

	uart_init();

	ret = uart_config_get(uart_dev, &uart_cfg);
	if (ret == 0) {
		printf("uart_config.baudrate=%d\n", uart_cfg.baudrate);
		printf("uart_config.parity=%d\n", uart_cfg.parity);
		printf("uart_config.stop_bits=%d\n", uart_cfg.stop_bits);
		printf("uart_config.data_bits=%d\n", uart_cfg.data_bits);
		printf("uart_config.flow_ctrl=%d\n", uart_cfg.flow_ctrl);
	} else {
		printf("uart_config_get() error\n");
	}

	while (1) {
		k_sleep(SLEEP_TIME);
	}
}
  • baud rate
    I tested it by changing the baud rate.
    The baud rate of EM1399 and stm32f4_disco are set equal.
    The test results show that the data was read correctly only on 2400 and 4800.
    Below is the log by the baud rate I tested in stm32f4_disco.
  1. baud rate: 1200
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=1200
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
uart_isr: 00 (1 bytes)
  1. baud date: 2400
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=2400
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 39 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 39 (1 bytes)
uart_isr: 32 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 37 (1 bytes)
uart_isr: 34 (1 bytes)
uart_isr: 31 (1 bytes)
uart_isr: 34 (1 bytes)
uart_isr: 36 (1 bytes)
uart_isr: 0d (1 bytes)
uart_isr: 0a (1 bytes)
  1. baud rate: 4800
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=4800
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 39 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 39 (1 bytes)
uart_isr: 32 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 37 (1 bytes)
uart_isr: 34 (1 bytes)
uart_isr: 31 (1 bytes)
uart_isr: 34 (1 bytes)
uart_isr: 36 (1 bytes)
uart_isr: 0d (1 bytes)
uart_isr: 0a (1 bytes)
  1. baud rate: 9600
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=9600
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 32 (1 bytes)
uart_isr: 37 (1 bytes)
uart_isr: 31 (1 bytes)
uart_isr: 36 (1 bytes)
uart_isr: 0a (1 bytes)
  1. baud rate: 14400
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=14400
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 39 (1 bytes)
uart_isr: 32 (1 bytes)
uart_isr: 34 (1 bytes)
uart_isr: 36 (1 bytes)
  1. baud rate: 19200
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=19200
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 30 (1 bytes)
uart_isr: 37 (1 bytes)
uart_isr: 36 (1 bytes)
  1. baud rate: 38400
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=38400
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 37 (1 bytes)
  1. baud rate: 57600
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=57600
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)
uart_isr: 34 (1 bytes)
  1. baud rate: 115200
***** Booting Zephyr OS zephyr-v1.13.0-5106-g34550e11e9 *****
Sample app running on: stm32f4_disco
uart_init() done
uart_config.baudrate=115200
uart_config.parity=0
uart_config.stop_bits=1
uart_config.data_bits=3
uart_config.flow_ctrl=0
uart_isr: 38 (1 bytes)
uart_isr: 38 (1 bytes)

I'm sorry I do not have enough English.
Thank you.

Metadata

Metadata

Assignees

Labels

area: UARTUniversal Asynchronous Receiver-TransmitterbugThe issue is a bug, or the PR is fixing a bugplatform: STM32ST Micro STM32priority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions