- 
                Notifications
    
You must be signed in to change notification settings  - Fork 348
 
feat: uart break send + detect #4284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            zpg6
  wants to merge
  30
  commits into
  esp-rs:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
zpg6:feat/uart-break
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 5 commits
      Commits
    
    
            Show all changes
          
          
            30 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      9be5d23
              
                feat: uart break send + detect
              
              
                zpg6 91ef610
              
                fix: example configs
              
              
                zpg6 97bb924
              
                Merge branch 'main' into feat/uart-break
              
              
                zpg6 8426ce4
              
                fix: not needed directives
              
              
                zpg6 ef52491
              
                fix: instability::unstable; one line doc comment
              
              
                zpg6 56fd47e
              
                Update esp-hal/CHANGELOG.md
              
              
                zpg6 b49bd13
              
                fix: fold in hil test
              
              
                zpg6 0001ee1
              
                chore: remove old test from toml
              
              
                zpg6 d8b7544
              
                feat: add missing `wait_for_break` fn
              
              
                zpg6 e750ea7
              
                fix: self.regs
              
              
                zpg6 ebda145
              
                feat: wait_for_break with timeout + async
              
              
                zpg6 70861fb
              
                chore: fmt
              
              
                zpg6 5ff884b
              
                Merge branch 'main' into feat/uart-break
              
              
                zpg6 dcbd3b4
              
                Merge branch 'main' into feat/uart-break
              
              
                zpg6 fd088aa
              
                fix: pins now match embassy_serial example
              
              
                zpg6 adc4fa5
              
                Merge branch 'main' into feat/uart-break
              
              
                zpg6 d54743a
              
                test: increase break length
              
              
                zpg6 1a8a819
              
                test: uses wait_for_break method
              
              
                zpg6 4a5dfa4
              
                test: with timeout
              
              
                zpg6 2b83646
              
                fix: extend break on other test
              
              
                zpg6 fa05bbd
              
                fix: missing assert
              
              
                zpg6 accb847
              
                test: explicit enable before first break
              
              
                zpg6 eef7167
              
                test: delay after enable
              
              
                zpg6 ca684f0
              
                test: sync_regs on c6/h2
              
              
                zpg6 b975aee
              
                test: interleaved
              
              
                zpg6 c1c4203
              
                test: sync and delay
              
              
                zpg6 6d027ef
              
                test: c6/h2 sync on send
              
              
                zpg6 87c809d
              
                test: sync only without additional delay
              
              
                zpg6 cd7704b
              
                test: break detection amongst transmission
              
              
                zpg6 c805a66
              
                fix: data tests should flush to allow full tx
              
              
                zpg6 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
          Some comments aren't visible on the classic Files Changed page.
        
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [target.'cfg(target_arch = "riscv32")'] | ||
| runner = "espflash flash --monitor" | ||
| rustflags = [ | ||
| "-C", "link-arg=-Tlinkall.x", | ||
| "-C", "force-frame-pointers", | ||
| ] | ||
| 
     | 
||
| [target.'cfg(target_arch = "xtensa")'] | ||
| runner = "espflash flash --monitor" | ||
| rustflags = [ | ||
| # GNU LD | ||
| "-C", "link-arg=-Wl,-Tlinkall.x", | ||
| "-C", "link-arg=-nostartfiles", | ||
| 
     | 
||
| # LLD | ||
| # "-C", "link-arg=-Tlinkall.x", | ||
| # "-C", "linker=rust-lld", | ||
| ] | ||
| 
     | 
||
| [env] | ||
| ESP_LOG = "info" | ||
| 
     | 
||
| [unstable] | ||
| build-std = ["core", "alloc"] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| [package] | ||
| name = "uart_interrupt" | ||
| version = "0.0.0" | ||
| edition = "2024" | ||
| publish = false | ||
| 
     | 
||
| [dependencies] | ||
| critical-section = "1.1.3" | ||
| esp-backtrace = { path = "../../../esp-backtrace", features = [ | ||
| "panic-handler", | ||
| "println", | ||
| ] } | ||
| esp-bootloader-esp-idf = { path = "../../../esp-bootloader-esp-idf" } | ||
| esp-hal = { path = "../../../esp-hal", features = ["log-04", "unstable"] } | ||
| esp-println = { path = "../../../esp-println", features = ["log-04"] } | ||
| 
     | 
