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

Complete rewrite of STM32 gpio driver #836

Merged
merged 4 commits into from
Oct 26, 2023

Conversation

UncleGrumpy
Copy link
Collaborator

@UncleGrumpy UncleGrumpy commented Oct 3, 2023

  • Moves all GPIO related atoms from platform_defaultatoms.c (& .h) into gpio_driver.c
  • Improved input validation.
  • Adds read and interrupt support to port driver.
  • Adds nif functions to support digital_read/1, digital_write/2, and set_pin_mode/2 (used to set all configuration options).
  • Adds cmake configuration options to disable nifs and/or port driver when building the VM.
  • Updates edocs and types in the Erlang driver code to accommodate differences of the STM32 platform.
  • Details in the "Programmers Guide" on where the STM32 port differs from ESP32 and rp2040 ports.

Closes #571
Addresses #894 on STM32 platform.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 4, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Complete rewrite of the stm32 gpio driver using updated APIs.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 4, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Add support for interrupts to stm32 gpio port driver.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 4, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Updates the types and edoc entries for gpio.erl, and the "Programmers Guide"
with details about the updated STM32 gpio driver.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 4, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Complete rewrite of the stm32 gpio driver using updated APIs.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 4, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Add support for interrupts to stm32 gpio port driver.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 4, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Updates the types and edoc entries for gpio.erl, and the "Programmers Guide"
with details about the updated STM32 gpio driver.

Signed-off-by: Winford <[email protected]>
@UncleGrumpy UncleGrumpy marked this pull request as draft October 6, 2023 17:32
@UncleGrumpy UncleGrumpy force-pushed the stm32_gpio_driver branch 2 times, most recently from 9b3c67f to 87b6a67 Compare October 14, 2023 04:55
@UncleGrumpy UncleGrumpy marked this pull request as ready for review October 14, 2023 05:13
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 14, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Complete rewrite of the stm32 gpio driver using updated APIs.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 14, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Add support for interrupts to stm32 gpio port driver.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 14, 2023
TEMPORARY: SUBMITTED IN atomvm#836.
Updates the types and edoc entries for gpio.erl, and the "Programmers Guide"
with details about the updated STM32 gpio driver.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 14, 2023
TEMPORARY: SUBMITTED IN atomvm#836.

Complete rewrite of the stm32 gpio driver using updated APIs.

Moves all GPIO related atoms from `platform_defaultatoms.{c,h}` into `gpio_driver.c`
Improved input validation.
Adds read support port driver.
Adds nif functions to support read and write.
Adds cmake configuration options to disable nifs and/or port driver when building the VM.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 14, 2023
TEMPORARY: SUBMITTED IN atomvm#836.

To prevent accidental reset, or configuration of pins currently in use by system
peripherals on the stm32 platform, reserved pins (such as the CONSOLE) may be
locked using `sys_lock_pin`, and unlocked with `sys_unlock_pin` so they are not
unintentionally reset later when other peripherals such as gpio are configured.
This is also intended to support other drivers that consume gpio pins, such as
SPI and I2C, to avoid inadvertent resets or re-configuration by other drivers.
The libopencm3 libraries on the stm32 platform provide no protection from
re-confuguring a gpio pin that is in active use.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 14, 2023
TEMPORARY: SUBMITTED IN atomvm#836.

Add support for interrupts to stm32 gpio port driver.

Signed-off-by: Winford <[email protected]>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this pull request Oct 14, 2023
TEMPORARY: SUBMITTED IN atomvm#836.

Updates the types and edoc entries for gpio.erl, and the "Programmers Guide"
with details about the updated STM32 gpio driver.

Signed-off-by: Winford <[email protected]>
Copy link
Collaborator

@fadushin fadushin left a comment

Choose a reason for hiding this comment

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

Mostly LGTM. A few small doc/type nits, but also found some potential memory leaks in error conditions that will need attention.

doc/src/programmers-guide.md Outdated Show resolved Hide resolved
doc/src/programmers-guide.md Outdated Show resolved Hide resolved
libs/eavmlib/src/gpio.erl Outdated Show resolved Hide resolved
libs/eavmlib/src/gpio.erl Outdated Show resolved Hide resolved
libs/eavmlib/src/gpio.erl Show resolved Hide resolved
src/platforms/stm32/src/lib/gpio_driver.c Show resolved Hide resolved
src/platforms/stm32/src/lib/gpio_driver.c Outdated Show resolved Hide resolved
src/platforms/stm32/src/lib/gpio_driver.c Outdated Show resolved Hide resolved
src/platforms/stm32/src/lib/gpio_driver.c Outdated Show resolved Hide resolved
src/platforms/stm32/src/lib/gpio_driver.c Outdated Show resolved Hide resolved
@UncleGrumpy UncleGrumpy force-pushed the stm32_gpio_driver branch 8 times, most recently from 0a76a11 to 31ca8d6 Compare October 25, 2023 23:03
Copy link
Collaborator

@fadushin fadushin left a comment

Choose a reason for hiding this comment

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

Just a few more to hit!

src/platforms/stm32/src/lib/gpio_driver.c Outdated Show resolved Hide resolved
src/platforms/stm32/src/lib/gpio_driver.c Outdated Show resolved Hide resolved
src/platforms/stm32/src/lib/gpio_driver.c Outdated Show resolved Hide resolved
Complete rewrite of the stm32 gpio driver using updated APIs.

Moves all GPIO related atoms from `platform_defaultatoms.{c,h}` into `gpio_driver.c`
Improved input validation.
Adds read support port driver.
Adds nif functions to support read and write.
Adds cmake configuration options to disable nifs and/or port driver when building the VM.

Closes atomvm#571
Addresses atomvm#894 on STM32 platform.

Signed-off-by: Winford <[email protected]>
To prevent accidental reset, or configuration of pins currently in use by system
peripherals on the stm32 platform, reserved pins (such as the CONSOLE) may be
locked using `sys_lock_pin`, and unlocked with `sys_unlock_pin` so they are not
unintentionally reset later when other peripherals such as gpio are configured.
This is also intended to support other drivers that consume gpio pins, such as
SPI and I2C, to avoid inadvertent resets or re-configuration by other drivers.
The libopencm3 libraries on the stm32 platform provide no protection from
re-confuguring a gpio pin that is in active use.

Signed-off-by: Winford <[email protected]>
Add support for interrupts to stm32 gpio port driver.

Signed-off-by: Winford <[email protected]>
Updates the types and edoc entries for gpio.erl, and the "Programmers Guide"
with details about the updated STM32 gpio driver.

Signed-off-by: Winford <[email protected]>
@fadushin fadushin merged commit 25c09a0 into atomvm:master Oct 26, 2023
72 of 75 checks passed
@UncleGrumpy UncleGrumpy deleted the stm32_gpio_driver branch October 26, 2023 03:50
@bettio bettio mentioned this pull request Oct 27, 2023
bettio added a commit that referenced this pull request Oct 27, 2023
STM32 GPIO driver fixes

This PR fixes few issues introduced with #836.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
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.

STM32 does not support GPIO input
2 participants