<p></p>
<h4>Description</h4>
<p>I'm sending data with LoRa after that im trying to create a PWM signal on a buzzer pin to generate a tone. After the LoRa Message got sended by OTAA there is a error in the Terminal that the stack pointer got corrupt. My question is, how could this happend and what is the best method to debug a stack issue? If i remove the PWM buzzer function it will not create a stack corruption. PWM Should be simple?</p>
<p><strong>Thread code:</strong></p>
<pre><code>static void *mainThread(void *arg)
{
    (void)arg;

    while (1) {
                printf("Mean Thread Called \n");
                switch (State){
                        case Alarm:
                                printf("Im in alarm state \n");
                                // If LoRaSendAlarm or TurnBuzzerOn got commented it won't crash.
                                loraSendAlarm();                                
                                TurnBuzzerOn();  // Causes error (Stack error)
                                break;
                        default:
                                break;
                }
                xtimer_msleep(5000);
    }
        return 0;
}
</code></pre>
<p><em>Definition of PWM Buzzer:</em>  <code>#define PWM_BUZZER PWM_DEV(0)</code></p>
<p><strong>Function TurnBuzzerOn</strong></p>
<pre><code>void TurnBuzzerOn(void)
{
    pwm_poweron(PWM_BUZZER);
}

</code></pre>
<p><strong>Init PWM</strong></p>
<pre><code>void Init_PWM(void)
{
        pwm_init(PWM_BUZZER, PWM_CENTER, freq, (u_int32_t)100); // Freq  = 500
        pwm_set(PWM_BUZZER, 0, 50);
        pwm_poweroff(PWM_BUZZER);
}

</code></pre>
<p>The PWM Function is Causing corrupt stack.</p>
<h4>Steps to reproduce the issue</h4>
<p>Setting up the Thread and sending Data with LoRaMac from Examples (Lorawan)<br>
And enabling PWM on Pin.</p>
<h4>Expected results</h4>
<p>Working stackpointer (No Corruption)</p>
<h4>Actual results</h4>
<pre><code>Stack pointer corrupted, reset to top of stack
FSR/FAR:
 CFSR: 0x00001400
 HFSR: 0x40000000
 DFSR: 0x00000008
 AFSR: 0x00000000
Misc
EXC_RET: 0xfffffff1
</code></pre>
<h4>Versions</h4>
<p>Windows GCC / Nucleo64 Board</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/issues/16484">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABE7WYCAGG72LXB2X4NGKZDTOQVBLANCNFSM45FRBUHA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABE7WYFDC4LZEROENRS7ZBDTOQVBLA5CNFSM45FRBUHKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4NLG3TMQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/issues/16484",
"url": "https://github.com/RIOT-OS/RIOT/issues/16484",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>