Skip to content

PORTENTA_H7: CYW4343X support and BLE low power implementation #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
#include "CyH4TransportDriver.h"
#include "mbed_power_mgmt.h"
#include "drivers/InterruptIn.h"
#include "cybsp_types.h"
#include "Callback.h"
#include "rtos/ThisThread.h"
#include <chrono>
@@ -31,9 +30,9 @@ namespace cypress_ble {

using namespace std::chrono_literals;


CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, PinName bt_power_name, int baud, PinName bt_host_wake_name, PinName bt_device_wake_name, uint8_t host_wake_irq, uint8_t dev_wake_irq) :
cts(cts), rts(rts),
tx(tx), rx(rx),
uart(tx, rx), cts(cts), rts(rts),
bt_host_wake_name(bt_host_wake_name),
bt_device_wake_name(bt_device_wake_name),
bt_power(bt_power_name, PIN_OUTPUT, PullNone, 0),
@@ -47,8 +46,8 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
bt_host_wake_active = false;
}

CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, PinName bt_power_name, int baud) :
cts(cts),
CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, PinName bt_power_name, int baud) :
uart(tx, rx), cts(cts),
rts(rts),
tx(tx), rx(rx),
bt_host_wake_name(NC),
@@ -107,16 +106,15 @@ void CyH4TransportDriver::bt_host_wake_fall_irq_handler(void)
}
}

