Page 1 of 1

can't import name pwm

Posted: Fri Oct 22, 2021 1:04 pm
by dragon12
For some reason I cannot find PWM module:

Code: Select all

MicroPython v1.17-68-g35fb90bd5-dirty on 2021-09-24; NUCLEO-F401RE with STM32F401xE

Type "help()" for more information.
>>> from machine import pwm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: can't import name pwm
>>> dir(machine)
['__class__', '__name__', 'RTC', 'ADC', 'DEEPSLEEP_RESET', 'HARD_RESET', 'I2C', 'PWRON_RESET', 'Pin', 'SOFT_RESET', 'SPI', 'Signal', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'WDT', 'WDT_RESET', 'bitstream', 'bootloader', 'deepsleep', 'disable_irq', 'enable_irq', 'freq', 'idle', 'info', 'lightsleep', 'mem16', 'mem32', 'mem8', 'reset', 'reset_cause', 'sleep', 'soft_reset', 'time_pulse_us', 'unique_id']
>>> 
The same on another board:

Code: Select all

MicroPython v1.17-6-g9792c9105 on 2021-09-03; NUCLEO-L476RG with STM32L476RG

Type "help()" for more information.
>>> from machine import pwm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: can't import name pwm
>>> dir(machine)
['__class__', '__name__', 'RTC', 'ADC', 'DEEPSLEEP_RESET', 'HARD_RESET', 'I2C', 'PWRON_RESET', 'Pin', 'SOFT_RESET', 'SPI', 'Signal', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'WDT', 'WDT_RESET', 'bitstream', 'bootloader', 'deepsleep', 'disable_irq', 'enable_irq', 'freq', 'idle', 'info', 'lightsleep', 'mem16', 'mem32', 'mem8', 'reset', 'reset_cause', 'rng', 'sleep', 'soft_reset', 'time_pulse_us', 'unique_id']
>>> 
Could somebody explain what I'm doing wrong?

Re: can't import name pwm

Posted: Fri Oct 22, 2021 1:23 pm
by Roberthh
On the STM32 port pwm is part of the pyb.Timer module. See: https://docs.micropython.org/en/latest/ ... hlight=pwm

Re: can't import name pwm

Posted: Fri Oct 22, 2021 1:38 pm
by dragon12
Roberthh wrote:
Fri Oct 22, 2021 1:23 pm
On the STM32 port pwm is part of the pyb.Timer module. See: https://docs.micropython.org/en/latest/ ... hlight=pwm
Thank you for helping me with this. I assumed that machine is common hardware library and all its modules present on all boards.

Re: can't import name pwm

Posted: Fri Oct 22, 2021 2:25 pm
by Roberthh
I ran into that same problem a few days ago. STM32 was the first hardware platform for MicroPython. And not all changes have been mapped back to that platform. There are legacy extensions and omissions.