UART HAL Module Guide
UART HAL Module Guide
Read from UART device. If a transfer instance is used for reception, the
received bytes are stored directly in the read input buffer, uart0_buf. When a
transfer is complete, the callback is called with event
UART_EVENT_RX_COMPLETE. Bytes received outside an active transfer
are received in the callback function with event UART_EVENT_RX_CHAR.
Write to UART device. The write buffer is used until write is complete. Do not
overwrite write buffer contents until the write is finished. When the write is
complete (all bytes are fully transmitted on the wire), the callback called with
event UART_EVENT_TX_COMPLETE.
.baudSet g_uart0.p_api->baudSet(g_uart0.p_ctrl, (uint32_t)9600);
The UART on SCI HAL module invokes the user callback function from the RXI ISR at the top and at the end
of processing.
The callback function argument “level” refers to the signal level on the RTS pin for the selected SCI channel.
Note: The HAL module does not handle the GPIO pin initialization or control it. Instead, you need to initialize
the GPIO pin before starting the UART reception.
When the UART HAL module on r_sci_uart is added to a thread as shown in the following figure, the
configurator automatically adds the needed lower-level drivers. Any drivers that need additional configuration
information will be box text highlighted in Red. Modules with a Gray band are individual modules that stand
alone. Modules with a Blue band are shared or common and need only be added once and can be used by
multiple stacks.
When the mouse hovers over the Red position, the required operations for correcting the configuration will
display. Please follow the instructions to enable the SCI Receive Interrupt (RXI), SCI Transmit Interrupt
(TXI), and SCI Transmit End Interrupt (TEI) in the Properties window to complete a valid configuration.
Default: BSP
Name g_uart0 The name to be used for UART on SCI module
control block instance. This name is also used
as the prefix of the other variable instances.
Channel 0-9 SCI channel number.
Baud Rate 9600 Baud rate selection.
Data Bits 7 bits, 8, bits, 9 bits UART data bits.
Default: 8 bits
Parity None, Odd, Even UART parity bits.
Default: None
Stop Bits 1 bit, 2 bits UART stop bits.
Default: 1 bit
Default: Disabled
Transmit Interrupt Priority 0 (highest), Priority Transmit interrupt priority selection.
Priority 1:2, Priority 3 (CM4: valid,
CM0+: lowest- not valid if
using ThreadX), Priority 4:14
(CM4: valid, CM0+: invalid),
Priority 15 (CM4 lowest - not
valid if using ThreadX,
CM0+: invalid)
Default: Disabled
Transmit End Priority 0 (highest), Priority Transmit end interrupt priority selection.
Interrupt Priority 1:2, Priority 3 (CM4: valid,
CM0+: lowest- not valid if
using ThreadX), Priority 4:14
(CM4: valid, CM0+: invalid),
Priority 15 (CM4 lowest - not
valid if using ThreadX,
CM0+: invalid)
Default: Disabled
Error Interrupt Priority Priority 0 (highest), Priority Error interrupt priority selection.
1:2, Priority 3 (CM4: valid,
CM0+: lowest- not valid if
using ThreadX), Priority 4:14
(CM4: valid, CM0+: invalid),
Priority 15 (CM4 lowest - not
valid if using ThreadX,
CM0+: invalid)
Default: Disabled
Baud rate Percent Value must be greater than Maximum baud rate percent error allowed in
Error 0.0 and less than 15.0 order for the
Default; 2.0 module to function
UART RS232, RS485 UART communication mode
Communication Default: RS232 selection, usually it is RS232
Mode mode
UART RS485 Half Duplex, Full Duplex UART RS485 communication mode selection
Communication Default: Half duplex as half duplex or full duplex
Mode
RS485 DE Port 00 to 11 Select the port number of Driver Enable Pin
Default: 09
RS485 DE Pin 00 to 15 Select the pin number of Driver
Default: 14 Enable Pin
Note: The example values and defaults are for a project using the Synergy S7G2. Other MCUs may have
different default values and available configuration settings.
In some cases, settings other than the defaults for lower-level modules can be desirable. For example, it
might be useful to select different noise cancellation settings. The configurable properties for the lower-level
stack modules are given in the following sections for completeness and as a reference.
Note: Most of the property settings for lower-level modules are fairly intuitive and usually can be determined
by inspection of the associated Properties window from the SSP configurator.
5.1 Configuration Settings for the UART HAL Module Lower Level Modules
Typically, only a small number of settings must be modified from the default for lower-level modules as
indicated via the red text in the thread stack block. Notice that some of the configuration properties must be
set to a certain value for proper framework operation and will be locked to prevent user modification. The
following table identifies all the settings within the properties section for the module.
Table 5. Configuration for the Transfer Driver on r_dtc Event SCI0 TXI
ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled Selects if code for parameter checking
is to be included in the build
Default: BSP
Default: Disabled
Linker section to keep .ssp_dtc_vector_table Linker section setting
DTC vector table
Name g_transfer0 Module name
Mode Normal Mode selection
Transfer Size 1 Bytes Transfer size selection
Destination Address Mode Fixed Destination address mode selection
Source Address Mode Incremented Source address mode selection
Repeat Area (Unused in Source Repeat area selection
Normal Mode)
Interrupt Frequency After all transfers have Interrupt frequency selection
completed
Destination Pointer NULL Destination pointer selection
Source Pointer NULL Source pointer selection
Number of Transfers 0 Number of transfers selection
Number of Blocks (Valid 0 Number of blocks selection
only in Block Mode)
Activation Source (Must Event SCI0 TXI Activation source selection
enable IRQ)
Auto Enable True, False Auto enable selection
Default: True
Callback (Only valid with NULL Callback selection
Software start)
ELC Software Event Priority 0 (highest), Priority 1:2, ELC Software Event interrupt priority
Interrupt Priority Priority 3 (CM4: valid, CM0+: selection
lowest- not valid if using
ThreadX), Priority 4:14 (CM4:
valid, CM0+: invalid), Priority
15 (CM4 lowest - not valid if
using ThreadX, CM0+: invalid)
Default: Disabled
Note: The example values and defaults are for a project using the Synergy S7G2 MCU Family. Other MCUs
may have different default values and available configuration settings.
Table 6. Configuration for the Transfer Driver on r_dtc Event SCI0 RXI
ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled Selects if code for parameter checking
is to be included in the build
Default: BSP
Software Start Enabled, Disabled Set start mode
Default: Disabled
Linker section to keep .ssp_dtc_vector_table Linker section setting
DTC vector table
Name g_transfer1 Module name
Mode Normal Mode selection
Transfer Size 1 Bytes Transfer size selection
Destination Address Incremented Destination address mode selection
Mode
Source Address Mode Fixed Source address mode selection
When the UART with CTS and RTS function are used simultaneously, the transfer driver cannot be used.
Delete all transfer drivers on the low level. After being deleted, the optional transfer driver will display in pink,
which means that the driver is recommended but optional, as in the following figure.
Important Note: Two SK-S7G2 kits are required to demonstrate the flow control example.
The specific operation flow of CTS/RTS hardware flow-control using external GPIO pin as the RTS signal is
as follows (for UART0):
• Initialize the UART HAL module using the open API.
• Change baud rate as needed using the baudSet API.
• Store received data into user-defined buffer in the interrupt callback function (when the event code of
UART_EVENT_RX_CHAR is set).
• Set the flag in the interrupt callback function when data reception is completed.
• Operate on the received data as needed by the application when the received completion flag is set.
• Transmit data to external device according to the application.
• Wait for the completion of transmission. In the interrupt callback function, after the last data is sent, the
event code of UART_EVENT_TX_COMPLETE is set.
• Close the UART HAL Module using the close API after the data transmission is finished.
A simple flow diagram of the application project is given in the following figures.
Callback Function
Switch Event
UART0 UART4
Return
If the semi-hosting function is enabled, the printf function will output all received data and send data to the
Debug Virtual Console.
Note: This description assumes you are familiar with using printf() with the Debug Console in the
Synergy Software Package. If you are unfamiliar with this, refer to the “How do I Use Printf() with the
Debug Console in the Synergy Software Package” available as described in the References section
at the end of this document. Alternatively, you can see results via the watch variables in the debug
mode.
A few key properties are configured in this application project to support the required operations and the
physical properties of the target board and MCU. The properties with the values set for this specific project
are listed in the following tables. You can also open the application project and view these settings in the
Properties window as a hands-on exercise.
To access a particular channel or pin, the SCI pin must be set in the Pins tab of the ISDE.
The following tables illustrate the method for selecting the pins within the SSP configuration window and
example selections for the SCI pin.
UART0 in specific operation
Table 12. Pin Selection Sequence for UART HAL Module on SCI
Resource ISDE Tab Pin selection Sequence
SCI Pins Select Peripherals > Connectivity: SCI > SCI0
Table 13. Pin Configuration Settings for UART HAL Module on SCI
Pin Configuration Property Value
Pin Group Selection Mixed
Operation Mode Custom
TXD_MOSI P411
RXD_MISO P410
SCK, SDA, SCL None
Table 17. Pin Configuration Settings for UART HAL Module on SCI
Pin Configuration Property Value
Pin Group Selection Mixed
Operation Mode Asynchronous UART
TXD_MOSI P512
RXD_MISO P511
Note: The example values are for a project using the Synergy S7G2 and the SK-S7G2 Kit. Other Synergy
Kits and other Synergy MCUs may have different available pin configuration settings. For pins used,
see the following graphic.
UART0
UART0
UART4
Initialize UART
.open
No
Is S1 button pressed?
Yes
Send data to slave device
.write
No
Send finish?
Yes
Read feedback from slave device
.read
No
Receive finish?
Yes
Compare received data with stored data
and output received data
Initialize UART
.open
No
Receive finish?
Yes
Is received data
equal to stored data?
Yes No
Send “Received data is right!” Send “Received data is right!”
.write .write
No
Send finish?
Yes
Figure 22. Example Output from RS-485 Master Project when received data is right
Figure 23. Example Output from RS-485 Master Project when received data is wrong
Trademarks
Renesas and the Renesas logo are trademarks of Renesas Electronics
Corporation. All trademarks and registered trademarks are the property
of their respective owners.