<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>NRF52840 Missing Timer / Counter Interrupts when BLE is on</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48994/nrf52840-missing-timer-counter-interrupts-when-ble-is-on</link><description>Hello, 
 I am experiencing a problem similar to this thread, when I am using the counter feature of timer 2 together with PPI to count the number of SPI DMA (SPI3 currently but I cnfirmed the problem with SPI0-3) transactions and stop data transfer when</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 26 Jun 2019 03:17:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48994/nrf52840-missing-timer-counter-interrupts-when-ble-is-on" /><item><title>RE: NRF52840 Missing Timer / Counter Interrupts when BLE is on</title><link>https://devzone.nordicsemi.com/thread/194743?ContentTypeID=1</link><pubDate>Wed, 26 Jun 2019 03:17:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:693e7aa5-e11a-42ee-9386-d5b78d71acfc</guid><dc:creator>kdubovenko</dc:creator><description>&lt;p&gt;Ah, well I guess that solves it. I was used to NRF52832 and made the assumption that DMA size was the same. From the NRF52840 datasheet: &amp;quot;Any data stored in memory type(s) not accessible by the DMA engine must be copied to SRAM before it can be processed by the CRYPTOCELL subsystem. Maximum DMA transaction size is limited to (2^16)-1 bytes.&amp;quot; So DMA should be 65535... which is more than I will need. Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Missing Timer / Counter Interrupts when BLE is on</title><link>https://devzone.nordicsemi.com/thread/194742?ContentTypeID=1</link><pubDate>Wed, 26 Jun 2019 03:08:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4519eab9-11eb-47f1-8b66-ab3cf068d6a7</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;haven&amp;#39;t had a chance to read it all yet, did have one comment &amp;quot;SPI DMA can send 255 bytes max&amp;quot; .. doesn&amp;#39;t the 52840 have 16bit DMA lengths instead of 8 bit? I remember this was a regular complaint about the nRF52836, that DMA was limited to 255, so I thought it was changed. I had a quick look at the SPIM/SPIS peripherals in the datasheet and it looks to me like the relevant ones are 16 bit now.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Missing Timer / Counter Interrupts when BLE is on</title><link>https://devzone.nordicsemi.com/thread/194741?ContentTypeID=1</link><pubDate>Wed, 26 Jun 2019 02:56:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5fd4588-46cd-41c6-973d-cc745a1ee85a</guid><dc:creator>kdubovenko</dc:creator><description>&lt;p&gt;After a little more debugging, I can now see that the interrupt that it is missing the final one that I set up nand_burst_stop function with&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_drv_timer_extended_compare(&amp;amp;timer2, NRF_TIMER_CC_CHANNEL0, 1, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Perhaps the reason why it isn&amp;#39;t triggering is becasue the next SPI transaction finishes before I set up this final interrupt due to a higher priority interrupt running a BLE routine? I&amp;#39;m investigating...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Missing Timer / Counter Interrupts when BLE is on</title><link>https://devzone.nordicsemi.com/thread/194740?ContentTypeID=1</link><pubDate>Wed, 26 Jun 2019 01:42:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4bbe67c3-1f29-48bd-9c6e-a8439866960d</guid><dc:creator>kdubovenko</dc:creator><description>&lt;p&gt;Sure, I&amp;#39;m happy to explain further. SPI DMA can send 255 bytes max, I need to send much more than that (4k+) while using minimal power. To achieve that, I do the following:&lt;/p&gt;
