EmbDev.net

Forum: ARM programming with GCC/GNU tools How to reset flag of USB interruption?


Author: Dima Bulkin (mrengineer)
Posted on:

Rate this post
0 useful
not useful
Hello

Please, help me.
I write my application based on BasicUSB example. Use SAM7-H256 olimex
board with AT91SAM7S256.

I decided to transfer USB data recive/send code from polling (main()
{...}) into USB interruption. But when I done it another code in main{}
stop working and my PC does not recognize my board.

Looks like that interuption function in some loop. Repeats again and
again. In PIC's, as I know, I should to clear interruption flag in
interruption code to retern to point where interruption happens. But how
do that in ARMs, espeialy in case of USB, I can't find.

Please, explain me how to build USB interruption corectily. To keep
main{} functionality.

Here is the code:


/* Interruspts programm when MC get some USB query */
void USB_Interrupt(void){

//This is my try to clear interruption
AT91F_UDP_InterruptClearRegister(AT91C_BASE_UDP, AT91C_UDP_SOFINT);
AT91F_AIC_ClearIt(AT91C_BASE_AIC, AT91C_ID_UDP);
}

/* To adjust USB interruption */
void USB_IR_init(void){

AT91F_AIC_ConfigureIt (AT91C_BASE_AIC, AT91C_ID_UDP,
USB_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, USB_Interrupt);
AT91F_UDP_EnableIt(AT91C_BASE_UDP, AT91C_UDP_SOFINT);
AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_UDP);
}


/* To connect to usb */
void PullUpResistor_Enable(void){
// Enable UDP PullUp (USB_DP_PUP) : enable & Clear of the corresponding
PIO
// Set in PIO mode and Configure in Output
AT91F_PIO_CfgOutput (AT91C_BASE_PIOA, AT91C_PIO_PA16);
// Clear for set the PullUp resistor
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, AT91C_PIO_PA16);
}



void AT91F_USB_Open(void)
{
// Set the PLL USB Divider
AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;

// Specific Chip USB Initialisation
// Enables the 48MHz USB clock UDPCK and System Peripheral USB Clock
AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_UDP;
AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDP);

PullUpResistor_Enable();

// CDC Open by structure initialization
AT91F_CDC_Open(&pCDC, AT91C_BASE_UDP);
}



int main ( void ) {
char data[MSG_SIZE] = "";
unsigned int length;

AT91F_USB_Open(); // Init USB device
USB_IR_init();

while (1) {
if (pCDC.IsConfigured(&pCDC)) { // Check enumeration

//Get data from PC...
length = pCDC.Read(&pCDC, data, MSG_SIZE);
//Blah-blah-blah... Working code

pCDC.Write(&pCDC, data, length); //Send data to pc
}
}
}

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.