<?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>HW timer issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/61932/hw-timer-issue</link><description>Hi, 
 
 I&amp;#39;m trying to enable a HW timer (TIMER1) in my BLE application. I&amp;#39;m using SDK 16, and following the pattern shown in examples/peripherals/timer. However, when I get to nrf_drv_timer_enable(), I get a system reset before exiting this function.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Jun 2020 15:13:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/61932/hw-timer-issue" /><item><title>RE: HW timer issue</title><link>https://devzone.nordicsemi.com/thread/255324?ContentTypeID=1</link><pubDate>Tue, 16 Jun 2020 15:13:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bd327f8-fedc-4847-bdef-e29f51d6e118</guid><dc:creator>Brian</dc:creator><description>&lt;p&gt;Thanks for the suggestions.&amp;nbsp; I&amp;#39;ve resolved the problem.&amp;nbsp; I&amp;#39;m using Monitor Mode Debugging, and breakpoints within ISR&amp;#39;s do not seem to work as expected.&amp;nbsp; I actually was getting to the timer interrupt handler, but I was not using the FreeRTOS &amp;quot;FromISR&amp;quot; version of the function to release a semaphore.&amp;nbsp; Once I changed this code in the timer ISR, everything worked fine.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HW timer issue</title><link>https://devzone.nordicsemi.com/thread/252923?ContentTypeID=1</link><pubDate>Wed, 03 Jun 2020 08:41:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96c331d3-1914-4f18-8c43-38846f88e38f</guid><dc:creator>Edvin</dc:creator><description>[quote user="bpeavey"]&amp;nbsp; I can single-step into this function.&amp;nbsp; When I step from the 1st line to the 2nd line (which I believe starts the timer), the CPU resets and I go back to main.&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;Does this mean that it resets during the NRFX_ASSERT(m_cb[p_instance-&amp;gt;instance_id].state == NRFX_DRV_STATE_INITALIZED);?&lt;/p&gt;
