You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3ec15cd
Browse filesBrowse the repository at this point in the historyBrowse files
<navclass="md-nav" aria-label="Manage the interrupt of a U(S)ART in the sketch">
3437
+
<ulclass="md-nav__list">
3438
+
3439
+
<liclass="md-nav__item">
3440
+
<ahref="#example_4" class="md-nav__link">
3441
+
<spanclass="md-ellipsis">
3442
+
3443
+
Example:
3444
+
3445
+
</span>
3446
+
</a>
3447
+
3448
+
</li>
3449
+
3450
+
</ul>
3451
+
</nav>
3452
+
3397
3453
</li>
3398
3454
3399
3455
<liclass="md-nav__item">
@@ -3409,7 +3465,7 @@
3409
3465
<ulclass="md-nav__list">
3410
3466
3411
3467
<liclass="md-nav__item">
3412
-
<ahref="#example_4" class="md-nav__link">
3468
+
<ahref="#example_5" class="md-nav__link">
3413
3469
<spanclass="md-ellipsis">
3414
3470
3415
3471
Example:
@@ -3811,6 +3867,39 @@ <h6 id="example-for-a-nucleo-l496zg-p">Example for a <strong>Nucleo L496ZG-P</st
3811
3867
<pclass="admonition-title">Note</p>
3812
3868
<p>Serial Rx/TX buffer size can be changed, see <ahref="../customization/Custom-definitions/">Custom-definitions#serial-rxtx-buffer-size</a></p>
3813
3869
</div>
3870
+
<h5id="manage-the-interrupt-of-a-usart-in-the-sketch">Manage the interrupt of a U(S)ART in the sketch</h5>
3871
+
<p>The core defines the <code>USARTx_IRQHandler()</code> used by <code>Serial</code> and <code>Uart</code>. To manage a U(S)ART peripheral by yourself (e.g. a <code>USART</code> in synchronous mode served by <code>HAL_USART_IRQHandler()</code>) while keeping <code>Serial</code> or another <code>Uart</code> on the other peripherals:</p>
3872
+
<ul>
3873
+
<li><code>bool uart_attach_irq_handler(USART_TypeDef *instance, void (*handler)(void))</code>: register a function called from the core interrupt handler of <code>instance</code>, instead of the one used by <code>Serial</code>/<code>Uart</code>. Use <code>NULL</code> as <code>handler</code> to unregister. Returns <code>false</code> if the instance is not a supported U(S)ART.</li>
3874
+
</ul>
3875
+
<p>The registration is by peripheral, so it also works when several U(S)ART share the same interrupt vector: the others are still served by the core.</p>
3876
+
<divclass="admonition warning">
3877
+
<pclass="admonition-title">Warning</p>
3878
+
<p>The sketch has to initialize the peripheral and enable its interrupt in the NVIC. A <code>Serial</code>/<code>Uart</code> using the same peripheral does not receive its interrupts while a handler is registered.</p>
<spanclass="w"></span><spanclass="n">Serial</span><spanclass="p">.</span><spanclass="n">begin</span><spanclass="p">(</span><spanclass="mi">115200</span><spanclass="p">);</span><spanclass="w"></span><spanclass="c1">// Serial on another peripheral</span>
3893
+
<spanclass="w"></span><spanclass="c1">// ... initialize husart2 with HAL_USART_Init() ...</span>
<p>A sketch which does not use <code>Serial</code> nor <code>Uart</code> can simply define its own <code>USARTx_IRQHandler()</code>: the core one is then not linked.</p>
0 commit comments