wolfSSL / wolfTPM

wolfTPM is a highly portable TPM 2.0 library, designed for embedded use.
https://www.wolfssl.com
GNU General Public License v2.0
232 stars 56 forks source link

Add GPIO example for NPCT7xx #172

Closed tomoveu closed 3 years ago

tomoveu commented 3 years ago

UPDATE: WolfTPM Supports GPIO for NPCT75x

Draft PR - Added vendor commands to configure GPIO

It seems like NPCT7xx support only GPIO Output mode and configuration happens in a completely different way than we have right now in gpio/gpio_config.c Therefore, I am thinking of adding newgpio/gpio_npct7xx.c example.

First, I will confirm my suspicion before moving forward.

Signed-off-by: Dimitar Tomov dimi@wolfssl.com

tomoveu commented 3 years ago

Feedback taken in. Testing it tomorrow on the real hardware.

tomoveu commented 3 years ago

@dgarske I've already contacted Nuvoton, waiting on reply to confirm it is a design limitation. I suspect only output modes are supported.

Our example:

I am worried that if I have added the Nuvoton code in the existing gpio_config example, the code will not be very readable. Because there is no matching of values and defines. I could rename gpio_config_st and gpio_config_nuvoton?

tomoveu commented 3 years ago

@dgarske yes, please hold.

I am in communication with Nuvoton about GPIO modes and I also need to confirm some NV attributes, as well.

tomoveu commented 3 years ago

Changes pushed based on vendor feedback:

Result:

Failure:

Progress made. Must remain on hold @dgarske until we fix the two remaining issues.

tomoveu commented 3 years ago

@dgarske Ready for merge 👍

Details:

Test output from the real hardware:

pi@raspberrypi:~/wolftpm $ sudo ./examples/gpio/gpio_nuvoton 4 1
Example for GPIO configuration of a NPTC7xx TPM 2.0 module
GPIO number: 4
GPIO mode: 1
wolfTPM2_Init: success
First, the current NPCT7xx config will be read
then modified with the new GPIO configuration
Successfully read the current NPCT7xx configuration
NTC2_PreConfig success
NV Index for GPIO access created
pi@raspberrypi:~/wolftpm $ sudo ./examples/gpio/gpio_set 4 -low
GPIO4 set to low level
pi@raspberrypi:~/wolftpm $ sudo ./examples/gpio/gpio_read 4
GPIO4 is Low.
pi@raspberrypi:~/wolftpm $ sudo ./examples/gpio/gpio_set 4 -high
GPIO4 set to high level
pi@raspberrypi:~/wolftpm $ sudo ./examples/gpio/gpio_read 4
GPIO4 is High.
pi@raspberrypi:~/wolftpm $ sudo ./examples/gpio/gpio_nuvoton 4 2
Example for GPIO configuration of a NPTC7xx TPM 2.0 module
GPIO number: 4
GPIO mode: 2
wolfTPM2_Init: success
First, the current NPCT7xx config will be read
then modified with the new GPIO configuration
Successfully read the current NPCT7xx configuration
NTC2_PreConfig success
NV Index for GPIO access created
pi@raspberrypi:~/wolftpm $ sudo ./examples/gpio/gpio_read 4
GPIO4 is Low.
pi@raspberrypi:~/wolftpm $ sudo ./examples/gpio/gpio_nuvoton -h
Expected usage:
./examples/gpio/gpio_config [num] [mode]
* num is a GPIO number between 3 and 4 (default 3)
* mode is either push-pull, open-drain or open-drain with pull-up
    1. pushpull  - output in push pull configuration
    2. opendrain - output in open drain configuration
    3. pullup - output in open drain with pull-up enabled
    4. unconfig - delete NV index for GPIO access
Example usage, without parameters, configures GPIO3 as push-pull output.
pi@raspberrypi:~/wolftpm $