Skip to content
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

Fix only PWM 0 being enabled via Pinmux #369

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

AlexJones0
Copy link
Contributor

@AlexJones0 AlexJones0 commented Dec 19, 2024

Currently, all the PWMs (minus the LCD backlight) are being routed through pinmux, but the value being passed for the PWM output enable is the constant '{'b1}. Because the inner value is 'b1, this is extended to fill the 7 bit PWM output range as 0000001, instead of using '1 which would extend to 1111111. Hence, to fix this, we would want to use the value '{'1} instead.

Thanks to @elliotb-lowrisc who came up with a slightly more robust and comprehensible alternative, where we more explicitly cast/extend these values to match the output size and module count. These changes should probably be propagated to the other port connections (e.g. SPI), but are isolated to just PWM for this PR to keep this PR focused on fixing the bug. This ensures that all outputs of all PWM devices are now enabled through pinmux.

I've tested this fix makes the correct values appear on the waveforms in simulation, and I've built a bitstream and tested muxing pwm_out_1 to PMOD0_2 and using a digtal multimeter to read a range of values, which wasn't working previously. The code snippet used for testing is as below:

auto pinmux = SonataPinmux();
auto pwm = MMIO_CAPABILITY(SonataPwm, pwm);

pinmux.output_pin_select(SonataPinmux::OutputPin::pmod0_2, 3); // Pinmux PMOD0_2 to PWM_OUT_1
pwm->output_set(1, 255, 255);

Edit: I've also now manually tested (again on FPGA using a multimeter) every single possible mux of PWM/pin - all seem to be working as expected.

Currently, all the PWMs (minus the LCD backlight) are being routed
through pinmux, but the value being passed for the PWM output
enable is the constant `'{'b1}'`. Because the inner value is `'b1`,
this is extended to fill the 7 bit PWM output range as `000001`,
instead of using `'1` which would extend to `111111`.

This commit makes the casting/extension of these constant enable
values more explicitly match the PWM output size and module count, to
ensure that all outputs of all PWM devices are being enabled through
pinmux.
Copy link
Contributor

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

Yup, this looks correct to me. I'm a bit annoyed this wasn't flagged as a lint error. I've double checked the syntax using this toy example: https://codeberg.org/marno/toy-verilator/src/branch/main/array_width/array_width.v

@marnovandermaas marnovandermaas merged commit 5816e4c into lowRISC:main Dec 19, 2024
3 checks passed
@AlexJones0 AlexJones0 mentioned this pull request Dec 19, 2024
@AlexJones0 AlexJones0 deleted the pwm_pinmux_fix branch December 19, 2024 15:21
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