Skip to content

rework RP2040 PIO UART interrupt path#840

Merged
HaoboGu merged 1 commit into
HaoboGu:mainfrom
scottlamb:fix-pio-tx-full
May 10, 2026
Merged

rework RP2040 PIO UART interrupt path#840
HaoboGu merged 1 commit into
HaoboGu:mainfrom
scottlamb:fix-pio-tx-full

Conversation

@scottlamb
Copy link
Copy Markdown
Contributor

The TX path was broken if PIO::uart_buffer().buf_tx.is_full() was true on entry; it would not drain or disable the interrupt, so the it'd repeat forever, starving other work. Best guess this was supposed to be is_empty(), but the check is unnecessary anyway.

I accidentally reproduced this quite reliably by sending several maximum-length messages in a row. :-/

While here, I adjusted both TX and RX loops to transfer up to 8 bytes per availability check rather than 1 by using the FLEVEL register instead of FSTAT.

The TX path was broken if `PIO::uart_buffer().buf_tx.is_full()` was
true on entry; it would not drain or disable the interrupt, so the
it'd repeat forever, starving other work. Best guess this was supposed
to be `is_empty()`, but the check is unnecessary anyway.

I accidentally reproduced this quite reliably by sending several
maximum-length messages in a row. :-/

While here, I adjusted both TX and RX loops to transfer up to 8 bytes
per availability check rather than 1 by using the FLEVEL register
instead of FSTAT.
@github-actions
Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 356.2 KiB 356.2 KiB +0.00% ⬆️ +8 0 0
use_config/nrf52840_ble 406.3 KiB 406.3 KiB +0.00% ⬇️ -8 0 0
use_config/nrf52840_ble_split (central) 482.2 KiB 482.2 KiB +0.00% ⬇️ -8 0 0
use_config/nrf52840_ble_split (peripheral) 307.2 KiB 307.2 KiB +0.00% ⬆️ +4 0 0
use_config/pi_pico_w_ble 640.2 KiB 640.2 KiB +0.00% 0 0 0
use_config/rp2040 146.6 KiB 146.7 KiB +0.00% ⬆️ +4 0 0
use_config/rp2040_split (central) 158.4 KiB 158.4 KiB +0.00% ⬆️ +8 0 0
use_config/rp2040_split (peripheral) 25.9 KiB 25.9 KiB -0.01% ⬇️ -4 0 0
use_config/stm32f1 62.3 KiB 62.3 KiB +0.00% 0 0 0
use_config/stm32h7 99.7 KiB 99.7 KiB +0.00% ⬇️ -4 0 0
use_rust/nrf52832_ble 345.3 KiB 345.3 KiB +0.00% 0 0 0
use_rust/nrf52840_ble 401.6 KiB 401.5 KiB +0.00% ⬇️ -12 0 0
use_rust/nrf52840_ble_split (central) 490.5 KiB 490.5 KiB +0.00% ⬆️ +8 0 0
use_rust/nrf52840_ble_split (peripheral) 304.5 KiB 304.5 KiB +0.00% ⬆️ +4 0 0
use_rust/pi_pico_w_ble 640.7 KiB 640.8 KiB +0.00% ⬆️ +32 0 0
use_rust/rp2040 146.4 KiB 146.4 KiB +0.00% ⬆️ +8 0 0
use_rust/rp2040_split (central) 157.7 KiB 157.7 KiB +0.00% ⬇️ -4 0 0
use_rust/rp2040_split (peripheral) 26.4 KiB 26.4 KiB -0.01% ⬇️ -4 0 0
use_rust/stm32f1 61.8 KiB 61.8 KiB +0.00% ⬇️ -4 0 0
use_rust/stm32h7 120.8 KiB 120.8 KiB +0.00% ⬆️ +4 0 0
use_config/nrf52832_ble — 356.2 KiB → 356.2 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 326056	   5192	  33464	 364712	  590a8	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 326048	   5192	  33464	 364704	  590a0	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +436  [ = ]       0    .debug_info
   +60%     +24  [ = ]       0    [Unmapped]
  +0.2%     +17  [ = ]       0    .debug_abbrev
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -8  [ = ]       0    .debug_line
  -0.0%    -601  [ = ]       0    .debug_str
  -0.0%    -124  +0.0%      +8    TOTAL
