add Relazione falsa e inizio file
This commit is contained in:
parent
2775cc2108
commit
3de21f2577
33 changed files with 5944 additions and 2868 deletions
|
|
@ -31,7 +31,7 @@ extern "C" {
|
|||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include "pansi.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief Funzione per la calibrazione dell'ADC
|
||||
*
|
||||
*/
|
||||
void myADC3_calibration(void);
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief Funzione per configurazione dei tempi del TIM6
|
||||
*
|
||||
*/
|
||||
void myTIM6_configure(void);
|
||||
|
||||
|
||||
void myTIM6_start();
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief Funzione per l'inizializzazione della USART3
|
||||
*
|
||||
*/
|
||||
void myUSART3_init(void);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void myUSART3_it();
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "main.h"
|
||||
#include "stm32h743xx.h"
|
||||
#include "stm32h7xx.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
|
@ -13,12 +14,16 @@
|
|||
*/
|
||||
#define __rdon const
|
||||
#define __rdwr
|
||||
#define __prv8 __attribute__(( deprecated("Questo campo è PRIVATO. Non usarlo. Usa i metodi adatti alla manipolazione o controlla la tua implementazione"))) const
|
||||
#define __prv8 \
|
||||
__attribute__(( \
|
||||
deprecated("Questo campo è PRIVATO. Non usarlo. Usa i metodi adatti " \
|
||||
"alla manipolazione o controlla la tua implementazione"))) const
|
||||
#define __in_un_altro_file extern;
|
||||
|
||||
/**
|
||||
Protezione dal linking esterno.
|
||||
Funzioni e variabili globali in un file .c. Limita la funzione/variabile al solo
|
||||
file in cui è definita (visibilità "privata" al file).
|
||||
Funzioni e variabili globali in un file .c. Limita la funzione/variabile al
|
||||
solo file in cui è definita (visibilità "privata" al file).
|
||||
*/
|
||||
#define READONLY const
|
||||
#define PUBLIC
|
||||
|
|
@ -32,36 +37,61 @@
|
|||
#define EXT_GLOBAL extern
|
||||
|
||||
/// MY DEBUG 1 = debug | 0 = no my debug
|
||||
#define MY_DEBUG 1
|
||||
#define NO_HAL_IT 0 // 0 disable 1 enable
|
||||
#define MY_DEBUG 1
|
||||
#define NO_HAL_IT 0 // 0 disable 1 enable
|
||||
|
||||
/*
|
||||
======= bit functions =========
|
||||
Macro presenti anche in:
|
||||
Drivers/CMSIS/Device/ST/STM32H7xx/Include/stm32h7xx.h
|
||||
*/
|
||||
/**
|
||||
* @brief Imposta a 1 un bit specifico in un byte (SET).
|
||||
* * Esegue un'operazione OR bit a bit. I bit che erano a 1 rimangono a 1,
|
||||
* il bit all'indice n viene forzato a 1.
|
||||
* * @param byte Puntatore al byte da modificare.
|
||||
* @param n L'indice del bit da impostare (0-7).
|
||||
*/
|
||||
static inline void set_bit(uint8_t *byte, uint8_t n) {
|
||||
*byte = *byte | (1u << n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Imposta a 0 un bit specifico in un byte (CLEAR).
|
||||
* * Esegue un AND con una maschera inversa. Il bit all'indice n
|
||||
* viene forzato a 0, gli altri rimangono invariati.
|
||||
* * @param byte Puntatore al byte da modificare.
|
||||
* @param n L'indice del bit da pulire (0-7).
|
||||
*/
|
||||
static inline void clear_bit(uint8_t *byte, uint8_t n) {
|
||||
*byte = *byte & ~(1u << n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverte lo stato di un bit specifico (TOGGLE).
|
||||
* * Se il bit è 0 diventa 1, se è 1 diventa 0. Usa l'operatore XOR.
|
||||
* * @param byte Puntatore al byte da modificare.
|
||||
* @param n L'indice del bit da invertire (0-7).
|
||||
*/
|
||||
static inline void toggle_bit(uint8_t *byte, uint8_t n) {
|
||||
*byte = *byte ^ (1u << n);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Legge lo stato di un bit specifico.
|
||||
* * @param byte Puntatore al byte (costante, sola lettura).
|
||||
* @param n L'indice del bit da leggere (0-7).
|
||||
* @return uint8_t Ritorna diverso da 0 se il bit è 1, oppure 0 se il bit è 0.
|
||||
* Nota: non ritorna necessariamente "1", ma il valore del bit nella sua posizione (es. 4, 8, 16).
|
||||
*/
|
||||
static inline uint8_t read_bit(const uint8_t *byte, uint8_t n) {
|
||||
return (*byte & (1u << n));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ====== USART ================
|
||||
|
||||
/**
|
||||
* @brief Inizializza la periferica USART3.
|
||||
* @note Questa implementazione assume PD8=TX, PD9=RX (AF7).
|
||||
* @param pclk_freq La frequenza del clock della periferica (PCLK1 per USART3).
|
||||
* @param baudRate Il baud rate desiderato (es. 115200).
|
||||
*/
|
||||
PUBLIC void Pansi_USART3_Init(uint32_t pclk_freq, uint32_t baudRate);
|
||||
|
||||
/**
|
||||
* @brief Invia un singolo carattere su USART3 (bloccante).
|
||||
* @param c Il carattere da inviare.
|
||||
*/
|
||||
PUBLIC void Pansi_USART3_SendChar(char c);
|
||||
|
||||
/**
|
||||
* @brief Invia una stringa (terminata da null) su USART3.
|
||||
* @param str La stringa da inviare.
|
||||
*/
|
||||
PUBLIC void Pansi_USART3_SendString(const char *str);
|
||||
|
||||
/**
|
||||
* @brief Riceve un singolo carattere da USART3 (bloccante).
|
||||
* @return Il carattere ricevuto.
|
||||
*/
|
||||
PUBLIC char Pansi_USART3_ReceiveChar(void);
|
||||
// ====== END USART ============
|
||||
|
||||
// ====== TIM6 =================
|
||||
|
|
@ -75,4 +105,3 @@ PUBLIC char Pansi_USART3_ReceiveChar(void);
|
|||
* presenti sulla board.
|
||||
*/
|
||||
void MOTD_init(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
#include "myADC.h"
|
||||
#include "pansi.h"
|
||||
#include <stdint.h>
|
||||
// #include "stm32h743xx.h"
|
||||
// #include <stdint.h>
|
||||
|
||||
/**
|
||||
* Temperature Sensor Characteristics
|
||||
* uint16_t perché la grandezza è di 2 byte da datasheet
|
||||
|
||||
| Table 93. Temperature sensor calibration values |
|
||||
| Symbol | Parameter | Memory address
|
||||
=====================================================================
|
||||
|TS_CAL1 | Temperature sensor raw data | 0x1FF1E820 - 0x1FF1E821
|
||||
acquired value at 30 °C,
|
||||
VDDA =3.3 V
|
||||
---------------------------------------------------------------------
|
||||
/TS_CAL2 / Temperature sensor raw data | 0x1FF1E840 - 0x1FF1E841
|
||||
acquired value at 110 °C,
|
||||
VDDA = 3.3 V
|
||||
=====================================================================
|
||||
*/
|
||||
#define TS_CAL1 *(uint16_t *)0x1FF1E820
|
||||
#define TS_CAL2 *(uint16_t *)0x1FF1E840
|
||||
|
||||
#define TCAL_30C *(uint16_t *)0x1FF1E820
|
||||
#define TCAL_110C *(uint16_t *)0x1FF1E840
|
||||
|
||||
static volatile uint16_t *tsc_cal1 = (uint16_t *)0x1FF1E820;
|
||||
static volatile uint16_t *tsc_cal2 = (uint16_t *)0x1FF1E840;
|
||||
|
||||
|
||||
#define VREFINT_C *(uint16_t *)(0x1FF1E860)
|
||||
// Internal Referance Voltage 30
|
||||
static volatile uint16_t *VRefInCal = (uint16_t *)0x1FF1E860;
|
||||
|
||||
/**
|
||||
* @brief Funzione per la calibrazione dell'ADC
|
||||
* 3 step. (1). controllo se ad è spenta e in caso spengo io
|
||||
* (2). Avvio la calibrazione degli offset e quela lineare
|
||||
* (3). Aspetto la fine della calibrazione
|
||||
*/
|
||||
void myADC3_calibration(void) {
|
||||
|
||||
|
||||
// (1) check if the ADC is disable after start calibration
|
||||
if (ADC3->CR & ADC_CR_ADEN) {
|
||||
ADC3->CR |= ADC_CR_ADDIS; // disable
|
||||
while (ADC3->CR & ADC_CR_ADEN) {
|
||||
// aspettando che si spenga la periferica
|
||||
// blink RED led TODO
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// (2)
|
||||
// configure for a linear calibration.
|
||||
ADC3->CR |= ADC_CR_ADCALLIN;
|
||||
// start calibration. reset by hardware when the calibration complete
|
||||
ADC3->CR |= ADC_CR_ADCAL;
|
||||
|
||||
// (3)
|
||||
while (ADC3->CR & ADC_CR_ADCAL) {
|
||||
// blink GREEN led
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#include "myTIM.h"
|
||||
#include "stm32h743xx.h"
|
||||
|
||||
|
||||
|
||||
void myTIM6_configure(void){
|
||||
// update interrupt ivent
|
||||
TIM7->DIER |= TIM_DIER_UIE;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void myTIM6_start();
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#include "myUSART.h"
|
||||
|
||||
|
||||
void myUSART3_init() {
|
||||
// abilita rx/tx su USART3
|
||||
USART3->CR1 |= USART_CR1_RE; // enable RX flag
|
||||
USART3->CR1 |= USART_CR1_TE; // enable TX flag
|
||||
// abilita rx/tx interrupts su USART3
|
||||
USART3->CR1 |= USART_CR1_RXNEIE;
|
||||
}
|
||||
338
Core/Src/main.c
338
Core/Src/main.c
|
|
@ -1,31 +1,32 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 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 "adc.h"
|
||||
#include "gpio.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include "myADC.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
|
@ -63,203 +64,192 @@ static void MPU_Config(void);
|
|||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void) {
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
/* USER CODE BEGIN 1 */
|
||||
char *welcome = "Hi from STM32H7 - by. PanSi21";
|
||||
(void)welcome;
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/* MPU Configuration--------------------------------------------------------*/
|
||||
MPU_Config();
|
||||
|
||||
/* MPU Configuration--------------------------------------------------------*/
|
||||
MPU_Config();
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
/* Configure the peripherals common clocks */
|
||||
PeriphCommonClock_Config();
|
||||
|
||||
/* Configure the peripherals common clocks */
|
||||
PeriphCommonClock_Config();
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_ADC3_Init();
|
||||
MX_TIM6_Init();
|
||||
MX_USART3_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
myADC3_calibration();
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_ADC3_Init();
|
||||
MX_TIM6_Init();
|
||||
MX_USART3_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1) {
|
||||
/* USER CODE END WHILE */
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void) {
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
|
||||
|
||||
/** Supply configuration update enable
|
||||
*/
|
||||
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
||||
/** Supply configuration update enable
|
||||
*/
|
||||
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
|
||||
|
||||
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
|
||||
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {
|
||||
}
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 5;
|
||||
RCC_OscInitStruct.PLL.PLLN = 192;
|
||||
RCC_OscInitStruct.PLL.PLLP = 2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 2;
|
||||
RCC_OscInitStruct.PLL.PLLR = 2;
|
||||
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
||||
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
||||
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 5;
|
||||
RCC_OscInitStruct.PLL.PLLN = 192;
|
||||
RCC_OscInitStruct.PLL.PLLP = 2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 2;
|
||||
RCC_OscInitStruct.PLL.PLLR = 2;
|
||||
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
|
||||
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
||||
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|
||||
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
||||
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
|
||||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1 |
|
||||
RCC_CLOCKTYPE_D1PCLK1;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
||||
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Peripherals Common Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void PeriphCommonClock_Config(void)
|
||||
{
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||
* @brief Peripherals Common Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void PeriphCommonClock_Config(void) {
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
|
||||
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC|RCC_PERIPHCLK_USART3;
|
||||
PeriphClkInitStruct.PLL2.PLL2M = 2;
|
||||
PeriphClkInitStruct.PLL2.PLL2N = 12;
|
||||
PeriphClkInitStruct.PLL2.PLL2P = 2;
|
||||
PeriphClkInitStruct.PLL2.PLL2Q = 2;
|
||||
PeriphClkInitStruct.PLL2.PLL2R = 2;
|
||||
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3;
|
||||
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOMEDIUM;
|
||||
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
|
||||
PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_PLL2;
|
||||
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC | RCC_PERIPHCLK_USART3;
|
||||
PeriphClkInitStruct.PLL2.PLL2M = 2;
|
||||
PeriphClkInitStruct.PLL2.PLL2N = 12;
|
||||
PeriphClkInitStruct.PLL2.PLL2P = 2;
|
||||
PeriphClkInitStruct.PLL2.PLL2Q = 2;
|
||||
PeriphClkInitStruct.PLL2.PLL2R = 2;
|
||||
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3;
|
||||
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOMEDIUM;
|
||||
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
|
||||
PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_PLL2;
|
||||
PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/* MPU Configuration */
|
||||
/* MPU Configuration */
|
||||
|
||||
void MPU_Config(void)
|
||||
{
|
||||
MPU_Region_InitTypeDef MPU_InitStruct = {0};
|
||||
void MPU_Config(void) {
|
||||
MPU_Region_InitTypeDef MPU_InitStruct = { 0 };
|
||||
|
||||
/* Disables the MPU */
|
||||
HAL_MPU_Disable();
|
||||
/* Disables the MPU */
|
||||
HAL_MPU_Disable();
|
||||
|
||||
/** Initializes and configures the Region and the memory to be protected
|
||||
*/
|
||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
|
||||
MPU_InitStruct.BaseAddress = 0x0;
|
||||
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
|
||||
MPU_InitStruct.SubRegionDisable = 0x87;
|
||||
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
|
||||
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
|
||||
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
|
||||
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
|
||||
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
||||
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
/* Enables the MPU */
|
||||
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
||||
/** Initializes and configures the Region and the memory to be protected
|
||||
*/
|
||||
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
|
||||
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
|
||||
MPU_InitStruct.BaseAddress = 0x0;
|
||||
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
|
||||
MPU_InitStruct.SubRegionDisable = 0x87;
|
||||
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
|
||||
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
|
||||
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
|
||||
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
|
||||
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
|
||||
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
|
||||
|
||||
HAL_MPU_ConfigRegion(&MPU_InitStruct);
|
||||
/* Enables the MPU */
|
||||
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
* @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 */
|
||||
* @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 */
|
||||
|
|
|
|||
|
|
@ -1,25 +1,27 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 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 "stm32h7xx_it.h"
|
||||
#include "main.h"
|
||||
#include "stm32h743xx.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
|
@ -66,131 +68,117 @@ extern UART_HandleTypeDef huart3;
|
|||
/* Cortex Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void) {
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1) {
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void) {
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1) {
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void) {
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
||||
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
||||
}
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
while (1) {
|
||||
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
||||
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pre-fetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
* @brief This function handles Pre-fetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void) {
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
||||
/* USER CODE END W1_BusFault_IRQn 0 */
|
||||
}
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
while (1) {
|
||||
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
||||
/* USER CODE END W1_BusFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void) {
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
||||
/* USER CODE END W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
while (1) {
|
||||
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
||||
/* USER CODE END W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SVCall_IRQn 0 */
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void) {
|
||||
/* USER CODE BEGIN SVCall_IRQn 0 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 0 */
|
||||
/* USER CODE BEGIN SVCall_IRQn 1 */
|
||||
/* USER CODE END SVCall_IRQn 0 */
|
||||
/* USER CODE BEGIN SVCall_IRQn 1 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 1 */
|
||||
/* USER CODE END SVCall_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void) {
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN PendSV_IRQn 0 */
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void) {
|
||||
/* USER CODE BEGIN PendSV_IRQn 0 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 0 */
|
||||
/* USER CODE BEGIN PendSV_IRQn 1 */
|
||||
/* USER CODE END PendSV_IRQn 0 */
|
||||
/* USER CODE BEGIN PendSV_IRQn 1 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 1 */
|
||||
/* USER CODE END PendSV_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void) {
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
@ -201,45 +189,48 @@ void SysTick_Handler(void)
|
|||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles USART3 global interrupt.
|
||||
*/
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART3_IRQn 0 */
|
||||
|
||||
/* USER CODE END USART3_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart3);
|
||||
/* USER CODE BEGIN USART3_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART3_IRQn 1 */
|
||||
* @brief This function handles USART3 global interrupt.
|
||||
*/
|
||||
void USART3_IRQHandler(void) {
|
||||
/* USER CODE BEGIN USART3_IRQn 0 */
|
||||
#if NO_HAL
|
||||
/* USER CODE END USART3_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart3);
|
||||
/* USER CODE BEGIN USART3_IRQn 1 */
|
||||
#endif
|
||||
/* USER CODE END USART3_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM6 global interrupt, DAC1_CH1 and DAC1_CH2 underrun error interrupts.
|
||||
*/
|
||||
void TIM6_DAC_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
|
||||
* @brief This function handles TIM6 global interrupt, DAC1_CH1 and DAC1_CH2 underrun error interrupts.
|
||||
*/
|
||||
void TIM6_DAC_IRQHandler(void) {
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM6_DAC_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim6);
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
|
||||
#if NO_HAL
|
||||
/* USER CODE END TIM6_DAC_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim6);
|
||||
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
|
||||
#endif
|
||||
// controlla se è stato l'evento Update (UIF) a far scattare l'interrupt
|
||||
if (TIM6->SR & TIM_SR_UIF) {
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE END TIM6_DAC_IRQn 1 */
|
||||
/* USER CODE END TIM6_DAC_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles ADC3 global interrupt.
|
||||
*/
|
||||
void ADC3_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN ADC3_IRQn 0 */
|
||||
|
||||
/* USER CODE END ADC3_IRQn 0 */
|
||||
HAL_ADC_IRQHandler(&hadc3);
|
||||
/* USER CODE BEGIN ADC3_IRQn 1 */
|
||||
|
||||
/* USER CODE END ADC3_IRQn 1 */
|
||||
* @brief This function handles ADC3 global interrupt.
|
||||
*/
|
||||
void ADC3_IRQHandler(void) {
|
||||
/* USER CODE BEGIN ADC3_IRQn 0 */
|
||||
#if NO_HAL
|
||||
/* USER CODE END ADC3_IRQn 0 */
|
||||
HAL_ADC_IRQHandler(&hadc3);
|
||||
/* USER CODE BEGIN ADC3_IRQn 1 */
|
||||
#endif
|
||||
/* USER CODE END ADC3_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue