Felix-LJY opened a new pull request, #4182:
URL: https://github.com/apache/nuttx-apps/pull/4182

   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
   `examples/audio_rttl` plays every tone through a PWM device with 
`PWMIOC_SETCHARACTERISTICS`, `PWMIOC_START`, `usleep()` and `PWMIOC_STOP`. A 
pause (the `p` note) comes out of the parser with a frequency of 0 and was 
passed to the driver like any other note.
   
   Several PWM lower halves refuse a frequency of 0 in `pwm_start()`: RA4, 
HT32F491x3, GD32VW55x, GD32W51x and TLSR82 return `-EINVAL`, Ameba returns 
`-ERANGE` and LiteX `-EPERM`. On such a driver `play_pwm()` printed an error 
and returned before the `usleep()`, so every pause lasted nothing, the 
following notes were played too early and one error line was printed per pause.
   
   The pause is now handled before the PWM device is touched: `play_pwm()` 
waits for the duration of the pause and returns. The output is stopped at that 
point, since every note ends with `PWMIOC_STOP`. Notes are played as before.
   
   ## Impact
   
   Only `audio_rttl` runs that name a PWM device are affected:
   
   - With a driver that refuses 0 Hz, pauses now keep their duration and 
nothing is printed. Before, the tune was shorter than written and every pause 
produced an error line.
   - With a driver that accepts 0 Hz, a pause no longer depends on what the 
driver makes of such a request: the output simply stays stopped.
   - Tunes without pauses behave as before.
   
   No change to Kconfig, the build system or any driver.
   
   ## Testing
   
   Build host: Ubuntu 26.04.1 LTS, x86_64 (AMD Ryzen 9 8940HX), GCC 15.2.0, 
CMake 4.2.3.
   
   ### Target 1: `arm/n32h7`, custom board with an N32H760 (`bft_v1:nsh`, local 
tree based on NuttX 13.0.1), arm-none-eabi-gcc 15.3.1
   
   A passive buzzer is driven by a timer PWM output, `/dev/pwm2`. The PWM lower 
half of this board refuses 0 Hz in `pwm_start()` with `-EINVAL`, like the RA4 
driver. One tick is 10 ms.
   
   To keep the test silent the tune has pauses only. Two images were built that 
differ only in `examples/audio_rttl/audio_rttl_main.c`: one with the file as on 
`apache/master` (`c621be657`), one with this change. `audio_rttl_main()` was 
started with the command line below from a test thread whose `stderr` was 
redirected to memory and read back over the debug probe, together with the 
timer control register and the pin level.
   
   ```
   audio_rttl -s "T:d=4,o=6,b=2000:p,p,p,p" /dev/pwm2
   ```
   
   Before:
   
   ```
   Failed to start PWM: 22
   Failed to start PWM: 22
   Failed to start PWM: 22
   Failed to start PWM: 22
   ```
   
   The call returned within the tick it was started in.
   
   After:
   
   ```
   (no output)
   ```
   
   The call returned after 16 ticks (160 ms; a 30 ms `usleep()` takes 4 ticks 
on this target). In both cases the timer counter was disabled and the output 
pin was low afterwards.
   
   ### Target 2: `sim:nsh` on `apache/nuttx` master `58250c3546`
   
   No in-tree board configuration builds the example, so it was switched on by 
hand: `CONFIG_PWM=y`, `CONFIG_AUDIO=y`, `CONFIG_AUDIOUTILS_RTTTL_C=y`, 
`CONFIG_EXAMPLES_AUDIO_SOUND=y`. The example builds without warnings and 
`audio_rttl` is in the built-in command list.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to