Skip to content

pkg/driver_atwinc15x0: remove the compilation of the SPI Flash driver part #21494

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 4 commits into from
May 19, 2025

Conversation

gschorcht
Copy link
Contributor

Contribution description

The PR removes the compilation of the SPI Flash driver part of the package. This allows also to use the ATWINC15x0 for ESPs.

The SPI flash integrated in the ATWINC15x0 chip is not used in RIOT. It is therefore not necessary to compile the SPI flash driver part of the package. The only function of this part that is called by other parts of the driver package is spi_enable_flash(0) to disable the SPI flash during the driver deinitialization for power consumption reasons. Since we are not deinitializing the driver, the function is not called and can be commented out to be able to compile the package without the SPI flash driver part.

Testing procedure

A networking application should still work for any board with a ATWINC15x0 WiFi module that uses the ATWINC15x0 driver package, for example:

CFLAGS='-DWIFI_SSID=\"<ssid>\" -DWIFI_PASS=\"<pass>\"' \
BOARD=feather-m0-wifi make -C examples/networking/gnrc/gnrc_networking flash term

The PR has been tested with

Issues/PRs references

gschorcht added 3 commits May 16, 2025 15:43
The SPI flash integrated in the ATWINC15x0 chip is not used in RIOT. It is therefore not necessary to use the SPI flash driver of the package.
The only function of the SPI flash driver part that is called by other parts of the package is `spi_enable_flash(0)` to disable the SPI flash during driver deinitialisation for power consumption reasons. Since we are not deinitialising the driver, the function is not called and can be commented out to compile the package without the SPI flash driver part.
@github-actions github-actions bot added Area: pkg Area: External package ports Area: drivers Area: Device drivers labels May 16, 2025
@gschorcht gschorcht force-pushed the drivers/atwinc15x0_cleanup branch from c804868 to 5668a96 Compare May 16, 2025 14:08
@gschorcht gschorcht added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 16, 2025
@gschorcht gschorcht requested a review from benpicco May 16, 2025 14:26
@benpicco benpicco requested a review from fabian18 May 16, 2025 15:01
@@ -40,8 +40,10 @@ sint8 nm_bus_init(void *arg)
assert(atwinc15x0);
assert(gpio_is_valid(atwinc15x0->params.ssn_pin));

#if !defined(CPU_ESP32) && !defined(CPU_ESP8266)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do these need a special case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 For the ESP32x, the CS pin is implicitly initialised as an SPI pin in spi_acquire, so it is not necessary to initialise it explicitly as GPIO_OUT. If the CS pin also corresponds to the pin defined as CS0 pin, which is the case here, it is already initialized as CS pin during auto-initialization, i.e. it is already marked as SPI pin. If the pin is marked as an SPI pin, the GPIO peripheral driver will complain if the application tries to initialize the pin as something else to prevent attempts to use a GPIO for multiple purposes at the same time.

To avoid this special case, we would have to remove this already used as something else check from the ESP32x GPIO peripheral driver.

int _gpio_init_mode_check(gpio_t pin, gpio_mode_t mode)
{
assert(pin < GPIO_PIN_NUMOF);
/* check if the pin can be used as GPIO or if it is used for something else */
if (_gpio_pin_usage[pin] != _GPIO) {
LOG_TAG_ERROR("gpio", "GPIO%d is already used as %s signal\n", pin,
_gpio_pin_usage_str[_gpio_pin_usage[pin]]);
return -1;
}
return 0;
}

assert(_gpio_init_mode_check(pin, mode) == 0);

Copy link
Contributor

Choose a reason for hiding this comment

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

But won't this be a problem for every driver that expects a software CS pin?
On all other platforms we don't user hardware CS since that sometimes has a weird behavior (deasserts after every byte) so I'd be surprised if ESP32 is special here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, we could just remove the check _gpio_init_mode_check from gpio_init. Then it should be possible to reinitialize a GPIO. However, the check for accidental multiple use would then no longer work.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather remove the initialization of the CS pin from the cpu, all drivers that make use of a CS pin will initialize it on their own.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all drivers that make use of a CS pin will initialize it on their own.

Yes, but they use spi_init_cs instead of gpio_init 🤔 So the problem is that the driver doesn't use the right function to initialize the CS pin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I replaced gpio_init by spi_init_cs, it seems to work.

@riot-ci
Copy link

riot-ci commented May 16, 2025

Murdock results

✔️ PASSED

bb2a7b1 drivers/atwinc15x0: use spi_init_cs to initialize CS pin

Success Failures Total Runtime
10348 0 10348 11m:50s

Artifacts

@gschorcht gschorcht added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 19, 2025
@gschorcht gschorcht enabled auto-merge May 19, 2025 13:49
@gschorcht gschorcht added this pull request to the merge queue May 19, 2025
Merged via the queue into RIOT-OS:master with commit 045c35a May 19, 2025
28 checks passed
@gschorcht
Copy link
Contributor Author

@benpicco Thanks for reviewing and merging.

@gschorcht gschorcht deleted the drivers/atwinc15x0_cleanup branch May 20, 2025 05:22
@Teufelchen1 Teufelchen1 added this to the Release 2025.07 milestone Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants