This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-F28027: Unable to change LOSPCP, resulting in failed SCI transmissions.

Part Number: LAUNCHXL-F28027
Other Parts Discussed in Thread: ADS8326, C2000WARE, CONTROLSUITE

Hello,

I am a beginner with the F28027 and am trying to configure SCI. I have succeeded in configuring the device for 9600 Baud, but am having trouble increasing it to 115200. 

First, I set the low speed clock prescaler (LOSPCP) to /1.

CLK_setLowSpdPreScaler(myClk, CLK_LowSpdPreScaler_SysClkOut_by_1);

Next, I set the BRR register value, which I calculated as follows:
BRR = (60MHz/(115200*8))-1 = 64.10 ~ 64
Back calculate Baud --> (60MHz)/((16+1)*8) = 115384.61 Baud, 0.16% error

SCI_setBaudRate(mySci, (SCI_BaudRate_e)64);

When I open the Terminal, the transmission is a bunch of random characters. 

I double checked the registers and found that BRR is updating as expected, but LOSPCP is not changing from the default 0x0002.

I am using the CLK_setLowSpdPreScaler() function but it doesn't seem to have an effect. I looked at the clk.c file and it seems to handle EALLOW and EDIS, so I'm assuming that's not the problem.

Does something else need to be changed or set in order to modify LOSPCP? I'm sorry if this is a basic question but I'm struggling to find information in the reference manual about changing this register besides needing to set EALLOW.

Here is a screenshot of the project: 

Here is my main.c :

#include "DSP28x_Project.h" // Device Headerfile and Examples Include File (includes stdint.h)

// Include driver header files
#include "f2802x_common/include/adc.h"
#include "f2802x_common/include/clk.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/timer.h"
#include "f2802x_common/include/wdog.h"
#include "f2802x_common/include/sci.h"
#include "f2802x_common/include/spi.h"

// Declare function prototype
__interrupt void cpu_timer0_isr(void);
void gpio_setup(void);
void sci_setup(void);
void spi_setup(void);
void spi_fifo_init(void);

// Declare Handles
ADC_Handle myAdc;
CLK_Handle myClk;
GPIO_Handle myGpio;
PIE_Handle myPie;
TIMER_Handle myTimer;
SCI_Handle mySci;
SPI_Handle mySpi;

int main(void)
{
// Declare local handles
CPU_Handle myCpu;
WDOG_Handle myWDog;
PLL_Handle myPll;

// Initialize handles
myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
myTimer = TIMER_init((void *)TIMER0_BASE_ADDR, sizeof(TIMER_Obj));
myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
mySci = SCI_init((void *)SCIA_BASE_ADDR,sizeof(SCI_Obj));
mySpi = SPI_init((void *)SPIA_BASE_ADDR, sizeof(SPI_Obj));

// Initialize watchdog handle and disable.
myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
WDOG_disable(myWDog);

// Load oscillator calibration values using Device_cal
// According to TRM section 1.3.2.1.2, ADC clocks must be enabled to calibrate the oscillators and ADC parameters.
CLK_enableAdcClock(myClk);
(*Device_cal)();
CLK_disableAdcClock(myClk); //Since the ADC is not needed for this application, it is disabled once calibration is done.

// Set internal oscillator 1 as the clock source.
CLK_setOscSrc(myClk, CLK_OscSrc_Internal);

// Internal oscillator 1 runs at 10MHz, I need 60MHz. Multiply 10MHz by 12, divide by 2
PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);

//Disable PIE and all interrupts before changing PIE
PIE_disable(myPie);
PIE_disableAllInts(myPie);
CPU_disableGlobalInts(myCpu);
CPU_clearIntFlags(myCpu);

// Re-enable PIE
PIE_enable(myPie);

// Register interrupt handlers in the PIE vector table
// Group number and subgroup number from TRM Table 1-110.
PIE_registerPieIntHandler(myPie, PIE_GroupNumber_1, PIE_SubGroupNumber_7,
(intVec_t)&cpu_timer0_isr);

