0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Realtek AmebaのUARTについて

Posted at

Realtek AmebaのUARTについて

Realtek Amebaのベアメタルな環境でUARTを使いたいので調べてみました。

ビルドは、https://github.com/eggman/rtl_ameba_gcc_sample のmain.cを書き換えて行いました。

まとめ

  • ROMにあるUARTの関数を呼べば動作する。
  • UART初期化は起動時にROMのコードが行っている。その際のUARTの設定は38400bps,8,N,1になっている。
  • いろいろな機能を使いたい場合は調査が必要。

送信

  • 1文字送信はROMに内蔵されている HalSerialPutcRtl8195a()を使う
extern _LONG_CALL_ VOID
HalSerialPutcRtl8195a(
    IN  u8 c
    );

受信

  • 1文字受信は ROMに内蔵されている HalSerialGetcRtl8195a()を使う。引数PullModeには1を設定する。0だと動かなかった。
extern _LONG_CALL_ u8
HalSerialGetcRtl8195a(
    IN  BOOL    PullMode
    );

サンプルプログラム

  • キーボードからの改行までの複数文字の入力を表示するサンプル
# include "rtl8195a.h"

# define KEY_ENTER 13

char lbuf[128];

void _putc(char c)
{
    HalSerialPutcRtl8195a((u8) c);
}

char getc(void)
{
    return (char) HalSerialGetcRtl8195a(1);
}

void newline(void)
{
    _putc(13);
    _putc(10);
}

void _puts(const char *s)
{
    while (*s) _putc(*s++);
}

void gets(void)
{
    char c;
    size_t len;

    len=0;
    while( (c = getc()) != KEY_ENTER)
    {
        lbuf[len++] = c;
        _putc(c);
    }

    newline();
    lbuf[len] = 0;
}

int main(void)
{
    while (1) {
        _puts(">");

        gets();

        _puts(">> input is ");
        _puts(lbuf);
        newline();
    }
}

動作例

===== Enter Image 2 ====
>ABC
>> input is ABC
>DEF
>> input is DEF
>XYZ
>> input is XYZ
>
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?