Other Parts Discussed in Thread: CC2540, CC2541
Hi,
I've tried to produce a code adding SPI slave functionality to SimpleBLEx projects (peripheral for now). The idea is to use twin DMA channels (ch3, ch4) to offload 8051 core as much as possible (with my code, radio stack have hard time working with 1MHz SPI and 32-byte transfers). For simplicity, an extra GPIO pin was used to signal SPI master (C5515 DSP) to perform SPI read transaction. We are using USART0 alternative location on a board.
Now the solution itself is
a) initialize DMA channels 3 and 4, ch3 having U0DBUF as target, ch4 having it as source,
b) use DMA ISR which, upon stoppage of either channel will set a flag for this channel and set an event to be processed in SimpleBLEPeripheral_ProcessEvents,
c) the event processing branch that reset the flags and rearms the channels. Before arming ch4, a data buffer is copied to a variable at ch4 source pointer.
All pretty conventional. The problem is occasional glitch that happens randomly, but typically occurs once in 30-100 tranfers. Too bad I have no screenshots from logic analyzer, but the glitch involves either stoppage of DMA transfer in a middle, or substituting data bytes with either zeros or 255s. This definitely has something to do with other timing critical resources, as simply stopping the CC2540 via IAR and then resuming it will cripple radio stack (it stops advertising, which is clearly visible using BLE dongle under Btool) - but at the same time SPI transfers begin to work flawlessly. Event processing definitely works at this time (without it, no channels would be rearmed, hence no DMA transfers would happen).
The question is - what kind of timing-critical operation may disrupt DMA transfer in process? I've been hinted that USART0 alternative location shares SS pin with Timer1, but according to IO register, it is placed withing P0_x pins. I'm new to concept of using various HAL layers - does it all mean that I should place a function to process flags from interrupt to some event-processing loop withing HAL tasks? Will high-priority task (processed before HCI) be appropriate, or it will cripple RF part of application? Thanks in advance,