yangsong8-a1 opened a new pull request, #4057:
URL: https://github.com/apache/nuttx-apps/pull/4057

   ## Summary
   
   With `CONFIG_PWM_FREQUENCY_FIXED`, `pwm_info_s.frequency` is `ub32_t`
   (Hz in 32.32 fixed point).  The example assigned the raw Hz value to it
   without converting, and printed it with `PRIu32`, which does not even
   build on 64-bit targets:
   
       examples/pwm/pwm_main.c:477:10: error: format '%u' expects argument
       of type 'unsigned int', but argument 2 has type 'pwm_freq_t'
       {aka 'long unsigned int'} [-Werror=format=]
   
   Convert the frequency with `uitoub32()` and print the Hz value directly.
   
   ## Impact
   
   No impact on the default (non-fixed-point) configuration; the change is
   entirely inside `#ifdef CONFIG_PWM_FREQUENCY_FIXED`.  No new API.
   
   A regression test in nuttx-apps is not possible for this: the failure
   mode is a build error that only appears in a configuration combination
   that no apps test harness builds; the build logs below are the
   regression test.
   
   ## Testing
   
   Ubuntu 22.04, aarch64-none-elf-gcc 13.2, riscv64-unknown-elf-gcc 10.2,
   QEMU 6.2.
   
   - qemu-armv8a:nsh + CONFIG_PWM + CONFIG_PWM_FREQUENCY_FIXED +
     CONFIG_EXAMPLES_PWM: fails to build before this change (error above),
     builds clean after.
   - qemu-armv8a:nsh + CONFIG_PWM + CONFIG_EXAMPLES_PWM (no fixed point):
     builds clean before and after.
   - Ran the example on QEMU rv-virt (rv32) with a SiFive PWM lower half
     pointed at guest RAM (QEMU has no SiFive PWM model), reference clock
     16 MHz.  `pwm -f 100 -t 15` with the default 50 % duty:
   
         pwm_main: starting output with frequency: 100 channel: 1 duty: 00007fff
         pwm_main: stopping output
   
     A QEMU monitor dump of the "registers" while the output was active
     shows the frequency reached the driver (100 Hz from 16 MHz needs
     prescaler 2, and 50 % duty is the complement compare value):
   
         0000000083000000: 0x00001002 0x00000000 0x00000000 0x00000000
         0000000083000020: 0x00008001 0x0000ffff 0x0000ffff 0x0000ffff
   
     PWMCFG = 0x1002 (ENALWAYS | SCALE = 2), PWMCMP0 = 0x8001, PWMCMP1-3
     idle.  Without the conversion the driver would read the frequency as
     0 Hz.
   


-- 
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