#ifdef _FLASH
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif

// Configure CPU-Timer 0 to interrupt every 100 milliseconds:
// 60MHz CPU Frequency
TIMER_stop(myTimer);
TIMER_setPeriod(myTimer, (uint32_t)(60 * 100000));
TIMER_setPreScaler(myTimer, 0);
TIMER_reload(myTimer);
TIMER_setEmulationMode(myTimer, TIMER_EmulationMode_StopAfterNextDecrement); //Note this is the default.
TIMER_enableInt(myTimer);

TIMER_start(myTimer);

//Initialize GPIO
gpio_setup();

//Set up SCIA
sci_setup();

//Set up SPI
spi_setup();
spi_fifo_init(); // Initialize the SPI FIFOs

// Enable CPU INT1 which is connected to CPU-Timer 0:
CPU_enableInt(myCpu, CPU_IntNumber_1);

// Enable TINT0 in the PIE: Group 1 interrupt 7
PIE_enableTimer0Int(myPie);

// Enable global Interrupts and higher priority real-time debug events
CPU_enableGlobalInts(myCpu);
CPU_enableDebugInt(myCpu);

while(1){

//Control state of LED D4 using Switch S3
if(GPIO_getData(myGpio, GPIO_Number_12)){
GPIO_setLow(myGpio, GPIO_Number_1);
}
else{
GPIO_setHigh(myGpio, GPIO_Number_1);
}
}

}

void gpio_setup(void){
//LED D2 is connected to GPIO0. Set GPIO0 to GPIO configuration, output direction, and disable pull-up.
GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output);
GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable);
GPIO_setHigh(myGpio, GPIO_Number_0); //Initialize GPIO0 to known state

//LED D4 is connected to GPIO1. Set GPIO1 to GPIO configuration, output direction, and disable pull-up.
GPIO_setMode(myGpio, GPIO_Number_1, GPIO_0_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Output);
GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable);
GPIO_setHigh(myGpio, GPIO_Number_1); //Initialize GPIO0 to known state

//LED D3 is connected to GPIO2.
GPIO_setMode(myGpio, GPIO_Number_2, GPIO_0_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output);
GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable);
GPIO_setHigh(myGpio, GPIO_Number_2); //Initialize GPIO0 to known state

//Switch S3 is connected to GPIO12. Set GPIO12 to GPIO configuration, input direction, and disable pull-up.
GPIO_setMode(myGpio, GPIO_Number_12, GPIO_0_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_12, GPIO_Direction_Input);
GPIO_setPullUp(myGpio, GPIO_Number_12, GPIO_PullUp_Disable);
}

__interrupt void cpu_timer0_isr(void){
uint16_t txData16 = 0xFFFF;
uint16_t adcData = 0x0000;
uint16_t rxData1 = 0x0000;
uint16_t rxData2 = 0x0000;
//int i = 0;

//Set GPIO0 for debugging/LED
GPIO_setHigh(myGpio, GPIO_Number_0);

//SPI Transmit two 16 bit words to TX FIFO
SPI_write(mySpi,txData16);
SPI_write(mySpi,txData16);

//Wait for 2 words to arrive
while(SPI_getRxFifoStatus(mySpi) != SPI_FifoStatus_2_Words)
{
}

//SPI Read two 16 bit words from RX FIFO
rxData1 = SPI_read(mySpi);
rxData2 = SPI_read(mySpi);

//Combine rxData; discard first 6
adcData = ((rxData1 << 6) & 0xFFC0) | ((rxData2 >> 10) & 0x003F);

//UART Transmit
//Send 16 bit integer as 4 4-bit integers (
//Terminate with line feed "\n"
SCI_putDataBlocking(mySci, (uint8_t)(((adcData & 0xF000) >> 12) + 0x41));
SCI_putDataBlocking(mySci, (uint8_t)(((adcData & 0x0F00) >> 8) + 0x41));
SCI_putDataBlocking(mySci, (uint8_t)(((adcData & 0x00F0) >> 4) + 0x41));
SCI_putDataBlocking(mySci, (uint8_t)(((adcData & 0x000F) >> 0) + 0x41));
SCI_putDataBlocking(mySci, 0x0A); //LF

//Acknowledge interrupt so more interrupts from group 1 can be received.
PIE_clearInt(myPie, PIE_GroupNumber_1);

//Set GPIO0
GPIO_setLow(myGpio, GPIO_Number_0);
}