static void on_controller_irq(void *callback_arg, cyhal_uart_event_t event)
void CyH4TransportDriver::on_controller_irq()
{
(void)(event);
cyhal_uart_t *uart_obj = (cyhal_uart_t *)callback_arg;
sleep_manager_lock_deep_sleep();

while (cyhal_uart_readable(uart_obj)) {
while (uart.readable()) {
uint8_t char_received;
cyhal_uart_getc(uart_obj, &char_received, 0);
CyH4TransportDriver::on_data_received(&char_received, 1);
if (uart.read(&char_received, 1)) {
CordioHCITransportDriver::on_data_received(&char_received, 1);
}
}

sleep_manager_unlock_deep_sleep();
@@ -129,14 +127,24 @@ void CyH4TransportDriver::initialize()
bt_power = 0;
rtos::ThisThread::sleep_for(1ms);

cyhal_uart_init(&uart, tx, rx, NULL, NULL);
uart.baud(DEF_BT_BAUD_RATE);

uart.format(
/* bits */ 8,
/* parity */ mbed::SerialBase::None,
/* stop bit */ 1
);

uart.set_flow_control(
/* flow */ mbed::SerialBase::RTSCTS,
/* rts */ rts,
/* cts */ cts
);

const cyhal_uart_cfg_t uart_cfg = { .data_bits = 8, .stop_bits = 1, .parity = CYHAL_UART_PARITY_NONE, .rx_buffer = NULL, .rx_buffer_size = 0 };
cyhal_uart_configure(&uart, &uart_cfg);
cyhal_uart_set_flow_control(&uart, cts, rts);
cyhal_uart_clear(&uart);
cyhal_uart_register_callback(&uart, &on_controller_irq, &uart);
cyhal_uart_enable_event(&uart, CYHAL_UART_IRQ_RX_NOT_EMPTY, CYHAL_ISR_PRIORITY_DEFAULT, true);
uart.attach(
mbed::callback(this, &CyH4TransportDriver::on_controller_irq),
mbed::SerialBase::RxIrq
);

bt_power = 1;

@@ -160,17 +168,6 @@ void CyH4TransportDriver::initialize()

void CyH4TransportDriver::terminate()
{
cyhal_uart_event_t enable_irq_event = (cyhal_uart_event_t)(CYHAL_UART_IRQ_RX_DONE
| CYHAL_UART_IRQ_TX_DONE
| CYHAL_UART_IRQ_RX_NOT_EMPTY
);

cyhal_uart_enable_event(&uart,
enable_irq_event,
CYHAL_ISR_PRIORITY_DEFAULT,
false
);

if(bt_host_wake.is_connected())
{
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
@@ -182,7 +179,7 @@ void CyH4TransportDriver::terminate()

bt_power = 0; //BT_POWER is an output, should not be freed only set inactive

cyhal_uart_free(&uart);
uart.close();
}

uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
@@ -194,11 +191,11 @@ uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)

while (i < len + 1) {
uint8_t to_write = i == 0 ? type : pData[i - 1];
while (cyhal_uart_writable(&uart) == 0);
cyhal_uart_putc(&uart, to_write);
while (uart.writeable() == 0);
uart.write(&to_write, 1);
++i;
}
while(cyhal_uart_is_tx_active(&uart));
while (uart.writeable() == 0);

deassert_bt_dev_wake();
sleep_manager_unlock_deep_sleep();
@@ -234,8 +231,7 @@ void CyH4TransportDriver::deassert_bt_dev_wake()

void CyH4TransportDriver::update_uart_baud_rate(int baud)
{
uint32_t ignore;
cyhal_uart_set_baud(&uart, (uint32_t)baud, &ignore);
uart.baud((uint32_t)baud);
}

bool CyH4TransportDriver::get_enabled_powersave()
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
#include "ble/driver/CordioHCITransportDriver.h"
#include "drivers/DigitalInOut.h"
#include "drivers/InterruptIn.h"
#include "cyhal_uart.h"
#include "drivers/UnbufferedSerial.h"

namespace ble {
namespace vendor {
@@ -81,6 +81,7 @@ class CyH4TransportDriver : public CordioHCITransportDriver {
private:
void assert_bt_dev_wake();
void deassert_bt_dev_wake();
void on_controller_irq();

// Use HAL serial because Cypress UART is buffered.
// The PUTC function does not actually blocks until data is fully transmitted,
@@ -89,8 +90,7 @@ class CyH4TransportDriver : public CordioHCITransportDriver {
// However UART APIs does not prevent the BT radio from going to sleep.
// Use the HAL APIs to prevent the radio from going to sleep until UART transmition is complete.
// Mbed layer has no API that distinguish between data in HW buffer v.s. data already transmitted.

cyhal_uart_t uart;
mbed::UnbufferedSerial uart;
PinName cts;
PinName rts;
PinName tx;
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*******************************************************************************
* \file cy_bt_cordio_cfg.cpp
* \version 1.0
*
*
* Low Power Assist BT Pin configuration implementation.
*
********************************************************************************
* \copyright
* Copyright 2019 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* 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.
*******************************************************************************/

#include <stdio.h>
#include "ble/driver/CordioHCIDriver.h"
#include "hci_api.h"
#include "hci_cmd.h"
#include "hci_core.h"
#include "bstream.h"
#include "assert.h"
#include <stdbool.h>
#include "hci_mbed_os_adaptation.h"
#include "CyH4TransportDriver.h"

#define cyhal_gpio_to_rtos(x) (x)
#define CYCFG_BT_LP_ENABLED (1)
#define CYCFG_BT_HOST_WAKE_IRQ_EVENT WAKE_EVENT_ACTIVE_LOW
#define CYCFG_BT_DEV_WAKE_POLARITY WAKE_EVENT_ACTIVE_LOW

/*******************************************************************************
* Function Name: ble_cordio_get_h4_transport_driver
********************************************************************************
*
* Strong implementation of function which calls CyH4TransportDriver constructor and return it
*
* \param none
*
* \return
* Returns the transport driver object
*******************************************************************************/
ble::vendor::cypress_ble::CyH4TransportDriver& ble_cordio_get_h4_transport_driver()
{
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)

#if (defined(CYCFG_BT_LP_ENABLED))
if (CYCFG_BT_LP_ENABLED) {
static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver(
/* TX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_TX),
/* RX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RX),
/* cts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_CTS),
/* rts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RTS),
/* power */ cyhal_gpio_to_rtos(CYBSP_BT_POWER),
DEF_BT_BAUD_RATE,
cyhal_gpio_to_rtos(CYBSP_BT_HOST_WAKE),
cyhal_gpio_to_rtos(CYBSP_BT_DEVICE_WAKE),
CYCFG_BT_HOST_WAKE_IRQ_EVENT,
CYCFG_BT_DEV_WAKE_POLARITY
);
return s_transport_driver;
} else { /* CYCFG_BT_LP_ENABLED */
static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver(
/* TX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_TX),
/* RX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RX),
/* cts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_CTS),
/* rts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RTS),
/* power */ cyhal_gpio_to_rtos(CYBSP_BT_POWER),
DEF_BT_BAUD_RATE);
return s_transport_driver;
}
#else /* (defined(CYCFG_BT_LP_ENABLED)) */
static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver(
/* TX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_TX),
/* RX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RX),
/* cts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_CTS),
/* rts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RTS),
/* power */ cyhal_gpio_to_rtos(CYBSP_BT_POWER),
DEF_BT_BAUD_RATE),
cyhal_gpio_to_rtos(CYBSP_BT_HOST_WAKE), cyhal_gpio_to_rtos(CYBSP_BT_DEVICE_WAKE)
);
return s_transport_driver;
#endif /* (defined(CYCFG_BT_LP_ENABLED)) */

#else /* (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER) */
static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver(
/* TX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_TX),
/* RX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RX),
/* cts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_CTS),
/* rts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RTS),
/* power */ cyhal_gpio_to_rtos(CYBSP_BT_POWER),
DEF_BT_BAUD_RATE);
return s_transport_driver;
#endif /* (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER) */
}
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_functional/callback/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-mbed-functional-callback)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_functional/callback_big/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-mbed-functional-callback-big)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_functional/callback_small/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-mbed-functional-callback-small)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
15 changes: 15 additions & 0 deletions platform/tests/TESTS/mbed_micro/attributes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-mbed-micro-attributes)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

list(APPEND TEST_SOURCE_LIST weak.c attributes.c)

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET} TEST_SOURCES ${TEST_SOURCE_LIST})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_micro/call_before_main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-mbed-micro-call-before-main)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_micro/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-mbed-micro-cpp)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_micro/div/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-mbed-micro-div)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
15 changes: 15 additions & 0 deletions platform/tests/TESTS/mbed_micro/static_assert/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-mbed-micro-static-assert)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