&lt;p&gt;1. Configure timer 2 to work in counter mode&lt;/p&gt;
&lt;p&gt;2.&amp;nbsp; Link&amp;nbsp;NRF_TIMER_TASK_COUNT task with&amp;nbsp;NRF_SPIM_EVENT_END event using the following code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    //get timer counter address
    timer_count_task = nrf_drv_timer_task_address_get(&amp;amp;timer2, NRF_TIMER_TASK_COUNT);
	
    //Allocate PPI channels
    err = nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel_spi);
	if(err != NRF_SUCCESS)
	{
		return err;
	}
	
    //get SPI event end address 
    spi_end_evt = nrf_spim_event_address_get(m_spi_master.p_reg, NRF_SPIM_EVENT_END);
	
	// Configure the PPI to count the trasnsactions on the TIMER
	err = nrf_drv_ppi_channel_assign(ppi_channel_spi, spi_end_evt, timer_count_task);
	if(err != NRF_SUCCESS)
	{
		return err;
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;3. When data needs to be read / written, I calculate the number of SPI transactions I need (spi_cycle_num), configure the counter register with that value.&amp;nbsp;&lt;span&gt;spi_cycle_num holds one transaction less then the total needed because I want to make sure that I do not read/write too much&amp;nbsp;data and set up the last transaction manually. The code for this step is as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    spi_cycle_num = (len / MAX_DMA_XFER_SIZE - 1);

	//set up SPI for consecutive reads / writes, each one will be MAX_DMA_XFER_SIZE bytes
	nrf_drv_timer_extended_compare(&amp;amp;timer2, NRF_TIMER_CC_CHANNEL0, spi_cycle_num, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
	
    nrfx_spim_xfer_desc_t xfer = NRFX_SPIM_XFER_TRX(data_tx, MAX_DMA_XFER_SIZE, NULL, 0);
   
    uint32_t flags = NRFX_SPIM_FLAG_HOLD_XFER |
                    NRFX_SPIM_FLAG_REPEATED_XFER |
                    NRFX_SPIM_FLAG_TX_POSTINC  |
                    NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER;
	
	//set up proper SPI flags
    err = nrfx_spim_xfer(&amp;amp;m_spi_master, &amp;amp;xfer, flags);
  
	if(err != NRF_SUCCESS)
	{
		return err; 
	}
	
	//configure burst transfer
	err = nand_burst_start();
	if(err != NRF_SUCCESS)
	{
		return err; 
	}
	
	//kick off SPI transfer
	nrf_spim_task_trigger(m_spi_master.p_reg, NRF_SPIM_TASK_START);
	
	//wait for a flag or semaphore release here to signal a complete transfer...&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The function&amp;nbsp;nand_burst_start that configures PPI&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	err = nrf_drv_ppi_channel_enable(ppi_channel_spi);
	if(err != NRF_SUCCESS)
	{
		return err;
	}
	
	//This may not need to be enabled
	nrf_drv_timer_enable(&amp;amp;timer2);
	
	//configure shortcut 
	nrf_spim_shorts_enable(m_spi_master.p_reg, NRF_SPIM_SHORT_END_START_MASK);
	
	nrf_spim_enable(m_spi_master.p_reg);

	NAND_CS_ASSERT();&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;4. Finally when the&amp;nbsp;spi_cycle_num&amp;nbsp;cycle is complete, the timer peripheral triggers a compare interrupt (this is the one that occasionally misses). This interrupt signals the end of data with the exception of one last bit to be configured manually, not sent using PPI. The timer interrupt looks like this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    switch (event_type)
	{
		case NRF_TIMER_EVENT_COMPARE0:
			nand_burst_stop();
			break;

		default:
			//Do nothing.
			break;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;5.&amp;nbsp;nand_burst_stop function stops PPI and sets up one last SPI transaction. When the final transaction is complete this same function sets the &amp;quot;cycle complete&amp;quot; flag or releases the semaphore to indicate that all of the data has been read / written&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;    if(nand_burst_last_trx == true)
	{
		nrf_drv_timer_disable(&amp;amp;timer2);
		nand_burst_last_trx = false;
		err = nrf_drv_ppi_channel_disable(ppi_channel_spi);
		if(err != NRF_SUCCESS)
		{
			return err;
		}
		
		if(!keep_cs_active)
		{
			NAND_CS_DEASSERT();
		}
		

        //data transfer is complete set flag or release semaphore here
	}
	else
	{
		//disable the shortcut between SPI END and Counter increment
		nrf_spim_shorts_disable(m_spi_master.p_reg, NRF_SPIM_SHORT_END_START_MASK);
		
		// set up final transaction
		nrf_drv_timer_extended_compare(&amp;amp;timer2, NRF_TIMER_CC_CHANNEL0, 1, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
		nand_burst_last_trx = true;
	}
	
	return err;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If the counter does not trigger an interrupt, the code never enters the&amp;nbsp;nand_burst_stop&amp;nbsp;function, which means that the function writing the data never gets the &amp;quot;transfer completed&amp;quot; notification. This only fails when BLE is enabled, not necessarily even connected to another device, just on and in scanning mode. It is worth noting that I am using SDK 15.0 and previously when the code was running fine on NRF52832, the SoC was in peripheral&amp;nbsp;mode. I have not tried changing that here but I&amp;#39;m not sure how that could affect this issue. Using a logic analyzer I can tell that the final transaction before the interrupt failure is always complete, as in the SPI sends the correct amount of data, just never triggers the counter interrupt.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Konstantin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 Missing Timer / Counter Interrupts when BLE is on</title><link>https://devzone.nordicsemi.com/thread/194738?ContentTypeID=1</link><pubDate>Wed, 26 Jun 2019 00:55:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba1b985b-b23c-468d-b524-2904a67e32aa</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;So I&amp;#39;m a bit confused here, you say you&amp;#39;re using PPI but then you talk about interrupt priorities. If you&amp;#39;re using PPI then interrupts don&amp;#39;t matter. So I think you&amp;#39;re going to have to explain in a little more detail what exactly you&amp;#39;re doing which is PPI and what relies on an actual interrupt to be handled. It would also help if you explained what the failure is, too much data written, not enough data written, wrong data, buffers being written twice and why you think it&amp;#39;s due to &amp;#39;missed counter interrupts&amp;#39;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You&amp;#39;ve given a description of a problem and said you think it&amp;#39;s like another problem but you haven&amp;#39;t quite gotten to the meat of the issue in a way someone could start suggesting ideas.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>