void sci_setup(void){
//See Example_2802xSci_FFDLB_int.c and TRM section 9.4 for configuration instructions
GPIO_setPullUp(myGpio,GPIO_Number_28,GPIO_PullUp_Enable);
GPIO_setPullUp(myGpio,GPIO_Number_29,GPIO_PullUp_Disable);
GPIO_setQualification(myGpio,GPIO_Number_28,GPIO_Qual_ASync);
GPIO_setMode(myGpio,GPIO_Number_28,GPIO_28_Mode_SCIRXDA);
GPIO_setMode(myGpio,GPIO_Number_29,GPIO_29_Mode_SCITXDA);

//Peripheral registers cannot be modified unless clock to the specific peripheral is enabled.
//Source: Firmware Dev. Package User's Guide, section 2.6.
//Enable clock to SCIA
CLK_enableSciaClock(myClk);

//Set UART Settings. Parity disabled by default.
SCI_disableParity(mySci);
SCI_setNumStopBits(mySci, SCI_NumStopBits_One);
SCI_setCharLength(mySci, SCI_CharLength_8_Bits);

//Enable Rx, Tx, Rx interrupt, Tx interrupt
SCI_enableTx(mySci);
SCI_enableRx(mySci);
//SCI_enableTxInt(mySci); //Not needed.
SCI_enableRxInt(mySci);

//Disable loopback
SCI_disableLoopBack(mySci);

//RX ERR, Sleep, and TXWAKE are disabled by default after system reset.

//Set Baud Rate
//Clock for SCI comes from LSPCLK, which is just SYSCLKOUT divided down according to LOSPCP register, default /4.
//LSPCLK = SYSCLKOUT/(LOSPCP*2) . If LOSPCP = 0, LSPCLK = SYSCLKOUT
//Baud rate = LSPCLK / ((BRR+1)*8), or inverse BRR = (LSPCLK/(Baud*8))-1
//BRR is the 16 bit value stored across SCIHBAUD and SCILBAUD
// SCI BRR = LSPCLK/(SCI BAUDx8) - 1

//Assuming 60MHz clock for F28027 and goal of 9600 Baud, LSPCLK = 60MHz/4 = 15MHz
//BRR = (15MHz/(9600*8))-1 = 194.31 ~ 194
//Back calculate Baud --> (60MHz/4)/((194+1)*8) = 9615.3 Baud, 0.16% error
// SCI_setBaudRate(mySci, (SCI_BaudRate_e)194);

// For 115200, change LOSPCP pre-scaler to /1 for better resolution
//BRR = (60MHz/(115200*8))-1 = 64.10 ~ 64
//Back calculate Baud --> (60MHz)/((16+1)*8) = 115384.61 Baud, 0.16% error
CLK_setLowSpdPreScaler(myClk, CLK_LowSpdPreScaler_SysClkOut_by_1);
SCI_setBaudRate(mySci, (SCI_BaudRate_e)64);

//Enable SCI
SCI_enable(mySci);
}

