Last active
February 1, 2024 08:41
-
-
Save harrkout/f7edf6fa21a699e69fadcc347ea91779 to your computer and use it in GitHub Desktop.
Machine_Learning_Core_STM32WL55/SHUBv3_MLC Serial Output App with DIL24 socket STEVAL-MKI197V1's LSM6DSOX sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* WL55JCx + SHUBv3 + MKI197v1 | |
******************************************************************************* | |
* | |
* This project was created for the WL55JC1 board, combined with the Sensor | |
* Hub v3 and the MKI197v1, to enable the Machine Learning Core of the LSM6DSOX Sensor | |
* | |
* Author: Harris Koutsourelakis, ISCA Lab | |
* | |
****************************************************************************** | |
* @attention | |
* | |
* <h2><center>© Copyright (c) 2020 STMicroelectronics. | |
* All rights reserved.</center></h2> | |
* | |
* This software component is licensed by ST under BSD 3-Clause license, | |
* the "License"; You may not use this file except in compliance with the | |
* License. You may obtain a copy of the License at: | |
* opensource.org/licenses/BSD-3-Clause | |
* | |
****************************************************************************** | |
*/ | |
/* | |
* Some MLC examples are available at: | |
* https://github.com/STMicroelectronics/STMems_Machine_Learning_Core | |
* the same repository is linked to this repository in folder "_resources" | |
* | |
* For more information about Machine Learning Core tool please refer | |
* to AN5259 "LSM6DSOX: Machine Learning Core". | |
* | |
* This example was developed using the following STMicroelectronics | |
* evaluation boards: | |
* | |
* - STEVAL_MKI109V3 + STEVAL-MKI197V1 | |
* - NUCLEO_F411RE + STEVAL-MKI197V1 | |
* - DISCOVERY_SPC584B + STEVAL-MKI197V1 | |
* | |
* If you need to run this example on a different hardware platform a | |
* modification of the functions: `platform_write`, `platform_read`, | |
* `tx_com` and 'platform_init' is required. | |
* | |
*/ | |
//#define STEVAL_MKI109V3 /* little endian */ | |
//#define NUCLEO_F411RE /* little endian */ | |
//#define SPC584B_DIS /* big endian */ | |
/* ATTENTION: By default the driver is little endian. If you need switch | |
* to big endian please see "Endianness definitions" in the | |
* header file of the driver (_reg.h). | |
*/ | |
/* Includes ------------------------------------------------------------------*/ | |
#include <string.h> | |
#include <stdio.h> | |
//#include "lsm6dsox_vibration_monitoring.h" | |
#include "falling.h" | |
#include "lsm6dsox_reg.h" | |
//including WL55 bus header to get hi2c2 | |
#include "stm32wlxx_nucleo_bus.h" | |
#include "main.h" | |
#include "app_mems.h" | |
/* Private macro -------------------------------------------------------------*/ | |
#define BOOT_TIME 10 //ms | |
#define SENSOR_BUS hi2c2 | |
#define PWM_3V3 915 | |
/* Private variables ---------------------------------------------------------*/ | |
static uint8_t whoamI, rst; | |
static uint8_t tx_buffer[1000]; | |
/* Extern variables ----------------------------------------------------------*/ | |
/* Private functions ---------------------------------------------------------*/ | |
/* | |
* WARNING: | |
* Functions declare in this section are defined at the end of this file | |
* and are strictly related to the hardware platform used. | |
* | |
*/ | |
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, | |
uint16_t len); | |
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, | |
uint16_t len); | |
static void platform_delay(uint32_t ms); | |
static void tx_com( uint8_t *tx_buffer, uint16_t len ); | |
static void platform_init(void); | |
/* Main Example --------------------------------------------------------------*/ | |
void lsm6dsox_mlc(void) | |
{ | |
/* Variable declaration */ | |
lsm6dsox_pin_int1_route_t pin_int1_route; | |
lsm6dsox_all_sources_t status; | |
lsm6dsox_emb_sens_t emb_sens; | |
stmdev_ctx_t dev_ctx; | |
uint8_t mlc_out[8]; | |
uint32_t i; | |
/* Initialize mems driver interface */ | |
dev_ctx.write_reg = platform_write; | |
dev_ctx.read_reg = platform_read; | |
dev_ctx.handle = &SENSOR_BUS; | |
/* Init test platform */ | |
platform_init(); | |
/* Wait sensor boot time */ | |
platform_delay(BOOT_TIME); | |
/* Check device ID */ | |
lsm6dsox_device_id_get(&dev_ctx, &whoamI); | |
if (whoamI != LSM6DSOX_ID) | |
while (1); | |
/* Debugging prints | |
{ | |
sprintf("MLC_WHOAMI: %d\r\n", whoamI); | |
sprintf("lsm6dsox_device_id_get: %d\r\n", lsm6dsox_device_id_get); | |
} | |
*/ | |
/* Restore default configuration */ | |
lsm6dsox_reset_set(&dev_ctx, PROPERTY_ENABLE); | |
do { | |
lsm6dsox_reset_get(&dev_ctx, &rst); | |
} while (rst); | |
/* Change 'falling' with the name of the function of the header for the Machile Learning Core Dataset */ | |
for ( i = 0; i < (sizeof(falling) / | |
sizeof(ucf_line_t) ); i++ ) { | |
lsm6dsox_write_reg(&dev_ctx, falling[i].address, | |
(uint8_t *)&falling[i].data, 1); | |
} | |
/* End Machine Learning Core configuration */ | |
/* At this point the device is ready to run but if you need you can also | |
* interact with the device but taking in account the MLC configuration. | |
* | |
* For more information about Machine Learning Core tool please refer | |
* to AN5259 "LSM6DSOX: Machine Learning Core". | |
*/ | |
/* Turn off embedded features */ | |
lsm6dsox_embedded_sens_get(&dev_ctx, &emb_sens); | |
lsm6dsox_embedded_sens_off(&dev_ctx); | |
platform_delay(10); | |
/* Turn off Sensors */ | |
lsm6dsox_xl_data_rate_set(&dev_ctx, LSM6DSOX_XL_ODR_OFF); | |
lsm6dsox_gy_data_rate_set(&dev_ctx, LSM6DSOX_GY_ODR_OFF); | |
/* Disable I3C interface */ | |
lsm6dsox_i3c_disable_set(&dev_ctx, LSM6DSOX_I3C_DISABLE); | |
/* Enable Block Data Update */ | |
lsm6dsox_block_data_update_set(&dev_ctx, PROPERTY_ENABLE); | |
/* Set full scale */ | |
lsm6dsox_xl_full_scale_set(&dev_ctx, LSM6DSOX_4g); | |
lsm6dsox_gy_full_scale_set(&dev_ctx, LSM6DSOX_2000dps); | |
/* Route signals on interrupt pin 1 */ | |
lsm6dsox_pin_int1_route_get(&dev_ctx, &pin_int1_route); | |
pin_int1_route.mlc1 = PROPERTY_ENABLE; | |
lsm6dsox_pin_int1_route_set(&dev_ctx, pin_int1_route); | |
/* Configure interrupt pin mode notification */ | |
lsm6dsox_int_notification_set(&dev_ctx, | |
LSM6DSOX_BASE_PULSED_EMB_LATCHED); | |
/* Enable embedded features */ | |
lsm6dsox_embedded_sens_set(&dev_ctx, &emb_sens); | |
/* Set Output Data Rate. | |
* Selected data rate have to be equal or greater with respect | |
* with MLC data rate. | |
*/ | |
lsm6dsox_xl_data_rate_set(&dev_ctx, LSM6DSOX_XL_ODR_26Hz); | |
lsm6dsox_gy_data_rate_set(&dev_ctx, LSM6DSOX_GY_ODR_OFF); | |
/* Main loop */ | |
while (1) { | |
/* Read interrupt source registers in polling mode (no int) */ | |
lsm6dsox_all_sources_get(&dev_ctx, &status); | |
if (status.mlc1) { | |
lsm6dsox_mlc_out_get(&dev_ctx, mlc_out); | |
sprintf((char *)tx_buffer, "Detect MLC interrupt code: %02X\r\n", | |
mlc_out[0]); | |
tx_com(tx_buffer, strlen((char const *)tx_buffer)); | |
} | |
} | |
} | |
/* | |
* @brief Write generic device register (platform dependent) | |
* | |
* @param handle customizable argument. In this examples is used in | |
* order to select the correct sensor bus handler. | |
* @param reg register to write | |
* @param bufp pointer to data to write in register reg | |
* @param len number of consecutive register to write | |
* | |
*/ | |
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp, | |
uint16_t len) | |
{ | |
HAL_I2C_Mem_Write(handle, LSM6DSOX_I2C_ADD_L, reg, | |
I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000); | |
} | |
/* | |
* @brief Read generic device register (platform dependent) | |
* | |
* @param handle customizable argument. In this examples is used in | |
* order to select the correct sensor bus handler. | |
* @param reg register to read | |
* @param bufp pointer to buffer that store the data read | |
* @param len number of consecutive register to read | |
* | |
*/ | |
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, | |
uint16_t len) | |
{ | |
HAL_I2C_Mem_Read(handle, LSM6DSOX_I2C_ADD_L, reg, | |
I2C_MEMADD_SIZE_8BIT, bufp, len, 1000); | |
} | |
/* | |
* @brief platform specific outputs on terminal (platform dependent) | |
* | |
* @param tx_buffer buffer to transmit | |
* @param len number of byte to send | |
* | |
*/ | |
static void tx_com(uint8_t *tx_buffer, uint16_t len) | |
{ | |
HAL_UART_Transmit(&hlpuart1, tx_buffer, len, 1000); | |
} | |
/* | |
* @brief platform specific delay (platform dependent) | |
* | |
* @param ms delay in ms | |
* | |
*/ | |
static void platform_delay(uint32_t ms) | |
{ | |
// HAL_Delay(1000); | |
} | |
/* | |
* @brief platform specific initialization (platform dependent) | |
*/ | |
static void platform_init(void) | |
{ | |
TIM1->CCR1 = PWM_3V3; | |
// TIM1->CCR2 = PWM_3V3; | |
// HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); | |
// HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); | |
HAL_Delay(1000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* WL55JCx + SHUBv3 + MKI197v1 | |
******************************************************************************* | |
* | |
* This project was created for the WL55JC1 board, combined with the Sensor | |
* Hub v3 and the MKI197v1, to enable the Machine Learning Core of the LSM6DSOX Sensor | |
* | |
* Author: Harris Koutsourelakis, ISCA Lab | |
* | |
* | |
******************************************************************************* | |
******************************** SERIAL OUTPUT ******************************** | |
******************************************************************************* | |
/* USER CODE BEGIN Header */ | |
/** | |
****************************************************************************** | |
* @file : main.c | |
* @brief : Main program body | |
****************************************************************************** | |
* @attention | |
* | |
* Copyright (c) 2022 STMicroelectronics. | |
* All rights reserved. | |
* | |
* This software is licensed under terms that can be found in the LICENSE file | |
* in the root directory of this software component. | |
* If no LICENSE file comes with this software, it is provided AS-IS. | |
* | |
****************************************************************************** | |
*/ | |
/* USER CODE END Header */ | |
/* Includes ------------------------------------------------------------------*/ | |
#include "main.h" | |
#include "app_mems.h" | |
/* Private includes ----------------------------------------------------------*/ | |
/* USER CODE BEGIN Includes */ | |
#include "shub_v3_0.h" | |
//#include "falling_detection.h" | |
/* USER CODE END Includes */ | |
/* Private typedef -----------------------------------------------------------*/ | |
/* USER CODE BEGIN PTD */ | |
/* USER CODE END PTD */ | |
/* Private define ------------------------------------------------------------*/ | |
/* USER CODE BEGIN PD */ | |
/* USER CODE END PD */ | |
/* Private macro -------------------------------------------------------------*/ | |
/* USER CODE BEGIN PM */ | |
/* USER CODE END PM */ | |
/* Private variables ---------------------------------------------------------*/ | |
CRC_HandleTypeDef hcrc; | |
UART_HandleTypeDef huart1; | |
RTC_HandleTypeDef hrtc; | |
TIM_HandleTypeDef htim1; | |
TIM_HandleTypeDef htim2; | |
/* USER CODE BEGIN PV */ | |
/* USER CODE END PV */ | |
/* Private function prototypes -----------------------------------------------*/ | |
void SystemClock_Config(void); | |
static void MX_GPIO_Init(void); | |
static void MX_DMA_Init(void); | |
static void MX_CRC_Init(void); | |
static void MX_RTC_Init(void); | |
static void MX_TIM1_Init(void); | |
static void MX_USART1_UART_Init(void); | |
static void MX_TIM2_Init(void); | |
/* USER CODE BEGIN PFP */ | |
/* USER CODE END PFP */ | |
/* Private user code ---------------------------------------------------------*/ | |
/* USER CODE BEGIN 0 */ | |
/* USER CODE END 0 */ | |
/** | |
* @brief The application entry point. | |
* @retval int | |
*/ | |
int main(void) | |
{ | |
/* USER CODE BEGIN 1 */ | |
/* USER CODE END 1 */ | |
/* MCU Configuration--------------------------------------------------------*/ | |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ | |
HAL_Init(); | |
/* USER CODE BEGIN Init */ | |
/* USER CODE END Init */ | |
/* Configure the system clock */ | |
SystemClock_Config(); | |
/* USER CODE BEGIN SysInit */ | |
/* USER CODE END SysInit */ | |
/* Initialize all configured peripherals */ | |
MX_GPIO_Init(); | |
MX_DMA_Init(); | |
MX_CRC_Init(); | |
MX_RTC_Init(); | |
MX_TIM1_Init(); | |
MX_USART1_UART_Init(); | |
MX_TIM2_Init(); | |
MX_MEMS_Init(); | |
/* USER CODE BEGIN 2 */ | |
shub_init(); | |
shub_power_i2c_on(); | |
shub_power_i2c_mlc_on(); | |
/* USER CODE END 2 */ | |
/* Infinite loop */ | |
/* USER CODE BEGIN WHILE */ | |
while (1) | |
{ | |
// lsm6dsox_mlc(); | |
/* USER CODE END WHILE */ | |
MX_MEMS_Process(); | |
/* USER CODE BEGIN 3 */ | |
/* Call the MLC function inside the while(1) to have output of the Registers | |
* for the Machine Learning Core*/ | |
lsm6dsox_mlc(); | |
} | |
/* USER CODE END 3 */ | |
} | |
/** | |
* @brief System Clock Configuration | |
* @retval None | |
*/ | |
void SystemClock_Config(void) | |
{ | |
RCC_OscInitTypeDef RCC_OscInitStruct = {0}; | |
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; | |
/** Configure LSE Drive Capability | |
*/ | |
HAL_PWR_EnableBkUpAccess(); | |
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); | |
/** Configure the main internal regulator output voltage | |
*/ | |
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); | |
/** Initializes the CPU, AHB and APB buses clocks | |
*/ | |
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_LSE | |
|RCC_OSCILLATORTYPE_MSI; | |
RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
RCC_OscInitStruct.MSIState = RCC_MSI_ON; | |
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT; | |
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6; | |
RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV1; | |
RCC_OscInitStruct.LSIState = RCC_LSI_ON; | |
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; | |
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
/** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers | |
*/ | |
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK3|RCC_CLOCKTYPE_HCLK | |
|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1 | |
|RCC_CLOCKTYPE_PCLK2; | |
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI; | |
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; | |
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |
RCC_ClkInitStruct.AHBCLK3Divider = RCC_SYSCLK_DIV1; | |
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
} | |
/** | |
* @brief CRC Initialization Function | |
* @param None | |
* @retval None | |
*/ | |
static void MX_CRC_Init(void) | |
{ | |
/* USER CODE BEGIN CRC_Init 0 */ | |
/* USER CODE END CRC_Init 0 */ | |
/* USER CODE BEGIN CRC_Init 1 */ | |
/* USER CODE END CRC_Init 1 */ | |
hcrc.Instance = CRC; | |
hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; | |
hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; | |
hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; | |
hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; | |
hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; | |
if (HAL_CRC_Init(&hcrc) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
/* USER CODE BEGIN CRC_Init 2 */ | |
/* USER CODE END CRC_Init 2 */ | |
} | |
/** | |
* @brief USART1 Initialization Function | |
* @param None | |
* @retval None | |
*/ | |
static void MX_USART1_UART_Init(void) | |
{ | |
/* USER CODE BEGIN USART1_Init 0 */ | |
/* USER CODE END USART1_Init 0 */ | |
/* USER CODE BEGIN USART1_Init 1 */ | |
/* USER CODE END USART1_Init 1 */ | |
huart1.Instance = USART1; | |
huart1.Init.BaudRate = 115200; | |
huart1.Init.WordLength = UART_WORDLENGTH_8B; | |
huart1.Init.StopBits = UART_STOPBITS_1; | |
huart1.Init.Parity = UART_PARITY_NONE; | |
huart1.Init.Mode = UART_MODE_TX_RX; | |
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; | |
huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; | |
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; | |
if (HAL_UART_Init(&huart1) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
/* USER CODE BEGIN USART1_Init 2 */ | |
/* USER CODE END USART1_Init 2 */ | |
} | |
/** | |
* @brief RTC Initialization Function | |
* @param None | |
* @retval None | |
*/ | |
static void MX_RTC_Init(void) | |
{ | |
/* USER CODE BEGIN RTC_Init 0 */ | |
/* USER CODE END RTC_Init 0 */ | |
RTC_TimeTypeDef sTime = {0}; | |
RTC_DateTypeDef sDate = {0}; | |
/* USER CODE BEGIN RTC_Init 1 */ | |
/* USER CODE END RTC_Init 1 */ | |
/** Initialize RTC Only | |
*/ | |
hrtc.Instance = RTC; | |
hrtc.Init.HourFormat = RTC_HOURFORMAT_24; | |
hrtc.Init.AsynchPrediv = 127; | |
hrtc.Init.SynchPrediv = 255; | |
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; | |
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE; | |
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE; | |
hrtc.Init.BinMode = RTC_BINARY_NONE; | |
if (HAL_RTC_Init(&hrtc) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
/* USER CODE BEGIN Check_RTC_BKUP */ | |
/* USER CODE END Check_RTC_BKUP */ | |
/** Initialize RTC and set the Time and Date | |
*/ | |
sTime.Hours = 0x0; | |
sTime.Minutes = 0x0; | |
sTime.Seconds = 0x0; | |
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; | |
sTime.StoreOperation = RTC_STOREOPERATION_RESET; | |
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
sDate.WeekDay = RTC_WEEKDAY_MONDAY; | |
sDate.Month = RTC_MONTH_JANUARY; | |
sDate.Date = 0x1; | |
sDate.Year = 0x0; | |
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
/* USER CODE BEGIN RTC_Init 2 */ | |
/* USER CODE END RTC_Init 2 */ | |
} | |
/** | |
* @brief TIM1 Initialization Function | |
* @param None | |
* @retval None | |
*/ | |
static void MX_TIM1_Init(void) | |
{ | |
/* USER CODE BEGIN TIM1_Init 0 */ | |
/* USER CODE END TIM1_Init 0 */ | |
TIM_ClockConfigTypeDef sClockSourceConfig = {0}; | |
TIM_MasterConfigTypeDef sMasterConfig = {0}; | |
/* USER CODE BEGIN TIM1_Init 1 */ | |
/* USER CODE END TIM1_Init 1 */ | |
htim1.Instance = TIM1; | |
htim1.Init.Prescaler = 0; | |
htim1.Init.CounterMode = TIM_COUNTERMODE_UP; | |
htim1.Init.Period = 65535; | |
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; | |
htim1.Init.RepetitionCounter = 0; | |
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; | |
if (HAL_TIM_Base_Init(&htim1) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; | |
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; | |
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET; | |
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; | |
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
/* USER CODE BEGIN TIM1_Init 2 */ | |
/* USER CODE END TIM1_Init 2 */ | |
} | |
/** | |
* @brief TIM2 Initialization Function | |
* @param None | |
* @retval None | |
*/ | |
static void MX_TIM2_Init(void) | |
{ | |
/* USER CODE BEGIN TIM2_Init 0 */ | |
/* USER CODE END TIM2_Init 0 */ | |
TIM_ClockConfigTypeDef sClockSourceConfig = {0}; | |
TIM_MasterConfigTypeDef sMasterConfig = {0}; | |
/* USER CODE BEGIN TIM2_Init 1 */ | |
/* USER CODE END TIM2_Init 1 */ | |
htim2.Instance = TIM2; | |
htim2.Init.Prescaler = 0; | |
htim2.Init.CounterMode = TIM_COUNTERMODE_UP; | |
htim2.Init.Period = 4294967295; | |
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; | |
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; | |
if (HAL_TIM_Base_Init(&htim2) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; | |
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; | |
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; | |
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) | |
{ | |
Error_Handler(); | |
} | |
/* USER CODE BEGIN TIM2_Init 2 */ | |
/* USER CODE END TIM2_Init 2 */ | |
} | |
/** | |
* Enable DMA controller clock | |
*/ | |
static void MX_DMA_Init(void) | |
{ | |
/* DMA controller clock enable */ | |
__HAL_RCC_DMAMUX1_CLK_ENABLE(); | |
__HAL_RCC_DMA1_CLK_ENABLE(); | |
/* DMA interrupt init */ | |
/* DMA1_Channel6_IRQn interrupt configuration */ | |
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0); | |
HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn); | |
} | |
/** | |
* @brief GPIO Initialization Function | |
* @param None | |
* @retval None | |
*/ | |
static void MX_GPIO_Init(void) | |
{ | |
GPIO_InitTypeDef GPIO_InitStruct = {0}; | |
/* GPIO Ports Clock Enable */ | |
__HAL_RCC_GPIOA_CLK_ENABLE(); | |
__HAL_RCC_GPIOB_CLK_ENABLE(); | |
__HAL_RCC_GPIOC_CLK_ENABLE(); | |
/*Configure GPIO pin Output Level */ | |
HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin, GPIO_PIN_RESET); | |
/*Configure GPIO pin Output Level */ | |
HAL_GPIO_WritePin(GPIOC, FE_CTRL3_Pin|FE_CTRL2_Pin|FE_CTRL1_Pin, GPIO_PIN_RESET); | |
/*Configure GPIO pins : LED1_Pin LED2_Pin */ | |
GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin; | |
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; | |
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
/*Configure GPIO pins : FE_CTRL3_Pin FE_CTRL2_Pin FE_CTRL1_Pin */ | |
GPIO_InitStruct.Pin = FE_CTRL3_Pin|FE_CTRL2_Pin|FE_CTRL1_Pin; | |
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | |
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
/*Configure GPIO pin : PB1 */ | |
GPIO_InitStruct.Pin = GPIO_PIN_1; | |
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | |
/*Configure GPIO pin : PC0 */ | |
GPIO_InitStruct.Pin = GPIO_PIN_0; | |
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
/*Configure GPIO pin : PC6 */ | |
GPIO_InitStruct.Pin = GPIO_PIN_6; | |
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | |
/* EXTI interrupt init*/ | |
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); | |
HAL_NVIC_EnableIRQ(EXTI0_IRQn); | |
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0); | |
HAL_NVIC_EnableIRQ(EXTI1_IRQn); | |
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0); | |
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); | |
} | |
/* USER CODE BEGIN 4 */ | |
/* USER CODE END 4 */ | |
/** | |
* @brief This function is executed in case of error occurrence. | |
* @retval None | |
*/ | |
void Error_Handler(void) | |
{ | |
/* USER CODE BEGIN Error_Handler_Debug */ | |
/* User can add his own implementation to report the HAL error return state */ | |
__disable_irq(); | |
while (1) | |
{ | |
} | |
/* USER CODE END Error_Handler_Debug */ | |
} | |
#ifdef USE_FULL_ASSERT | |
/** | |
* @brief Reports the name of the source file and the source line number | |
* where the assert_param error has occurred. | |
* @param file: pointer to the source file name | |
* @param line: assert_param error line source number | |
* @retval None | |
*/ | |
void assert_failed(uint8_t *file, uint32_t line) | |
{ | |
/* USER CODE BEGIN 6 */ | |
/* User can add his own implementation to report the file name and line number, | |
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
/* USER CODE END 6 */ | |
} | |
#endif /* USE_FULL_ASSERT */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment