Skip to content

RMT refactoring based on IDF #6024

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

Merged
merged 7 commits into from
Dec 21, 2021
Merged

Conversation

SuGlider
Copy link
Collaborator

Summary

RMT HAL refactoring based on IDF.

Impact

Improves RMT by adding IDF v4.4 support.
Receiving RMT can handle any size of data.
rmtInit() has a new parameter - RxBufferSize - to hold any number of data when receiving RMT.
rmtWrite() has a new parameter - wait_tx_done - to block writing until sending all data.

Related links

fix #5905

@SuGlider SuGlider requested a review from me-no-dev December 15, 2021 04:44
@SuGlider SuGlider self-assigned this Dec 15, 2021

// USE SOC_RMT_CHANNELS_PER_GROUP
// LOOK to https://github.com/espressif/esp-idf/blob/master/components/hal/include/hal/rmt_types.h#L32

Copy link
Member

Choose a reason for hiding this comment

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

correct :) https://github.com/espressif/arduino-esp32/blob/master/tools/sdk/esp32/include/soc/esp32/include/soc/soc_caps.h#L195-L202

#include "soc/soc_caps.h"

#define MAX_CHANNELS (SOC_RMT_GROUPS * SOC_RMT_CHANNELS_PER_GROUP)
#define MAX_DATA_PER_CHANNEL SOC_RMT_MEM_WORDS_PER_CHANNEL
#define MAX_DATA_PER_ITTERATION (MAX_DATA_PER_CHANNEL - 2)

It is then chip independent. We should try to have as few chips specific things as possible

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. Done.

rmt_get_status(channel, &status);
rmt_get_source_clk(channel, &srcClk);

ESP_LOGD(tag, "Status for RMT channel %d", channel);
Copy link
Member

Choose a reason for hiding this comment

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

do not use ESP_LOGx in Arduino. Use log_x

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. Done.

RMT.apb_conf.fifo_mask = 1;
rmt_config_t config = RMT_DEFAULT_ARD_CONFIG_RX(pin, channel, buffers);
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 1024, 0)); //, rxBufferSize, 0));
Copy link
Member

Choose a reason for hiding this comment

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

rxBufferSize is ignored here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Solved by keeping 1024 to all SoCs. Tested it with ESP32, S2 and C3.
One possible solution is to use default values in the function signature, but that would require changing to change esp32-hal-rmt.c to cpp instead.

@me-no-dev
Copy link
Member

Overall very good, but here are a few things:

  • do not change the API, let's think how we can accommodate rxBufferSize while keeping init the same.
  • same goes for write. Add a new function rmtWriteBlocking
  • clean up all unused definitions and variables
  • convert the ones left to soc_caps (I gave example in a comment)

@SuGlider
Copy link
Collaborator Author

SuGlider commented Dec 17, 2021

Overall very good, but here are a few things:

* do not change the API, let's think how we can accommodate `rxBufferSize` while keeping init the same.

* same goes for write. Add a new function `rmtWriteBlocking`

* clean up all unused definitions and variables

* convert the ones left to `soc_caps` (I gave example in a comment)

OK. All done.
rmtInit() is back to the original. I just removed rxBufferSize and it is being initialized with 1024 as buffer size always.
1024 works fine in all the SoCs - even with RMT_MEM_512 in ESP32 for RX.

return _rmtSendOnce(rmt, data, size, false);
}
RMT_MUTEX_LOCK(channel);
ESP_ERROR_CHECK(rmt_tx_stop(channel));
Copy link
Member

Choose a reason for hiding this comment

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

ESP_ERROR_CHECK is also an IDF API that boils down to ESP_LOGx

Copy link
Collaborator Author

@SuGlider SuGlider Dec 20, 2021

Choose a reason for hiding this comment

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

Actually ESP_ERROR_CHECK boils down directly to esp_rom_printf(), which seems to be a ROM function, thus, it should be fine for Arduino.
What do you say? Let's keep it?
I like the error message with all necessary details about code line, function name and so on.

https://github.com/espressif/esp-idf/blob/master/components/esp_common/include/esp_err.h#L121-L127
https://github.com/espressif/esp-idf/blob/master/components/esp_system/esp_err.c#L23-L33

Copy link
Member

Choose a reason for hiding this comment

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

what it looks like is that it will abort and produce some IDF formatted message. Let's stick to Arduino constructs and log_e if not ESP_OK

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. Done.
I removed ESP_ERROR_CHECK() from IDF function calls that only checked IDF parameters and left it on the function call that really could return error on IDF operations.

@VojtechBartoska VojtechBartoska added this to the 2.0.2 milestone Dec 20, 2021
@me-no-dev me-no-dev merged commit 7cf1623 into espressif:master Dec 21, 2021
@Jason2866
Copy link
Collaborator

Compile with Arduino Lib Builder does fail with this PR

@SuGlider
Copy link
Collaborator Author

Compile with Arduino Lib Builder does fail with this PR

With IDF 4.4?

Could you please share the log?

@Jason2866
Copy link
Collaborator

Jason2866 commented Dec 21, 2021

@SuGlider Here is the log. Yes with IDF4.4. Lib Builder https://github.com/Jason2866/esp32-arduino-lib-builder
logs_701.zip

@SuGlider SuGlider mentioned this pull request Dec 22, 2021
@SuGlider
Copy link
Collaborator Author

@SuGlider Here is the log. Yes with IDF4.4. Lib Builder https://github.com/Jason2866/esp32-arduino-lib-builder logs_701.zip

Thanks @Jason2866!
I just submitted a fixing PR.

@me-no-dev @VojtechBartoska -
I think that the CI may not have the same compilation options as in the Lib Builder, otherwise this problem should have been caught in the CI testing. Could you please check it?

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.

Change RMT to use ESP-IDF API
4 participants