UART adapter

Description

This example shows:

  • How to develop a custom UART based on the UART adapter provided in GVSOC blocks.

  • How to instantiate it in a custom board.

  • How to access it from C code.

The UART model is instantiated inside a custom board on which simulation is launched to interact with it.

The UART model is relying on the UART adapter for the low-level interaction with the chip UART interface, so that it can just focus on sending and receiving bytes:

../../../../../../_images/block.drawio.png

More information about modeling UART peripherals can be found in the GVSOC developer documentation, under “tutorials / 20 - How to model a UART peripheral”.

More information about the UART adapters can be found in the GVSOC developer documentation, under “Models / Utility blocks / UUART adapters”.

Code

#
# Copyright (C) 2022 GreenWaves Technologies
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import argparse
import gvsoc.runner
import gvsoc.systree
import gap.gap9.bare_board
import my_uart


# This is the Gapy descriptor for our board which will make it available on the command-line.
class Target(gvsoc.runner.Target):

    gapy_description = "GAP9 bare board with uart"

    def __init__(self, parser, options):
            super(Target, self).__init__(parser, options,
                model=MyBoard)


# This our custom board with our UART model.
# It just starts from a bare board which contains only a chip and the reset, and then add
# and connects our uart model
class MyBoard(gap.gap9.bare_board.Gap9BareBoard):

    def __init__(self, parent: gvsoc.systree.Component, name: str, parser: argparse.ArgumentParser,
                options: list):

        super(MyBoard, self).__init__(parent, name, parser, options)

        uart = my_uart.MyUart(self, 'uart')

        # Note that we also specify the pads where the UART is connected.
        # This is optional and is used to activate padframe model, which will check if pads
        # are well configured from the SW.
        self.get_chip().o_UART(0, uart.i_UART(), rx=60, tx=61, rts=62, cts=63)

Usage

To be able to use a custom board and model, gvsoc must be recompiled for the custom board.

For that we must first give to the SDK an additional path where it can find our board and model:

export GVSOC_MODULES="$GVSOC_MODULES;$PWD/models"

Then GVSOC must be recompiled for our board:

make all GVSOC_TARGETS=my_board