Update: This problem was resolved with "-fno-zero-initialized-in-bss" flag during compile time.
=======================================
Hi,
I'm trying to use McSPI in beaglebone. I copied and pasted evmAM35x's mcspiFlash.c. I removed all Flash related parts. Then I commented out EVMProfileGet(); from mcspi.c and just assgined '2' to 'profile' in mcspi.c. I did this because EVMProfileGet() seems to perform I2C initialization in EVM and doesn't seem to related to McSPI (or is it?).
Now, the compilation is OK (both Debug and Release mode). But the system does not produce interrupt. I put UARTPuts in the McSPIIsr() to see if this service routine is ever called. But no text was seen. Could you help me to figure out? (Or is it really related to EVMProfileGet(); function? Then, how can I simplify for beaglebone?)
Thank you very much for your help in advance.
=========================
BTW, the output of the following code looks like...
*********************
sending data...
Raw status get 0
pending irq masked status get 0
**********************
==============================================
/* Include the necessary header files */
#include "soc_AM335x.h"
#include "beaglebone.h"
#include "interrupt.h"
#include "uartStdio.h"
#include "hw_types.h"
#include "mcspi.h"
#include "hw_control_AM335x.h"
#include "hw_cm_per.h"
#define MCSPI_OUT_FREQ (24000000u)
#define MCSPI_IN_CLK (48000000u)
/******************************************************************************
** INTERNAL FUNCTION PROTOTYPES
******************************************************************************/
static void McSPITransfer(void);
static void McSPIIsr(void);
/******************************************************************************
** GLOBAL VARIABLE DEFINITIONS
******************************************************************************/
volatile unsigned int flag = 1;
unsigned int chNum = 0;
unsigned char txBuffer[260];
unsigned char rxBuffer[260];
unsigned char *p_tx;
unsigned char *p_rx;
unsigned int length = 0;
/******************************************************************************
** INTERNAL FUNCTION DEFINITIONS
******************************************************************************/
int main(void) {
McSPI0ModuleClkConfig();
McSPIPinMuxSetup(0);
McSPI0CSPinMuxSetup(chNum);
/* McSPI Setup */
McSPIReset(SOC_SPI_0_REGS);
McSPICSEnable(SOC_SPI_0_REGS);
McSPIMasterModeEnable(SOC_SPI_0_REGS);
McSPIMasterModeConfig(SOC_SPI_0_REGS, MCSPI_SINGLE_CH, MCSPI_TX_RX_MODE, MCSPI_DATA_LINE_COMM_MODE_1,chNum);
McSPIClkConfig(SOC_SPI_0_REGS, MCSPI_IN_CLK, MCSPI_OUT_FREQ, chNum,
MCSPI_CLK_MODE_0);
McSPIWordLengthSet(SOC_SPI_0_REGS, MCSPI_WORD_LENGTH(8), chNum);
McSPICSPolarityConfig(SOC_SPI_0_REGS, MCSPI_CS_POL_LOW, chNum);
McSPITxFIFOConfig(SOC_SPI_0_REGS, MCSPI_TX_FIFO_ENABLE, chNum);
McSPIRxFIFOConfig(SOC_SPI_0_REGS, MCSPI_RX_FIFO_ENABLE, chNum);
/* Map McSPI Interrupts to AINTC */
IntAINTCInit();
IntRegister(SYS_INT_SPI0INT, McSPIIsr);
IntPrioritySet(SYS_INT_SPI0INT, 1, AINTC_HOSTINT_ROUTE_IRQ);
IntSystemEnable(SYS_INT_SPI0INT);
IntMasterIRQEnable();
UARTPuts("sending data... \n\r",-1);
txBuffer[0] = 0x03;
txBuffer[1] = 0x80; ; // 0x80 to program baud rate
length = 2;
McSPITransfer();
while(1);
return -1;
}
/*
** This function will activate/deactivate CS line and also enable Tx and Rx
** interrupts of McSPI peripheral.
*/
static void McSPITransfer(void) {
p_tx = txBuffer;
p_rx = rxBuffer;
McSPICSAssert(SOC_SPI_0_REGS, chNum); /* SPIEN line is forced to low state.*/
McSPIIntEnable(SOC_SPI_0_REGS, MCSPI_INT_TX_EMPTY(chNum) | MCSPI_INT_RX_FULL(chNum)); /* Enable the Tx/Rx interrupts of McSPI.*/
McSPIChannelEnable(SOC_SPI_0_REGS, chNum); /* Enable the McSPI channel for communication.*/
unsigned int kkk;
kkk = (unsigned int)IntRawStatusGet(SYS_INT_SPI0INT);
UARTprintf("Raw status get %d\n\r", kkk);
unsigned int lll;
lll = (unsigned int) IntPendingIrqMaskedStatusGet(SYS_INT_SPI0INT);
UARTprintf("pending irq masked status get %d\n\r",lll);
/* Wait until control returns back from McSPI ISR.*/
while(flag);
flag = 1;
UARTPuts("DeAssert\n\r",-1);
McSPICSDeAssert(SOC_SPI_0_REGS, chNum); /* Force SPIEN line to the inactive state.*/
UARTPuts("ChannelDisable\n\r",-1);
McSPIChannelDisable(SOC_SPI_0_REGS, chNum); /* Disable the McSPI channel.*/
}
/*
** McSPI Interrupt Service Routine. This function will clear the status of the
** Tx/Rx interrupts when generated. Will write the Tx data on transmit data
** register and also will put the received data from receive data register to
** a location in memory.
*/
static void McSPIIsr(void)
{
unsigned int intCode = 0;
UARTPuts("Int StatusGet\n\r",-1); <<<<<====== I want to see this string.
intCode = McSPIIntStatusGet(SOC_SPI_0_REGS);
UARTprintf("intCode = %d\n\r", intCode);
while(intCode){
if(MCSPI_INT_TX_EMPTY(chNum) == (intCode & MCSPI_INT_TX_EMPTY(chNum))) {
McSPIIntStatusClear(SOC_SPI_0_REGS, MCSPI_INT_TX_EMPTY(chNum));
length--;
McSPITransmitData(SOC_SPI_0_REGS,(unsigned int)(*p_tx++), chNum); /* McSPI transmit */
if(!length) {
McSPIIntDisable(SOC_SPI_0_REGS, MCSPI_INT_TX_EMPTY(chNum));
McSPIIntStatusClear(SOC_SPI_0_REGS, MCSPI_INT_TX_EMPTY(chNum));
}
}
if(MCSPI_INT_RX_FULL(chNum) == (intCode & MCSPI_INT_RX_FULL(chNum))) {
McSPIIntStatusClear(SOC_SPI_0_REGS, MCSPI_INT_RX_FULL(chNum));
*p_rx++ = (unsigned char) McSPIReceiveData(SOC_SPI_0_REGS, chNum); /* McSPI receive */
if(!(length)) {
McSPIIntDisable(SOC_SPI_0_REGS, MCSPI_INT_RX_FULL(chNum));
flag = 0;
}
}
UARTprintf("intCode in while = %d\n\r", intCode);
intCode = McSPIIntStatusGet(SOC_SPI_0_REGS);
}
}
/********************************* End Of File ******************************/