void spi_setup(void){
// Initialize GPIO for SPI
GPIO_setPullUp(myGpio, GPIO_Number_16, GPIO_PullUp_Enable);
GPIO_setPullUp(myGpio, GPIO_Number_17, GPIO_PullUp_Enable);
GPIO_setPullUp(myGpio, GPIO_Number_18, GPIO_PullUp_Enable);
GPIO_setPullUp(myGpio, GPIO_Number_19, GPIO_PullUp_Enable);
GPIO_setQualification(myGpio, GPIO_Number_16, GPIO_Qual_ASync); //See TRM 1.4.4.1, SPI peripheral controls synchronization.
GPIO_setQualification(myGpio, GPIO_Number_17, GPIO_Qual_ASync);
GPIO_setQualification(myGpio, GPIO_Number_18, GPIO_Qual_ASync);
GPIO_setQualification(myGpio, GPIO_Number_19, GPIO_Qual_ASync);
GPIO_setMode(myGpio, GPIO_Number_16, GPIO_16_Mode_SPISIMOA);
GPIO_setMode(myGpio, GPIO_Number_17, GPIO_17_Mode_SPISOMIA);
GPIO_setMode(myGpio, GPIO_Number_18, GPIO_18_Mode_SPICLKA);
GPIO_setMode(myGpio, GPIO_Number_19, GPIO_19_Mode_SPISTEA_NOT);

// Set GPIO 32 and 33 to inputs because they are jumped by traces to GPIO 16 and 17
//32 and 33 default to GPIO (see GPBMUX1 register), input direction (GPBDIR), enabled pull-up (GPBPUD).

//Enable clock first to allow change of configuration registers.
CLK_enableSpiaClock(myClk);

//Set SPISWRESET bit, as directed by TRM 8.4.2
//This will also clear the OVERRUN_FLAG and INT_FLAG bits
SPI_reset(mySpi);

// Enable master mode
SPI_setMode(mySpi, SPI_Mode_Master);
SPI_enableTx(mySpi);

//ADC is TI ADS8326, positive edge for DOUT
SPI_setClkPhase(mySpi, SPI_ClkPhase_Normal);
SPI_setClkPolarity(mySpi, SPI_ClkPolarity_OutputFallingEdge_InputRisingEdge);

SPI_setBaudRate(mySpi, SPI_BaudRate_1_MBaud); //DIFFERENT VALUE MIGHT BE NEEDED SINCE ENUM ASSUMES 12.5MHz
//ADC can handle 24kHz to 6MHz. 15/12 = 1.25MHz

// Set 16-bit char bits
SPI_setCharLength(mySpi, SPI_CharLength_16_Bits);

// Release SPI from Reset
SPI_enable(mySpi);

return;
}

