Hi Team, The project that I am working on needs to read from SD card to MSP432 using the SDSPI communication driver and then write the same data to CC1310 using the SPI communication bus. Both the tasks need to run one after another. Basically, first reading a chunk of data of complete file from SD to MSP432 and then writting the same chunk to CC1310 . In this scenario, I am using the SDSPI driver to read the data from SD card and using the 4-wire concept where I have used GPIO pin P5_6 as CS. However the enabling and disabling of the CS i have left to the driver code of SDSPI (basically the fopen will enable the CS and fclose disables the CS) Secondly, I am using the 4-wire SPI for writting this data to CC1310 SPI bus. I am manually enabling and disabling the CS for the SPI communication to CC1310 . MSP432 acts as master and SD card and CC1310 acts as slaves. Now the problem is after reading first chunk of data, I enable the SPI CS line and the write operation is executed once following which I disable the CS line for SPI. But then when it tries to read the second chunk of data from SD card, the execution gets stuck in while loop in the SDSPI driver function "rxSPI" the one that is highlighted below. /* * ======== rxSPI ======== * Function to receive one byte onto the SPI bus. Polling (Blocked) * * @param hwAttrs Pointer to hardware attributes */ static inline uint8_t rxSPI(SDSPIMSP432_HWAttrs const *hwAttrs) { uint8_t rcvdat; /* Wait for all TX/RX to finish */ while (!(MAP_SPI_getInterruptStatus(hwAttrs->baseAddr, EUSCI_A_SPI_TRANSMIT_INTERRUPT) & EUSCI_A_SPI_TRANSMIT_INTERRUPT)) {} /* write dummy data */ MAP_SPI_transmitData(hwAttrs->baseAddr, 0xFF); /* Wait while not ready for RX */ while (!(MAP_SPI_getInterruptStatus(hwAttrs->baseAddr, EUSCI_A_SPI_RECEIVE_INTERRUPT) & EUSCI_A_SPI_RECEIVE_INTERRUPT)) {} /* Read data frm RX */ rcvdat = MAP_SPI_receiveData(hwAttrs->baseAddr); return (rcvdat); } Can't understand what the issue is? Please provide your valuable input. Thank you. PS: I am attaching the entire code too if you find any issue in that too to recommend. /* * Copyright (c) 2015, Texas Instruments Incorporated * All rights reserved. * * 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. */ /* * ======== spiloopback.c ======== */ /* XDCtools Header files */ #include #include #include #include #include #include /* BIOS Header files */ #include #include #include #include #include /* TI-RTOS Header files */ #include #include #include #include /* Example/Board Header files */ #include "Board.h" /* Buffer size used for the file copy process */ #ifndef CPY_BUFF_SIZE #define CPY_BUFF_SIZE 512//2048 Change made as per MSP432 - CC1310 data transfer V.T. #endif /* String conversion macro */ #define STR_(n) #n #define STR(n) STR_(n) /* Drive number used for FatFs */ #define DRIVE_NUM 0 #define SPI_MSG_LENGTH 512 #define TASKSTACKSIZE 768 #define SPI_TASK_STACK_SIZE 1024 #define SPI_WRITE_TASK_PRIORITY 3 #define SPI_READ_TASK_PRIORITY 3 const char inputfile[] = "fat:"STR(DRIVE_NUM)":V0000368.txt"; const char outputfile[] = "fat:"STR(DRIVE_NUM)":output.txt"; const char textarray[] = \ "*********************************************************************** \n" "This is the FWLT Beta Project \n" "Testing the microSd card on the FWLT Beta PCB board \n" "............ Passed the TEST \n" "EII - Mississauga, Ontario \n" "Mike Alfaham. \n" "*********************************************************************** \n"; /* Allocate buffers in .dma section of memory for concerto devices */ #ifdef MWARE #pragma DATA_SECTION(masterRxBuffer, ".dma"); #pragma DATA_SECTION(masterTxBuffer, ".dma"); #pragma DATA_SECTION(slaveRxBuffer, ".dma"); #pragma DATA_SECTION(slaveTxBuffer, ".dma"); #endif //Task_Struct task0Struct, task1Struct; //Char task0Stack[TASKSTACKSIZE], task1Stack[TASKSTACKSIZE]; char cpy_buff[CPY_BUFF_SIZE + 1]; /* Variables to keep track of the file copy progress */ unsigned int bytesRead = 0; unsigned int bytesWritten = 0; unsigned int filesize; unsigned int totalBytesCopied = 0; unsigned int no_of_chunks = 0; unsigned int end_of_data = 0; unsigned int chunks_read = 0; unsigned int padding = 0; Task_Struct task0Struct; Char task0Stack[SPI_TASK_STACK_SIZE]; Semaphore_Struct spiSem; /* not static so you can see in ROV */ static Semaphore_Handle SpiHandle; Semaphore_Params semParam; SPI_Handle masterSpi; SPI_Transaction masterTransaction; SDSPI_Params sdspiParams; SDSPI_Handle sdspiHandle; static Task_Params spiWriteTaskParams; Task_Struct spiWriteTask; /* not static so you can see in ROV */ static uint8_t spiWriteTaskStack[SPI_TASK_STACK_SIZE]; static Task_Params spiReadTaskParams; Task_Struct spiReadTask; /* not static so you can see in ROV */ static uint8_t spiReadTaskStack[SPI_TASK_STACK_SIZE]; Event_Struct spiWriteEvent; /* not static so you can see in ROV */ static Event_Handle spiWriteEventHandle; uint8_t masterRxBuffer[SPI_MSG_LENGTH + 1]; uint8_t masterTxBuffer[SPI_MSG_LENGTH + 1]; bool transferOK; uint8_t delay = 0; /* Variables for the CIO functions */ FILE *src, *dst; /* Events used in the application */ typedef enum { KeyPressUp_Event = Event_Id_00, KeyPressDown_Event = Event_Id_01, KeyPressAll_Event = KeyPressUp_Event + KeyPressDown_Event, } KeyPressEvent; /***** Prototypes *****/ void spiBusTransmitFinished(SPI_Handle handle, SPI_Transaction *transaction); void spiBusTransmit(); void spiBus_Init(); static void spiWriteTaskFunction(UArg arg0, UArg arg1); static void spiReadTaskFunction(UArg arg0, UArg arg1); void sdspiBus_Init(); void spiBus_Init(){ Event_Params eventParam; Event_Params_init(&eventParam); Event_construct(&spiWriteEvent, &eventParam); spiWriteEventHandle = Event_handle(&spiWriteEvent); /* Create the keypress task */ Task_Params_init(&spiWriteTaskParams); spiWriteTaskParams.stackSize = SPI_TASK_STACK_SIZE; spiWriteTaskParams.priority = SPI_WRITE_TASK_PRIORITY; spiWriteTaskParams.stack = &spiWriteTaskStack; Task_construct(&spiWriteTask, spiWriteTaskFunction, &spiWriteTaskParams, NULL); } static void spiWriteTaskFunction(UArg arg0, UArg arg1) { SPI_Params masterSpiParams; SPI_Params_init(&masterSpiParams); masterSpiParams.transferMode = SPI_MODE_CALLBACK; masterSpiParams.mode = SPI_MASTER; masterSpiParams.frameFormat = SPI_POL0_PHA1; masterSpiParams.bitRate = 1000000; masterSpiParams.transferCallbackFxn = spiBusTransmitFinished; masterSpi = SPI_open(Board_SPI0, &masterSpiParams); if (masterSpi == NULL) { System_abort("Error initializing SPI\n"); } else { System_printf("SPI initialized\n"); } strcpy((char*)masterTxBuffer,"Hello, This is Master SPI"); /* Initialize master SPI transaction structure */ masterTransaction.count = SPI_MSG_LENGTH; masterTransaction.txBuf = (Ptr)masterTxBuffer; masterTransaction.rxBuf = (Ptr)masterRxBuffer; masterTransaction.arg = NULL; while(1) { /* Wait for event */ uint32_t events = Event_pend(spiWriteEventHandle, 0, KeyPressAll_Event, BIOS_WAIT_FOREVER); /* If new ADC value, send this data */ if (events & (KeyPressUp_Event|KeyPressDown_Event)) { memset(masterTxBuffer,0,sizeof(masterTxBuffer)); strcpy((char*)masterTxBuffer,(char*)cpy_buff); /* Initiate transmission */ System_printf("\"%s\"...", masterTxBuffer); spiBusTransmit(); SPI_transfer(masterSpi, &masterTransaction); //Semaphore_post(SpiHandle); } } } /* * ======== taskFxn ======== * Task to perform a file copy * Task for this function is created statically. See the project's .cfg file. */ void sdspiBus_Init() { Task_Params_init(&spiReadTaskParams); spiReadTaskParams.stackSize = SPI_TASK_STACK_SIZE; spiReadTaskParams.priority = SPI_READ_TASK_PRIORITY; spiReadTaskParams.stack = &spiReadTaskStack; Task_construct(&spiReadTask, spiReadTaskFunction, &spiReadTaskParams, NULL); } static void spiReadTaskFunction(UArg arg0, UArg arg1) { /* Mount and register the SD Card */ SDSPI_Params_init(&sdspiParams); sdspiParams.bitRate = 1000000; sdspiHandle = SDSPI_open(Board_SDSPI0, DRIVE_NUM, &sdspiParams); if (sdspiHandle == NULL) { System_abort("Error starting the SD card\n"); } else { System_printf("Drive %u is mounted\n", DRIVE_NUM); } /* Try to open the source file */ src = fopen(inputfile, "r"); if (!src) { System_printf("Creating a new file \"%s\"...", inputfile); /* Open file for both reading and writing */ src = fopen(inputfile, "w+"); if (!src) { System_printf("Error: \"%s\" could not be created.\n" "Please check the Getting Started Guide " "if additional jumpers are necessary.\n", inputfile); System_abort("Aborting...\n"); } fwrite(textarray, 1, strlen(textarray), src); fflush(src); /* Reset the internal file pointer */ rewind(src); System_printf("done\n"); } else { System_printf("Using existing copy of \"%s\"\n", inputfile); } /* Create a new file object for the file copy */ dst = fopen(outputfile, "w"); if (!dst) { System_printf("Error opening \"%s\"\n", outputfile); System_abort("Aborting...\n"); } else { System_printf("Starting file copy\n"); } /* Get the filesize of the source file */ fseek(src, 0, SEEK_END); filesize = ftell(src); no_of_chunks = filesize/CPY_BUFF_SIZE; end_of_data = filesize%CPY_BUFF_SIZE; rewind(src); /* Copy the contents from the src to the dst */ while (true) { if(totalBytesCopied == filesize) { //System_flush(); fclose(src); break; } /* Read from source file */ memset(cpy_buff, 0, sizeof(cpy_buff)); GPIO_write(Spi_CHIP_SELECT, Spi_DISABLED); fseek(src,totalBytesCopied,SEEK_SET); if(!chunks_read) { cpy_buff[0] = no_of_chunks; } else { cpy_buff[0] = no_of_chunks - chunks_read; } if((end_of_data != 0) && (no_of_chunks == chunks_read)) { bytesRead = fread(cpy_buff, 1, end_of_data, src); for(padding = end_of_data; padding < CPY_BUFF_SIZE; padding++) { cpy_buff[padding] = '\0'; } } else { bytesRead = fread(cpy_buff + 1, 1, CPY_BUFF_SIZE, src); chunks_read++; } /* Write to dst file */ bytesWritten = fwrite(cpy_buff, 1, bytesRead, dst); if (bytesWritten < bytesRead) { System_printf("Disk Full\n"); break; /* Error or Disk Full */ } Event_post(spiWriteEventHandle,KeyPressUp_Event); Semaphore_pend(SpiHandle, BIOS_WAIT_FOREVER); /* Update the total number of bytes copied */ totalBytesCopied += bytesRead; } fclose(dst); } void spiBusTransmit(){ GPIO_write(Spi_CHIP_SELECT, Spi_ENABLED); transferOK = SPI_transfer(masterSpi, &masterTransaction); } void spiBusTransmitFinished(SPI_Handle handle, SPI_Transaction *transaction){ GPIO_toggle(Board_LED0); GPIO_write(Spi_CHIP_SELECT, Spi_DISABLED); System_flush(); Semaphore_post(SpiHandle); } /* * ======== main ======== */ int main(void) { Semaphore_Params_init(&semParam); Semaphore_construct(&spiSem, 0, &semParam); SpiHandle = Semaphore_handle(&spiSem); /* Call board init functions. */ Board_initGeneral(); Board_initGPIO(); Board_initSPI(); Board_initSDSPI(); /* Initialize spi transmission task */ spiBus_Init(); sdspiBus_Init(); System_printf("Starting the SPI loop-back example\nSystem provider is set to" " SysMin. Halt the target to view any SysMin contents in ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); System_printf("This example requires external wires to be connected to the " "header pins. Please see the Getting Started Guide for " "details.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); /* Start BIOS */ // BIOS_start(); // Activate LDO2 via P2.4 (Active Hi) GPIO_write(Board_LDO2, LDO_ON); // Automatic ENABLE the microSD // Test TIVA board... GPIO_write(Board_LDO1, LDO_OFF); // Activate LDO1 - TIVA and Pulser BIOS_start(); return (0); }
↧