list(APPEND TEST_SOURCE_LIST test_c.c test_cpp.cpp)

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET} TEST_SOURCES ${TEST_SOURCE_LIST})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/CircularBuffer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-circular-buffer)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/FileHandle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-filehandle)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/SharedPtr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-sharedptr)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/SingletonPtr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-singletonptr)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/Stream/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-stream)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/Transaction/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-transaction)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/atomic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-atomic)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/crash_reporting/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-crash-reporting)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/critical_section/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-critical-section)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/error_handling/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-error-handling)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-minimal-printf-compliance)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET} TEST_SOURCES mbed_printf.c)
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/stats_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-stats-cpu)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/stats_heap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-stats-heap)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/stats_sys/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-stats-sys)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/stats_thread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-stats-thread)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/system_reset/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-system-reset)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
13 changes: 13 additions & 0 deletions platform/tests/TESTS/mbed_platform/wait_ns/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../.. CACHE INTERNAL "")
set(TEST_TARGET mbed-platform-wait-ns)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)

project(${TEST_TARGET})

mbed_greentea_cmake_macro(TEST_NAME ${TEST_TARGET})
9 changes: 8 additions & 1 deletion targets/targets.json
Original file line number Diff line number Diff line change
@@ -3021,7 +3021,14 @@
],
"detect_code": ["0813"],
"components_add": [
"QSPIF"
"QSPIF",
"CYW43XXX"
],
"extra_labels_add": [
"CORDIO"
],
"features": [
"BLE"
],
"device_has_add": [
"USBDEVICE",
21 changes: 21 additions & 0 deletions tools/cmake/README.md
Original file line number Diff line number Diff line change
@@ -76,3 +76,24 @@ If you're running CMake directly, you may need to pass it in yourself as follows
```
cmake -S <source-dir> -B <build-dir> -DCMAKE_BUILD_TYPE=debug
```
## How to build a greentea test
Install prerequisites suggested in the previous section and follow the below steps to build:
* Generate the `.mbedbuild/` configuration directory for the Mbed target you want to run the test on using [mbed-os-example-blinky](https://github.com/ARMmbed/mbed-os-example-blinky)
```
$ mbedtools configure -t <TOOLCHAIN> -m <MBED_TARGET>
```
* Copy `.mbedbuild/` into the test suite directory.
* Set your current directory to the test suite directory
* Run the following command to build the test binary with the full profile
```
touch mbed-os.lib && mkdir cmake_build && cd cmake_build && cmake .. -G Ninja && cmake --build .
```
* Run the following command to build the test binary with the baremetal profile
```
touch mbed-os.lib && mkdir cmake_build && cd cmake_build && cmake .. -G Ninja -DMBED_BAREMETAL_GREENTEA_TEST=ON && cmake --build .
```
Note: These steps will change when `mbedtools` implements a sub-command to invoke Greentea tests
78 changes: 78 additions & 0 deletions tools/cmake/mbed_greentea.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

set(MBED_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.mbedbuild CACHE INTERNAL "")

include(${MBED_PATH}/tools/cmake/app.cmake)

# CMake Macro for generalizing CMake configuration across the greentea test suite with configurable parameters
# Macro args:
# TEST_NAME - Test suite name
# TEST_INCLUDE_DIRS - Test suite include directories for the test
# TEST_SOURCES - Test suite sources
# TEST_REQUIRED_LIBS - Test suite required libraries
#
# calling the macro:
# mbed_greentea_cmake_macro(
# TEST_NAME mbed-platform-system-reset
# TEST_INCLUDE_DIRS mbed_store
# TEST_SOURCES foo.cpp bar.cpp
# TEST_REQUIRED_LIBS mbed-kvstore mbed-xyz
# )

macro(mbed_greentea_cmake_macro)
set(options)
set(singleValueArgs TEST_NAME)
set(multipleValueArgs
TEST_INCLUDE_DIRS
TEST_SOURCES
TEST_REQUIRED_LIBS
)
cmake_parse_arguments(MBED_GREENTEA
"${options}"
"${singleValueArgs}"
"${multipleValueArgs}"
${ARGN}
)

set(TEST_NAME ${MBED_GREENTEA_TEST_NAME})

add_subdirectory(${MBED_PATH} build)

add_executable(${TEST_NAME})

mbed_configure_app_target(${TEST_NAME})

mbed_set_mbed_target_linker_script(${TEST_NAME})

target_include_directories(${TEST_NAME}
PRIVATE
.
${MBED_GREENTEA_TEST_INCLUDE_DIRS}
)

target_sources(${TEST_NAME}
PRIVATE
main.cpp
${MBED_GREENTEA_TEST_SOURCES}
)

if(MBED_BAREMETAL_GREENTEA_TEST)
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-baremetal mbed-greentea)
else()
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-os mbed-greentea)
endif()

target_link_libraries(${TEST_NAME}
PRIVATE
${MBED_GREENTEA_TEST_REQUIRED_LIBS}
)

mbed_set_post_build(${TEST_NAME})

option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()

endmacro()