use_config/nrf52840_ble — 406.3 KiB → 406.3 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 360616	   5200	  50248	 416064	  65940	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 360624	   5200	  50248	 416072	  65948	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.57Ki  [ = ]       0    .debug_info
  +0.2% +1.03Ki  [ = ]       0    .debug_loc
  +0.0%    +706  [ = ]       0    .debug_str
  +0.1%    +411  [ = ]       0    .debug_line
   +12%      +6  [ = ]       0    [Unmapped]
  -0.0%      -8  [ = ]       0    .debug_aranges
  -0.0%      -8  -0.0%      -8    .text
  -0.0%     -20  [ = ]       0    .debug_frame
  -0.0%     -25  [ = ]       0    .strtab
  -0.0%     -32  [ = ]       0    .debug_ranges
  -0.0%     -32  [ = ]       0    .symtab
  +0.1% +4.57Ki  -0.0%      -8    TOTAL
use_config/nrf52840_ble_split (central) — 482.2 KiB → 482.2 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 441164	   6524	  46056	 493744	  788b0	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 441172	   6524	  46056	 493752	  788b8	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.90Ki  [ = ]       0    .debug_info
  +0.1% +1.00Ki  [ = ]       0    .debug_loc
  +0.0%    +105  [ = ]       0    .debug_line
  +7.5%      +5  [ = ]       0    [Unmapped]
  -0.0%      -8  [ = ]       0    .debug_aranges
  -0.0%      -8  -0.0%      -8    .text
  -0.0%     -20  [ = ]       0    .debug_frame
  -0.0%     -25  [ = ]       0    .strtab
  -0.0%     -32  [ = ]       0    .debug_ranges
  -0.0%     -32  [ = ]       0    .symtab
  -0.0% -1.18Ki  [ = ]       0    .debug_str
  +0.0% +1.71Ki  -0.0%      -8    TOTAL
use_config/nrf52840_ble_split (peripheral) — 307.2 KiB → 307.2 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 282128	   5888	  26520	 314536	  4cca8	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 282124	   5888	  26520	 314532	  4cca4	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +4  +0.0%      +4    .text
  -0.0%      -2  [ = ]       0    .debug_line
  -3.1%      -2  [ = ]       0    [Unmapped]
  -0.0%     -32  [ = ]       0    .debug_loc
  -0.0%    -664  [ = ]       0    .debug_info
  -0.0% -1.00Ki  [ = ]       0    .debug_str
  -0.0% -1.68Ki  +0.0%      +4    TOTAL
use_config/pi_pico_w_ble — 640.2 KiB → 640.2 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 600944	      0	  54632	 655576	  a00d8	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 600944	      0	  54632	 655576	  a00d8	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0% +1.37Ki  [ = ]       0    .debug_str
  -0.0%     -33  [ = ]       0    .debug_line
  -0.0%    -154  [ = ]       0    .debug_info
  +0.0% +1.19Ki  [ = ]       0    TOTAL
use_config/rp2040 — 146.6 KiB → 146.7 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 134928	      0	  15244	 150172	  24a9c	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 134924	      0	  15244	 150168	  24a98	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +156  [ = ]       0    .debug_line
  +0.0%     +88  [ = ]       0    .debug_info
   +64%     +25  [ = ]       0    [Unmapped]
  +0.0%      +4  +0.0%      +4    .text
  -0.0%     -12  [ = ]       0    .debug_loc
  -0.0%    -393  [ = ]       0    .debug_str
  -0.0%    -132  +0.0%      +4    TOTAL
