diff --git a/Examples/MAX32690/Bluetooth/PAL_UART/README.md b/Examples/MAX32690/Bluetooth/PAL_UART/README.md index a27ed5565e2..1ab4aeca2f4 100644 --- a/Examples/MAX32690/Bluetooth/PAL_UART/README.md +++ b/Examples/MAX32690/Bluetooth/PAL_UART/README.md @@ -1,8 +1,6 @@ # Description -Bluetooth version 5.2 controller, accepts HCI commands via Serial Port. - -Refer to the [BLE5_ctr](../../../../Libraries/Cordio/docs/Applications/BLE5_ctr.md) documentation in the Cordio Library. +A minimal program for testing serial echoing by utilizing Cordio's PAL UART implementation. ## Software @@ -13,27 +11,19 @@ Universal instructions on building, flashing, and debugging this project can be ### Required Connections If using the MAX32690EVKIT: -- Connect a USB cable between the PC and the CN2 (USB/PWR) connector. -- Install headers JP7(RX\_EN) and JP8(TX\_EN). -- Open a terminal app on the PC and connect to the EV kit's console UART at 115200, 8-N-1. -- If using the EvKit, the HCI UART is configured as LPUART and is accessible via the CMSIS-DAP. No external serial converter is needed. -- Optionally you can reconfigure the UART definitions in board.h to use the on-board USB to UART - adapter for the HCI UART. +- Connect a USB cable between the PC and the CN2 (USB/PWR - UART) connector. +- Install JP7(RX_EN) and JP8(TX_EN) headers. +- Open a terminal application on the PC and connect to the EV kit's console UART at 115200, 8-N-1. +- Close jumper JP5 (LED1 EN). +- Close jumper JP6 (LED2 EN). If using the MAX32690FTHR: - Connect a USB cable between the PC and the J5 (USB/PWR) connector. - Open a terminal application on the PC and connect to the EV kit's console UART at 115200, 8-N-1. -- Use an external USB-to-UART adapter to access HCI UART. Connect a USB cable between the PC or BLE Tester - and USB side of the adapter. Connect UART side of the adapter to board TX,RX and GND header pins. -- Optionally you can reconfigure the UART definitions in board.h to use the on-board USB to UART - adapter for the HCI UART. If using the AD-APARD32690-SL: - Connect a USB cable between the PC and the P10 (USB-C) connector. -- Connect a MAXPICO Debug adapter to P9 (SWD Connector) - Open a terminal application on the PC and connect to the MAXPICO's console UART at 115200, 8-N-1. -- Use an external USB-to-UART adapter to access HCI UART. Connect a USB cable between the PC or BLE Tester - and USB side of the adapter. Connect UART side of the adapter to board TX,RX and GND header pins. P3 Pin 1 and 2. ### Project-Specific Build Notes * Setting `TRACE=1` in [**project.mk**](project.mk) initializes the on-board USB-to-UART adapter for diff --git a/Examples/MAX32690/Bluetooth/PAL_UART/main.c b/Examples/MAX32690/Bluetooth/PAL_UART/main.c index f0ac691b4b2..a511a384169 100644 --- a/Examples/MAX32690/Bluetooth/PAL_UART/main.c +++ b/Examples/MAX32690/Bluetooth/PAL_UART/main.c @@ -1,7 +1,7 @@ /*************************************************************************************************/ /*! * @file main.c - * @brief Bluetooth version 5.2 controller, accepts HCI commands via Serial Port. + * @brief PAL UART, echoes input via Serial Port. * * Copyright (c) 2013-2019 Arm Ltd. All Rights Reserved. * @@ -23,44 +23,18 @@ */ /*************************************************************************************************/ #include -#include "ll_init_api.h" -#include "chci_tr.h" -#include "lhci_api.h" -#include "hci_defs.h" -#include "wsf_assert.h" -#include "wsf_buf.h" -#include "wsf_heap.h" -#include "wsf_timer.h" -#include "wsf_trace.h" -#include "wsf_bufio.h" -#include "wsf_types.h" -#include "wsf_os.h" -#include "wsf_cs.h" -#include "bb_ble_sniffer_api.h" -#include "pal_bb.h" -#include "pal_cfg.h" -#include "mxc_device.h" +#include "mxc_delay.h" #include "uart.h" -#include "nvic_table.h" #include "board.h" -#include "pal_timer.h" #include "pal_uart.h" -#define MAX_PRIORITY ((0x1 << __NVIC_PRIO_BITS) - 1) -/*! \brief UART TX buffer size */ -#define PLATFORM_UART_TERMINAL_BUFFER_SIZE 2048U - -#define DEFAULT_TX_POWER 0 /* dBm */ /************************************************************************************************** Global Variables **************************************************************************************************/ -/*! \brief Persistent BB runtime configuration. */ -static BbRtCfg_t mainBbRtCfg; +static uint8_t rxData[10]; -/*! \brief Persistent LL runtime configuration. */ -static LlRtCfg_t mainLlRtCfg; /************************************************************************************************** Functions @@ -68,244 +42,33 @@ static LlRtCfg_t mainLlRtCfg; /*************************************************************************************************/ /*! - * \brief Load runtime configuration. - */ -/*************************************************************************************************/ -static void mainLoadConfiguration(void) -{ - PalBbLoadCfg((PalBbCfg_t *)&mainBbRtCfg); - LlGetDefaultRunTimeCfg(&mainLlRtCfg); - PalCfgLoadData(PAL_CFG_ID_LL_PARAM, &mainLlRtCfg.maxAdvSets, sizeof(LlRtCfg_t) - 9); - PalCfgLoadData(PAL_CFG_ID_BLE_PHY, (uint8_t *)&mainLlRtCfg.phy2mSup, 4); - - /* Set 5.0 requirements. */ - mainLlRtCfg.btVer = BT_VER; - - /* Set the 32k sleep clock accuracy into one of the following bins, default is 20 - HCI_CLOCK_500PPM - HCI_CLOCK_250PPM - HCI_CLOCK_150PPM - HCI_CLOCK_100PPM - HCI_CLOCK_75PPM - HCI_CLOCK_50PPM - HCI_CLOCK_30PPM - HCI_CLOCK_20PPM - */ - mainBbRtCfg.clkPpm = 20; - - /* Set the default connection power level */ - mainLlRtCfg.defTxPwrLvl = DEFAULT_TX_POWER; - - /* Adjust the extended advertising and ISO settings */ - mainLlRtCfg.maxAdvSets = 2; - mainLlRtCfg.maxAdvReports = 4; - mainLlRtCfg.numIsoTxBuf = 8; - mainLlRtCfg.maxCis = 2; - mainLlRtCfg.maxBis = 2; -} - -/*************************************************************************************************/ -/*! - * \brief Initialize WSF. - */ -/*************************************************************************************************/ -static void mainWsfInit(void) -{ - uint32_t llmemUsed, memUsed; - - mainLoadConfiguration(); - - /* +12 for message headroom, + 2 event header, +255 maximum parameter length. */ - const uint16_t maxRptBufSize = 12 + 2 + 255; - - /* +12 for message headroom, +ISO Data Load, +4 for header. */ - const uint16_t dataBufSize = - 12 + HCI_ISO_DL_MAX_LEN + mainLlRtCfg.maxAclLen + 4 + BB_DATA_PDU_TAILROOM; - - /* Use single pool for data buffers. */ -#if (BT_VER > 9) - WSF_ASSERT(mainLlRtCfg.maxAclLen == mainLlRtCfg.maxIsoSduLen); -#endif - - /* Ensure pool buffers are ordered correctly. */ - WSF_ASSERT(maxRptBufSize < dataBufSize); - - wsfBufPoolDesc_t poolDesc[] = { - { 16, 8 }, - { 32, 4 }, - { 128, mainLlRtCfg.maxAdvReports }, - { maxRptBufSize, mainLlRtCfg.maxAdvReports }, /* Extended reports. */ - { dataBufSize, mainLlRtCfg.numTxBufs + mainLlRtCfg.numRxBufs + mainLlRtCfg.numIsoTxBuf + - mainLlRtCfg.numIsoRxBuf } - }; - - const uint8_t numPools = sizeof(poolDesc) / sizeof(poolDesc[0]); - - /* Calculate how much memory we will need for the LL initialization */ - WsfCsEnter(); - - LlInitRtCfg_t llCfg = { - .pBbRtCfg = &mainBbRtCfg, - .wlSizeCfg = 4, - .rlSizeCfg = 4, - .plSizeCfg = 4, - .pLlRtCfg = &mainLlRtCfg, - /* Not significant yet, only being used for memory size requirement calculation. */ - .pFreeMem = WsfHeapGetFreeStartAddress(), - /* Not significant yet, only being used for memory size requirement calculation. */ - .freeMemAvail = WsfHeapCountAvailable() - }; - - llmemUsed = LlInitSetRtCfg(&llCfg); - - WsfCsExit(); - - /* Initial buffer configuration. */ - WsfCsEnter(); - memUsed = WsfBufCalcSize(numPools, poolDesc); - WsfHeapAlloc(memUsed); - WsfBufInit(numPools, poolDesc); - WsfCsExit(); - - WsfOsInit(); - WsfTimerInit(); - -#if (WSF_TRACE_ENABLED == TRUE) - WsfCsEnter(); - WsfHeapAlloc(PLATFORM_UART_TERMINAL_BUFFER_SIZE); - WsfBufIoUartInit(WsfHeapGetFreeStartAddress(), PLATFORM_UART_TERMINAL_BUFFER_SIZE); - WsfCsExit(); - - WsfTraceRegisterHandler(WsfBufIoWrite); - WsfTraceEnable(TRUE); -#endif - - /* Complete the LL initialization */ - WsfCsEnter(); - - /* Allocate the memory */ - WsfHeapAlloc(llmemUsed); - - /* Set the free memory pointers */ - llCfg.pFreeMem = WsfHeapGetFreeStartAddress(); - llCfg.freeMemAvail = WsfHeapCountAvailable(); - - /* Run the initialization with properly set the free memory pointers */ - if (llmemUsed != LlInitControllerInit(&llCfg)) { - WSF_ASSERT(0); - } - - WsfCsExit(); -} - -/*************************************************************************************************/ -/*! - * \brief Check and service tokens (Trace and sniffer). - * - * \return TRUE if there is token pending. + * \brief Read callback that immediately echoes. */ /*************************************************************************************************/ -static bool mainCheckServiceTokens(void) +void rd_callback(void) { - bool_t eventPending = FALSE; - -#if (WSF_TOKEN_ENABLED == TRUE) || (BB_SNIFFER_ENABLED == TRUE) - eventPending = LhciIsEventPending(); -#endif - -#if WSF_TOKEN_ENABLED == TRUE - /* Allow only a single token to be processed at a time. */ - if (!eventPending) { - eventPending = WsfTokenService(); - } -#endif - -#if (BB_SNIFFER_ENABLED == TRUE) - /* Service one sniffer packet, if in the buffer. */ - if (!eventPending) { - eventPending = LhciSnifferHandler(); - } -#endif - - return eventPending; + PalUartWriteData(PAL_UART_ID_TERMINAL, rxData, 1); } /*************************************************************************************************/ /*! - * \brief Adjust interrupt priorities to let HCI UART interrupt have second highest after PAL timer - * - * \return None + * \brief A write callback that reads after echoing. */ /*************************************************************************************************/ -void setInterruptPriority(void) +void wr_callback(void) { - /* Interrupts using FreeRTOS functions must have priorities between MAX_PRIORITY and - configMAX_SYSCALL_INTERRUPT_PRIORITY, lower priority number is higher priority */ - - /* Setup BLE hardware interrupt priorities */ - NVIC_SetPriority(BTLE_TX_DONE_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_RX_RCVD_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_RX_ENG_DET_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_SFD_DET_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_SFD_TO_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_GP_EVENT_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_CFO_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_SIG_DET_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_AGC_EVENT_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_RFFE_SPIM_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_TX_AES_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_RX_AES_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_INV_APB_ADDR_IRQn, (MAX_PRIORITY - 2)); - NVIC_SetPriority(BTLE_IQ_DATA_VALID_IRQn, (MAX_PRIORITY - 2)); - - /* Setup scheduler timer priorities */ - NVIC_SetPriority(TMR0_IRQn, (MAX_PRIORITY - 1)); - NVIC_SetPriority(TMR1_IRQn, (MAX_PRIORITY - 1)); - - NVIC_SetPriority(WUT0_IRQn, (MAX_PRIORITY - 1)); - - /* Setup additional peripheral timer priorities */ - NVIC_SetPriority(UART1_IRQn, (MAX_PRIORITY - 0)); - NVIC_SetPriority(UART2_IRQn, (MAX_PRIORITY - 0)); - NVIC_SetPriority(UART3_IRQn, (MAX_PRIORITY - 0)); - - NVIC_SetPriority(DMA0_IRQn, (MAX_PRIORITY - 0)); - NVIC_SetPriority(DMA1_IRQn, (MAX_PRIORITY - 0)); - NVIC_SetPriority(DMA2_IRQn, (MAX_PRIORITY - 0)); - NVIC_SetPriority(DMA3_IRQn, (MAX_PRIORITY - 0)); - - NVIC_SetPriority(GPIO0_IRQn, (MAX_PRIORITY - 0)); - NVIC_SetPriority(GPIO1_IRQn, (MAX_PRIORITY - 0)); - - /* Trace UART */ - NVIC_SetPriority(UART0_IRQn, 3); - /* HCI UART highest priority */ - NVIC_SetPriority(MXC_UART_GET_IRQ(MXC_UART_GET_UART(HCI_UART)), 0); - /* PAL Timer */ - PalTimerSetIRQPriority(2); + PalUartReadData(PAL_UART_ID_TERMINAL, rxData, 1); } -static char txData[10]; -static char rxData[10]; /*************************************************************************************************/ /*! * \brief Main entry point. */ /*************************************************************************************************/ -void rd_callback(void) -{ - PalUartWriteData(PAL_UART_ID_TERMINAL, rxData, 1); - -} -void wr_callback(void) -{ - PalUartReadData(PAL_UART_ID_TERMINAL, rxData, 1); -} int main(void) { - printf("Starting\n"); - + MXC_Delay(500000); const PalUartConfig_t pCfg = { .rdCback = rd_callback, diff --git a/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_sys.c b/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_sys.c index 8fdfb75e74b..54be4451b86 100644 --- a/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_sys.c +++ b/Libraries/Cordio/platform/targets/maxim/max32690/sources/pal_sys.c @@ -103,7 +103,11 @@ void PalExitCs(void) __enable_irq(); } - +/*************************************************************************************************/ +/*! + * \brief DMA interrupt handlers. + */ +/*************************************************************************************************/ void DMA0_IRQHandler(void) { MXC_DMA_Handler(); /* DMA channel 0 is associated with DMA instance 0 */