LoginSignup
0
1

More than 3 years have passed since last update.

Zephyr + STM32F769 Discovery Kit > UART > UART6の設定表示まで | baud rateの設定: stm32f769i_disco.dts

Last updated at Posted at 2019-11-23
動作環境
Ubuntu 18.04 LTS
STM32F769 Discovery Kit (以下、STM32F769)
Zephyr 2.1.0-rc1

概要

  • STM32F769にはUART1とUART6が用意されている
    • ST STM32F769I Discovery
    • > UART_1 TX/RX : PA9/PA10 (ST-Link Virtual Port Com)
    • > UART_6 TX/RX : PC6/PC7 (Arduino Serial)
  • UARTの使用例 demo sampleコードが見当たらない
  • 検索で見つかったコードを例として、実装してみる
    • UART6の設定表示まで

参考

実装

  1. zephyr/samples/babisc/blinkyのディレクトリをwrk_uart_191123としてコピー
  2. prj.conのCONFIG_SERIALをyに変更
    • printk()デバッグに使用するため
  3. main.cを下記のように実装

(LEDのblink処理も残っている)

main.c
/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <sys/printk.h>

#include <device.h>
#include <drivers/gpio.h>
// added 2019-11-23
#include <uart.h>
#include <console.h>
#include <tty.h>
#include <string.h>

#define LED_PORT    DT_ALIAS_LED0_GPIOS_CONTROLLER
#define LED     DT_ALIAS_LED0_GPIOS_PIN

/* 1000 msec = 1 sec */
#define SLEEP_TIME  1000

#define BARCODE_UART_PORT   "UART_6"
static struct device *uart_dev;
static struct tty_serial console_serial;

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

    uart_dev = device_get_binding(BARCODE_UART_PORT);
    if (uart_dev == NULL) {
        printk("Failed to get %s\n", BARCODE_UART_PORT);
        return -1;
    }

    ret = uart_config_get(uart_dev, &uart_cfg);
    if (!ret) {
        printk("\n======== [%s] ========\n", BARCODE_UART_PORT);
        printk("[%s] uart_config.baudrate=%d\n", BARCODE_UART_PORT, uart_cfg.baudrate);
        printk("[%s] uart_config.parity=%d\n", BARCODE_UART_PORT, uart_cfg.parity);
        printk("[%s] uart_config.stop_bits=%d\n", BARCODE_UART_PORT, uart_cfg.stop_bits);
        printk("[%s] uart_config.data_bits=%d\n", BARCODE_UART_PORT, uart_cfg.data_bits);
        printk("[%s] uart_config.flow_ctrl=%d\n", BARCODE_UART_PORT, uart_cfg.flow_ctrl);
    } else {
        printk("uart_config_get() error\n");
        return -1;
    }
}

void main(void)
{
    u32_t cnt = 0;
    struct device *dev;

    printk("Hello World! %s\n", CONFIG_BOARD);

    dev = device_get_binding(LED_PORT);
    /* Set LED pin as output */
    gpio_pin_configure(dev, LED, GPIO_DIR_OUT);

    uart_init();

    while (1) {
        /* Set pin to HIGH/LOW every 1 second */
        gpio_pin_write(dev, LED, cnt % 2);
        cnt++;
        k_sleep(SLEEP_TIME);
    }
}

実行

一つのターミナルにて下記を実行する。

$ sudo screen /dev/ttyACM0 115200

参考: screenを使ったserial接続と終了の方法メモ by @135yshr さん

情報感謝です。

別のターミナルにて下記を実行する。
プロジェクトは~/Zephyr_191116/zephyrproject以下に配置している。

$ cd ~/Zephyr_191116/zephyrproject
$ west build -p auto -b stm32f769i_disco zephyr/samples/basic/wrk_uart_191123
$ west flash

もう一つのターミナル(screen実行)に下記のように表示される。

Hello World! stm32f769i_disco

======== [UART_6] ========
[UART_6] uart_config.baudrate=115200
[UART_6] uart_config.parity=0
[UART_6] uart_config.stop_bits=1
[UART_6] uart_config.data_bits=3
[UART_6] uart_config.flow_ctrl=0

baud rateの設定

UART1とUART6のbaud rateの設定は下記のファイルに見つかった。
zephyr/boards/arm/stm32f769i_disco/stm32f769i_disco.dts

zephyr/boards/arm/stm32f769i_disco/stm32f769i_disco.dts
&usart1 {
    current-speed = <115200>;
    status = "okay";
};

&usart6 {
    current-speed = <115200>;
    status = "okay";
};
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1