Skip to content

drivers/stmpe811: fix initialization if callback function parameter is NULL #19881

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 2 commits into from
Aug 24, 2023

Conversation

gschorcht
Copy link
Contributor

Contribution description

This PR fixes the stmpe811 driver initialization if the callback function parameter cb is `NULL. This might be the case for example if the application uses the touch device in polling mode.

If the interrupt pin is initialized if the callback function parameter cb is NULL, the driver crashes the first time an interrupt is triggered. Therefore, the INT pin must be initialized only if also the callback function parameter cb is not NULL.

To be able to test the polling mode, this PR also includes a change of the tests/drivers/stmpe811 application which introduces the environment variables STMPE811_POLLING_MODE STMPE811_POLLING_PERIOD and in the makefile.

Testing procedure

  1. Use a stm32f429i-disc1 board and test it in polling mode:

    STMPE811_POLLING_MODE=1 BOARD=stm32f429i-disc1 make -C tests/drivers/stmpe811 flash term
    

    It should work as expected.

    main(): This is RIOT! (Version: 2023.10-devel-119-g26e7a-drivers/stmpe811_fix_cb_null)
    STMPE811 test application
    +------------Initializing------------+
    Initialization successful
    Pressed!
    X: 113, Y:135
    X: 113, Y:135
    X: 113, Y:136
    Released!
    
  2. Checkout master branch and cerry-pick commit 691a5e6. The test application tests/drivers/stmpe811 will crash once a touch event occur:

    main(): This is RIOT! (Version: 2023.10-devel-117-g91441)
    STMPE811 test application
    +------------Initializing------------+
    Initialization successful
    Stack pointer corrupted, reset to top of stack
    FSR/FAR:
     CFSR: 0x00020000
     HFSR: 0x40000000
     DFSR: 0x00000008
     AFSR: 0x00000000
    Misc
    EXC_RET: 0xfffffff1
    *** RIOT kernel panic:
    HARD FAULT HANDLER
    

Issues/PRs references

@github-actions github-actions bot added Area: doc Area: Documentation Area: tests Area: tests and testing framework Area: drivers Area: Device drivers labels Aug 12, 2023
@gschorcht gschorcht added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 12, 2023
@riot-ci
Copy link

riot-ci commented Aug 12, 2023

Murdock results

✔️ PASSED

42c73bf tests/drivers/stmpe811: introduce STMPE811_POLLING_MODE

Success Failures Total Runtime
7939 0 7939 12m:55s

Artifacts

@gschorcht
Copy link
Contributor Author

@maribu Thank you for reviewing so promptly.

While modifying tests/drivers/touch_dev in PR #19882, I realized that at least the device interrupts have to be configured in any case, even if the interrupt pin is not initialized because of the parameter cb. The reason is that the the touch device API first initializes the device with NULL for the callback function parameter cb and later it just initializes the interrupt pin. Configuring the device interrupts in any case isn't a problem even if the interrupt pin is not used at all since the interrupt status is cleared on every read operation.

Therefore, I pushed commit 3e35dba with a small additional change. I could squash it with commit 16abf02 if you prefer.

@maribu
Copy link
Member

maribu commented Aug 12, 2023

I could squash it with commit 16abf02 if you prefer.

as you prefer. The ACK remains valid in either case

If the INT pin is initialized if the callback function parameter `cb` is `NULL`, the driver crashes the first time an interrupt is triggered. Therefore, the INT pin must be initialized only if also the callback function parameter `cb` is not `NULL`.

Even if the interrupt pin is not initialized here because the callback function parameter `cb` is NULL, the device interrupts are configured here so that they will work when the interrupt pin is initialized later, as is the case when the Touch Device API is used, for example. Since the interrupt state is cleared on each read, this is not a problem even if the interrupt pin is not used at all.
To be able to test the STMPE811 device driver in polling mode, variable `STMPE811_POLLING_MODE` is introduced. It is set to 0 by default and can be overriden by 1 to use the polling mode. The polling period can be controlled by the `STMPE811_POLLING_PERIOD` variable.
@gschorcht gschorcht force-pushed the drivers/stmpe811_fix_cb_null branch from 3e35dba to 42c73bf Compare August 13, 2023 15:12
@gschorcht
Copy link
Contributor Author

gschorcht commented Aug 13, 2023

I could squash it with commit 16abf02 if you prefer.

as you prefer. The ACK remains valid in either case

I decided to squash them because it makes the change more clear if is in one commit instead of two commits.

@maribu
Copy link
Member

maribu commented Aug 13, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Aug 13, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@bors
Copy link
Contributor

bors bot commented Aug 13, 2023

GitHub status checks took too long to complete, so bors is giving up. You can adjust bors configuration to have it wait longer if you like.

@benpicco
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Aug 23, 2023

👎 Rejected by PR status

@benpicco benpicco 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 Aug 23, 2023
@benpicco
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Aug 24, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit d1edbd9 into RIOT-OS:master Aug 24, 2023
@gschorcht
Copy link
Contributor Author

Thanks for reviewing and mergin.

bors bot added a commit that referenced this pull request Aug 30, 2023
19882: tests/drivers/touch_dev: allow to test a touch device in polling mode r=aabadie a=gschorcht

### Contribution description

To be able to test the touch device in polling mode, variable `TOUCH_DEV_POLLING` is introduced. It is set to 0 by default and can be overriden by 1 to use the polling mode. The polling period can be controlled by the `TOUCH_DEV_POLLING_PERIOD` variable.

To use it for `ft5x06` and `stmpe811` drivers, the polling mode has to be fixed for these touch device drivers (PR #19880 respective PR #19881).

### Testing procedure

Use any board with touch device driver that uses the generic touch device API, for example (PR #19881 is required)
```
TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 \
BOARD=stm32f429i-disc1 make -C tests/drivers/touch_dev flash term
```
or (PR #19880 is required)
```
TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 \
BOARD=stm32f746g-disco make -C tests/drivers/touch_dev flash term
```

### Issues/PRs references

Depends partially on PR #19880
Depends partially on PR #19881

Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
@gschorcht gschorcht deleted the drivers/stmpe811_fix_cb_null branch September 2, 2023 15:02
@MrKevinWeiss MrKevinWeiss added this to the Release 2023.10 milestone Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: doc Area: Documentation Area: drivers Area: Device drivers Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants