Skip to content
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

Adding STM32 Expansion Pack #287

Merged
merged 4 commits into from Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions IDE/STM32CUBE/README.md
@@ -0,0 +1,23 @@
# wolfTPM for STM32 Cube IDE

The wolfTPM Cube Pack can be found [here](https://www.wolfssl.com/files/ide/I-CUBE-wolfTPM.pack) and has an optional (and recommended) dependency on the `wolfCrypt` library.

1. The first step is to set up the wolfCrypt library in your ST project following the guide here [https://github.com/wolfSSL/wolfssl/blob/master/IDE/STM32Cube/README.md](https://github.com/wolfSSL/wolfssl/blob/master/IDE/STM32Cube/README.md). To run the wolfTPM unit tests, name the entry function `wolfTPMTest` instead of `wolfCryptDemo`.

2. Then install the wolfTPM Cube Pack in the same manner as the wolfSSL pack with CUBEMX.

3. Open the project `.ioc` file and click the `Software Packs` drop down menu and then `Select Components`. Expand the `wolfTPM` pack and check all the components.

4. In the `Software Packs` configuration category of the `.ioc` file, click on the wolfTPM pack and enable the library by checking the box.

5. In the `Connectivity` category, find and enable SPI for you project.

6. In the `Software Packs` configuration category, open the wolfTPM pack and set `Enable wolfCrypt` parameter to True.

7. Save your changes and select yes to the prompt asking about generating code.

8. Build the project and run the unit tests.

## Notes
- Make sure to make [these changes](https://github.com/wolfSSL/wolfssl/tree/master/IDE/STM32Cube#stm32-printf) to redirect the printf's to the UART.

100 changes: 100 additions & 0 deletions IDE/STM32CUBE/default_conf.ftl
@@ -0,0 +1,100 @@
[#ftl]
/**
******************************************************************************
* File Name : ${name}
* Description : This file provides code for the configuration
* of the ${name} instances.
******************************************************************************
[@common.optinclude name=mxTmpFolder+"/license.tmp"/][#--include License text --]
******************************************************************************
*/
[#assign s = name]
[#assign toto = s?replace(".","_")]
[#assign toto = toto?replace("/","")]
[#assign toto = toto?replace("-","_")]
[#assign inclusion_protection = toto?upper_case]
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __${inclusion_protection}__
#define __${inclusion_protection}__

#ifdef __cplusplus
extern "C" {
#endif


/* Includes ------------------------------------------------------------------*/
[#if includes??]
[#list includes as include]
#include "${include}"
[/#list]
[/#if]

[#-- SWIPdatas is a list of SWIPconfigModel --]
[#list SWIPdatas as SWIP]
[#-- Global variables --]
[#if SWIP.variables??]
[#list SWIP.variables as variable]
extern ${variable.value} ${variable.name};
[/#list]
[/#if]

[#-- Global variables --]

[#assign instName = SWIP.ipName]
[#assign fileName = SWIP.fileName]
[#assign version = SWIP.version]

/**
MiddleWare name : ${instName}
MiddleWare fileName : ${fileName}
MiddleWare version : ${version}
*/
[#if SWIP.defines??]
[#list SWIP.defines as definition]
/*---------- [#if definition.comments??]${definition.comments}[/#if] -----------*/
#define ${definition.name} #t#t ${definition.value}
[#if definition.description??]${definition.description} [/#if]
[/#list]
[/#if]



[/#list]

/* ------------------------------------------------------------------------- */
/* Platform */
/* ------------------------------------------------------------------------- */
#define NO_FILESYSTEM
#define NO_MAIN_DRIVER
#define WOLFTPM_EXAMPLE_HAL
dgarske marked this conversation as resolved.
Show resolved Hide resolved

/* ------------------------------------------------------------------------- */
/* Enable Features */
/* ------------------------------------------------------------------------- */
#undef WOLFTPM2_NO_WOLFCRYPT
#if defined(WOLFTPM_CONF_WOLFCRYPT) && WOLFTPM_CONF_WOLFCRYPT == 0
#define WOLFTPM2_NO_WOLFCRYPT
#endif

#undef USE_HW_SPI_CS
#if defined(WOLFTPM_CONF_HW_SPI) && WOLFTPM_CONF_HW_SPI == 1
#define USE_HW_SPI_CS
#endif

/* ------------------------------------------------------------------------- */
/* Debugging */
/* ------------------------------------------------------------------------- */
#if defined(WOLFTPM_CONF_DEBUG) && WOLFTPM_CONF_DEBUG == 1
#define DEBUG_WOLFTPM
#endif

#ifdef __cplusplus
}
#endif
#endif /* ${inclusion_protection}_H */

/**
* @}
*/

/*****END OF FILE****/
8 changes: 8 additions & 0 deletions IDE/STM32CUBE/include.am
@@ -0,0 +1,8 @@
# vim:ft=automake
# included from Top Level Makefile.am
# All paths should be given relative to the root

EXTRA_DIST+= ide/STM32CUBE/wolftpm_test.c
EXTRA_DIST+= ide/STM32CUBE/wolftpm_test.h
EXTRA_DIST+= ide/STM32CUBE/README.md
EXTRA_DIST+= ide/STM32CUBE/default_conf.ftl
52 changes: 52 additions & 0 deletions IDE/STM32CUBE/wolftpm_test.c
@@ -0,0 +1,52 @@
/* wolftpm_test.c
*
* Copyright (C) 2014-2023 wolfSSL Inc.
*
* This file is part of wolfTPM.
*
* wolfTPM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfTPM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wolfTPM. If not, see <http://www.gnu.org/licenses/>.
*/

#include "wolftpm_test.h"

#ifndef SINGLE_THREADED
#include <cmsis_os.h>

#ifdef WOLFSSL_DEBUG_MEMORY
/* for memory debugging */
#include <task.h>
#endif
#endif

#include <stdio.h>
#include <string.h>

extern int TPM2_Wrapper_Test(void* userCtx);

#ifdef CMSIS_OS2_H_
void wolfTPMTest(void* argument)
#else
void wolfTPMTest(const void* argument)
#endif
{
int ret = 0;

printf("Running wolfTPM Wrap Test...\n");

/* Run wolfTPM wrap test */
ret = TPM2_Wrapper_Test(NULL);

printf("wolfTPM wrap test: Return code %d\n", ret);

}
38 changes: 38 additions & 0 deletions IDE/STM32CUBE/wolftpm_test.h
@@ -0,0 +1,38 @@
/* wolftpm_test.h
*
* Copyright (C) 2014-2023 wolfSSL Inc.
*
* This file is part of wolfTPM.
*
* wolfTPM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfTPM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wolfTPM. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef WOLFTPM_TEST_H_
#define WOLFTPM_TEST_H_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef SINGLE_THREADED
#include <cmsis_os.h>
#endif

#ifdef CMSIS_OS2_H_
void wolfTPMTest(void* argument);
#else
void wolfTPMTest(void const * argument);
#endif

#endif /* WOLFTPM_TEST_H_ */
1 change: 1 addition & 0 deletions IDE/include.am
Expand Up @@ -2,6 +2,7 @@
# included from Top Level Makefile.am
# All paths should be given relative to the root

include IDE/STM32CUBE/include.am
include IDE/OPENSTM32/include.am
include IDE/IAR-EWARM/include.am
include IDE/QNX/include.am
5 changes: 4 additions & 1 deletion wolftpm/tpm2_types.h
Expand Up @@ -29,7 +29,10 @@
#include <wolftpm/visibility.h>
#include <stdint.h>

#ifndef WOLFTPM_USER_SETTINGS
#if defined(USE_HAL_DRIVER) && !defined(HAVE_CONFIG_H)
/* STM Configuration File (generated by CubeMX) */
#include "wolfSSL.I-CUBE-wolfTPM_conf.h"
#elif !defined(WOLFTPM_USER_SETTINGS)
/* use generated options.h or a custom one */
#include <wolftpm/options.h>
#endif
Expand Down