&lt;p&gt;If so, then it is the assert. The timer is not initialized.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="bpeavey"]&amp;nbsp; I&amp;#39;ve tested the code I&amp;#39;m using to setup the timer directly in the ble_app_hrs_freertos example code.&amp;nbsp; This code works fine.&amp;nbsp; The only other change I had to make was to enable the timer in sdk_config.h (#define TIMER1_ENABLED 1).[/quote]
&lt;p&gt;&amp;nbsp;I am sorry. It is hard to say what the issue is only by looking at the sdk_config.h file. Check if &lt;a href="https://devzone.nordicsemi.com/members/hmolesworth"&gt;hmolesworth&lt;/a&gt;&amp;#39;s suggestion points to the assert. If it does, try to initialize the timer first.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HW timer issue</title><link>https://devzone.nordicsemi.com/thread/252812?ContentTypeID=1</link><pubDate>Tue, 02 Jun 2020 15:49:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a912ef2-48cb-4907-bba5-4f6a6d45a713</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Only time for a cursory read, but it seems you would do well by replacing the default assert handler which is probably causing the reset; then it&amp;#39;s easier to debug the code by putting a breakpoint on the handler. Add this to main.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Override the default handler which causes a reset, but track occurrences in case they need investigating
static uint32_t ErrorHandlerCounter = 0;
static uint32_t LastError_id = 0;
static uint32_t LastError_pc = 0;
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{
   ErrorHandlerCounter++;
   LastError_id = id;
   LastError_pc = pc;
   NRF_LOG_INFO(&amp;quot;Error: id %u, pc %u, count %u&amp;quot;, LastError_id, LastError_pc, ErrorHandlerCounter);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HW timer issue</title><link>https://devzone.nordicsemi.com/thread/252805?ContentTypeID=1</link><pubDate>Tue, 02 Jun 2020 15:28:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1065a138-ba25-461e-9791-2cee2ba1b110</guid><dc:creator>Brian</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I am using TIMER1, not TIMER0.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I have set a breakpoint in app_error_fault_handler, but my code never hits the breakpoint.&amp;nbsp; I added the call to APP_ERROR_CHECK(1) for a test, and I do hit the breakpoint in that case.&amp;nbsp; I can see that app_error_fault_handler is called by app_error_handler, although this is the top of the stack.&amp;nbsp; I don&amp;#39;t see where app_error_handler is being called from.&amp;nbsp; I have changed my compile optimization from -Og to -O0, with the same results.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I have DEBUG already defined in my build.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; nrf_drv_timer_enable() is mapped to nrfx_timer_enable() in nrf_drv_timer.h.&amp;nbsp; This function is 4 lines long -&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void nrfx_timer_enable(nrfx_timer_t const * const p_instance)
{
    NRFX_ASSERT(m_cb[p_instance-&amp;gt;instance_id].state == NRFX_DRV_STATE_INITIALIZED);
    nrf_timer_task_trigger(p_instance-&amp;gt;p_reg, NRF_TIMER_TASK_START);
    m_cb[p_instance-&amp;gt;instance_id].state = NRFX_DRV_STATE_POWERED_ON;
    NRFX_LOG_INFO(&amp;quot;Enabled instance: %d.&amp;quot;, p_instance-&amp;gt;instance_id);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; I can single-step into this function.&amp;nbsp; When I step from the 1st line to the 2nd line (which I believe starts the timer), the CPU resets and I go back to main.&amp;nbsp; I have set a breakpoint on the 3rd line of this function and I never hit it.&amp;nbsp; I have tried to set a long timeout for the timer (several seconds), but this has no affect.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I&amp;#39;ve tested the code I&amp;#39;m using to setup the timer directly in the ble_app_hrs_freertos example code.&amp;nbsp; This code works fine.&amp;nbsp; The only other change I had to make was to enable the timer in sdk_config.h (#define TIMER1_ENABLED 1).&amp;nbsp; Bringing my version of sdk_config.h into this code causes it to also fail.&amp;nbsp; Therefore, it appears there is something in my sdk_config (attached several messages earlier) that is causing this problem.&amp;nbsp; I just have not been able to figure out which setting is causing the problem.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; So to answer your last question, nrf_drv_timer_enable never returns, nor does any function inside this function return an error.&amp;nbsp; The only thing I can see is the MCU resetting when I hit the 2nd line of this function.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Any ideas on what to try next?&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Thanks...&lt;/p&gt;
&lt;p&gt;Brian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HW timer issue</title><link>https://devzone.nordicsemi.com/thread/252669?ContentTypeID=1</link><pubDate>Tue, 02 Jun 2020 09:52:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68bdea9b-1464-4e11-99c8-d2b5bf4a4254</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;You are not trying to use TIMER0 for your application, right? Remember that TIMER0 and RTC0 are used by the softdevice.&lt;/p&gt;
&lt;p&gt;Have you tried to set a breakpoint in the error handler? I suggest that you define &amp;quot;DEBUG&amp;quot; in your preprocessor definitions, and set a breakpoint on&amp;nbsp;app_error_fault_handler() (line 57 in app_error.c). Try to put an APP_ERROR_CHECK(1) in your main() function to test that this breakpoint works properly. Also, use this to check if you need to disable optimization in order to see where the error handler comes from.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Either way, what does nrf_drv_timer_enable return? If not NRF_SUCCESS, then what function call inside returns the error?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HW timer issue</title><link>https://devzone.nordicsemi.com/thread/252588?ContentTypeID=1</link><pubDate>Mon, 01 Jun 2020 15:18:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:753c8f23-2b24-4736-8db1-6fecbf205bde</guid><dc:creator>Brian</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I&amp;#39;ve tried some additional things to narrow down the source of this problem.&amp;nbsp; It appears the source of the issue is in the sdk_config.h file, but I&amp;#39;m just not sure what part of it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; When I go back to the ble_app_hrs_freertos example code and add the changes above, the HW timer works fine.&amp;nbsp; My project has changed quite a bit since starting with this as the seed code - we added support for various tasks, sensors, I/O peripherals, etc.&amp;nbsp; So my code now looks quite a bit different than this example code.&amp;nbsp; Part of this process has been modifications to sdk_config.h to enable various peripherals.&amp;nbsp; If I take this modified version of sdk_config.h and use it in the ble_app_hrs_freertos example, I get the exact same behavior - the processor resets when trying to enable the HW timer at the call to&amp;nbsp;nrf_drv_timer_enable().&amp;nbsp; Using the original sdk_config.h, with only the change to enable TIMER1 works fine.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I&amp;#39;m attaching my version of sdk_config.h which causes the reset problem.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Any ideas on what part of this file is causing the issue?&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Thanks...&lt;/p&gt;
&lt;p&gt;Brian&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3716.sdk_5F00_config.h"&gt;devzone.nordicsemi.com/.../3716.sdk_5F00_config.h&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HW timer issue</title><link>https://devzone.nordicsemi.com/thread/252541?ContentTypeID=1</link><pubDate>Sun, 31 May 2020 22:20:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:89a8b973-04c9-4ebb-8e27-6d7c1f4d2669</guid><dc:creator>Brian</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Yes - I&amp;#39;ve seen the legacy vs new peripheral defines.&amp;nbsp; I&amp;#39;ve removed the old ones rather than set them to 0.&amp;nbsp; However, I&amp;#39;ve also tried to go back and add the old timer configurations just for a test, but no difference in behavior.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I do not have the NRF logging enabled, but I have re-directed the logging output from the error handlers to the serial port.&amp;nbsp; So assert_nrf_callback is defined and should output serial data.&amp;nbsp; I&amp;#39;ve set a breakpoint on this function, in addition to app_error_fault_handler, but I never get to either of them.&amp;nbsp; Are there other error handlers I should be looking at?&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I&amp;#39;m using Timer1 and IRQ priority 6, which I believe should be fine as far as the S140 softdevice is concerned.&amp;nbsp; Are there other considerations I&lt;span&gt;&amp;nbsp;&lt;/span&gt;need to take into account?&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Thanks...&lt;/p&gt;
&lt;p&gt;Brian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HW timer issue</title><link>https://devzone.nordicsemi.com/thread/252425?ContentTypeID=1</link><pubDate>Fri, 29 May 2020 13:18:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0f776cc-82d2-4185-b340-e3786b35d196</guid><dc:creator>Edvin</dc:creator><description>[quote user=""] Note that I have removed all of the legacy defines in this file, including TIMER_ENABLED.[/quote]
&lt;p&gt;&amp;nbsp;When you say that you have removed them, did you comment them out/delete them, or set them to 0? The reason I ask is because of a file called apply_old_config.h. Check it out.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Did you enable logging in your project? Does your log say anything?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""] I get a system reset before exiting this function.[/quote]
&lt;p&gt;&amp;nbsp;It sounds like the error handler is being called. Is that the case?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>