void spi_fifo_init()
{
// Initialize SPI FIFO registers
SPI_enableChannels(mySpi);
SPI_enableFifoEnh(mySpi);
SPI_resetTxFifo(mySpi);
SPI_clearTxFifoInt(mySpi);
SPI_resetRxFifo(mySpi);
SPI_clearRxFifoInt(mySpi);
SPI_setRxFifoIntLevel(mySpi, SPI_FifoLevel_4_Words);

}

  • Hi Oscar,

    Can you try stepping through your code while watching the LOSPCP register in the CCS registers window with continuous refresh on to see if/when the register value changes - in particular, please watch to see if it changes to 000 (this would be /1) from the line:

    CLK_setLowSpdPreScaler(myClk, CLK_LowSpdPreScaler_SysClkOut_by_1);

    And if it does change, keep stepping through to see if it changes back to the default value afterwards.

    Best Regards,

    Allison

  • Hi Allison,

    Thank you for the suggestion. I entered debug mode and turned on continuous refresh as you suggested. When I click 'Step Into (F5)', I get an error saying "Can't find a source file at "..." " as shown in the screenshot below:

    I've never tried this before; is this what I should expect? I checked that clk.c was included at the top of my main.c file, so I assume it's present? 

    I also tried the 'view disassembly' button on that error window and stepped through with "Assembly Step Into". When I step through the assembly instructions while watching LOSPCP it does not change. I retried this and manually clicked refresh after each line to make sure things were refreshing, but no luck. LOSPCP stayed as 0x0002 the entire time. Here's a screenshot of the assembly instructions I stepped through.

    To make sure stepping through the assembly instructions worked for something else, I also stepped through the following line:
    SCI_setBaudRate(mySci, (SCI_BaudRate_e)64);

    I watched SCILBAUD change to 0x0040 as expected, so it seems like continuous refresh and stepping through instructions works for other things.

    As I mentioned above, I've never tried single stepping through while in debug mode, so if I am making a basic error using debug mode, please let me know. 

    Thank you!

    Oscar

  • Hi Oscar,

    Did you try using the "Step Over" the lines of your application code just to see (at a high level) which line changes the LOSPCP (if any)?

    If you saw the SCILBAUD change as expected, it seems like your debug session setup is working fine. My speculation was that perhaps your function was changing LOSPCP properly at first, but then after you configure it to /1, another code was setting it back to the default value. Can you set a breakpoint on the line where you configure LOSPCP and directly after? This might also help to see if it changes. 

    Best Regards,

    Allison

  • Hi Allison,

    I just tried "Step Over" through all of main.c and watched LOSPCP. None of the lines change LOSPCP, but I could see other registers (for example PCLKCR0) changing at different points. 

    I also tried your suggestion of setting a break point at the CLK_setLowSpdPreScaler() and manually changing LOSPCP to 0x0000. This worked! I kept stepping over until I reached while(1){} and LOSPCP did not change back to 0x0002. I then let the execution resume and checked my serial monitor. The expected result (shown in the screenshot below) came though. Before only junk symbols were received. 

    I assume this means CLK_setLowSpdPreScaler() just isn't having an effect?

    I tried a few other things that hopefully are informative.

    I tried replacing the following line:
    CLK_setLowSpdPreScaler(myClk, CLK_LowSpdPreScaler_SysClkOut_by_1);

    with these three lines:

    EALLOW;
    SysCtrlRegs.LOSPCP.all = 0x0000;
    EDIS;

    This did not change LOSPCP when I stepped over it in debug mode, but I did get a bunch of warnings after building. The warnings are shown in the screenshot below:

    I think this is related to the linker file (which I know very little about) but don't know how to get rid of the errors. Is this a concern in terms of being able to change LOSPCP or is it unrelated?

    Another thing I tried was moving the CLK_setLowSpdPreScaler() line to various points in the configuration. For example, just after the watchdog is disabled, after CLK_setOscSrc(), after PLL_setup(), and many other locations. My theory was that maybe LOSPCP configuration needs to happen at a particular stage of configuring other clock-related things. This didn't help unfortunately. 

    The last thing I noticed while stepping through main() was that the #ifdef _FLASH directive is not entered and memcpy() is not reached. I don't know if this affects being able to change LOSPCP, but I thought I had configured things to run from flash. I checked this by power cycling the launchpad and the application definitely restarts (verified by getting the usual junk characters over serial).

    Thank you for your help so far,

    Oscar

  • Hi Oscar,

    Good debug progress! Thanks for the updates. One note I wanted to also point out is in our examples we usually call InitSysCtrl() f near the beginning of the main() to disable the watchdog, set the PLLCR for proper SYSCLKOUT frequency, set the pre-scaler for the high and low frequency peripheral clocks, and enable the clocks to the peripherals. Are you/have you tried using the InitSysCtrl() function to set your system control registers to a known state? 

    In general, I wanted to ask if you have already been referencing some of our existing C2000Ware examples to compare your initializations? If not that could be helpful as well since the initialization order is in working-state in our examples. I'm wondering if there is something else that needs to be done first before you can set up LOSPCP that isn't getting set up properly.

    Best Regards,

    Allison

  • Hi Allison,

    Thank you for the suggestion. I tried to add InitSysCtrl() to the start of main.c but this causes a few errors. I haven't figured out how to get rid of the errors yet but will keep trying. Looking at the examples that use InitSysCtrl(), they only seem to need #include "DSP28x_Project.h", which I have included in my code so I am not sure why it doesn't work. Do you know what could be going wrong here?

    Regarding the C2000Ware examples, they have been very helpful. My code is mostly a combination of "Example_2802xCpuTimer.c" and "Example_2802xScia_FFDLB.c", specifically from the 'driver' example folder. I noticed in the 'driver' examples that InitSysCtrl() isn't used, but for 'struct' examples it is. I think the 'driver' examples rely on functions like CLK_init() to do the work of InitSysCtrl(), but I could be wrong.

    I looked through the definition of InitSysCtrl() and it sets LOSPCP to the default 0x0002 similarly to how I tried (unsuccessfully) with 
    EALLOW;

    SysCtrlRegs.LOSPCP.all = 0x0000;

    EDIS;

    I'll keep trying other things in the definition. One thing I came across in the Firmware Development Package Users Guide is that a clock must be enabled to a peripheral to change registers.

    Does the low speed clock count as a peripheral, and do you know what clock would be associated with it? This seems unlikely to be the problem since I have watched other registers in SYSCRTL like PCLKCR0 change successfully, so if those can change I'm not sure what makes LOSPCP different.

    Last question for now, do you know of any examples that successfully change LOSPCP to something other than the default 0x0002 value? If so I can try to run that code and see if it works on my device.

    Best Regards,

    Oscar

  • Hi Oscar,

    If you are using the drivers examples, you can just stick with comparing yours to the initializations in those examples Slight smile no need to overcomplicate it. And the low speed clock doesn't count as a peripheral so I don't see that as a likely issue.

    Let me discuss this with a few others to look into this and update you later today.

    Have you already tried running any of the examples without changing anything else but adding code to change the LSPCLK divider with success?

    Best Regards,

    Allison

  • Hi Oscar,

    We dug into this quite a bit and saw something peculiar in the "clk.c" file. It seems the CLK_setLowSpdPreScaler() function does not clear the LOSPCP bits before trying to do a bitwise "OR" to assign new values to the LOSPCP bits. I think this might be the cause of LOSPCP retaining its default value. Please try to add the following lines instead (in "clk.c" or your main):

    //
    // CLK_setLowSpdPreScaler -
    //
    void
    CLK_setLowSpdPreScaler(CLK_Handle clkHandle,
    const CLK_LowSpdPreScaler_e preScaler)
    {
    CLK_Obj *clk = (CLK_Obj *)clkHandle;

    ENABLE_PROTECTED_REGISTER_WRITE_MODE;


    //
    // clear the bits
    //
    clk->LOSPCP &= (~CLK_LOSPCP_LSPCLK_BITS);


    //
    // set the bits
    //
    clk->LOSPCP |= preScaler;

    DISABLE_PROTECTED_REGISTER_WRITE_MODE;

    return;
    };

    Let me know if you are able to implement the change and see a difference in behavior!

    Best Regards,

    Allison

  • Hi Allison,

    I just tried your suggestion of running an example and changing nothing except trying to change LOSPCP. I imported the driver version of "Example_2802xSci_Echoback.c" and added CLK_setLowSpdPreScaler(myClk, CLK_LowSpdPreScaler_SysClkOut_by_1); just before the for(;;) loop. Unfortunately the LOSPCP register did not change when I stepped through.

    I also tried modifying clk.c as you suggested. Here is what it is now:

    Unfortunately this didn't change LOSPCP either. 

    I also tried the following lines in main and none of them changed LOSPCP from the 0x0002 default value.

    On the off-chance that EALLOW wasn't working, I double checked that EALLOW is actually changing ST1 and confirmed that it is:

    Thank you,

    Oscar

  • Hi Oscar,

    After you changed the clk.c function, did you also regenerate the driverlib.lib?

    I believe these projects use the driverlib.lib library to pull the source code from (the very last file in the image below):

    But this driverlib.lib is pre-generated and then just pulled into CCS when you import a project. If you make a change to any of the source files used to generate driverlib.lib (including clk.c), then you need to regenerate driverlib.lib to update it with the change. You can do so by importing the driverlib project, editing the clk.c, and "building" the project in your CCS workspace. The driverlib project is located at {C2000Ware}\device_support\f2802x\common\ccs. 

    You can see below I've imported it and it uses the clk.c file we need to change:

    Please let me know if you are able to do so and/or this changes what you see. 

    Best Regards,

    Allison

  • Hi Allison,

    Unfortunately LOSPCP still is not changing when I step through. 

    Previously I had imported driverlib to my project (F28027_LVDT_r1) from the controlSUITE directory and had not imported the driverlib project to my workspace. To follow your suggestion I did the following:
    1. Imported the driverlib.lib project and checked that clk.c has the modifications you suggested in your last message. Please see the screenshot below.

    2. Rebuilt the driverlib project.

    2. Re-added the driverlib.lib file to the F28027_LVDT_r1 project, this time from the C2000Ware directory.

    3. Rebuilt the F28027_LVDT_r1 project.

    4. Debugged the F28027_LVDT_r1 project and watched the LOSPCP register while stepping through the program.

    Please let me know if I missed any steps.

    I noticed in your first screenshot that you are using F2802x_Headers_nonBIOS.cmd. I haven't included this before; here is my project right now:

    Should I be using F2802x_Headers_nonBIOS.cmd? 

    Could the age of my development board have anything to do with this problem? I purchased it back in 2018 but didn't get around to using it until recently. The box says it was produced "Week:19/2017". By any chance did the ability to change LOSPCP get implemented since then? If so I can try purchasing a new development board.

    Thank you,

    Oscar

  • Hi Oscar,

    I just tested this out myself to be sure. This is what I did:

    1. I imported a simple echoback SCI example ({C2000Ware}\device_support\f2802x\examples\drivers\sci_echoback)
    2. I added the code to change LOSPCP (I just added it after the PLL_setup(); in case you were wondering):
      1.     CLK_setLowSpdPreScaler(myClk, CLK_LowSpdPreScaler_SysClkOut_by_1);
    3. I went into my C2000Ware SDK ({C2000Ware}\device_support\f2802x\common\source\clk.c) to open clk.c and added the missing code to the function, then saved the file:
    4. I imported the driverlib project to my CCS workspace and selected the button to 'built' the driverlib project
    5. I went back to the SCI example project, right clicked on the project folder and selected "Rebuild Project" to pull in the changes
    6. I then reloaded the .out file and ran the example again. I "ran to" the LOSPCP line and then "stepped over" the line and saw LOSPCP change correctly:

    Let me know if you are able to follow these steps and get it working - thanks for the patience and persistence Slight smile

    • Note that you should also be able to set a breakpoint at that CLK_setLowSpdPreScaler line and then use "step into" button to verify that the clk.c that the project is referencing does indeed hold the correct version of the function:

    Hope this helps! I've also already filed this as a bug, so should be fixed in future SDK releases.

    Best Regards,

    Allison

  • Hi Allison,

    I was able to follow your instructions with the same example file, but when I step over CLK_setLowSpdPreScaler LOSPCP does not change.
    When I tried stepping into that instruction, I get the following error: 

    Can't find a source file at "C:/Users/a0221343/Git/cs30_f2802x_f2802x0/f2802xX_common/source/clk.c"
    Locate the file or edit the source lookup path to include its location.

    I tried stepping through anyway to watch the progress arrow move through the dissassmbly and noticed that it skips line 008002. As I step through it, the little blue arrow points to 008001 then jumps to 008003 on the next click of "Step Into". I am not sure if this is related but thought it might be.

    Thank you for all of your help so far!

    Best Regards,

    Oscar 

  • I just tried clicking "Locate File" and selected {C2000Ware}\device_support\f2802x\common\source as the place for CCS to look. 

    This worked in the sense that I no longer get the "Can't find source file..." error, but when I step into clk.c the little blue progress arrow is pointing to lines that aren't in CLK_setLowSpdPreScaler(). 

    If I scroll down in clk.c it shows CLK_SetLowSpdPreScaler() with the modified instructions, so maybe I pointed CCS to the edited clk.c file but CCS isn't using that file when it loads the project onto the device?

    I'm not sure if this is a good sign, but when I look at the Include folder in the Project tree and navigate to the clk.c file, it shows the modifications:

    Although the "Can't find source file..." error is gone, unfortunately LOSPCP still doesn't change.

    Best Regards,

    Oscar

  • Hi Oscar,

    The source of function definitions is actually coming from that driverlib.lib file at the very bottom of the example's project tree when you import it. So although that clk.c file you showed does have the changes within the project tree, unfortunately that change will not be implemented unless you recompile the driverlib.lib library ("building" the "driverlib" CCS project should regenerate the driverlib.lib with any new files/changes that you made to clk.c in your C2000ware. And then when you "Rebuild" (not just "build") your example project, that should re-import the correct driverlib.lib and other files to refresh them with your changes). 

    One last resort to try (which I have also tried see working). Is just copying and pasting the corrected function directly into the main .c file of your project. You can change the name of that function (e.g. CLK_setLowSpdPreScaler2() ) as well and then use that new function in your code instead. In this way, when you call it, the application code will use the corrected function. You can again set a breakpoint on your CLK_setLowSpdPreScaler2 and then step over/into to see if LOSPCP changes accordingly.

    //
    // CLK_setLowSpdPreScaler -
    //
    void
    CLK_setLowSpdPreScaler2(CLK_Handle clkHandle,
    const CLK_LowSpdPreScaler_e preScaler)
    {
    CLK_Obj *clk = (CLK_Obj *)clkHandle;

    ENABLE_PROTECTED_REGISTER_WRITE_MODE;


    //
    // clear the bits
    //
    clk->LOSPCP &= (~CLK_LOSPCP_LSPCLK_BITS);


    //
    // set the bits
    //
    clk->LOSPCP |= preScaler;

    DISABLE_PROTECTED_REGISTER_WRITE_MODE;

    return;
    };

    If you try these things and still see no change in LOSPCP, then let's set up a quick call next week so I can help walk you through things and figure out what's going wrong. Thanks again for the persistence!

    Best Regards,

    Allison

  • Hi Allison,

    Success! Never before has seeing 0x0000 been so exciting!

    The problem was solved when I looked for the file being generated by the imported driverlib project. Originally I was adding the driverlib.lib file from {C2000Ware}\device_support\f2802x\common\ccs\Debug to my F28027_LVDT_r1 project. I noticed in file explorer that the 'Last Modified' date for that driverlib file was 2022, which seemed suspicious given that all the rebuilding should have modified it more recently.

    I looked at the properties for the driverlib file in the Debug subfolder of the imported driverlib project and noticed that is was generating new driverlib files in a different location (with more believable Modified dates):

    After adding the driverlib file from {C2000Ware}\device_support\common\ccs\Debug\driverlib.lib to my project, everything worked as expected.

    Thank you for all of your help with this, I wouldn't have figured this out without you!

    I also appreciate the suggestion of creating a CLK_setLowSpdPreScaler2() function in main. This worked for me as well and was a great sanity check that LOSPCP could be changed.

    Best Regards,

    Oscar

  • Hi Oscar,

    That's excellent news!! And so glad that you were able to locate that corrected file/verify it with creating your own function in main. Like I mentioned, I did document this bug so hopefully we can save you and others the headache in future releases. Thanks again for sticking with it and hopefully you at least gained a few more debugging tips out of all this as well Slight smile 

    Feel free to open another thread if you run into any further issues! 

    Best Regards,

    Allison