diff options
author | Paul Selkirk <paul@psgd.org> | 2017-05-02 17:10:02 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2017-05-02 17:10:02 -0400 |
commit | 1175ff63f2a8c4762692551403862f9f0789aef8 (patch) | |
tree | d7d004e639ffa35296b6c91a64711bcc34f63a9b /stm-keystore.c | |
parent | 716694ae77259e31526a6d64db867ced5c231ced (diff) |
Merge branch 'init_cleanup' into no-rtos
Clean up Makefiles and initialization code.
Diffstat (limited to 'stm-keystore.c')
-rw-r--r-- | stm-keystore.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/stm-keystore.c b/stm-keystore.c index b941489..6bec008 100644 --- a/stm-keystore.c +++ b/stm-keystore.c @@ -32,14 +32,36 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stm32f4xx_hal.h" -#include "stm-keystore.h" #include "stm-init.h" +#include "stm-keystore.h" -SPI_HandleTypeDef hspi_keystore; +static SPI_HandleTypeDef hspi_keystore; struct spiflash_ctx keystore_ctx = {&hspi_keystore, KSM_PROM_CS_N_GPIO_Port, KSM_PROM_CS_N_Pin}; +/* SPI1 (keystore memory) init function */ +void keystore_init(void) +{ + /* Set up GPIOs for the keystore memory. + * KEYSTORE_GPIO_INIT is defined in stm-keystore.h. + */ + KEYSTORE_GPIO_INIT(); + + hspi_keystore.Instance = SPI1; + hspi_keystore.Init.Mode = SPI_MODE_MASTER; + hspi_keystore.Init.Direction = SPI_DIRECTION_2LINES; + hspi_keystore.Init.DataSize = SPI_DATASIZE_8BIT; + hspi_keystore.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi_keystore.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi_keystore.Init.NSS = SPI_NSS_SOFT; + hspi_keystore.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; + hspi_keystore.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi_keystore.Init.TIMode = SPI_TIMODE_DISABLE; + hspi_keystore.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi_keystore.Init.CRCPolynomial = 10; + HAL_SPI_Init(&hspi_keystore); +} + int keystore_check_id(void) { return n25q128_check_id(&keystore_ctx); |