Skip to content

Commit fe4ee52

Browse files
committed
Support MPS3 AN524 UART0
Enable UART0 support to be able to print logs from Azure RTOS to serial console. Signed-off-by: Devaraj Ranganna <devaraj.ranganna@linaro.org>
1 parent be99477 commit fe4ee52

File tree

7 files changed

+88
-11
lines changed

7 files changed

+88
-11
lines changed

Arm/MPS3_AN524/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set(LINKER_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/startup/mps3_an524.ld")
66
set(SOURCES
77
startup/startup_cmsdk_mps3_an524_bl2.S
88
main.c
9+
board_init.c
10+
console.c
911
)
1012

1113
add_executable(${PROJECT_NAME} ${SOURCES})

Arm/MPS3_AN524/app/board_init.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* Copyright (c) 2021 Linaro Limited. */
2+
3+
#include <stdio.h>
4+
#include <assert.h>
5+
6+
#include "board_init.h"
7+
8+
/* Initialise uart console */
9+
static void console_init()
10+
{
11+
int32_t ret;
12+
13+
/* Initialize the USART driver */
14+
ret = Driver_USART0.Initialize(NULL);
15+
assert(ret == ARM_DRIVER_OK);
16+
17+
/* Power up the USART peripheral */
18+
ret = Driver_USART0.PowerControl(ARM_POWER_FULL);
19+
assert(ret == ARM_DRIVER_OK);
20+
21+
/* Configure the USART to 115200 (DEFAULT_UART_BAUDRATE) Bits/sec */
22+
ret = Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS,
23+
DEFAULT_UART_BAUDRATE);
24+
assert(ret == ARM_DRIVER_OK);
25+
26+
/* Enable Transmitter line */
27+
Driver_USART0.Control(ARM_USART_CONTROL_TX, 1);
28+
}
29+
30+
/* Initialise the board */
31+
void board_init()
32+
{
33+
/* Initialise uart console */
34+
console_init();
35+
}

Arm/MPS3_AN524/app/board_init.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Copyright (c) 2021 Linaro Limited. */
2+
3+
#ifndef _BOARD_INIT_H
4+
#define _BOARD_INIT_H
5+
6+
#include "Driver_USART.h"
7+
#include "device_cfg.h"
8+
9+
/* USART0 driver */
10+
extern ARM_DRIVER_USART Driver_USART0;
11+
12+
void board_init();
13+
14+
#endif // _BOARD_INIT_H

Arm/MPS3_AN524/app/console.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Copyright (c) 2021 Linaro Limited. */
2+
3+
#include <assert.h>
4+
#include <stdio.h>
5+
6+
#include "board_init.h"
7+
8+
/* Override `_write` function to redirect printf to uart console */
9+
int _write(int fd, char *str, int len)
10+
{
11+
(void)fd;
12+
int32_t ret;
13+
14+
/* Send string and return the number of characters written */
15+
ret = Driver_USART0.Send(str, len);
16+
assert(ret == ARM_DRIVER_OK);
17+
18+
/* Add a busy wait after sending. */
19+
while (Driver_USART0.GetStatus().tx_busy);
20+
21+
return Driver_USART0.GetTxCount();
22+
}

Arm/MPS3_AN524/app/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
#include <stdio.h>
44

5+
#include "board_init.h"
6+
57
int main(void)
68
{
7-
/* ToDo: HW init (UART, pins, etc. ) */
9+
/* Initialise the board */
10+
board_init();
11+
12+
printf("Azure RTOS running on MPS3 board\n");
13+
814

915
/* tx_kernel_enter(); */
1016

Arm/MPS3_AN524/lib/AN524/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4-
# Exceptions required by CMSIS UART driver
5-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-ignored-qualifiers -Wno-return-type")
6-
74
set(SOURCES
85
src/CMSIS/Driver_USART.c
96
src/device/source/system_core_init.c
7+
src/device/source/device_definition.c
108
src/native_drivers/uart_cmsdk_drv.c
119
)
1210

Arm/MPS3_AN524/lib/AN524/src/device/source/device_definition.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include "device_definition.h"
2727
#include "platform_base_address.h"
28-
#include "tfm_plat_defs.h"
28+
// #include "tfm_plat_defs.h"
2929

3030
/* UART CMSDK driver structures */
3131
#ifdef UART0_CMSDK_S
@@ -343,16 +343,16 @@ struct ppc_sse200_dev_t APB_PPCEXP2_DEV_S = {
343343

344344
/* CMSDK Timer driver structures */
345345
#ifdef CMSDK_TIMER0_S
346-
static const struct timer_cmsdk_dev_cfg_t CMSDK_TIMER0_DEV_CFG_S
347-
TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_IRQ_TEST_1", "APP-ROT") = {
346+
static const struct timer_cmsdk_dev_cfg_t CMSDK_TIMER0_DEV_CFG_S = {
347+
// TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_IRQ_TEST_1", "APP-ROT") = {
348348
.base = CMSDK_TIMER0_BASE_S
349349
};
350-
static struct timer_cmsdk_dev_data_t CMSDK_TIMER0_DEV_DATA_S
351-
TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_IRQ_TEST_1", "APP-ROT") = {
350+
static struct timer_cmsdk_dev_data_t CMSDK_TIMER0_DEV_DATA_S = {
351+
// TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_IRQ_TEST_1", "APP-ROT") = {
352352
.is_initialized = 0
353353
};
354-
struct timer_cmsdk_dev_t CMSDK_TIMER0_DEV_S
355-
TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_IRQ_TEST_1", "APP-ROT") = {
354+
struct timer_cmsdk_dev_t CMSDK_TIMER0_DEV_S = {
355+
// TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_IRQ_TEST_1", "APP-ROT") = {
356356
&(CMSDK_TIMER0_DEV_CFG_S),
357357
&(CMSDK_TIMER0_DEV_DATA_S)
358358
};

0 commit comments

Comments
 (0)