use_config/rp2040_split (central) — 158.4 KiB → 158.4 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 146156	      0	  16008	 162164	  27974	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 146148	      0	  16008	 162156	  2796c	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +910  [ = ]       0    .debug_str
  +0.1%    +140  [ = ]       0    .debug_line
  +0.0%     +69  [ = ]       0    .debug_info
  +0.0%     +22  [ = ]       0    .debug_loc
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -1  [ = ]       0    .strtab
 -18.2%      -8  [ = ]       0    [Unmapped]
  +0.0% +1.11Ki  +0.0%      +8    TOTAL
use_config/rp2040_split (peripheral) — 25.9 KiB → 25.9 KiB (-0.01% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  24016	     56	   2412	  26484	   6774	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  24020	     56	   2412	  26488	   6778	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +3  [ = ]       0    .debug_str
  +2.7%      +1  [ = ]       0    [Unmapped]
  -0.1%      -4  -0.1%      -4    .rodata
  [ = ]       0  -0.0%      -4    TOTAL
use_config/stm32f1 — 62.3 KiB → 62.3 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  56312	     28	   7432	  63772	   f91c	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  56312	     28	   7432	  63772	   f91c	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  -1.6%      -1  [ = ]       0    [Unmapped]
  -0.0%     -14  [ = ]       0    .debug_line
  -0.0%    -134  [ = ]       0    .debug_info
  -0.0%    -143  [ = ]       0    .debug_str
  -0.0%    -292  [ = ]       0    TOTAL
use_config/stm32h7 — 99.7 KiB → 99.7 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  92116	    268	   9664	 102048	  18ea0	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  92120	    268	   9664	 102052	  18ea4	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  -0.0%      -4  -0.0%      -4    .text
  -0.0%    -123  [ = ]       0    .debug_info
  -0.1%    -139  [ = ]       0    .debug_line
  -0.0%    -298  [ = ]       0    .debug_str
  -0.0%    -564  -0.0%      -4    TOTAL
use_rust/nrf52832_ble — 345.3 KiB → 345.3 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 315944	   5200	  32456	 353600	  56540	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 315944	   5200	  32456	 353600	  56540	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +277  [ = ]       0    .debug_info
  +1.4%    +110  [ = ]       0    .debug_abbrev
  +0.0%     +10  [ = ]       0    .debug_loc
  +5.7%      +3  [ = ]       0    [Unmapped]
  -0.0%      -9  [ = ]       0    .debug_line
  -0.0%    -507  [ = ]       0    .debug_str
  -0.0%    -116  [ = ]       0    TOTAL
use_rust/nrf52840_ble — 401.6 KiB → 401.5 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 360256	   5200	  45728	 411184	  64630	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 360268	   5200	  45728	 411196	  6463c	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.37Ki  [ = ]       0    .debug_info
  +0.2% +1.03Ki  [ = ]       0    .debug_loc
  +0.1%    +207  [ = ]       0    .debug_line
   +29%     +15  [ = ]       0    [Unmapped]
  -0.0%      -8  [ = ]       0    .debug_aranges
  -0.0%     -12  -0.0%     -12    .text
  -0.0%     -20  [ = ]       0    .debug_frame
  -0.0%     -25  [ = ]       0    .strtab
  -0.0%     -32  [ = ]       0    .debug_ranges
  -0.0%     -32  [ = ]       0    .symtab
  -0.0%    -915  [ = ]       0    .debug_str
  +0.0% +2.60Ki  -0.0%     -12    TOTAL
use_rust/nrf52840_ble_split (central) — 490.5 KiB → 490.5 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 443984	   6524	  51792	 502300	  7aa1c	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 443976	   6524	  51792	 502292	  7aa14	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +40%     +19  [ = ]       0    [Unmapped]
  +0.0%      +8  +0.0%      +8    .text
  +0.0%      +7  [ = ]       0    .debug_line
  -0.0%     -31  [ = ]       0    .debug_loc
  -0.0%    -851  [ = ]       0    .debug_str
  -0.0%    -964  [ = ]       0    .debug_info
  -0.0% -1.77Ki  +0.0%      +8    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 304.5 KiB → 304.5 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 281148	   5328	  25288	 311764	  4c1d4	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 281144	   5328	  25288	 311760	  4c1d0	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +50  [ = ]       0    .debug_info
   +65%     +26  [ = ]       0    [Unmapped]
  +0.0%      +4  +0.0%      +4    .text
  -0.0%      -1  [ = ]       0    .debug_loc
  -0.0%      -2  [ = ]       0    .debug_line
  -0.0%    -349  [ = ]       0    .debug_str
  -0.0%    -272  +0.0%      +4    TOTAL
use_rust/pi_pico_w_ble — 640.7 KiB → 640.8 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 601380	      0	  54776	 656156	  a031c	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 601348	      0	  54776	 656124	  a02fc	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.32Ki  [ = ]       0    .debug_str
  +0.0%    +203  [ = ]       0    .debug_loc
  +0.1%    +150  [ = ]       0    .strtab
  +0.0%     +85  [ = ]       0    .debug_info
  +0.0%     +45  [ = ]       0    .debug_line
  +0.0%     +32  [ = ]       0    .symtab
  +0.0%     +32  +0.0%     +32    .text
  +0.1%     +28  [ = ]       0    .debug_frame
  +0.0%      +8  [ = ]       0    .debug_aranges
  +0.0%      +8  [ = ]       0    .debug_ranges
   +12%      +5  [ = ]       0    [Unmapped]
  +0.0% +2.90Ki  +0.0%     +32    TOTAL
use_rust/rp2040 — 146.4 KiB → 146.4 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 134800	      0	  15124	 149924	  249a4	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 134792	      0	  15124	 149916	  2499c	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +129  [ = ]       0    .debug_line
  +0.0%     +73  [ = ]       0    .debug_str
  +0.0%     +39  [ = ]       0    .debug_info
   +50%     +21  [ = ]       0    [Unmapped]
  +0.0%     +10  [ = ]       0    .debug_loc
  +0.0%      +8  +0.0%      +8    .text
  +0.0%    +280  +0.0%      +8    TOTAL
use_rust/rp2040_split (central) — 157.7 KiB → 157.7 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 145656	      0	  15788	 161444	  276a4	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 145660	      0	  15788	 161448	  276a8	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +36  [ = ]       0    .debug_line
  +0.0%      +7  [ = ]       0    .debug_str
  +5.6%      +3  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    .strtab
  -0.0%      -4  -0.0%      -4    .text
  -0.0%    -297  [ = ]       0    .debug_info
  -0.0%    -256  -0.0%      -4    TOTAL
use_rust/rp2040_split (peripheral) — 26.4 KiB → 26.4 KiB (-0.01% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  24316	     56	   2676	  27048	   69a8	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  24320	     56	   2676	  27052	   69ac	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +2  [ = ]       0    .debug_str
  +3.5%      +2  [ = ]       0    [Unmapped]
  -0.1%      -4  -0.1%      -4    .rodata
  [ = ]       0  -0.0%      -4    TOTAL
use_rust/stm32f1 — 61.8 KiB → 61.8 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  55848	     28	   7408	  63284	   f734	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  55852	     28	   7408	  63288	   f738	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +16  [ = ]       0    .debug_str
 +10.0%      +4  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0%     +16  -0.0%      -4    TOTAL
use_rust/stm32h7 — 120.8 KiB → 120.8 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 107972	    324	  15452	 123748	  1e364	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 107968	    324	  15452	 123744	  1e360	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +132  [ = ]       0    .debug_line
  +0.0%      +4  +0.0%      +4    .text
  +0.0%      +1  [ = ]       0    .strtab
  -9.3%      -4  [ = ]       0    [Unmapped]
  -0.0%    -199  [ = ]       0    .debug_info
  -0.0%    -870  [ = ]       0    .debug_str
  -0.0%    -936  +0.0%      +4    TOTAL

Copy link
Copy Markdown
Owner

@HaoboGu HaoboGu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks a lot!

@HaoboGu HaoboGu merged commit e2f2be6 into HaoboGu:main May 10, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants