add SST25VF016B Flash testing function
This commit is contained in:
69
Core/Src/SST25VF016B.c
Normal file
69
Core/Src/SST25VF016B.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "main.h"
|
||||
#include "lcd.h"
|
||||
#include "SST25VF016B.h"
|
||||
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
|
||||
void SST25VF016B_run_test(void)
|
||||
{
|
||||
DISPLAY_CLEAR;
|
||||
display_write_data_seq("SST25VF016B Flas");
|
||||
|
||||
HAL_StatusTypeDef op_result;
|
||||
size_t err_count = 0;
|
||||
|
||||
uint8_t tx_buffer[8] = {0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t rx_buffer[9];
|
||||
rx_buffer[8] = '\0';
|
||||
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET);
|
||||
HAL_Delay(50);
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_RESET);
|
||||
|
||||
for (size_t t = 0; t < 5; t++) {
|
||||
op_result = HAL_SPI_TransmitReceive(&hspi1, tx_buffer, rx_buffer, 8, 2000);
|
||||
|
||||
if (op_result) {
|
||||
err_count++;
|
||||
|
||||
DISPLAY_CLEAR;
|
||||
display_write_data_seq("SST25VF016B Flas");
|
||||
|
||||
DISPLAY_SET_CURSOR(1, 0);
|
||||
display_write_data_byte('1' + t);
|
||||
display_write_data_seq("/5 ");
|
||||
|
||||
switch (op_result) {
|
||||
case HAL_ERROR:
|
||||
display_write_data_seq("ERROR");
|
||||
break;
|
||||
case HAL_BUSY:
|
||||
display_write_data_seq("BUSY");
|
||||
break;
|
||||
case HAL_TIMEOUT:
|
||||
display_write_data_seq("TIMEOUT");
|
||||
break;
|
||||
}
|
||||
|
||||
HAL_Delay(2000);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET);
|
||||
|
||||
DISPLAY_CLEAR;
|
||||
display_write_data_seq("SST25VF016B Flas");
|
||||
|
||||
if (err_count) {
|
||||
DISPLAY_SET_CURSOR(1, 1);
|
||||
display_write_data_byte('0' + err_count % 10);
|
||||
display_write_data_seq(" Errors");
|
||||
} else {
|
||||
DISPLAY_SET_CURSOR(1, 1);
|
||||
display_write_data_seq("OK");
|
||||
DISPLAY_SET_CURSOR(1, 8);
|
||||
display_write_data_seq((char) rx_buffer);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "PCA9685.h"
|
||||
#include "24AA02E48.h"
|
||||
#include "CS43L22.h"
|
||||
#include "SST25VF016B.h"
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
@@ -54,6 +55,8 @@ ADC_HandleTypeDef hadc1;
|
||||
|
||||
I2C_HandleTypeDef hi2c1;
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
void ((*executors[])(void)) = {
|
||||
@@ -61,7 +64,8 @@ void ((*executors[])(void)) = {
|
||||
DNI_show_fahrenheit,
|
||||
PCA9685_run_test,
|
||||
EEPROM_24AA02E48_run_test,
|
||||
CS43L22_run_test
|
||||
CS43L22_run_test,
|
||||
SST25VF016B_run_test
|
||||
};
|
||||
|
||||
void ((*cleanup_functions[])(void)) = {
|
||||
@@ -69,10 +73,11 @@ void ((*cleanup_functions[])(void)) = {
|
||||
NULL,
|
||||
PCA9685_cleanup,
|
||||
NULL,
|
||||
CS43L22_cleanup
|
||||
CS43L22_cleanup,
|
||||
NULL
|
||||
};
|
||||
|
||||
int delay_between_runs[] = {250, 250, -1, -1, -1};
|
||||
int delay_between_runs[] = {250, 250, -1, -1, -1, -1};
|
||||
|
||||
size_t current_executor_id = 0;
|
||||
|
||||
@@ -85,6 +90,7 @@ void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
static void MX_I2C1_Init(void);
|
||||
static void MX_SPI1_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
@@ -95,7 +101,7 @@ static void MX_I2C1_Init(void);
|
||||
void switch_to_next_test(void)
|
||||
{
|
||||
current_executor_id += 1;
|
||||
current_executor_id %= 5;
|
||||
current_executor_id %= 6;
|
||||
}
|
||||
|
||||
void buttons_switch_to_interrupt(void)
|
||||
@@ -251,6 +257,7 @@ int main(void)
|
||||
MX_GPIO_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_SPI1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
buttons_interrupt_enabled = 0;
|
||||
|
||||
@@ -423,6 +430,44 @@ static void MX_I2C1_Init(void)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_SPI1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN SPI1_Init 0 */
|
||||
|
||||
/* USER CODE END SPI1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN SPI1_Init 1 */
|
||||
|
||||
/* USER CODE END SPI1_Init 1 */
|
||||
/* SPI1 parameter configuration*/
|
||||
hspi1.Instance = SPI1;
|
||||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi1.Init.CRCPolynomial = 10;
|
||||
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN SPI1_Init 2 */
|
||||
|
||||
/* USER CODE END SPI1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
@@ -447,7 +492,7 @@ static void MX_GPIO_Init(void)
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
|
||||
|GPIO_PIN_4, GPIO_PIN_RESET);
|
||||
|GPIO_PIN_4|GPIO_PIN_7, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);
|
||||
@@ -468,9 +513,9 @@ static void MX_GPIO_Init(void)
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PD12 PD13 PD14 PD15
|
||||
PD4 */
|
||||
PD4 PD7 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
|
||||
|GPIO_PIN_4;
|
||||
|GPIO_PIN_4|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
|
||||
@@ -208,6 +208,84 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param hspi: SPI handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(hspi->Instance==SPI1)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_MspInit 0 */
|
||||
|
||||
/* USER CODE END SPI1_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**SPI1 GPIO Configuration
|
||||
PA5 ------> SPI1_SCK
|
||||
PB4 ------> SPI1_MISO
|
||||
PB5 ------> SPI1_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspInit 1 */
|
||||
|
||||
/* USER CODE END SPI1_MspInit 1 */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param hspi: SPI handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
||||
{
|
||||
if(hspi->Instance==SPI1)
|
||||
{
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END SPI1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_SPI1_CLK_DISABLE();
|
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA5 ------> SPI1_SCK
|
||||
PB4 ------> SPI1_MISO
|
||||
PB5 ------> SPI1_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_4|GPIO_PIN_5);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END SPI1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
Reference in New Issue
Block a user