Part Number: CC1352R
Hi TI experts,
We are porting MSP430 bootloader host(BSL-SIMPLELINK-HOST) to CC1352R1 application(which is based on example <<simple_peripheral_CC13X2R1_LAUNCHXL_tirtos_ccs>>) but no luck:
The problem is the PC could not return from the delay function in the BSLEntrySequence(). Here is the source code, could you help to review it?
void BSLEntrySequence()
{
GPIO_IF_setOutputHighOnPin(Board_TEST_PIN);
GPIO_IF_setOutputHighOnPin(Board_RESET_PIN);
bslDelayMs(200);//200ms
GPIO_IF_setOutputLowOnPin(Board_TEST_PIN);
bslDelayUs(800);
GPIO_IF_setOutputLowOnPin(Board_RESET_PIN);
bslDelayUs(20);
GPIO_IF_setOutputHighOnPin(Board_TEST_PIN);
bslDelayUs(20);
GPIO_IF_setOutputLowOnPin(Board_TEST_PIN);
bslDelayUs(20);
GPIO_IF_setOutputHighOnPin(Board_TEST_PIN);
bslDelayUs(20);
GPIO_IF_setOutputHighOnPin(Board_RESET_PIN);
bslDelayUs(20);
GPIO_IF_setOutputLowOnPin(Board_TEST_PIN);
bslDelayUs(20);
}
/* * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ //****************************************************************************** // Version history: // 1.0 07/17 Initial version. (Nima Eskandari) // 1.1 07/17 Added Comments. (Nima Eskandari) //---------------------------------------------------------------------------- // Designed 2017 by Texas Instruments // // Nima Eskandari // Texas Instruments Inc. // August 2017 // Built with CCS Version: Code Composer Studio v7 //****************************************************************************** #include <stdio.h> #include <stdbool.h> #include <stddef.h> #include <unistd.h> //#include <time.h> /* Driver configuration */ #include "ti_drivers_config.h" #include <ti/drivers/timer/GPTimerCC26XX.h> #include <ti/sysbios/BIOS.h> #include <xdc/runtime/Types.h> #include <ti/sysbios/knl/Clock.h> #include <ti/sysbios/knl/Semaphore.h> //#include <config.h> //#include <debug.h> GPTimerCC26XX_Handle bslDelayTimer; GPTimerCC26XX_Params bslTimerParams; //Types_FreqHz freq; static Semaphore_Handle bslTimerSemHandle; static Semaphore_Struct bslTimerSemaphore; uint32_t counter = 0; void bslTimerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) { counter --; if (counter <= 0) Semaphore_post(bslTimerSemHandle); } void InitializeDelayTimer() { Semaphore_Params semParamsBslTimer; // Create bslDelayTimer semaphore Semaphore_Params_init(&semParamsBslTimer); semParamsBslTimer.mode = Semaphore_Mode_BINARY; Semaphore_construct(&bslTimerSemaphore, 0, &semParamsBslTimer); bslTimerSemHandle = Semaphore_handle(&bslTimerSemaphore); //BIOS_getCpuFreq(&freq); GPTimerCC26XX_Params_init(&bslTimerParams); bslTimerParams.width = GPT_CONFIG_16BIT; bslTimerParams.mode = GPT_MODE_PERIODIC_UP; bslTimerParams.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; } //***************************************************************************** // Get delay in milli seconds ************************************************* // time: The number of milliseconds to delay ********************************** //***************************************************************************** void bslDelayMs(uint32_t time) { if (time <= 0) { return; } else if (time <= 2) { counter = 1; } else { counter = time - 1; } bslDelayTimer = GPTimerCC26XX_open(CONFIG_GPTIMER_1, &bslTimerParams); if(bslDelayTimer == NULL) { } GPTimerCC26XX_Value loadVal = (48 * 1000) - 1 ; //47999 GPTimerCC26XX_setLoadValue(bslDelayTimer, loadVal); GPTimerCC26XX_registerInterrupt(bslDelayTimer, bslTimerCallback, GPT_INT_TIMEOUT); GPTimerCC26XX_start(bslDelayTimer); Semaphore_pend(bslTimerSemHandle, BIOS_WAIT_FOREVER); GPTimerCC26XX_unregisterInterrupt(bslDelayTimer); GPTimerCC26XX_stop(bslDelayTimer); GPTimerCC26XX_close(bslDelayTimer); } //***************************************************************************** // Get delay in micro seconds ************************************************* // time: Number of micro seconds to delay ************************************* //***************************************************************************** void bslDelayUs(uint32_t time) { if (time <= 0) return; if (time <= 200) { counter = 1; } else { counter = time / 100 - 1; } bslDelayTimer = GPTimerCC26XX_open(CONFIG_GPTIMER_1, &bslTimerParams); if(bslDelayTimer == NULL) { } GPTimerCC26XX_Value loadVal = (48 * 100) - 1 ; //4799 GPTimerCC26XX_setLoadValue(bslDelayTimer, loadVal); GPTimerCC26XX_registerInterrupt(bslDelayTimer, bslTimerCallback, GPT_INT_TIMEOUT); GPTimerCC26XX_start(bslDelayTimer); Semaphore_pend(bslTimerSemHandle, BIOS_WAIT_FOREVER); GPTimerCC26XX_unregisterInterrupt(bslDelayTimer); GPTimerCC26XX_stop(bslDelayTimer); GPTimerCC26XX_close(bslDelayTimer); }
For comparison, the delay timer of software_uart.c worked very well, the difference is software_uart used <<CONFIG_GPTIMER_0>> with "GPT_MODE_ONESHOT_UP" mode but BSLEntrySequence() used <<CONFIG_GPTIMER_1>> with "GPT_MODE_PERIODIC_UP" mode.
Meanwhile, I also tried usleep() but still could not work.