||
| [features] | ||
| esp32 = ["esp-backtrace/esp32", "esp-bootloader-esp-idf/esp32", "esp-hal/esp32"] | ||
| esp32c2 = [ | ||
| "esp-backtrace/esp32c2", | ||
| "esp-bootloader-esp-idf/esp32c2", | ||
| "esp-hal/esp32c2", | ||
| ] | ||
| esp32c3 = [ | ||
| "esp-backtrace/esp32c3", | ||
| "esp-bootloader-esp-idf/esp32c3", | ||
| "esp-hal/esp32c3", | ||
| ] | ||
| esp32c6 = [ | ||
| "esp-backtrace/esp32c6", | ||
| "esp-bootloader-esp-idf/esp32c6", | ||
| "esp-hal/esp32c6", | ||
| ] | ||
| esp32h2 = [ | ||
| "esp-backtrace/esp32h2", | ||
| "esp-bootloader-esp-idf/esp32h2", | ||
| "esp-hal/esp32h2", | ||
| ] | ||
| esp32s2 = [ | ||
| "esp-backtrace/esp32s2", | ||
| "esp-bootloader-esp-idf/esp32s2", | ||
| "esp-hal/esp32s2", | ||
| ] | ||
| esp32s3 = [ | ||
| "esp-backtrace/esp32s3", | ||
| "esp-bootloader-esp-idf/esp32s3", | ||
| "esp-hal/esp32s3", | ||
| ] | ||
| 
     | 
||
| [profile.release] | ||
| debug = true | ||
| debug-assertions = true | ||
| lto = "fat" | ||
| codegen-units = 1 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| //! Example of responding to UART interrupts. | ||
| //! | ||
| //! The following wiring is assumed: | ||
| //! - RX => GPIO16 | ||
| 
     | 
||
| #![no_std] | ||
| #![no_main] | ||
| 
     | 
||
| use core::cell::RefCell; | ||
| 
     | 
||
| use critical_section::Mutex; | ||
| use esp_backtrace as _; | ||
| use esp_hal::{ | ||
| Blocking, | ||
| handler, | ||
| main, | ||
| ram, | ||
| uart::{Config as UartConfig, DataBits, Parity, RxConfig, StopBits, Uart, UartInterrupt}, | ||
| }; | ||
| 
     | 
||
| static SERIAL: Mutex<RefCell<Option<Uart<Blocking>>>> = Mutex::new(RefCell::new(None)); | ||
| 
     | 
||
| #[main] | ||
| fn main() -> ! { | ||
| let peripherals = esp_hal::init(esp_hal::Config::default()); | ||
| let uart_config = UartConfig::default() | ||
| .with_baudrate(19200) | ||
| .with_data_bits(DataBits::_8) | ||
| .with_parity(Parity::None) | ||
| .with_stop_bits(StopBits::_1) | ||
| .with_rx(RxConfig::default().with_fifo_full_threshold(1)); | ||
| let mut uart = Uart::new(peripherals.UART1, uart_config) | ||
| .expect("Failed to initialize UART") | ||
| .with_rx(peripherals.GPIO16); | ||
| 
     | 
||
| uart.set_interrupt_handler(handler); | ||
| 
     | 
||
| critical_section::with(|cs| { | ||
| uart.clear_interrupts(UartInterrupt::RxBreakDetected | UartInterrupt::RxFifoFull); | ||
| uart.listen(UartInterrupt::RxBreakDetected | UartInterrupt::RxFifoFull); | ||
| SERIAL.borrow_ref_mut(cs).replace(uart); | ||
| }); | ||
| 
     | 
||
| loop {} | ||
| } | ||
| 
     | 
||
| #[handler] | ||
| #[ram] | ||
| fn handler() { | ||
| critical_section::with(|cs| { | ||
| let mut serial = SERIAL.borrow_ref_mut(cs); | ||
| let serial = serial.as_mut().unwrap(); | ||
| 
     | 
||
| if serial.interrupts().contains(UartInterrupt::RxBreakDetected) { | ||
| esp_println::print!("\nBREAK"); | ||
| } | ||
| if serial.interrupts().contains(UartInterrupt::RxFifoFull) { | ||
| let mut byte = [0u8; 1]; | ||
| serial.read(&mut byte).unwrap(); | ||
| esp_println::print!(" {:02X}", byte[0]); | ||
| } | ||
| 
     | 
||
| serial.clear_interrupts(UartInterrupt::RxBreakDetected | UartInterrupt::RxFifoFull); | ||
| }); | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [target.'cfg(target_arch = "riscv32")'] | ||
| runner = "espflash flash --monitor" | ||
| rustflags = [ | ||
| "-C", "link-arg=-Tlinkall.x", | ||
| "-C", "force-frame-pointers", | ||
| ] | ||
| 
     | 
||
| [target.'cfg(target_arch = "xtensa")'] | ||
| runner = "espflash flash --monitor" | ||
| rustflags = [ | ||
| # GNU LD | ||
| "-C", "link-arg=-Wl,-Tlinkall.x", | ||
| "-C", "link-arg=-nostartfiles", | ||
| 
     | 
||
| # LLD | ||
| # "-C", "link-arg=-Tlinkall.x", | ||
| # "-C", "linker=rust-lld", | ||
| ] | ||
| 
     | 
||
| [env] | ||
| ESP_LOG = "info" | ||
| 
     | 
||
| [unstable] | ||
| build-std = ["core", "alloc"] | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.