Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ using var rxChannel = new ReceiverChannel(rxChannelSettings);
rxChannel.Start(clearBuffer: true);
```

## GPIO Pin Restrictions

The ESP32 MCU restricts which GPIO pins can be used for the Transmit Channel (TX). Ports 34 to 39 (inclusive) cannot be used for TX. Attempting to use these ports will cause the `TransmitChannelSettings` class to throw an `ArgumentOutOfRangeException`.
Copy link
Member

Choose a reason for hiding this comment

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

  1. Shouldn't these be referred as pins, instead of ports?
  2. are these valid for all ESP32 series?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Absolutely! Sorry about that.. been doing a lot of web dev and networking-related stuff for a while now 😁
  2. I based this on what I read in the RMT legacy driver code. Essentially rmt_config(..) calls rmt_set_gpio(..) which performs the following validation:
ESP_RETURN_ON_FALSE(((GPIO_IS_VALID_GPIO(gpio_num) && (mode == RMT_MODE_RX)) ||
                         (GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) && (mode == RMT_MODE_TX))), ESP_ERR_INVALID_ARG, TAG, RMT_GPIO_ERROR_STR);

The GPIO_IS_VALID_OUTPUT_GPIO macro is used to make sure the pins are not 34-39:

/// Check whether it can be a valid GPIO number of output mode
#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \
                                              (((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0))

There aren't any compiler directive around this validation code which tells me it is applicable to all ESP32 boards. However, The RMT docs on the Espressif website for IDF version 4.4.6 makes no specific mention of this.

Copy link
Member

Choose a reason for hiding this comment

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

Please note that we're currently at IDF v5.4. Not sure if that makes any difference in the API/docs.


## Build status

| Component | Build Status | NuGet Package |
Expand Down
7 changes: 7 additions & 0 deletions nanoFramework.Hardware.Esp32.Rmt/TransmitChannelSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,15 @@ public TransmitChannelSettings(int pinNumber) : this(channel: -1, pinNumber)
/// <param name="channel">The channel number to use. Valid value range is 0 to 7 (inclusive).</param>
/// <param name="pinNumber">The GPIO Pin number to use with the channel.</param>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="channel"/> must be between 0 and 7.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="pinNumber"/> must not be between 34 and 39.</exception>
public TransmitChannelSettings(int channel, int pinNumber) : base(channel, pinNumber)
{
// ESP32 RMT TX channels cannot use GPIO pins 34-39
if (pinNumber >= 34 && pinNumber <= 39)
{
throw new ArgumentOutOfRangeException();
}

_enableCarrierWave = true;
_carrierLevel = true;
_carrierWaveFrequency = 38_000;
Expand Down