Page 1 of 1

how to use SPI IRQ Handler?

Posted: Fri Jul 26, 2019 4:07 am
by laksonobudi
hi...i use SPI mode slave in STM32F746.
i want to use SPI IRQ Handler to detect interrupt in RXNE flag, how to do that?
in my case there is hang when run nvicenablevector function...

my SPI setting
================================================================
/* SPI setup and enable.*/
spip->spi->CR1 = 0;
if (spip->config->slave_mode) {
spip->spi->CR1 = spip->config->cr1;
spip->spi->CR2 = SPI_CR2_FRXTH | SPI_CR2_RXNEIE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
}

/*
Bit 12 FRXTH: FIFO reception threshold
This bit is used to set the threshold of the RXFIFO that triggers an RXNE event
0: RXNE event is generated if the FIFO level is greater than or equal to 1/2 (16-bit)
1: RXNE event is generated if the FIFO level is greater than or equal to 1/4 (8-bit)

Bit 6 RXNEIE: RX buffer not empty interrupt enable
0: RXNE interrupt masked
1: RXNE interrupt not masked. Used to generate an interrupt request when the RXNE flag is
set.
*/
================================================================

my code
================================================================
/*
* The reference variable must be initially set to NULL.
*/
thread_reference_t spi_thread_ref = NULL;

//Table 44. STM32F75xxx and STM32F74xxx vector table
#define SPI2_IRQ VectorD0

/*
* ISR serving the SPI RX FIFO interrupt.
*/
CH_IRQ_HANDLER(SPI2_IRQ) {
CH_IRQ_PROLOGUE();
chprintf(chp,"RUN...\r\n");

if ((SPI2->SR & SPI_SR_RXNE) != 0) {

/* Entering I-Locked state and resuming the thread, if suspended.*/
chSysLockFromISR();
chThdResumeI(&uart_thread_ref, MSG_OK);
chprintf(chp,"DETECT...\r\n");
chSysUnlockFromISR();

/* Resetting interrupt source.*/
SPI2->SR &= ~SPI_SR_RXNE;
}
CH_IRQ_EPILOGUE();
}

int main(){
.
.
nvicEnableVector(SPI2_IRQn,STM32_SPI_SPI2_IRQ_PRIORITY);
.
.
}

Re: how to use SPI IRQ Handler?

Posted: Fri Jul 26, 2019 12:01 pm
by laksonobudi
anyone could help will apreciate...

Re: how to use SPI IRQ Handler?

Posted: Fri Jul 26, 2019 8:47 pm
by Giovanni
Hi,

ChibiOS SPI driver does not support slave mode, so cannot comment on your changes.

One possible problem is chprintf() used in an ISR, depending on what you use as output stream you cannot do that.

Giovanni

Re: how to use SPI IRQ Handler?

Posted: Mon Jul 29, 2019 2:26 am
by laksonobudi
Giovanni wrote:Hi,

ChibiOS SPI driver does not support slave mode, so cannot comment on your changes.

One possible problem is chprintf() used in an ISR, depending on what you use as output stream you cannot do that.

Giovanni


why it doesn't suport?
i try directly read spi interface in register level code, not use spi driver in chibios. and i have comment out chprintf and change it to GPIO set, it still hang when activate nvic... :(
another thing that i do in my code is i use timer for generate SCLK for stm32 & ADC external, because in my case i try communicate with high speed ADC external, if i disable timer it not hang, but i need timer for generate SCLK & SPI RXNE interrupt when data recieved

Re: how to use SPI IRQ Handler?

Posted: Mon Jul 29, 2019 2:22 pm
by mikeprotts
I use STM32 in master mode, with pwm to generate CONVST to an SPI attached ADC. This gives a regular trigger to the ADC.

I am then using either the trigger off BUSY or the callback from the pwm (with a tight wait loop until BUSY is off) to resume a thread. The reason for the pwm & wait loop is to reduce jitter, but I suspect I'll work out a better way.

The thread processes the data with spiPolledExchange()

I'm able to process at about 150ksps with a STM32F4.

If you can't switch to master mode, then I think you'll have to use the interactive debugger, setting breakpoints so you'll get control within the IRQ code (setting a few GPIO pins to narrow down the area of code helps). It's possible that when you enable the vector, it's immediately driven and that takes control away earlier than you expect, which might mean the resume running before the other thread has suspended.

Mike

Re: how to use SPI IRQ Handler?

Posted: Wed Aug 14, 2019 3:51 am
by laksonobudi
mikeprotts wrote:I use STM32 in master mode, with pwm to generate CONVST to an SPI attached ADC. This gives a regular trigger to the ADC.

I am then using either the trigger off BUSY or the callback from the pwm (with a tight wait loop until BUSY is off) to resume a thread. The reason for the pwm & wait loop is to reduce jitter, but I suspect I'll work out a better way.

The thread processes the data with spiPolledExchange()

I'm able to process at about 150ksps with a STM32F4.

If you can't switch to master mode, then I think you'll have to use the interactive debugger, setting breakpoints so you'll get control within the IRQ code (setting a few GPIO pins to narrow down the area of code helps). It's possible that when you enable the vector, it's immediately driven and that takes control away earlier than you expect, which might mean the resume running before the other thread has suspended.

Mike


what ADC type that u use?

Re: how to use SPI IRQ Handler?

Posted: Wed Aug 14, 2019 1:11 pm
by mikeprotts
I've used LTC2328, LTC2326 and AD7616 (single channel only). There are minor differences, but mostly I use the same code.

Mike

Re: how to use SPI IRQ Handler?

Posted: Thu Aug 15, 2019 5:10 am
by laksonobudi
mikeprotts wrote:I've used LTC2328, LTC2326 and AD7616 (single channel only). There are minor differences, but mostly I use the same code.

Mike


ok, thanks for ur information , now i can aquire data 1 chanel ADC external using SPI DMA interrupt max in 40Ksps because i use 32 bit SPI communication, but now i have problem when use it in UGFX, the interrupt now show up :cry: