pinMode() disables timer even if no PWM mode involved

Please post bugs and enhancements for the STM core here
rmdMoba
Posts: 12
Joined: Thu May 11, 2017 10:44 am

Re: pinMode() disables timer even if no PWM mode involved

Postby rmdMoba » Fri May 19, 2017 9:36 pm

victor_pv wrote:or you were using the normal ones, then if you switch to the alternate ones for SPI1 then PWM works again?
That's it

victor_pv
Posts: 1228
Joined: Mon Apr 27, 2015 12:12 pm

Re: pinMode() disables timer even if no PWM mode involved

Postby victor_pv » Fri May 19, 2017 9:38 pm

rmdMoba wrote:
victor_pv wrote:or you were using the normal ones, then if you switch to the alternate ones for SPI1 then PWM works again?
That's it


So it is something related to the original pins still being linked to the SPI and possible hold in a certain state.
Did you check if the end() method for the SPI port disables the SPI peripheral? perhaps that's all that's needed and for some reason is not yet in the spi code.

rmdMoba
Posts: 12
Joined: Thu May 11, 2017 10:44 am

Re: pinMode() disables timer even if no PWM mode involved

Postby rmdMoba » Fri May 19, 2017 9:42 pm

victor_pv wrote:Did you check if the end() method for the SPI port disables the SPI peripheral?
It seems to do so ...

Code: Select all

void SPIClass::end(void) {
    if (!spi_is_enabled(_currentSetting->spi_d)) {
        return;
    }

    // Follows RM0008's sequence for disabling a SPI in master/slave
    // full duplex mode.
    while (spi_is_rx_nonempty(_currentSetting->spi_d)) {
        // FIXME [0.1.0] remove this once you have an interrupt based driver
        volatile uint16 rx __attribute__((unused)) = spi_rx_reg(_currentSetting->spi_d);
    }
    while (!spi_is_tx_empty(_currentSetting->spi_d))
        ;
    while (spi_is_busy(_currentSetting->spi_d))
        ;
    spi_peripheral_disable(_currentSetting->spi_d);
}

rmdMoba
Posts: 12
Joined: Thu May 11, 2017 10:44 am

Re: pinMode() disables timer even if no PWM mode involved

Postby rmdMoba » Sat May 20, 2017 2:39 pm

After several tests I did not find a reason why pwm doesn't work again after SPI has been active. The only solution I found is to remap the SPI pins ( or execute a hardware reset ). It seems that SPI blocks the AF on this pin if it once has been activated. Even setting all SPI registers back to '0' (the state after reset ) does not help. The same seems to be true on pins that share UART and PWM as AF.

Because PWM works after remapping SPI this is obviously not a problem of PWM/timer channel configuration.

The changes to pinMode() now don't stop attached IRQ's when setting non PWM modes. The latest version of the fix is like this:

Code: Select all

    if (PIN_MAP[pin].timer_device != NULL) {
        if ( pwm ) { // we're switching into PWM, enable timer channels
        timer_set_mode(PIN_MAP[pin].timer_device,
                       PIN_MAP[pin].timer_channel,
                       TIMER_PWM );
        } else {  // disable channel output in non pwm-Mode             
            timer_cc_disable(PIN_MAP[pin].timer_device,
                            PIN_MAP[pin].timer_channel);
        }
    }
In non PWM mode the timer channel is disconnected from the pin, but nothing else is changed in timer/channel configuration. This worked fine in all my tests, and so I will create a pull request on Github soon.


Return to “STM core: Bugs and enhancements”

Who is online

Users browsing this forum: No registered users and 1 guest