Init Repo

This commit is contained in:
Noah Piqué
2021-10-11 15:48:02 +02:00
parent 2ff60e7641
commit f93f487979
161 changed files with 175233 additions and 0 deletions

View File

@ -0,0 +1,200 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: INIT_Initialization
// Filename: INIT_Initialization.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: Initialization module
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
#include "../PDEF_ProjectDefinitions.h"
#include "INIT_Initialization.h"
// Application
//#include "VARH_VariableHandler.h"
//#include "RTOS_RealTimeOS.h"
//#include "ELOG_ErrorLogger.h"
//#include "SYSS_SystemStateSignalization.h"
#include "MAIN_MainApplication.h"
// Drivers
//#include "../Drivers/IRQH_IntRequestHandler.h"
//#include "../Drivers/MRAM_MRam.h"
#include "../Drivers/ANPI_AnalogPortsIn.h"
#include "../Drivers/ANPO_AnalogPortsOut.h"
#include "../Drivers/SPID_SpiDriver.h"
#include "../Drivers/DIPO_DigitalPorts.h"
#include "../Drivers/ADCD_AdcDriver.h"
#include "../Drivers/TEMP_Temperature.h"
#include "../Drivers/PECO_PeltierController.h"
#include "../Drivers/CAND_CanDriver.h"
//#include "../Drivers/UART_UartDriver.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL osThreadId_t m_pstThreadID = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"INIT_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityHigh7, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE VOID vInitTask ( PVOID arg )__NORETURN;
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: INIT_boCreateTask
// Description: Create the init Task
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL INIT_boCreateTask( VOID )
{
BOOL boOK = TRUE;
boOK &= ((m_pstThreadID = osThreadNew( vInitTask, NULL, &stTaskAttribute )) != NULL); // create init Task
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: vInitTask
// Description: Initialization Task, priority must be high!
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vInitTask( PVOID arg )
{
UNUSED( arg );
BOOL boOK = TRUE;
BOOL boInitConfig = TRUE;
// boOK &= RTOS_boInitializeModule();
boOK &= DIPO_boInitializeModule();
boOK &= ANPI_boInitializeModule();
boOK &= ANPO_boInitializeModule();
boOK &= SPID_boInitializeModule();
// boOK &= MRAM_boInitializeModule( &boInitConfig );
// boOK &= CALI_boInitializeModule( boInitConfig );
boOK &= ADCD_boInitializeModule();
boOK &= TEMP_boInitializeModule();
boOK &= PECO_boInitializeModule();
boOK &= CAND_boInitializeModule();
boOK &= MAIN_boInitializeModule();
//!boOK ? RTOS_vFatalError() : NULL;
// boInitConfig ? ELOG_ADD_LOG( ELOG_eFactoryReset ) : NULL;
//
// ELOG_ADD_LOG( ELOG_eSystemRebooted );
//RTOS_vStartSystemLoadCounter();
osThreadSuspend( m_pstThreadID );
while(1);
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================

View File

@ -0,0 +1,94 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Initialization
// Filename: INIT_Initialization
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef INIT_INITIALIZATION_H
#define INIT_INITIALIZATION_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL INIT_boCreateTask( VOID );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,381 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: High Stability Current Source
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Main Application
// Filename: MAIN_MainApplication.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: HVCT_HvController
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "MAIN_MainApplication.h"
// Application
//#include "VARH_VariableHandler.h"
//#include "ELOG_ErrorLogger.h"
// Drivers
#include "../Drivers/TEMP_Temperature.h"
#include "../Drivers/DIPO_DigitalPorts.h"
#include "../Drivers/CAND_CanDriver.h"
#include "../Drivers/PECO_PeltierController.h"
#include "../Drivers/ANPI_AnalogPortsIn.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define SLOW_TEXT (U32)0x83767987
#define FAST_TEXT (U32)0x46415354
#define MSG_QUEUE_SIZE 8
#define EVENT_NEW_MESSAGE ((U32)(1<<0))
#define EVENT_TIMER_UPDATE ((U32)(1<<1))
#define EVENT_FLAGS_ALL ( EVENT_NEW_MESSAGE | EVENT_TIMER_UPDATE )
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE VOID vMainTask( PVOID arg );
PRIVATE VOID vEventCallback( PVOID pvData );
PRIVATE VOID vMsgRxCallback( CAND_Message stMessage );
//PRIVATE BOOL boSetValCheck( PVOID pvCallbackData, VARH_UVariable uNewValue );
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osMessageQueueId_t m_pstCANRxMsgQueueID = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
LOCAL osTimerId_t m_pstUpdateTimer = NULL;
LOCAL U32 m_u32DataCnt = 0;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"MAIN_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityNormal, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
LOCAL CONST osMessageQueueAttr_t stCANRxMsgQueueAttribute =
{
"MAIN_CAN_Rx_Queue", // name of the message queue
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for data storage
0, // size of provided memory for data storage
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"MAIN_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
LOCAL CONST osTimerAttr_t stTimerAttribute =
{
"MAIN_UpdateTimer", // name of the timer
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//extern CRC_HandleTypeDef hcrc;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: MAIN_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL MAIN_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ((m_pstEventID = osEventFlagsNew( &stEventAttribute )) == NULL) ? FALSE : TRUE;
boOK &= ((m_pstThreadID = osThreadNew( vMainTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
boOK &= ((m_pstCANRxMsgQueueID = osMessageQueueNew( MSG_QUEUE_SIZE, sizeof(CAND_Message), &stCANRxMsgQueueAttribute ) ) == NULL ) ? FALSE : TRUE;
boOK &= (m_pstUpdateTimer = osTimerNew( vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stTimerAttribute )) != NULL ? TRUE : FALSE;
/*boOK &= VARH_boRegisterRangeCheck( VARH_eVoltageRefEn, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eStatusG, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eStatusR, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eEnabledG, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eEnabledR, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eInvertedG, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eInvertedR, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eSpareG, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eSpareR, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterNotification( VARH_eVoltageRefEn, VARH_eNewValue, vEventCallback, (PVOID)EVENT_VREF );
boOK &= VARH_boRegisterNotification( VARH_eStatusG, VARH_eNewValue, vEventCallback, (PVOID)EVENT_STATUS_G );
boOK &= VARH_boRegisterNotification( VARH_eStatusR, VARH_eNewValue, vEventCallback, (PVOID)EVENT_STATUS_R );
boOK &= VARH_boRegisterNotification( VARH_eEnabledG, VARH_eNewValue, vEventCallback, (PVOID)EVENT_ENABLE_G );
boOK &= VARH_boRegisterNotification( VARH_eEnabledR, VARH_eNewValue, vEventCallback, (PVOID)EVENT_ENABLE_R );
boOK &= VARH_boRegisterNotification( VARH_eInvertedG, VARH_eNewValue, vEventCallback, (PVOID)EVENT_INVERT_G );
boOK &= VARH_boRegisterNotification( VARH_eInvertedR, VARH_eNewValue, vEventCallback, (PVOID)EVENT_INVERT_R );
boOK &= VARH_boRegisterNotification( VARH_eSpareG, VARH_eNewValue, vEventCallback, (PVOID)EVENT_SPARE_G );
boOK &= VARH_boRegisterNotification( VARH_eSpareR, VARH_eNewValue, vEventCallback, (PVOID)EVENT_SPARE_R );
boOK &= VARH_boRegisterRangeCheck( VARH_eEnable, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eInvertA, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eInvertB, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eSetMode, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eDACStartStop, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eExtSyncEnable, VARH_boBooleanVarCheck, NULL );
boOK &= VARH_boRegisterRangeCheck( VARH_eSetValue, boSetValCheck, NULL );
boOK &= VARH_boRegisterNotification( VARH_eEnable, VARH_eRising, vEventCallback, (PVOID)EVENT_ENABLE );
boOK &= VARH_boRegisterNotification( VARH_eEnable, VARH_eFalling, vEventCallback, (PVOID)EVENT_DISABLE );
boOK &= VARH_boRegisterNotification( VARH_eInvertA, VARH_eNewValue, vEventCallback, (PVOID)EVENT_INVERT );
boOK &= VARH_boRegisterNotification( VARH_eInvertB, VARH_eNewValue, vEventCallback, (PVOID)EVENT_INVERT );
boOK &= VARH_boRegisterNotification( VARH_eExtSyncEnable, VARH_eNewValue, vEventCallback, (PVOID)EVENT_EXT_SYNC_ENABLE );
boOK &= VARH_boRegisterNotification( VARH_eSetValue, VARH_eNewValue, vEventCallback, (PVOID)EVENT_NEW_SET_VALUE );
boOK &= VARH_boRegisterNotification( VARH_eSetMode, VARH_eNewValue, vEventCallback, (PVOID)EVENT_NEW_MODE );
boOK &= VARH_boRegisterNotification( VARH_eDACStartStop, VARH_eRising, vEventCallback, (PVOID)EVENT_DAC_START );
boOK &= VARH_boRegisterNotification( VARH_eDACStartStop, VARH_eFalling, vEventCallback, (PVOID)EVENT_DAC_STOP ); */
// config DAC and ADC
// DACD_boConfig( BOOL boFast, CALI_St* pstOffsetGain, DACD_pfnWaveformCallback pfnWaveform, U16 u16WaveformLength )
// ADCD_boConfig( BOOL boFast, CALI_St* pstGainOffset, vEventCallback, (PVOID)EVENT_ADC_DATA_READY )
boOK &= (osTimerStart( m_pstUpdateTimer, 1000 ) == osOK ) ? TRUE : FALSE;
CAND_vSetRxCallback(vMsgRxCallback);
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: vMainTask
// Description: Main Application Task
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vMainTask( PVOID arg )
{
UNUSED( arg );
U32 u32Flags;
U8 au8Buffer[8];
while( TRUE )
{
u32Flags = osEventFlagsWait( m_pstEventID, EVENT_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
if( u32Flags & EVENT_NEW_MESSAGE ) {
CAND_Message stMessage;
osMessageQueueGet( m_pstCANRxMsgQueueID, &stMessage, NULL, 0 );
if(stMessage.u8Id == 0x10){
S16 ControlVoltage = ((S16)(ANPI_flGetInputValue(ANPI_eControlVoltage)*1000));
au8Buffer[0] = (ControlVoltage & 0xFF00) >> 8;
au8Buffer[1] = ControlVoltage & 0xFF;
CAND_boSendMessage(0x11, 2, au8Buffer);
} else if(stMessage.u8Id == 0x12){
S16 s16Voltage = stMessage.au8Data[0] << 8;
s16Voltage |= stMessage.au8Data[1];
PECO_boSetTemperature( s16Voltage );
} else if(stMessage.u8Id == 0x13){
S16 SupplyVoltage24V = ((S16)(ANPI_flGetInputValue(ANPI_eSupplyVoltage24V)*1000));
S16 SupplyCurrent24V = ((S16)(ANPI_flGetInputValue(ANPI_eSupplyCurrent24V)*1000));
S16 OutputVoltage = ((S16)(ANPI_flGetInputValue(ANPI_eOutputVoltage)*1000));
S16 OutputCurrent = ((S16)(ANPI_flGetInputValue(ANPI_eOutputCurrent)*1000));
au8Buffer[0] = (SupplyVoltage24V & 0xFF00) >> 8;
au8Buffer[1] = SupplyVoltage24V & 0xFF;
au8Buffer[2] = (SupplyCurrent24V & 0xFF00) >> 8;
au8Buffer[3] = SupplyCurrent24V & 0xFF;
au8Buffer[4] = (OutputVoltage & 0xFF00) >> 8;
au8Buffer[5] = OutputVoltage & 0xff;
au8Buffer[6] = (OutputCurrent & 0xFF00) >> 8;
au8Buffer[7] = OutputCurrent & 0xFF;
CAND_boSendMessage(0x14, 8, au8Buffer);
} else if(stMessage.u8Id == 0x15){
S16 Cold = (S16)(TEMP_dGetValue(ADCD_eCold)*100);
S16 Hot = (S16)(TEMP_dGetValue(ADCD_eHot)*100);
au8Buffer[0] = (Cold & 0xFF00) >> 8;
au8Buffer[1] = (Cold & 0xFF);
au8Buffer[2] = (Hot & 0xFF00) >> 8;
au8Buffer[3] = (Hot & 0xFF);
CAND_boSendMessage(0x16, 4, au8Buffer);
} else if(stMessage.u8Id == 0x17){
PECO_Enable(TRUE);
} else if(stMessage.u8Id == 0x18){
PECO_Enable(FALSE);
}
}
if( u32Flags & EVENT_TIMER_UPDATE )
{
DIPO_vToggleOutput(DIPO_eLED);
}
}
}
//-------------------------------------------------------------------------------------------------
// Function: vEventCallback
// Description: Callback for events
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vEventCallback( PVOID pvData )
{
osEventFlagsSet( m_pstEventID, (U32)pvData );
}
//-------------------------------------------------------------------------------------------------
// Function: vEventCallback
// Description: Callback for events
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vMsgRxCallback( CAND_Message stMessage )
{
osMessageQueuePut(m_pstCANRxMsgQueueID, &stMessage, 0, 0);
osEventFlagsSet( m_pstEventID, EVENT_NEW_MESSAGE );
}
//-------------------------------------------------------------------------------------------------
// Function: boSetValCheck
// Description: Checks the range of the set value
// Parameters: PVOID pvCallbackData
// VARH_UVariable uNewValue
// Returns: TRUE, the variable can be written
//-------------------------------------------------------------------------------------------------
/*PRIVATE BOOL boSetValCheck( PVOID pvCallbackData, VARH_UVariable uNewValue )
{
UNUSED( pvCallbackData );
return( uNewValue.flVal <= 200.0f && uNewValue.flVal >= -200.0f ? FALSE : TRUE );
}
*/

View File

@ -0,0 +1,92 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: High Stability Current Source
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Main Application
// Filename: MAIN_MainApplication.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef MAIN_MAINAPPLICATION_H
#define MAIN_MAINAPPLICATION_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL MAIN_boInitializeModule( VOID );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,395 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: ADC-Driver
// Filename: ADCD_AdcDriver.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the internal ADC-Driver
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "ADCD_AdcDriver.h"
// Drivers
#include "SPID_SpiDriver.h"
#include "DIPO_DigitalPorts.h"
//#include "EXTI_ExtiHandler.h"
// Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// CMSIS OS
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
// define commands
#define CMD_READ (0<<7)
#define CMD_WRITE (1<<7)
// define register
#define REG_CONFIG 0x00
#define REG_RTD_MSB 0x01
#define REG_RTD_LSB 0x02
#define REG_HIGH_FAULT_MSB 0x03
#define REG_HIGH_FAULT_LSB 0x04
#define REG_LOW_FAULT_MSB 0x05
#define REG_LOW_FAULT_LSB 0x06
#define REG_FAULT_STATUS 0x07
#define CONFIG_VBIAS_ON (1<<7)
#define CONFIG_VBIAS_OFF (0<<7)
#define CONFIG_MODE_AUTO (1<<6)
#define CONFIG_MODE_OFF (0<<6)
#define CONFIG_1SHOT (1<<5)
#define CONFIG_3WIRE (1<<4)
#define CONFIG_24WIRE (0<<4)
// Fault Detection not implemented yet
#define CONFIG_FAULTSTATCLEAR (1<<1)
#define CONFIG_FILT50HZ (1<<0)
#define CONFIG_FILT60HZ (0<<0)
#define FAULT_HIGHTHRESH 0x80
#define FAULT_LOWTHRESH 0x40
#define FAULT_REFINLOW 0x20
#define FAULT_REFINHIGH 0x10
#define FAULT_RTDINLOW 0x08
#define FAULT_OVUV 0x04
#define CONFIG (U8)(CONFIG_VBIAS_ON | CONFIG_MODE_OFF | CONFIG_24WIRE | CONFIG_FILT60HZ) // enable Vbias; autoconvert off; 4-wire; 60Hz;
#define EVENT_ENABLE ((U32)(1<<0))
#define EVENT_DISABLE ((U32)(1<<1))
#define EVENT_INVERT ((U32)(1<<2))
#define EVENT_EXT_SYNC_ENABLE ((U32)(1<<3))
#define EVENT_NEW_SET_VALUE ((U32)(1<<4))
#define EVENT_NEW_MODE ((U32)(1<<5))
#define EVENT_DAC_START ((U32)(1<<6))
#define EVENT_DAC_STOP ((U32)(1<<7))
#define EVENT_ADC_DATA_READY ((U32)(1<<8))
#define EVENT_RESET_DATA_COUNTER ((U32)(1<<9))
#define EVENT_FLAGS_ALL ( EVENT_ENABLE | EVENT_DISABLE | EVENT_INVERT | \
EVENT_EXT_SYNC_ENABLE | EVENT_NEW_SET_VALUE | EVENT_NEW_MODE | \
EVENT_DAC_START | EVENT_DAC_STOP | EVENT_ADC_DATA_READY | \
EVENT_RESET_DATA_COUNTER )
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osMutexAttr_t m_stMutexAttr =
{
"ADCD_Mutex", // human readable mutex name
osMutexRecursive | osMutexPrioInherit, // attr_bits
NULL, // memory for control block
0U // size for control block
};
// Data Ready Pin
//LOCAL CONST GPIO_TypeDef* m_pstDataReadyPort = GPIOD;
//LOCAL CONST U16 m_u16DataReadyPin = GPIO_PIN_8;
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL U8 m_au8RxData[8];
LOCAL U8 m_au8TxData[8];
LOCAL osMutexId_t m_pstMutexID = NULL;
LOCAL SPID_StHandle m_stSPIHandle =
{
SPID_eADC, // enSPI;
0xFF, // enCS (0xFF = hardware chip select)
m_au8TxData, // pu8TxBuf;
m_au8RxData, // pu8RxBuf;
0, // u16TransferSize;
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
//PRIVATE VOID vAttachDataReadyISR ( VOID );
//PRIVATE VOID vDeattachDataReadyISR ( VOID );
PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit );
PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: ADCD_boInitializeModule
// Description: Initializes the ADC module
// Parameters: None
// Returns: BOOL TRUE, if initializaiton sucessful, otherwise FALSE
//
//-------------------------------------------------------------------------------------------------
BOOL ADCD_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
U16 u16Data = 0;
boOK &= ((m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
osMutexAcquire( m_pstMutexID, osWaitForever );
DIPO_vSetOutput(DIPO_eCS_C);
boOK &= boWriteReg(REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE);
DIPO_vResetOutput(DIPO_eCS_C);
DIPO_vSetOutput(DIPO_eCS_H);
boOK &= boWriteReg(REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE);
DIPO_vResetOutput(DIPO_eCS_H);
osMutexRelease( m_pstMutexID );
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: ADCD_dReadData
// Description: Reads the conversion data form the ADC
// Parameters: PU8 pu8Error error
// Returns: DOUBLE conversion data
//
//-------------------------------------------------------------------------------------------------
BOOL ADCD_dReadData(ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data)
{
BOOL boOK = TRUE;
*pu8Error = 0; // reset error state
U16 u16Data = 0;
DIPO_EnDigitalOutput CS = DIPO_eCS_H;
if(eChannel == ADCD_eHot)CS = DIPO_eCS_H;
else if (eChannel == ADCD_eCold)CS = DIPO_eCS_C;
osMutexAcquire( m_pstMutexID, osWaitForever );
DIPO_vSetOutput(CS);
boOK &= boWriteReg(REG_CONFIG, CONFIG | CONFIG_1SHOT , FALSE);
DIPO_vResetOutput(CS);
osMutexRelease( m_pstMutexID );
osDelay(55);
osMutexAcquire( m_pstMutexID, osWaitForever );
DIPO_vSetOutput(CS);
boOK &= boReadReg(REG_RTD_MSB, &u16Data, TRUE);
DIPO_vResetOutput(CS);
osMutexRelease( m_pstMutexID );
if( !boOK )
{
*pu8Error |= ADCD_SPI_FAILURE;
return 0;
}
if((u16Data & 0x01) == 0x01)
{
*pu8Error |= ADCD_STATUS_DATA_ERROR;
osMutexAcquire( m_pstMutexID, osWaitForever );
DIPO_vSetOutput(CS);
boOK &= boReadReg(REG_FAULT_STATUS, &u16Data, FALSE);
DIPO_vResetOutput(CS);
osMutexRelease( m_pstMutexID );
//boWriteReg(REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE);
*pu8Error |= u16Data & 0xFC;
return 0;
}
u16Data = u16Data >> 1;
*pu16Data = u16Data;
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: boWriteReg
// Description: Writes to the regiser
// Parameters: U8 u8Register
// U16 u16Data
// BOOL boIs16bit TRUE, if Data is 16bit, FALSE, if Data is 8bit
// Returns: BOOL TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boWriteReg( U8 u8Register, U16 u16Data, BOOL boIs16bit )
{
BOOL boOK = TRUE;
if(boIs16bit){
m_au8TxData[0] = CMD_WRITE | u8Register;
m_au8TxData[1] = (U8)(u16Data>>8);
m_au8TxData[2] = (U8)u16Data;
m_stSPIHandle.u16TransferSize = 3;
boOK &= SPID_boSendReceive( &m_stSPIHandle );
} else {
m_au8TxData[0] = CMD_WRITE | u8Register;
m_au8TxData[1] = (U8)u16Data;
m_stSPIHandle.u16TransferSize = 2;
boOK &= SPID_boSendReceive( &m_stSPIHandle );
}
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: boReadReg
// Description: Reads the regiser
// Parameters: U8 u8Register
// PU16 pu16Data
// BOOL boIs16bit TRUE, if Data is 16bit, FALSE, if Data is 8bit
// Returns: BOOL TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
PRIVATE BOOL boReadReg( U8 u8Register, PU16 pu16Data, BOOL boIs16bit )
{
BOOL boOK = TRUE;
if(boIs16bit){
m_au8TxData[0] = CMD_READ | u8Register;
m_au8TxData[1] = 0;
m_au8TxData[2] = 0;
m_stSPIHandle.u16TransferSize = 3;
boOK &= SPID_boSendReceive( &m_stSPIHandle );
*pu16Data = ((U16)m_au8RxData[1]<<8) | ((U16)m_au8RxData[2]<<0);
} else {
m_au8TxData[0] = CMD_READ | u8Register;
m_au8TxData[1] = 0;
m_stSPIHandle.u16TransferSize = 2;
boOK &= SPID_boSendReceive( &m_stSPIHandle );
*pu16Data = (U16)m_au8RxData[1];
}
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: vEventCallback
// Description: Callback for events
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
//PRIVATE VOID vEventCallback( PVOID pvData )
//{
// osEventFlagsSet( m_pstEventID, (U32)pvData );
//}
//-------------------------------------------------------------------------------------------------
// Function: vAttachDataReadyISR
// Description: Set Data Ready Pin Mode to ISR falling Edge
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
//PRIVATE VOID vAttachDataReadyISR ( VOID )
//{
// GPIO_InitTypeDef GPIO_InitStruct = {0};
// /*Configure GPIO pin : ADC_RDY_Pin */
// GPIO_InitStruct.Pin = m_u16DataReadyPin;
// GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// HAL_GPIO_Init((GPIO_TypeDef*)m_pstDataReadyPort, &GPIO_InitStruct);
//}
//-------------------------------------------------------------------------------------------------
// Function: vDeattachDataReadyISR
// Description: Set Data Ready Pin Mode to Input
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
//PRIVATE VOID vDeattachDataReadyISR ( VOID )
//{
//
// HAL_GPIO_DeInit((GPIO_TypeDef*)m_pstDataReadyPort, m_u16DataReadyPin);
//}

View File

@ -0,0 +1,98 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: ADC-Driver
// Filename: ADCD_AdcDriver.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef ADCD_ADCDRIVER_H
#define ADCD_ADCDRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//#include "../Application/CALI_Calibration.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
#define ADCD_STATUS_DATA_ERROR (1<<0)
#define ADCD_SPI_FAILURE (1<<1)
//typedef VOID (*ADCD_pfnCallback)( PVOID pvCallbackArgument );
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
typedef enum {
ADCD_eHot = 0,
ADCD_eCold = 1,
ADCD_eNumberOfTemps // Must be last
}ADCD_EnTemps;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL ADCD_boInitializeModule( VOID );
//BOOL ADCD_boConfig( BOOL boFast, ADCD_pfnCallback pfnDataReadyCallback, PVOID pvCallbackArg );
BOOL ADCD_dReadData(ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,381 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Input
// Filename: ANPI_AnalogPortsIn.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the analog input ports
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "ANPI_AnalogPortsIn.h"
//Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define ADC_RES (4096) // ADC resolution: 12 bits
#define NR_OF_ADCS 5 // number of internal adc channels
// definitions of internal adc
#define INT_ADC_REF_HI (3.28f) // HI int. reference voltage for conversion
#define INT_ADC_REF_LO (0.0f) // LO int. reference voltage for conversion
#define INT_ADC_REF (INT_ADC_REF_HI-INT_ADC_REF_LO)// int. reference voltage for conversion
#define BUFFER_SIZE NR_OF_ADCS * ANPI_OVERSAMPLING_FACTOR * 2
#define BUFFER_HALF_SIZE NR_OF_ADCS * ANPI_OVERSAMPLING_FACTOR
#define ANPI_ADC_HALF_COMPLETE ((U32)1<<0)
#define ANPI_ADC_FULL_COMPLETE ((U32)1<<1)
#define ANPI_FLAGS_ALL ( ANPI_ADC_HALF_COMPLETE | ANPI_ADC_FULL_COMPLETE )
#define OFFSET 1.026f
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
// the number of ADCs
typedef enum
{
eADC1 = 0,
eNumberOfADCs,
} EnADC;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
typedef struct
{
ADC_TypeDef* pstADC;
} StADCInit; // struct for internal ACD
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL FLOAT m_aflValues[ANPI_eInNumberOfInputs]; // values
LOCAL U16 m_au16ADCDataBuffer[eNumberOfADCs][BUFFER_SIZE];
LOCAL U32 m_au32ADCRawData[eNumberOfADCs*NR_OF_ADCS] = {0}; // raw adc values
LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
LOCAL osMutexId_t m_pstMutexID = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
// conversion factors for the values
// Order must fit enumeration "ANPI_EnAnalogInput"
LOCAL CONST FLOAT m_aflConversionFactor[ANPI_eInNumberOfInputs] =
{
34.103f * 1.0f / ADC_RES * INT_ADC_REF, // 00 ANPI_eControlVoltage
10.0f / ADC_RES * INT_ADC_REF, // 01 ANPI_eSupplyVoltage24V
-(1.0f / (2.0f / 10.0f)) / ADC_RES * INT_ADC_REF, // 02 ANPI_eSupplyCurrent24V
34.103f * 1.0f / ADC_RES * INT_ADC_REF, // 03 ANPI_eOutputVoltage
(1.0f / (2.0f / 10.0f)) / ADC_RES * INT_ADC_REF, // 04 ANPI_eOutputCurrent
};
// offsets for the values before it gets multiplied
// Order must fit enumeration "ANPI_EnAnalogInput"
LOCAL CONST FLOAT m_aflOffset1[ANPI_eInNumberOfInputs] =
{
0.0f, // 00 ANPI_eControlVoltage
0.0f, // 01 ANPI_eSupplyVoltage24V
1.65f * ADC_RES / INT_ADC_REF, // 02 ANPI_eSupplyCurrent24V
0.0f, // 03 ANPI_eOutputVoltage
1.65f * ADC_RES / INT_ADC_REF, // 04 ANPI_eOutputCurrent
};
// offsets for the values after it gets multiplied
// Order must fit enumeration "ANPI_EnAnalogInput"
LOCAL CONST FLOAT m_aflOffset2[ANPI_eInNumberOfInputs] =
{
18.788f, // 00 ANPI_eControlVoltage
0.0f, // 01 ANPI_eSupplyVoltage24V
0.0f, // 02 ANPI_eSupplyCurrent24V
18.788f, // 03 ANPI_eOutputVoltage
0.0f, // 04 ANPI_eOutputCurrent
};
// initial values. Order must fit enumeration "ANPI_EnAnalogInput"
LOCAL CONST FLOAT m_afInitValues[ANPI_eInNumberOfInputs] =
{
0.0f, // 00 ANPI_eControlVoltage
0.0f, // 01 ANPI_eSupplyVoltage24V
0.0f, // 02 ANPI_eSupplyCurrent24V
0.0f, // 03 ANPI_eOutputVoltage
0.0f, // 04 ANPI_eOutputCurrent
};
// configuration data for the ADC
// order must fit enumeration EnADC
LOCAL CONST StADCInit m_astADCInit[eNumberOfADCs] =
{
{ADC1}, // 00 eADC1
};
// inputs are connected to the following ADCs
// ANPI_eControlVoltage ADC1, Channel 8
// ANPI_eSupplyVoltage24V ADC1, Channel 6
// ANPI_eSupplyCurrent24V ADC1, Channel 16
// ANPI_eOutputVoltage ADC1, Channel 7
// ANPI_eOutputCurrent ADC1, Channel 15
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"ANPI_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityBelowNormal, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"ANPI_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
LOCAL CONST osMutexAttr_t m_stMutexAttr =
{
"ANPI_Mutex", // human readable mutex name
osMutexRecursive | osMutexPrioInherit, // attr_bits
NULL, // memory for control block
0U // size for control block
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE VOID ANPI_vTask( PVOID arg );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern ADC_HandleTypeDef hadc1;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: ANPI_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPI_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
// set the init values
UTIL_vMemCopyU32( (PU32)m_afInitValues, (PU32)m_aflValues, sizeof(m_aflValues)/sizeof(FLOAT) );
boOK &= ((m_pstThreadID = osThreadNew( ANPI_vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
boOK &= ((m_pstEventID = osEventFlagsNew( &stEventAttribute )) == NULL) ? FALSE : TRUE;
boOK &= ((m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: ANPI_vTask
// Description: ANPI_vTask
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID ANPI_vTask( PVOID arg )
{
U32 u32Flags;
U16 u16Offset;
osDelay( 1 ); // Wait 1ms to have a Valid Value
HAL_ADC_Start_DMA( &hadc1, (PU32)&m_au16ADCDataBuffer[eADC1][0], BUFFER_SIZE);
while ( TRUE )
{
u32Flags = osEventFlagsWait( m_pstEventID, ANPI_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
if( u32Flags & ANPI_ADC_FULL_COMPLETE )
{
u16Offset = BUFFER_HALF_SIZE;
}
if( u32Flags & ANPI_ADC_HALF_COMPLETE )
{
u16Offset = 0;
}
// reset the sum for calculating the mean
memset( m_au32ADCRawData, 0, sizeof(m_au32ADCRawData) );
// calculate the mean of the samples to get a better result
// build the sum of the values...
for(U16 u16Cnt = 0; u16Cnt < BUFFER_HALF_SIZE; u16Cnt++ )
{
m_au32ADCRawData[ u16Cnt % NR_OF_ADCS ] += m_au16ADCDataBuffer[eADC1][u16Cnt + u16Offset];
}
// ... multiply by the conversion factor and add the offset
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
for(U16 u16Cnt = 0; u16Cnt < ANPI_eInNumberOfInputs; u16Cnt++ )
{
m_aflValues[u16Cnt] = ((((FLOAT)m_au32ADCRawData[u16Cnt] / (FLOAT)ANPI_OVERSAMPLING_FACTOR * OFFSET) - (FLOAT)m_aflOffset1[u16Cnt] ) *
(FLOAT)m_aflConversionFactor[u16Cnt]) - (FLOAT)m_aflOffset2[u16Cnt];
}
osMutexRelease( m_pstMutexID ); // release mutex
}
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_ADC_ConvCpltCallback
// Description: Handles the ADC interrupts
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
osEventFlagsSet( m_pstEventID, ANPI_ADC_FULL_COMPLETE );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_ADC_ConvHalfCpltCallback
// Description: Handles the ADC interrupts
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
{
osEventFlagsSet( m_pstEventID, ANPI_ADC_HALF_COMPLETE );
}
//-------------------------------------------------------------------------------------------------
// Function: ANPI_flGetInputValue
// Description: Gets the value of the analog input
// Parameters: ANPI_EnAnalogInput enInput Analog input to read
// Returns: FLOAT flValue Value from ADC in V
//-------------------------------------------------------------------------------------------------
FLOAT ANPI_flGetInputValue( ANPI_EnAnalogInput enInput )
{
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
FLOAT flValue = m_aflValues[enInput];
osMutexRelease( m_pstMutexID ); // release mutex
return( flValue );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: HAL_ADC_ErrorCallback
// Description: Error Callback for the ADC
// Parameters: ADC_HandleTypeDef* hadc
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_ADC_ErrorCallback( ADC_HandleTypeDef* hadc )
{
if( hadc->ErrorCode == HAL_ADC_ERROR_NONE )
{
}
if( hadc->ErrorCode == HAL_ADC_ERROR_INTERNAL )
{
}
if( hadc->ErrorCode == HAL_ADC_ERROR_OVR )
{
//ELOG_ADDLOG( ELOG_eADCOverrunError, NULL );
}
if( hadc->ErrorCode == HAL_ADC_ERROR_DMA )
{
// ELOG_ADDLOG( ELOG_eDMAHTransferError, NULL );
}
// check rx dma transfer error
if( hadc->DMA_Handle->ErrorCode & HAL_DMA_ERROR_TE )
{
// ELOG_ADDLOG( ELOG_eDMAHTransferError, NULL );
}
}

View File

@ -0,0 +1,110 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Input
// Filename: ANPI_AnalogPortsIn.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef ANPI_ANALOGPORTSIN_H
#define ANPI_ANALOGPORTSIN_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
// attention: perhaps you have to change the ADC sample time in ANPI_AnalogPortsIn.c
#define ANPI_OVERSAMPLING_FACTOR 64
#if( ANPI_OVERSAMPLING_FACTOR % 2 != 0 )
#error "ANPI_OVERSAMPLING_FACTOR must be power of 2!"
#endif
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
// Enumeration for analog inputs is used as array index later on. Thus enumeration must start
// at zero and must be numbered consecutively. Enumeration must never be changed.
typedef enum
{
ANPI_eControlVoltage = 0, // 00 control Voltage
ANPI_eSupplyVoltage24V = 1, // 01 voltage of 24V power supply
ANPI_eSupplyCurrent24V = 2, // 02 current of 24V power supply
ANPI_eOutputVoltage = 3, // 03 output voltage peltier element
ANPI_eOutputCurrent = 4, // 04 output current peltier element
ANPI_eInNumberOfInputs, // Must be last entry
} ANPI_EnAnalogInput;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL ANPI_boInitializeModule( VOID );
FLOAT ANPI_flGetInputValue( ANPI_EnAnalogInput enInput );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,169 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Output
// Filename: ANPO_AnalogPortsOut.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the analog outputs ports
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "ANPO_AnalogPortsOut.h"
//Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
U32 u32ConvertVoltagetoRaw( FLOAT Voltage );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern DAC_HandleTypeDef hdac1;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: ANPO_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: ANPO_boSetVoltage
// Description: Sets the DAC Output to a specific Voltage
// Parameters: FLOAT Voltage
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boSetVoltage( FLOAT Voltage ){
BOOL boOK = TRUE;
U32 RawData = u32ConvertVoltagetoRaw( Voltage );
boOK &= HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, RawData);
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: u32ConvertVoltagetoRaw
// Description: Convert Voltage to Raw value for the DAC
// Parameters: FLOAT Voltage
// Returns: U32
//-------------------------------------------------------------------------------------------------
U32 u32ConvertVoltagetoRaw( FLOAT Voltage ){
U32 RawData;
RawData = Voltage * 4095 / 3.28;
return RawData;
}

View File

@ -0,0 +1,99 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Output
// Filename: ANPO_AnalogPortsOut.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef ANPO_ANALOGPORTSOUT_H
#define ANPO_ANALOGPORTSOUT_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
typedef enum
{
ANPO_eControlVoltage = 0, // 00 control Voltage
ANPO_eInNumberOfInputs, // Must be last entry
} ANPO_EnAnalogOutput;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL ANPO_boInitializeModule( VOID );
BOOL ANPO_boSetVoltage( FLOAT Voltage );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,214 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Output
// Filename: ANPO_AnalogPortsOut.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the analog outputs ports
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "CAND_CanDriver.h"
//Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
CAND_pfnRxCallback m_pfnRxCallback = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern CAN_HandleTypeDef hcan1;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: CAND_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL CAND_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= HAL_CAN_Start(&hcan1) == HAL_OK ? TRUE : FALSE;
boOK &= HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) == HAL_OK ? TRUE : FALSE;
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: CAND_boSendMessage
// Description: Send a Message over the CAN Interface
// Parameters: U8 Id
// U8 Length
// PU8 Data Buffer
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL CAND_boSendMessage( U8 u8Id, U8 u8Len, PU8 pu8Buffer ){
BOOL boOK = TRUE;
if( u8Len > 8 ) return FALSE;
CAN_TxHeaderTypeDef header = {
u8Id,
0,
CAN_ID_STD,
CAN_RTR_DATA,
u8Len,
DISABLE
};
boOK &= HAL_CAN_AddTxMessage(&hcan1, &header, pu8Buffer, (PU32)CAN_TX_MAILBOX0 ) == HAL_OK ? TRUE : FALSE;
return boOK;
}
//-------------------------------------------------------------------------------------------------
// Function: CAND_vSetRxCallback
// Description: Send a Message over the CAN Interface
// Parameters: CAND_pfnRxCallback Callback Function
// Returns: none
//-------------------------------------------------------------------------------------------------
VOID CAND_vSetRxCallback( CAND_pfnRxCallback pfnRxCallback ){
m_pfnRxCallback = pfnRxCallback;
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: HAL_CAN_RxFifo0MsgPendingCallback
// Description: HAL Can Rx FIFO Msg Pending Callback
// Parameters: CAN_HandleTypeDef *hcan
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan){
CAN_RxHeaderTypeDef header;
U8 au8Data[8];
HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &header, au8Data);
CAND_Message stMessage;
stMessage.u8Id = header.StdId;
stMessage.u8Len = header.DLC;
UTIL_vMemCopy(au8Data,stMessage.au8Data,stMessage.u8Len);
m_pfnRxCallback(stMessage);
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_CAN_ErrorCallback
// Description: HAL Can error callback function
// Parameters: CAN_HandleTypeDef *hcan
// Returns: None
//-------------------------------------------------------------------------------------------------
void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan){
U32 u32Error = hcan->ErrorCode;
}

View File

@ -0,0 +1,101 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Output
// Filename: ANPO_AnalogPortsOut.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef CAND_CANDRIVER_H
#define CAND_CANDRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
typedef struct {
U8 u8Id;
U8 au8Data[8];
U8 u8Len;
} CAND_Message;
// callback functions
typedef VOID (*CAND_pfnRxCallback)( CAND_Message stMessage );
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL CAND_boInitializeModule( VOID );
BOOL CAND_boSendMessage( U8 u8Id, U8 u8Len, PU8 pu8Buffer );
VOID CAND_vSetRxCallback( CAND_pfnRxCallback pfnRxCallback );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,330 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Digital Ports
// Filename: DIPO_DigitalPorts.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the digtial I/O ports
// Convention: TRUE means active, FALSE means not active
// The polarity of the signal is set in the initialization struct (boLowActive)
// The name of the enumeration does not have any impact on the polarity
// Even with a signal nCs, TRUE means active (if low active => output low)
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "DIPO_DigitalPorts.h"
//Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
typedef struct
{
GPIO_TypeDef* pstPort; // Port
GPIO_InitTypeDef stGPIOInit; // init structure
BOOL boResetState; // reset state of pin
BOOL boSetState; // set state of pin
} StDigitalIO; // Represents one digital input or output
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
// Input order must fit enumeration "DIPO_EnDigitalInput".
LOCAL CONST StDigitalIO m_astInputs[DIPO_eInNumberOfInputs] =
{
{GPIOB, {GPIO_PIN_7, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, FALSE, TRUE}, // 00 DIPO_ePG
{GPIOB, {GPIO_PIN_4, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, FALSE, TRUE}, // 01 DIPO_eADR2
{GPIOB, {GPIO_PIN_3, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, FALSE, TRUE}, // 02 DIPO_eADR1
{GPIOA, {GPIO_PIN_15, GPIO_MODE_INPUT, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, FALSE, TRUE}, // 03 DIPO_eADR0
};
// order must fit enumeration "DIPO_EnDigitalOutput".
LOCAL CONST StDigitalIO m_astOutputs[DIPO_eOutNumberOfOutputs] =
{
{GPIOB, {GPIO_PIN_6, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, TRUE, FALSE }, // 00 DIPO_eCS_C
{GPIOB, {GPIO_PIN_5, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, TRUE, FALSE }, // 01 DIPO_eCS_H
{GPIOA, {GPIO_PIN_10, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, FALSE, TRUE }, // 02 DIPO_eLED
{GPIOA, {GPIO_PIN_8, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_MEDIUM,0}, FALSE, TRUE }, // 03 DIPO_eEN
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: DIPO_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// This function is thread save
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL DIPO_boInitializeModule( VOID )
{
U8 u8Cnt;
BOOL boOK = TRUE;
// enable APB2 syscfg clock
__HAL_RCC_SYSCFG_CLK_ENABLE();
// initialize the inputs
// ----------------------
if( DIPO_eInNumberOfInputs > 0 )
{
for( u8Cnt = 0 ; u8Cnt < DIPO_eInNumberOfInputs; u8Cnt++)
{
boOK &= (m_astInputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_INPUT) ? TRUE : FALSE;
// configure the GIO pin
HAL_GPIO_Init( m_astInputs[u8Cnt].pstPort, (GPIO_InitTypeDef*)&m_astInputs[u8Cnt].stGPIOInit);
}
}
// initialize the outputs
// ----------------------
if( DIPO_eOutNumberOfOutputs > 0 )
{
for( u8Cnt = 0 ; u8Cnt < DIPO_eOutNumberOfOutputs; u8Cnt++)
{
boOK &= (m_astOutputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_OUTPUT_PP || m_astOutputs[u8Cnt].stGPIOInit.Mode == GPIO_MODE_OUTPUT_OD) ? TRUE : FALSE;
// disable output
DIPO_vResetOutput( (DIPO_EnDigitalOutput)u8Cnt );
HAL_GPIO_Init( m_astOutputs[u8Cnt].pstPort, (GPIO_InitTypeDef*)&m_astOutputs[u8Cnt].stGPIOInit);
}
}
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vSetOutput
// Description: Turns a digital output on or off.
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to set on or off
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID DIPO_vSetOutput( DIPO_EnDigitalOutput enOutput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boSetState );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vResetOutput
// Description: Sets the output in reset state
// Parameters: DIPO_EnDigitalOutput enOutput Digital output
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID DIPO_vResetOutput( DIPO_EnDigitalOutput enOutput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boResetState );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vSetState
// Description: Sets the output state
// Parameters: DIPO_EnDigitalOutput enOutput Digital output
// BOOL boState
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID DIPO_vSetState( DIPO_EnDigitalOutput enOutput, BOOL boState )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
if( boState )
{
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boSetState );
}
else
{
HAL_GPIO_WritePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin, (GPIO_PinState) m_astOutputs[enOutput].boResetState );
}
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vGetOutput
// Description: Reads back a digital output.
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to get the data value
// Returns: BOOL TRUE, if output is active, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL DIPO_boGetOutput( DIPO_EnDigitalOutput enOutput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs || !IS_GPIO_ALL_INSTANCE( m_astOutputs[enOutput].pstPort ) || !IS_GPIO_PIN( m_astOutputs[enOutput].stGPIOInit.Pin ) )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return( FALSE );
}
#endif
BOOL boBitState = TRUE;
if( READ_BIT( m_astOutputs[enOutput].pstPort->ODR, m_astOutputs[enOutput].stGPIOInit.Pin ) == 0 )
{
boBitState = FALSE;
}
return( ( m_astOutputs[enOutput].boSetState == TRUE && boBitState == TRUE ) ||\
( m_astOutputs[enOutput].boResetState == TRUE && boBitState == FALSE ) ? TRUE : FALSE );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_boGetInput
// Description: Reads a digital input
// Parameters: DIPO_EnDigitalInput enInput Digital input to read
// Returns: BOOL TRUE, if intput is set active, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL DIPO_boGetInput( DIPO_EnDigitalInput enInput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enInput >= DIPO_eInNumberOfInputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return( FALSE );
}
#endif
GPIO_PinState enPinState = HAL_GPIO_ReadPin( m_astInputs[enInput].pstPort, (U16)m_astInputs[enInput].stGPIOInit.Pin );
return( ( m_astInputs[enInput].boSetState == TRUE && enPinState == GPIO_PIN_SET) ||\
( m_astInputs[enInput].boResetState == TRUE && enPinState == GPIO_PIN_RESET) ? TRUE : FALSE );
}
//-------------------------------------------------------------------------------------------------
// Function: DIPO_vToggleOutput
// Description: Toggles the digital output
// Parameters: DIPO_EnDigitalOutput enOutput Digital output to toggle
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID DIPO_vToggleOutput( DIPO_EnDigitalOutput enOutput )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( enOutput >= DIPO_eOutNumberOfOutputs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
HAL_GPIO_TogglePin( m_astOutputs[enOutput].pstPort, (U16)m_astOutputs[enOutput].stGPIOInit.Pin );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================

View File

@ -0,0 +1,131 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Digital Ports
// Filename: DIPO_DigitalPorts.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef DIPO_DIGITALPORTS_H
#define DIPO_DIGITALPORTS_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
// Enumeration for digital inputs is used as array index later on. Thus enumeration must start
// at zero and must be numbered consecutively. Enumeration must never be changed.
// Value 0xFF is reserved and must not be used.
typedef enum
{
DIPO_ePG = 0, // 00 DIP 1
DIPO_eADR2 = 1, // 01 DIP 2
DIPO_eADR1 = 2, // 02 DIP 3
DIPO_eADR0 = 3, // 03 DIP 4
DIPO_eInNumberOfInputs, // Must be last entry
} DIPO_EnDigitalInput;
// Enumeration for digital outputs is used as array index later on. Thus enumeration must start
// at zero and must be numbered consecutively. Enumeration must never be changed.
// Value 0xFF is reserved and must not be used.
typedef enum
{
DIPO_eCS_C = 0, // 00 Chip Select Cold
DIPO_eCS_H = 1, // 01 Chip Select Hot
DIPO_eLED = 2, // 02 Test LED
DIPO_eEN = 3, // 03 Enable
DIPO_eOutNumberOfOutputs, // Must be last entry
} DIPO_EnDigitalOutput;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL DIPO_boInitializeModule( VOID );
VOID DIPO_vSetOutput( DIPO_EnDigitalOutput enOutput );
VOID DIPO_vResetOutput( DIPO_EnDigitalOutput enOutput );
VOID DIPO_vSetState( DIPO_EnDigitalOutput enOutput, BOOL boState );
VOID DIPO_vToggleOutput( DIPO_EnDigitalOutput enOutput );
BOOL DIPO_boGetInput( DIPO_EnDigitalInput enInput );
BOOL DIPO_boGetOutput( DIPO_EnDigitalOutput enOutput );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,95 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: High Stability Current Source
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: EXTI Handler
// Filename: EXTI_ExtiHandler.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef EXTI_EXTIHANDLER_H
#define EXTI_EXTIHANDLER_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
// include STM32 drivers
#include "stm32h7xx_hal.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
typedef VOID (*EXTI_pfnCallback)( PVOID pvCallbackArgument );
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
VOID EXTI_vSetCallback( U16 GPIO_Pin, EXTI_pfnCallback pfnCallback, PVOID pvCallbackArgument );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,225 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Peltier Controller
// Filename: PECO_PeltierController.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the Peltier Controller Output
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "PECO_PeltierController.h"
// Driver
#include "../Drivers/ANPO_AnalogPortsOut.h"
#include "../Drivers/DIPO_DigitalPorts.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL osThreadId_t m_pstThreadID = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"PECO_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityNormal, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE VOID PECO_vTask( PVOID arg );
BOOL boSetPeltierVoltage( S16 Voltage );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern DAC_HandleTypeDef hdac1;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: PECO_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL PECO_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ((m_pstThreadID = osThreadNew( PECO_vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
boSetPeltierVoltage(0);
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: PECO_boSetTemperature
// Description: Sets the Peltier Controller to a Specific Temperature
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL PECO_boSetTemperature( S16 Temperature ){
BOOL boOK = TRUE;
boOK &= boSetPeltierVoltage( Temperature );
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: PECO_Enable
// Description: Enables the Peltier Controller Output
// Parameters: BOOL Enable
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID PECO_Enable( BOOL Enable ){
DIPO_vSetState(DIPO_eEN, Enable);
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: PECO_vTask
// Description: PECO_vTask
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID PECO_vTask( PVOID arg )
{
/*PECO_Enable(TRUE);
while ( TRUE )
{
boSetPeltierVoltage(1);
osDelay(5000);
boSetPeltierVoltage(0);
osDelay(5000);
boSetPeltierVoltage(-1);
osDelay(5000);
boSetPeltierVoltage(0);
osDelay(5000);
}*/
}
//-------------------------------------------------------------------------------------------------
// Function: boSetPeltierVoltage
// Description: Sets the Peltier elements to a specific Voltage
// Parameters: S8 Voltage (14V - -8V)
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL boSetPeltierVoltage( S16 Voltage ){
BOOL boOK = TRUE;
if( Voltage > 14000 ) Voltage = 14000;
if( Voltage < -8000 ) Voltage = -8000;
//Voltage -= 0.6; // Offset (hoffentlich nicht mehr)
boOK &= ANPO_boSetVoltage( ((((FLOAT)Voltage)/1000) + 20.088) / 34.103 );
return( boOK );
}

View File

@ -0,0 +1,95 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Peltier Controller
// Filename: PECO_PeltierController.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef PECO_PELTIERCONTROLLER_H
#define PECO_PELTIERCONTROLLER_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL PECO_boInitializeModule( VOID );
BOOL PECO_boSetTemperature( S16 Temperature );
VOID PECO_Enable( BOOL Enable );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,378 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: SPI-Driver
// Filename: SPID_SpiDriver.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the SPI-Driver
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "SPID_SpiDriver.h"
// Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// Drivers
#include "DIPO_DigitalPorts.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define OS_ADC_SPI_COMPLETE_FLAG ((U32)(1<<0))
#define OS_ADC_SPI_ERROR_FLAG ((U32)(1<<1))
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
typedef struct
{
SPI_HandleTypeDef* pstSPIHandle;
osMutexId_t pstMutexID;
CONST osMutexAttr_t* pstMutexAttribute;
U32 u32SPICompleteFlag;
U32 u32SPIErrorFlag;
} StSPI;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osMutexAttr_t m_stADCMutexAttr =
{
"SPID_ADC_Mutex", // human readable mutex name
osMutexRecursive | osMutexPrioInherit, // attr_bits
NULL, // memory for control block
0U // size for control block
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"SPID_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern SPI_HandleTypeDef hspi1;
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL StSPI m_astSPI[SPID_eNumberOfSPIs] =
{
// SPID_eSPI2
{
&hspi1, // SPI Handle
NULL, // pstMutexID
&m_stADCMutexAttr, // pstMutexAttribute
OS_ADC_SPI_COMPLETE_FLAG, // u32SPICompleteFlag
OS_ADC_SPI_ERROR_FLAG, // u32SPIErrorFlag
},
};
LOCAL osEventFlagsId_t m_pstEventID = NULL;
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE SPID_EnSPIs enGetSPI( SPI_HandleTypeDef* pstSPI );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: SPID_boInitializeModule
// Description: Initializes the module
// Parameters: None
// Returns: BOOL, TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL SPID_boInitializeModule( VOID )
{
BOOL boOK= TRUE;
boOK &= ((m_pstEventID = osEventFlagsNew( &stEventAttribute )) == NULL) ? FALSE : TRUE;
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: SPID_boSend
// Description: Sends a number of bytes
// Parameters: SPID_StHandle* pstHandle
// Returns: BOOL TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL SPID_boSend( SPID_StHandle* pstHandle )
{
BOOL boOK;
U32 u32Flags = 0;
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( pstHandle == NULL || pstHandle->enSPI >= SPID_eNumberOfSPIs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return( FALSE );
}
#endif
osMutexAcquire( m_astSPI[pstHandle->enSPI].pstMutexID, osWaitForever );
// clear all flags
osEventFlagsClear( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag );
// start SPI transmission
boOK = HAL_SPI_Transmit_DMA( m_astSPI[pstHandle->enSPI].pstSPIHandle, pstHandle->pu8TxBuf, pstHandle->u16TransferSize ) == HAL_OK ? TRUE : FALSE;
if( boOK )
{
// wait until transmisison done
u32Flags = osEventFlagsWait( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag, osFlagsWaitAny, osWaitForever );
}
boOK &= (u32Flags & m_astSPI[pstHandle->enSPI].u32SPIErrorFlag) ? FALSE : TRUE;
osMutexRelease( m_astSPI[pstHandle->enSPI].pstMutexID );
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: SPID_boSendReceive
// Description: Sends a and receives a number of bytes
// Parameters: SPID_StHandle* pstHandle
// DIPO_EnDigitalOutput enCS
// Returns: BOOL TRUE, if successful, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL SPID_boSendReceive( SPID_StHandle* pstHandle )
{
BOOL boOK;
U32 u32Flags = 0;
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( pstHandle == NULL || pstHandle->enSPI >= SPID_eNumberOfSPIs )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return( FALSE );
}
#endif
osMutexAcquire( m_astSPI[pstHandle->enSPI].pstMutexID, osWaitForever );
// clear all flags
osEventFlagsClear( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag );
// start SPI
boOK = HAL_SPI_TransmitReceive_DMA( m_astSPI[pstHandle->enSPI].pstSPIHandle, pstHandle->pu8TxBuf, pstHandle->pu8RxBuf, pstHandle->u16TransferSize ) == HAL_OK ? TRUE : FALSE;
if( boOK )
{
// wait until transmisison done
u32Flags = osEventFlagsWait( m_pstEventID, m_astSPI[pstHandle->enSPI].u32SPICompleteFlag | m_astSPI[pstHandle->enSPI].u32SPIErrorFlag, osFlagsWaitAny, osWaitForever );
}
boOK &= (u32Flags & m_astSPI[pstHandle->enSPI].u32SPIErrorFlag) ? FALSE : TRUE;
osMutexRelease( m_astSPI[pstHandle->enSPI].pstMutexID );
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
///-------------------------------------------------------------------------------------------------
// Function: HAL_SPI_TxRxCpltCallback
// Description: HAL spi rx/tx complete callback function
// Parameters: SPI_HandleTypeDef *hspi
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID HAL_SPI_TxRxCpltCallback( SPI_HandleTypeDef *hspi )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( hspi == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
SPID_EnSPIs enSPI = enGetSPI( hspi );
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_SPI_TxCpltCallback
// Description: HAL spi tx complete callback function
// Parameters: SPI_HandleTypeDef *hspi
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID HAL_SPI_TxCpltCallback( SPI_HandleTypeDef *hspi )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( hspi == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
SPID_EnSPIs enSPI = enGetSPI( hspi );
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_SPI_RxCpltCallback
// Description: HAL SPI rx complete callback function
// Parameters: SPI_HandleTypeDef *hspi
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID HAL_SPI_RxCpltCallback( SPI_HandleTypeDef *hspi )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( hspi == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
SPID_EnSPIs enSPI = enGetSPI( hspi );
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPICompleteFlag );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_SPI_ErrorCallback
// Description: HAL SPI error callback function
// Parameters: SPI_HandleTypeDef *hspi
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID HAL_SPI_ErrorCallback( SPI_HandleTypeDef *hspi )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( hspi == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
return;
}
#endif
// check rx overrun error
if( hspi->ErrorCode & HAL_SPI_ERROR_OVR )
{
//ELOG_ADD_LOG( ELOG_eSPIOverrunError );
}
// check rx dma transfer error
if( hspi->hdmarx->ErrorCode & HAL_DMA_ERROR_TE )
{
//ELOG_ADD_LOG( ELOG_eDMAHTransferError );
}
// check tx dma transfer error
if( hspi->hdmatx->ErrorCode & HAL_DMA_ERROR_TE )
{
//ELOG_ADD_LOG( ELOG_eDMAHTransferError );
}
SPID_EnSPIs enSPI = enGetSPI( hspi );
osEventFlagsSet( m_pstEventID, m_astSPI[enSPI].u32SPIErrorFlag );
}
//-------------------------------------------------------------------------------------------------
// Function: enGetSPI
// Description: Gets the SPI enumeration to the corresponding SPI handle
// Parameters: SPI_HandleTypeDef* pstSPI
// Returns: SPID_EnSPIs
//-------------------------------------------------------------------------------------------------
PRIVATE SPID_EnSPIs enGetSPI( SPI_HandleTypeDef* pstSPI )
{
#if defined(PDEF_FUNCTION_PARAMETER_CHECK_ENABLED) && PDEF_FUNCTION_PARAMETER_CHECK_ENABLED == TRUE
if( pstSPI == NULL )
{
ELOG_ADD_LOG( ELOG_eInvalidFunctionParameter );
ASRT_ASSERT( FALSE );
}
#endif
for( U8 u8Cnt = 0; u8Cnt < SPID_eNumberOfSPIs; u8Cnt++ )
{
if( m_astSPI[u8Cnt].pstSPIHandle == pstSPI )
{
return( u8Cnt );
}
}
//ASRT_ASSERT( FALSE );
return( 0 );
}

View File

@ -0,0 +1,113 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: SPI-Driver
// Filename: SPID_SpiDriver.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef SPID_SPIDRIVER_H
#define SPID_SPIDRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
#include "../Drivers/DIPO_DigitalPorts.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
// do not change the order of the enumeration!
typedef enum
{
SPID_eADC = 0,
SPID_eNumberOfSPIs, // Must be last
} SPID_EnSPIs;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
typedef struct
{
SPID_EnSPIs enSPI;
DIPO_EnDigitalOutput enCS;
PU8 pu8TxBuf;
PU8 pu8RxBuf;
U16 u16TransferSize;
SPI_InitTypeDef stInit;
} SPID_StHandle;
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL SPID_boInitializeModule( VOID );
BOOL SPID_boSend( SPID_StHandle* pstHandle );
BOOL SPID_boSendReceive( SPID_StHandle* pstHandle );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,332 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Temp
// Filename: TEMP_Temperature.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the temperature readout
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
//#include "../Application/VARH_VariableHandler.h"
#include "../PDEF_ProjectDefinitions.h"
#include "TEMP_Temperature.h"
// Application
//#include "../Application/ELOG_ErrorLogger.h"
//#include "../Application/RTOS_RealTimeOs.h"
// Toolbox
//#include "../Toolbox/ASRT_Assert.h"
#include "../Toolbox/UTIL_Utility.h"
// Drivers
#include "DIPO_DigitalPorts.h"
#include "SPID_SpiDriver.h"
#include "ADCD_ADCDriver.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include <math.h>
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define REFRESH_MS 100
// Konstanten f<>r Temperaturberechung
#define RTD_A 3.9083e-3
#define RTD_B -5.775e-7
#define R_REF 3900
#define R_NOMINAL 1000
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE FLOAT flConvertADCData( U16 dbRTemp );
PRIVATE VOID vTempTask( PVOID arg );
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osMutexAttr_t m_stMutexAttr =
{
"TEMP_Mutex", // human readable mutex name
osMutexRecursive | osMutexPrioInherit, // attr_bits
NULL, // memory for control block
0U // size for control block
};
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"TEMP_Thread", // name of the thread
osThreadDetached, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
NULL, // memory for stack
1024, // size of stack
osPriorityNormal, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osMutexId_t m_pstMutexID = NULL;
LOCAL FLOAT m_flTempData[ADCD_eNumberOfTemps];
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: TEMP_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// This function is thread save
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL TEMP_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
boOK &= ((m_pstThreadID = osThreadNew( vTempTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
boOK &= ((m_pstMutexID = osMutexNew( &m_stMutexAttr )) == NULL) ? FALSE : TRUE;
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: TEMP_dGetValue
// Description: Gets the desired temperature
// Parameters: ATEMP_EnTemperature enInput
// Returns: DOUBLE DValue Value from ADC
//-------------------------------------------------------------------------------------------------
FLOAT TEMP_dGetValue( ADCD_EnTemps enTemp )
{
osMutexAcquire( m_pstMutexID, osWaitForever );
DOUBLE dValue = m_flTempData[enTemp];
osMutexRelease( m_pstMutexID );
return( dValue );
}
//-------------------------------------------------------------------------------------------------
// Function: TEMP_boRegisterEventNotification
// Description: Register for a notification when there are new values
// Parameters: TEMP_pfnEventCallback pfnCallback
// PVOID pvCallbackArgument
// Returns: TRUE, if successfull, otherwise FALSE
//-------------------------------------------------------------------------------------------------
//BOOL TEMP_boRegisterEventNotification( TEMP_pfnEventCallback pfnCallback, PVOID pvCallbackArgument )
//{
// BOOL boRet = FALSE;
// osMutexAcquire( m_pstMutexID, osWaitForever );
// for( U16 u16Cnt = 0; u16Cnt < NUMBER_OF_EVENT_CALLBACKS; u16Cnt++ )
// {
// if( m_apfnEventCallback[u16Cnt] == NULL )
// {
// m_apfnEventCallback[u16Cnt] = pfnCallback;
// m_apvCallbackArgument[u16Cnt] = pvCallbackArgument;
// boRet = TRUE;
// break;
// }
// }
// osMutexRelease( m_pstMutexID );
// return( boRet );
//}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: vTempTask
// Description: vTempTask
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vTempTask( PVOID arg )
{
UNUSED( arg );
U32 u32Flags;
BOOL boOK = TRUE;
U8 error;
U16 u16ADC_data[ADCD_eNumberOfTemps];
U8 u8Channel;
FLOAT temp = 0;
osDelay(10);
while( TRUE )
{
//u32Flags = osEventFlagsWait( m_pstEventID, EVENT_REFRESH, osFlagsWaitAny, osWaitForever );
//if( u32Flags & EVENT_REFRESH )
//{
boOK &= ADCD_dReadData(ADCD_eHot, &error, &u16ADC_data[ADCD_eHot]);
if( boOK )
{
osMutexAcquire( m_pstMutexID, osWaitForever );
m_flTempData[ADCD_eHot] = flConvertADCData( u16ADC_data[ADCD_eHot] );
//temp = flConvertADCData( u16ADC_data[ADCD_eHot] ); // for debugging
//VARH_vSetVariableData( VARH_eTempHeatSink + u8Channel, (VARH_UVariable)(FLOAT)m_dbTempData[u8Channel] );
osMutexRelease( m_pstMutexID );
} else {
boOK = TRUE;
}
boOK &= ADCD_dReadData(ADCD_eCold, &error, &u16ADC_data[ADCD_eCold]);
if( boOK )
{
osMutexAcquire( m_pstMutexID, osWaitForever );
m_flTempData[ADCD_eCold] = flConvertADCData( u16ADC_data[ADCD_eCold] );
//temp = flConvertADCData( u16ADC_data[ADCD_eCold] ); // for debugging
//VARH_vSetVariableData( VARH_eTempHeatSink + u8Channel, (VARH_UVariable)(FLOAT)m_dbTempData[u8Channel] );
osMutexRelease( m_pstMutexID );
} else {
boOK = TRUE;
}
//}
osDelay(REFRESH_MS);
// wait for ADC conversions completed
// u32Flags = osEventFlagsWait( m_pstEventID, OS_EVENT_ADC_COMPLETED_FLAG, osFlagsWaitAll , ADC_TIMEOUT_MS );
// boTimeout = (u32Flags == osFlagsErrorTimeout) ? TRUE : FALSE;
// boError = FALSE;
//
// // check if we have a timeout
// if( boTimeout )
// {
// //ELOG_ADD_LOG( ELOG_eADCTimeout );
// }
//
// // read ADC data
// if( !(boSuccess = boReadADCData() ) )
// {
// //ELOG_ADD_LOG( ELOG_eADCReadingDataFailed );
// }
//// vIncrementChannel();
//
// // reinit ADC on error, on spi failure or when timeout reached
// if( boTimeout || !boSuccess )
// {
// boError = TRUE;
//// vADCInit();
// }
// // send event to worker task, if all channels completed and no error
// if( m_stADCData.u8Cannel == 0 && !boError )
// {
// // send event to tasks
// for( U16 u16Cnt = 0; u16Cnt < NUMBER_OF_EVENT_CALLBACKS; u16Cnt++ )
// {
// if( m_apfnEventCallback[u16Cnt] != NULL )
// {
// m_apfnEventCallback[u16Cnt]( m_apvCallbackArgument[u16Cnt] );
// }
// }
// }
}
}
//-------------------------------------------------------------------------------------------------
// Function: flConvertADCData
// Description: Converts resistor value to temperature data
// Parameters: U16 u16RTemp
// Returns: U16, temperature in Celcius
//-------------------------------------------------------------------------------------------------
PRIVATE FLOAT flConvertADCData( U16 u16RTemp )
{
u16RTemp = u16RTemp / 1000;
FLOAT flT = 9.9714f * u16RTemp;
flT += 235.904f;
flT *= u16RTemp;
flT += -245.876f;
return( flT );
}

View File

@ -0,0 +1,90 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Temperature
// Filename: TEMP_Temperature.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef TEMP_TEMPERATURE_H
#define TEMP_TEMPERATURE_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "../SDEF_StandardDefinitions.h"
#include "ADCD_AdcDriver.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//typedef VOID (*TEMP_pfnEventCallback)( PVOID pvData );
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL TEMP_boInitializeModule( VOID );
//BOOL TEMP_boRegisterEventNotification( TEMP_pfnEventCallback pfnCallback, PVOID pvCallbackArgument );
FLOAT TEMP_dGetValue( ADCD_EnTemps enTemp );
#ifdef __cplusplus
}
#endif
#endif

171
Core/Inc/FreeRTOSConfig.h Normal file
View File

@ -0,0 +1,171 @@
/* USER CODE BEGIN Header */
/*
* FreeRTOS Kernel V10.3.1
* Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/* USER CODE END Header */
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* These parameters and more are described within the 'configuration' section of the
* FreeRTOS API documentation available on the FreeRTOS.org web site.
*
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* Section where include file can be added */
/* USER CODE END Includes */
/* Ensure definitions are only used by the compiler, and not by the assembler. */
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
void xPortSysTickHandler(void);
#endif
#ifndef CMSIS_device_header
#define CMSIS_device_header "stm32l4xx.h"
#endif /* CMSIS_device_header */
#define configENABLE_FPU 0
#define configENABLE_MPU 0
#define configUSE_PREEMPTION 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 56 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)3000)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */
/* Defaults to size_t for backward compatibility, but can be changed
if lengths will always be less than the number of bytes in a size_t. */
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH 256
/* CMSIS-RTOS V2 flags */
#define configUSE_OS2_THREAD_SUSPEND_RESUME 1
#define configUSE_OS2_THREAD_ENUMERATE 1
#define configUSE_OS2_EVENTFLAGS_FROM_ISR 1
#define configUSE_OS2_THREAD_FLAGS 1
#define configUSE_OS2_TIMER 1
#define configUSE_OS2_MUTEX 1
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xQueueGetMutexHolder 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_eTaskGetState 1
/*
* The CMSIS-RTOS V2 FreeRTOS wrapper is dependent on the heap implementation used
* by the application thus the correct define need to be enabled below
*/
#define USE_FreeRTOS_HEAP_4
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4
#endif
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );}
/* USER CODE END 1 */
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
/* IMPORTANT: After 10.3.1 update, Systick_Handler comes from NVIC (if SYS timebase = systick), otherwise from cmsis_os2.c */
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1
/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
/* USER CODE END Defines */
#endif /* FREERTOS_CONFIG_H */

87
Core/Inc/main.h Normal file
View File

@ -0,0 +1,87 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 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
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32l4xx_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define EN_Pin GPIO_PIN_8
#define EN_GPIO_Port GPIOA
#define LED_Pin GPIO_PIN_10
#define LED_GPIO_Port GPIOA
#define ADR0_Pin GPIO_PIN_15
#define ADR0_GPIO_Port GPIOA
#define ADR1_Pin GPIO_PIN_3
#define ADR1_GPIO_Port GPIOB
#define ADR2_Pin GPIO_PIN_4
#define ADR2_GPIO_Port GPIOB
#define CS1_Pin GPIO_PIN_5
#define CS1_GPIO_Port GPIOB
#define CS2_Pin GPIO_PIN_6
#define CS2_GPIO_Port GPIOB
#define PG_Pin GPIO_PIN_7
#define PG_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,483 @@
/**
******************************************************************************
* @file stm32l4xx_hal_conf.h
* @author MCD Application Team
* @brief HAL configuration template file.
* This file should be copied to the application folder and renamed
* to stm32l4xx_hal_conf.h.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 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
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32L4xx_HAL_CONF_H
#define STM32L4xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
/*#define HAL_CRYP_MODULE_ENABLED */
#define HAL_CAN_MODULE_ENABLED
/*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */
#define HAL_DAC_MODULE_ENABLED
/*#define HAL_DCMI_MODULE_ENABLED */
/*#define HAL_DMA2D_MODULE_ENABLED */
/*#define HAL_DFSDM_MODULE_ENABLED */
/*#define HAL_DSI_MODULE_ENABLED */
/*#define HAL_FIREWALL_MODULE_ENABLED */
/*#define HAL_GFXMMU_MODULE_ENABLED */
/*#define HAL_HCD_MODULE_ENABLED */
/*#define HAL_HASH_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_LTDC_MODULE_ENABLED */
/*#define HAL_LCD_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
/*#define HAL_MMC_MODULE_ENABLED */
/*#define HAL_NAND_MODULE_ENABLED */
/*#define HAL_NOR_MODULE_ENABLED */
/*#define HAL_OPAMP_MODULE_ENABLED */
/*#define HAL_OSPI_MODULE_ENABLED */
/*#define HAL_OSPI_MODULE_ENABLED */
/*#define HAL_PCD_MODULE_ENABLED */
/*#define HAL_PKA_MODULE_ENABLED */
/*#define HAL_QSPI_MODULE_ENABLED */
/*#define HAL_QSPI_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */
/*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
/*#define HAL_SRAM_MODULE_ENABLED */
/*#define HAL_SWPMI_MODULE_ENABLED */
/*#define HAL_TIM_MODULE_ENABLED */
/*#define HAL_TSC_MODULE_ENABLED */
/*#define HAL_UART_MODULE_ENABLED */
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
/*#define HAL_EXTI_MODULE_ENABLED */
/*#define HAL_PSSI_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)40000000U) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal Multiple Speed oscillator (MSI) default value.
* This value is the default MSI range value after Reset.
*/
#if !defined (MSI_VALUE)
#define MSI_VALUE ((uint32_t)4000000U) /*!< Value of the Internal oscillator in Hz*/
#endif /* MSI_VALUE */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC and RNG.
* This internal oscillator is mainly dedicated to provide a high precision clock to
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
* which is subject to manufacturing process variations.
*/
#if !defined (HSI48_VALUE)
#define HSI48_VALUE ((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
The real value my vary depending on manufacturing process variations.*/
#endif /* HSI48_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature.*/
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief External clock source for SAI1 peripheral
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
* frequency.
*/
#if !defined (EXTERNAL_SAI1_CLOCK_VALUE)
#define EXTERNAL_SAI1_CLOCK_VALUE 2097000U /*!< Value of the SAI1 External clock source in Hz*/
#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
/**
* @brief External clock source for SAI2 peripheral
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
* frequency.
*/
#if !defined (EXTERNAL_SAI2_CLOCK_VALUE)
#define EXTERNAL_SAI2_CLOCK_VALUE 48000U /*!< Value of the SAI2 External clock source in Hz*/
#endif /* EXTERNAL_SAI2_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 0U
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */
/* ################## Register callback feature configuration ############### */
/**
* @brief Set below the peripheral configuration to "1U" to add the support
* of HAL callback registration/deregistration feature for the HAL
* driver(s). This allows user application to provide specific callback
* functions thanks to HAL_PPP_RegisterCallback() rather than overwriting
* the default weak callback functions (see each stm32l4xx_hal_ppp.h file
* for possible callback identifiers defined in HAL_PPP_CallbackIDTypeDef
* for each PPP peripheral).
*/
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U
#define USE_HAL_GFXMMU_REGISTER_CALLBACKS 0U
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U
#define USE_HAL_OSPI_REGISTER_CALLBACKS 0U
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U
#define USE_HAL_SD_REGISTER_CALLBACKS 0U
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U
#define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U
#define USE_HAL_TSC_REGISTER_CALLBACKS 0U
#define USE_HAL_UART_REGISTER_CALLBACKS 0U
#define USE_HAL_USART_REGISTER_CALLBACKS 0U
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 0U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32l4xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32l4xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32l4xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_DFSDM_MODULE_ENABLED
#include "stm32l4xx_hal_dfsdm.h"
#endif /* HAL_DFSDM_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32l4xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32l4xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_CAN_MODULE_ENABLED
#include "stm32l4xx_hal_can.h"
#endif /* HAL_CAN_MODULE_ENABLED */
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
#include "Legacy/stm32l4xx_hal_can_legacy.h"
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32l4xx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32l4xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32l4xx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32l4xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_DCMI_MODULE_ENABLED
#include "stm32l4xx_hal_dcmi.h"
#endif /* HAL_DCMI_MODULE_ENABLED */
#ifdef HAL_DMA2D_MODULE_ENABLED
#include "stm32l4xx_hal_dma2d.h"
#endif /* HAL_DMA2D_MODULE_ENABLED */
#ifdef HAL_DSI_MODULE_ENABLED
#include "stm32l4xx_hal_dsi.h"
#endif /* HAL_DSI_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32l4xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_GFXMMU_MODULE_ENABLED
#include "stm32l4xx_hal_gfxmmu.h"
#endif /* HAL_GFXMMU_MODULE_ENABLED */
#ifdef HAL_FIREWALL_MODULE_ENABLED
#include "stm32l4xx_hal_firewall.h"
#endif /* HAL_FIREWALL_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32l4xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_HASH_MODULE_ENABLED
#include "stm32l4xx_hal_hash.h"
#endif /* HAL_HASH_MODULE_ENABLED */
#ifdef HAL_HCD_MODULE_ENABLED
#include "stm32l4xx_hal_hcd.h"
#endif /* HAL_HCD_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32l4xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32l4xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32l4xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_LCD_MODULE_ENABLED
#include "stm32l4xx_hal_lcd.h"
#endif /* HAL_LCD_MODULE_ENABLED */
#ifdef HAL_LPTIM_MODULE_ENABLED
#include "stm32l4xx_hal_lptim.h"
#endif /* HAL_LPTIM_MODULE_ENABLED */
#ifdef HAL_LTDC_MODULE_ENABLED
#include "stm32l4xx_hal_ltdc.h"
#endif /* HAL_LTDC_MODULE_ENABLED */
#ifdef HAL_MMC_MODULE_ENABLED
#include "stm32l4xx_hal_mmc.h"
#endif /* HAL_MMC_MODULE_ENABLED */
#ifdef HAL_NAND_MODULE_ENABLED
#include "stm32l4xx_hal_nand.h"
#endif /* HAL_NAND_MODULE_ENABLED */
#ifdef HAL_NOR_MODULE_ENABLED
#include "stm32l4xx_hal_nor.h"
#endif /* HAL_NOR_MODULE_ENABLED */
#ifdef HAL_OPAMP_MODULE_ENABLED
#include "stm32l4xx_hal_opamp.h"
#endif /* HAL_OPAMP_MODULE_ENABLED */
#ifdef HAL_OSPI_MODULE_ENABLED
#include "stm32l4xx_hal_ospi.h"
#endif /* HAL_OSPI_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32l4xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_PKA_MODULE_ENABLED
#include "stm32l4xx_hal_pka.h"
#endif /* HAL_PKA_MODULE_ENABLED */
#ifdef HAL_PSSI_MODULE_ENABLED
#include "stm32l4xx_hal_pssi.h"
#endif /* HAL_PSSI_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32l4xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_QSPI_MODULE_ENABLED
#include "stm32l4xx_hal_qspi.h"
#endif /* HAL_QSPI_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32l4xx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32l4xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SAI_MODULE_ENABLED
#include "stm32l4xx_hal_sai.h"
#endif /* HAL_SAI_MODULE_ENABLED */
#ifdef HAL_SD_MODULE_ENABLED
#include "stm32l4xx_hal_sd.h"
#endif /* HAL_SD_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32l4xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32l4xx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32l4xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_SRAM_MODULE_ENABLED
#include "stm32l4xx_hal_sram.h"
#endif /* HAL_SRAM_MODULE_ENABLED */
#ifdef HAL_SWPMI_MODULE_ENABLED
#include "stm32l4xx_hal_swpmi.h"
#endif /* HAL_SWPMI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32l4xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_TSC_MODULE_ENABLED
#include "stm32l4xx_hal_tsc.h"
#endif /* HAL_TSC_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32l4xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32l4xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32l4xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t *file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* STM32L4xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

76
Core/Inc/stm32l4xx_it.h Normal file
View File

@ -0,0 +1,76 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32l4xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 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
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32L4xx_IT_H
#define __STM32L4xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);
void SysTick_Handler(void);
void DMA1_Channel2_IRQHandler(void);
void DMA1_Channel3_IRQHandler(void);
void ADC1_IRQHandler(void);
void CAN1_TX_IRQHandler(void);
void CAN1_RX0_IRQHandler(void);
void CAN1_RX1_IRQHandler(void);
void CAN1_SCE_IRQHandler(void);
void SPI1_IRQHandler(void);
void DMA2_Channel3_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32L4xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,147 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: High Stability Current Source
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Project definitions
// Filename: PDEF_ProjectDefinitions.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: Project definitions
//
//=================================================================================================
#ifndef PDEF_PROJECT_DEFINITIONS_H
#define PDEF_PROJECT_DEFINITIONS_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
// Firmare version:
// example: "1.1.2"
// 1. Digit: Major number for big changes = "01" and up
// 2. Digit: Minor number for small changes = "1" and up
// 3. Digit: Development version number = "1" and up
#define PDEF_FW_VERSION_HEX 0x0001 // coding: 0xUVW
// U: major number,
// V: minor number,
// W: development version
// Compiler switches
#define PDEF_FUNCTION_PARAMETER_CHECK_ENABLED FALSE
#define PDEF_USE_ASSERTION TRUE
#define PDEF_USE_STM32_FULL_ASSERT FALSE
// definie interrupt priorities
//-------------------------------------------------------------------------------------------------
// preemption priority range: 0-15
// sub priority range: no subpriority
// 0: highest priority, 15: lowest priority
// same priorities are allowed
#define PDEF_NVIC_PRIORITY_GROUPING NVIC_PRIORITYGROUP_4
#define PDEF_MSCB_IRQ_PREEMPT_PRIO 0
#define PDEF_MSCB_IRQ_SUB_PRIO 0
#define PDEF_RS485_IRQ_PREMPT_PRIO 0
#define PDEF_RS485_IRQ_SUB_PRIO 0
#define PDEF_EXTI_IRQ_PREEMPT_PRIO 1
#define PDEF_EXTI_IRQ_SUB_PRIO 0
#define PDEF_ADCS_SPI_IRQ_PREEMPT_PRIO 1
#define PDEF_ADCS_SPI_IRQ_SUB_PRIO 0
#define PDEF_DACS_SPI_IRQ_PREEMPT_PRIO 1
#define PDEF_DACS_SPI_IRQ_SUB_PRIO 0
#define PDEF_CHARGE_PUMP_DAC_SPI_IRQ_PREEMPT_PRIO 1
#define PDEF_CHARGE_PUMP_DAC_SPI_IRQ_SUB_PRIO 0
#define PDEF_CRC_DMA_IRQ_PREEMPT_PRIO 1
#define PDEF_CRC_DMA_IRQ_SUB_PRIO 0
#define PDEF_FLASH_IRQ_PREEMPT_PRIO 1
#define PDEF_FLASH_IRQ_SUB_PRIO 0
#define PDEF_SVC_IRQ_PREEMPT_PRIO 14 // must be one preempt prio higher than PendSV
#define PDEF_SVC_IRQ_SUB_PRIO 0
#define PDEF_PENDSV_IRQ_PREEMPT_PRIO 15 // lowest priority = same as systick
#define PDEF_PENDSV_IRQ_SUB_PRIO 0
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,198 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Standard definitions (data types, structures etc.)
// Filename: SDEF_StandardDefinitions.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This header file contains the data type definitions. These definitions must be
// used by all modules. Furthermore all global definitions, structures,
// enumerations, etc. are collected inside this file
//
//=================================================================================================
#ifndef STANDARD_DEFINITIONS_H_INCLUDED
#define STANDARD_DEFINITIONS_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
#define SDEF_S32MAX ((S32)(2147483647)) // Max S32 value
#define SDEF_S32MIN ((S32)(-2147483647 - 1) // Min S32 value
#define SDEF_U32MAX ((U32)(0xFFFFFFFF)) // Max U32 value
#define SDEF_S16MAX ((S16)(32767)) // Max U16 value
#define SDEF_S16MIN ((S16)(-32767 - 1)) // Min S16 value
#define SDEF_U16MAX ((U16)(0xFFFF)) // Max S16 value
//=================================================================================================
// DATA TYPES: Definition of standard data types to be used by all modules.
//
// Prefixes: Each data type has its own prefix (see data type definitions below).
// Other definitions are:
// XXXX_ Module identifer and file name. Example: "RTCK_RealtimeClock.c". The
// identifer is also used for global (public) definitions inside the module.
// g_ Global scope (variables). Example: "g_u32ElapsedTime".
// m_ Module scope (variables). Example: "m_u32ElapsedTime".
// a Array.
// p Pointer.
// pfn Pointer to function.
// St Definition of a structure.
// st Instance of a structure. Example:
// typedef struct
// {
// S32 s32CurrentMainsL1;
// S32 s32CurrentMainsL2;
// S32 s32CurrentMainsL3;
// } StMainsCurrent;
// StMainsCurrent m_stMainsCurrent;
// En Definition of an enumneration.
// e Member of an enumeration.
// en Instance of an enumeration. Example:
// typedef enum
// {
// eDeviceIdle = 0,
// eDeviceActive,
// } EnDeviceState;
// EnDeviceState m_enDeviceState = eDeviceIdle;
//
// Example: module scope, array of enums:
// m_aenInputs[] = [ eInput1, eInput2, eInput3];
//=================================================================================================
// Allow direct access to variables and functions while unit testing using GCC. This makes
// writing the test script much easier. The definition of the datatypes makes the code protable.
#define LOCAL static // m_ Local data type and visible within the
// actual file only
#define PRIVATE static // Private function and visible within the
// actual file only
#define INLINE __inline // force the compiler to inline the function
#define EXTERN extern // Defined at external level
#define CONST const // Constant data definition
#define VOLATILE volatile // Not to be placed in register
#define VOID void // v Void type
typedef VOID* PVOID; // pv Pointer to void type
typedef char CHAR; // c Character
typedef CHAR* PCHAR; // pc Pointer to character
typedef CHAR* PSZ; // psz Pointer to zero terminated string
typedef CONST CHAR* PSZC; // psz Pointer to constant zero terminated string
typedef unsigned char U8; // u8 Unsigned byte (DSP is 16 bit anyway)
typedef U8* PU8; // pu8 Pointer to unsigned byte
typedef signed char S8; // s8 Signed byte (DSP is 16 bit anyway)
typedef S8* PS8; // ps8 Pointer to signed byte
typedef unsigned short int U16; // u16 Unsigned short integer
typedef U16* PU16; // pu16 Pointer to unsigned short integer
typedef signed short int S16; // s16 Signed short integer
typedef S16* PS16; // ps16 Pointer to signed short integer
typedef long unsigned int U32; // u32 Unsigned integer
typedef U32* PU32; // pu32 Pointer to unsigned int integer
typedef long signed int S32; // s32 Signed integer
typedef S32* PS32; // ps32 Pointer to signed integer
typedef unsigned long long U64; // u64 Unsigned long long integer
typedef U64* PU64; // pu64 Pointer to unsigned long long integer
typedef signed long long S64; // s64 Signed long long integer
typedef S64* PS64; // ps64 Pointer to signed long long integer
typedef float FLOAT; // fl Float data type (32 bit)
typedef FLOAT* PFLOAT; // pfl Pointer to float
typedef double DOUBLE; // db Double data type (64 bit)
typedef DOUBLE* PDOUBLE; // pdb Pointer to double
typedef U32 BOOL; // bo Boolean
typedef BOOL* PBOOL; // pbo Pointer to bool data type
#ifndef FALSE
#define FALSE 0 // False --> must be zero,
#endif
#ifndef TRUE
#define TRUE 1 // True --> must be one
#endif
#ifndef NULL
#define NULL ((VOID *) 0)
#endif
#define __NORETURN __attribute__((noreturn)) // funciton attribute, function does not return
typedef enum
{
SDEF_eNormalByteOrder = 0,
SDEF_eReverseByteOrder = 1,
} SDEF_EnByteOrder;
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
#ifdef __cplusplus
}
#endif
#endif

61
Core/Src/freertos.c Normal file
View File

@ -0,0 +1,61 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : freertos.c
* Description : Code for freertos applications
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* 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 ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
/* USER CODE END Variables */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
/* USER CODE END FunctionPrototypes */
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
/* USER CODE END Application */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

547
Core/Src/main.c Normal file
View File

@ -0,0 +1,547 @@
/* USER CODE BEGIN Header */
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqué (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Filename: main.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions for starting the PeltierController
//
//=================================================================================================
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "../Application/INIT_Initialization.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 ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;
CAN_HandleTypeDef hcan1;
DAC_HandleTypeDef hdac1;
SPI_HandleTypeDef hspi1;
DMA_HandleTypeDef hdma_spi1_rx;
DMA_HandleTypeDef hdma_spi1_tx;
/* Definitions for Default */
osThreadId_t DefaultHandle;
const osThreadAttr_t Default_attributes = {
.name = "Default",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* 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_ADC1_Init(void);
static void MX_CAN1_Init(void);
static void MX_DAC1_Init(void);
static void MX_SPI1_Init(void);
void vDefaultTask(void *argument);
/* 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_ADC1_Init();
MX_CAN1_Init();
MX_DAC1_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Init scheduler */
osKernelInitialize();
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* creation of Default */
DefaultHandle = osThreadNew(vDefaultTask, NULL, &Default_attributes);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */
/* USER CODE END RTOS_EVENTS */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* 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};
/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != 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 = 4;
RCC_OscInitStruct.PLL.PLLN = 16;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief ADC1 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.NbrOfConversion = 5;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_6;
sConfig.Rank = ADC_REGULAR_RANK_2;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_16;
sConfig.Rank = ADC_REGULAR_RANK_3;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_7;
sConfig.Rank = ADC_REGULAR_RANK_4;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_15;
sConfig.Rank = ADC_REGULAR_RANK_5;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
/**
* @brief CAN1 Initialization Function
* @param None
* @retval None
*/
static void MX_CAN1_Init(void)
{
/* USER CODE BEGIN CAN1_Init 0 */
/* USER CODE END CAN1_Init 0 */
/* USER CODE BEGIN CAN1_Init 1 */
/* USER CODE END CAN1_Init 1 */
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 16;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_3TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN1_Init 2 */
/* USER CODE END CAN1_Init 2 */
}
/**
* @brief DAC1 Initialization Function
* @param None
* @retval None
*/
static void MX_DAC1_Init(void)
{
/* USER CODE BEGIN DAC1_Init 0 */
/* USER CODE END DAC1_Init 0 */
DAC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN DAC1_Init 1 */
/* USER CODE END DAC1_Init 1 */
/** DAC Initialization
*/
hdac1.Instance = DAC1;
if (HAL_DAC_Init(&hdac1) != HAL_OK)
{
Error_Handler();
}
/** DAC channel OUT1 config
*/
sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN DAC1_Init 2 */
/* USER CODE END DAC1_Init 2 */
}
/**
* @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_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */
/* USER CODE END SPI1_Init 2 */
}
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel2_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn);
/* DMA1_Channel3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
/* DMA2_Channel3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Channel3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(DMA2_Channel3_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();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, EN_Pin|LED_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, CS1_Pin|CS2_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : EN_Pin LED_Pin */
GPIO_InitStruct.Pin = EN_Pin|LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : ADR0_Pin */
GPIO_InitStruct.Pin = ADR0_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(ADR0_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : ADR1_Pin ADR2_Pin PG_Pin */
GPIO_InitStruct.Pin = ADR1_Pin|ADR2_Pin|PG_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : CS1_Pin CS2_Pin */
GPIO_InitStruct.Pin = CS1_Pin|CS2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/* USER CODE BEGIN Header_vDefaultTask */
/**
* @brief Function implementing the Default thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_vDefaultTask */
void vDefaultTask(void *argument)
{
/* USER CODE BEGIN 5 */
INIT_boCreateTask();
osThreadSuspend( DefaultHandle );
/* USER CODE END 5 */
}
/**
* @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 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,455 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32l4xx_hal_msp.c
* @brief This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 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
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern DMA_HandleTypeDef hdma_adc1;
extern DMA_HandleTypeDef hdma_spi1_rx;
extern DMA_HandleTypeDef hdma_spi1_tx;
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
/* System interrupt init*/
/* PendSV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/**
* @brief ADC MSP Initialization
* This function configures the hardware resources used in this example
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hadc->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspInit 0 */
/* USER CODE END ADC1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_ADC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**ADC1 GPIO Configuration
PA1 ------> ADC1_IN6
PA2 ------> ADC1_IN7
PA3 ------> ADC1_IN8
PB0 ------> ADC1_IN15
PB1 ------> ADC1_IN16
*/
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* ADC1 DMA Init */
/* ADC1 Init */
hdma_adc1.Instance = DMA2_Channel3;
hdma_adc1.Init.Request = DMA_REQUEST_0;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_adc1.Init.Mode = DMA_CIRCULAR;
hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH;
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
/* ADC1 interrupt Init */
HAL_NVIC_SetPriority(ADC1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(ADC1_IRQn);
/* USER CODE BEGIN ADC1_MspInit 1 */
/* USER CODE END ADC1_MspInit 1 */
}
}
/**
* @brief ADC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hadc: ADC handle pointer
* @retval None
*/
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
{
if(hadc->Instance==ADC1)
{
/* USER CODE BEGIN ADC1_MspDeInit 0 */
/* USER CODE END ADC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_ADC_CLK_DISABLE();
/**ADC1 GPIO Configuration
PA1 ------> ADC1_IN6
PA2 ------> ADC1_IN7
PA3 ------> ADC1_IN8
PB0 ------> ADC1_IN15
PB1 ------> ADC1_IN16
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1);
/* ADC1 DMA DeInit */
HAL_DMA_DeInit(hadc->DMA_Handle);
/* ADC1 interrupt DeInit */
HAL_NVIC_DisableIRQ(ADC1_IRQn);
/* USER CODE BEGIN ADC1_MspDeInit 1 */
/* USER CODE END ADC1_MspDeInit 1 */
}
}
/**
* @brief CAN MSP Initialization
* This function configures the hardware resources used in this example
* @param hcan: CAN handle pointer
* @retval None
*/
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hcan->Instance==CAN1)
{
/* USER CODE BEGIN CAN1_MspInit 0 */
/* USER CODE END CAN1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_CAN1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**CAN1 GPIO Configuration
PA11 ------> CAN1_RX
PA12 ------> CAN1_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* CAN1 interrupt Init */
HAL_NVIC_SetPriority(CAN1_TX_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
HAL_NVIC_SetPriority(CAN1_RX1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_RX1_IRQn);
HAL_NVIC_SetPriority(CAN1_SCE_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_SCE_IRQn);
/* USER CODE BEGIN CAN1_MspInit 1 */
/* USER CODE END CAN1_MspInit 1 */
}
}
/**
* @brief CAN MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hcan: CAN handle pointer
* @retval None
*/
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
{
if(hcan->Instance==CAN1)
{
/* USER CODE BEGIN CAN1_MspDeInit 0 */
/* USER CODE END CAN1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_CAN1_CLK_DISABLE();
/**CAN1 GPIO Configuration
PA11 ------> CAN1_RX
PA12 ------> CAN1_TX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
/* CAN1 interrupt DeInit */
HAL_NVIC_DisableIRQ(CAN1_TX_IRQn);
HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn);
HAL_NVIC_DisableIRQ(CAN1_RX1_IRQn);
HAL_NVIC_DisableIRQ(CAN1_SCE_IRQn);
/* USER CODE BEGIN CAN1_MspDeInit 1 */
/* USER CODE END CAN1_MspDeInit 1 */
}
}
/**
* @brief DAC MSP Initialization
* This function configures the hardware resources used in this example
* @param hdac: DAC handle pointer
* @retval None
*/
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hdac->Instance==DAC1)
{
/* USER CODE BEGIN DAC1_MspInit 0 */
/* USER CODE END DAC1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_DAC1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**DAC1 GPIO Configuration
PA4 ------> DAC1_OUT1
*/
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN DAC1_MspInit 1 */
/* USER CODE END DAC1_MspInit 1 */
}
}
/**
* @brief DAC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hdac: DAC handle pointer
* @retval None
*/
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
{
if(hdac->Instance==DAC1)
{
/* USER CODE BEGIN DAC1_MspDeInit 0 */
/* USER CODE END DAC1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_DAC1_CLK_DISABLE();
/**DAC1 GPIO Configuration
PA4 ------> DAC1_OUT1
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4);
/* USER CODE BEGIN DAC1_MspDeInit 1 */
/* USER CODE END DAC1_MspDeInit 1 */
}
}
/**
* @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();
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
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);
/* SPI1 DMA Init */
/* SPI1_RX Init */
hdma_spi1_rx.Instance = DMA1_Channel2;
hdma_spi1_rx.Init.Request = DMA_REQUEST_1;
hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_spi1_rx.Init.Mode = DMA_NORMAL;
hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hspi,hdmarx,hdma_spi1_rx);
/* SPI1_TX Init */
hdma_spi1_tx.Instance = DMA1_Channel3;
hdma_spi1_tx.Init.Request = DMA_REQUEST_1;
hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_spi1_tx.Init.Mode = DMA_NORMAL;
hdma_spi1_tx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(hspi,hdmatx,hdma_spi1_tx);
/* SPI1 interrupt Init */
HAL_NVIC_SetPriority(SPI1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(SPI1_IRQn);
/* 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
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
/* SPI1 DMA DeInit */
HAL_DMA_DeInit(hspi->hdmarx);
HAL_DMA_DeInit(hspi->hdmatx);
/* SPI1 interrupt DeInit */
HAL_NVIC_DisableIRQ(SPI1_IRQn);
/* USER CODE BEGIN SPI1_MspDeInit 1 */
/* USER CODE END SPI1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

320
Core/Src/stm32l4xx_it.c Normal file
View File

@ -0,0 +1,320 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32l4xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 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
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32l4xx_it.h"
#include "FreeRTOS.h"
#include "task.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
extern DMA_HandleTypeDef hdma_adc1;
extern ADC_HandleTypeDef hadc1;
extern CAN_HandleTypeDef hcan1;
extern DMA_HandleTypeDef hdma_spi1_rx;
extern DMA_HandleTypeDef hdma_spi1_tx;
extern SPI_HandleTypeDef hspi1;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @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 */
}
/**
* @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 */
}
}
/**
* @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 */
}
}
/**
* @brief This function handles Prefetch 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 */
}
}
/**
* @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 */
}
}
/**
* @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 1 */
}
/**
* @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();
#if (INCLUDE_xTaskGetSchedulerState == 1 )
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
{
#endif /* INCLUDE_xTaskGetSchedulerState */
xPortSysTickHandler();
#if (INCLUDE_xTaskGetSchedulerState == 1 )
}
#endif /* INCLUDE_xTaskGetSchedulerState */
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32L4xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32l4xx.s). */
/******************************************************************************/
/**
* @brief This function handles DMA1 channel2 global interrupt.
*/
void DMA1_Channel2_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel2_IRQn 0 */
/* USER CODE END DMA1_Channel2_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_spi1_rx);
/* USER CODE BEGIN DMA1_Channel2_IRQn 1 */
/* USER CODE END DMA1_Channel2_IRQn 1 */
}
/**
* @brief This function handles DMA1 channel3 global interrupt.
*/
void DMA1_Channel3_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel3_IRQn 0 */
/* USER CODE END DMA1_Channel3_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_spi1_tx);
/* USER CODE BEGIN DMA1_Channel3_IRQn 1 */
/* USER CODE END DMA1_Channel3_IRQn 1 */
}
/**
* @brief This function handles ADC1 global interrupt.
*/
void ADC1_IRQHandler(void)
{
/* USER CODE BEGIN ADC1_IRQn 0 */
/* USER CODE END ADC1_IRQn 0 */
HAL_ADC_IRQHandler(&hadc1);
/* USER CODE BEGIN ADC1_IRQn 1 */
/* USER CODE END ADC1_IRQn 1 */
}
/**
* @brief This function handles CAN1 TX interrupt.
*/
void CAN1_TX_IRQHandler(void)
{
/* USER CODE BEGIN CAN1_TX_IRQn 0 */
/* USER CODE END CAN1_TX_IRQn 0 */
HAL_CAN_IRQHandler(&hcan1);
/* USER CODE BEGIN CAN1_TX_IRQn 1 */
/* USER CODE END CAN1_TX_IRQn 1 */
}
/**
* @brief This function handles CAN1 RX0 interrupt.
*/
void CAN1_RX0_IRQHandler(void)
{
/* USER CODE BEGIN CAN1_RX0_IRQn 0 */
/* USER CODE END CAN1_RX0_IRQn 0 */
HAL_CAN_IRQHandler(&hcan1);
/* USER CODE BEGIN CAN1_RX0_IRQn 1 */
/* USER CODE END CAN1_RX0_IRQn 1 */
}
/**
* @brief This function handles CAN1 RX1 interrupt.
*/
void CAN1_RX1_IRQHandler(void)
{
/* USER CODE BEGIN CAN1_RX1_IRQn 0 */
/* USER CODE END CAN1_RX1_IRQn 0 */
HAL_CAN_IRQHandler(&hcan1);
/* USER CODE BEGIN CAN1_RX1_IRQn 1 */
/* USER CODE END CAN1_RX1_IRQn 1 */
}
/**
* @brief This function handles CAN1 SCE interrupt.
*/
void CAN1_SCE_IRQHandler(void)
{
/* USER CODE BEGIN CAN1_SCE_IRQn 0 */
/* USER CODE END CAN1_SCE_IRQn 0 */
HAL_CAN_IRQHandler(&hcan1);
/* USER CODE BEGIN CAN1_SCE_IRQn 1 */
/* USER CODE END CAN1_SCE_IRQn 1 */
}
/**
* @brief This function handles SPI1 global interrupt.
*/
void SPI1_IRQHandler(void)
{
/* USER CODE BEGIN SPI1_IRQn 0 */
/* USER CODE END SPI1_IRQn 0 */
HAL_SPI_IRQHandler(&hspi1);
/* USER CODE BEGIN SPI1_IRQn 1 */
/* USER CODE END SPI1_IRQn 1 */
}
/**
* @brief This function handles DMA2 channel3 global interrupt.
*/
void DMA2_Channel3_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Channel3_IRQn 0 */
/* USER CODE END DMA2_Channel3_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_adc1);
/* USER CODE BEGIN DMA2_Channel3_IRQn 1 */
/* USER CODE END DMA2_Channel3_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

156
Core/Src/syscalls.c Normal file
View File

@ -0,0 +1,156 @@
/**
******************************************************************************
* @file syscalls.c
* @author Auto-generated by STM32CubeIDE
* @brief STM32CubeIDE Minimal System calls file
*
* For more information about which c-functions
* need which of these lowlevel functions
* please consult the Newlib libc-manual
******************************************************************************
* @attention
*
* <h2><center>&copy; 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
*
******************************************************************************
*/
/* Includes */
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
/* Variables */
extern int __io_putchar(int ch) __attribute__((weak));
extern int __io_getchar(void) __attribute__((weak));
char *__env[1] = { 0 };
char **environ = __env;
/* Functions */
void initialise_monitor_handles()
{
}
int _getpid(void)
{
return 1;
}
int _kill(int pid, int sig)
{
errno = EINVAL;
return -1;
}
void _exit (int status)
{
_kill(status, -1);
while (1) {} /* Make sure we hang here */
}
__attribute__((weak)) int _read(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = __io_getchar();
}
return len;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}
int _close(int file)
{
return -1;
}
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _isatty(int file)
{
return 1;
}
int _lseek(int file, int ptr, int dir)
{
return 0;
}
int _open(char *path, int flags, ...)
{
/* Pretend like we always fail */
return -1;
}
int _wait(int *status)
{
errno = ECHILD;
return -1;
}
int _unlink(char *name)
{
errno = ENOENT;
return -1;
}
int _times(struct tms *buf)
{
return -1;
}
int _stat(char *file, struct stat *st)
{
st->st_mode = S_IFCHR;
return 0;
}
int _link(char *old, char *new)
{
errno = EMLINK;
return -1;
}
int _fork(void)
{
errno = EAGAIN;
return -1;
}
int _execve(char *name, char **argv, char **env)
{
errno = ENOMEM;
return -1;
}

80
Core/Src/sysmem.c Normal file
View File

@ -0,0 +1,80 @@
/**
******************************************************************************
* @file sysmem.c
* @author Generated by STM32CubeIDE
* @brief STM32CubeIDE System Memory calls file
*
* For more information about which C functions
* need which of these lowlevel functions
* please consult the newlib libc manual
******************************************************************************
* @attention
*
* <h2><center>&copy; 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
*
******************************************************************************
*/
/* Includes */
#include <errno.h>
#include <stdint.h>
/**
* Pointer to the current high watermark of the heap usage
*/
static uint8_t *__sbrk_heap_end = NULL;
/**
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
* and others from the C library
*
* @verbatim
* ############################################################################
* # .data # .bss # newlib heap # MSP stack #
* # # # # Reserved by _Min_Stack_Size #
* ############################################################################
* ^-- RAM start ^-- _end _estack, RAM end --^
* @endverbatim
*
* This implementation starts allocating at the '_end' linker symbol
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
* The implementation considers '_estack' linker symbol to be RAM end
* NOTE: If the MSP stack, at any point during execution, grows larger than the
* reserved size, please increase the '_Min_Stack_Size'.
*
* @param incr Memory size
* @return Pointer to allocated memory
*/
void *_sbrk(ptrdiff_t incr)
{
extern uint8_t _end; /* Symbol defined in the linker script */
extern uint8_t _estack; /* Symbol defined in the linker script */
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
const uint8_t *max_heap = (uint8_t *)stack_limit;
uint8_t *prev_heap_end;
/* Initialize heap end at first call */
if (NULL == __sbrk_heap_end)
{
__sbrk_heap_end = &_end;
}
/* Protect heap from growing into the reserved MSP stack */
if (__sbrk_heap_end + incr > max_heap)
{
errno = ENOMEM;
return (void *)-1;
}
prev_heap_end = __sbrk_heap_end;
__sbrk_heap_end += incr;
return (void *)prev_heap_end;
}

352
Core/Src/system_stm32l4xx.c Normal file
View File

@ -0,0 +1,352 @@
/**
******************************************************************************
* @file system_stm32l4xx.c
* @author MCD Application Team
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File
*
* This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32l4xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* After each device reset the MSI (4 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32l4xx.s" file, to
* configure the system clock before to branch to main program.
*
* This file configures the system clock as follows:
*=============================================================================
*-----------------------------------------------------------------------------
* System Clock source | MSI
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 4000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 4000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 1
*-----------------------------------------------------------------------------
* APB2 Prescaler | 1
*-----------------------------------------------------------------------------
* PLL_M | 1
*-----------------------------------------------------------------------------
* PLL_N | 8
*-----------------------------------------------------------------------------
* PLL_P | 7
*-----------------------------------------------------------------------------
* PLL_Q | 2
*-----------------------------------------------------------------------------
* PLL_R | 2
*-----------------------------------------------------------------------------
* PLLSAI1_P | NA
*-----------------------------------------------------------------------------
* PLLSAI1_Q | NA
*-----------------------------------------------------------------------------
* PLLSAI1_R | NA
*-----------------------------------------------------------------------------
* PLLSAI2_P | NA
*-----------------------------------------------------------------------------
* PLLSAI2_Q | NA
*-----------------------------------------------------------------------------
* PLLSAI2_R | NA
*-----------------------------------------------------------------------------
* Require 48MHz for USB OTG FS, | Disabled
* SDIO and RNG clock |
*-----------------------------------------------------------------------------
*=============================================================================
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Apache License, Version 2.0,
* 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/Apache-2.0
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32l4xx_system
* @{
*/
/** @addtogroup STM32L4xx_System_Private_Includes
* @{
*/
#include "stm32l4xx.h"
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_Defines
* @{
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (MSI_VALUE)
#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/
#endif /* MSI_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/* Note: Following vector table addresses must be defined in line with linker
configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
anywhere in Flash or Sram, else the vector table is kept at the automatic
remap of boot address selected */
/* #define USER_VECT_TAB_ADDRESS */
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM1_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_Variables
* @{
*/
/* The SystemCoreClock variable is updated in three ways:
1) by calling CMSIS function SystemCoreClockUpdate()
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
Note: If you use this function to configure the system clock; then there
is no need to call the 2 first functions listed above, since SystemCoreClock
variable is updated automatically.
*/
uint32_t SystemCoreClock = 4000000U;
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
const uint32_t MSIRangeTable[12] = {100000U, 200000U, 400000U, 800000U, 1000000U, 2000000U, \
4000000U, 8000000U, 16000000U, 24000000U, 32000000U, 48000000U};
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system.
* @retval None
*/
void SystemInit(void)
{
#if defined(USER_VECT_TAB_ADDRESS)
/* Configure the Vector Table location -------------------------------------*/
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
#endif
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 20U)|(3UL << 22U)); /* set CP10 and CP11 Full Access */
#endif
/* Reset the RCC clock configuration to the default reset state ------------*/
/* Set MSION bit */
RCC->CR |= RCC_CR_MSION;
/* Reset CFGR register */
RCC->CFGR = 0x00000000U;
/* Reset HSEON, CSSON , HSION, and PLLON bits */
RCC->CR &= 0xEAF6FFFFU;
/* Reset PLLCFGR register */
RCC->PLLCFGR = 0x00001000U;
/* Reset HSEBYP bit */
RCC->CR &= 0xFFFBFFFFU;
/* Disable all interrupts */
RCC->CIER = 0x00000000U;
}
/**
* @brief Update SystemCoreClock variable according to Clock Register Values.
* The SystemCoreClock variable contains the core clock (HCLK), it can
* be used by the user application to setup the SysTick timer or configure
* other parameters.
*
* @note Each time the core clock (HCLK) changes, this function must be called
* to update SystemCoreClock variable value. Otherwise, any configuration
* based on this variable will be incorrect.
*
* @note - The system frequency computed by this function is not the real
* frequency in the chip. It is calculated based on the predefined
* constant and the selected clock source:
*
* - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*)
*
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
*
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
*
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
* or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors.
*
* (*) MSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
* 4 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (**) HSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
* 16 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (***) HSE_VALUE is a constant defined in stm32l4xx_hal.h file (default value
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
* frequency of the crystal used. Otherwise, this function may
* have wrong result.
*
* - The result of this function could be not correct when using fractional
* value for HSE crystal.
*
* @retval None
*/
void SystemCoreClockUpdate(void)
{
uint32_t tmp, msirange, pllvco, pllsource, pllm, pllr;
/* Get MSI Range frequency--------------------------------------------------*/
if ((RCC->CR & RCC_CR_MSIRGSEL) == 0U)
{ /* MSISRANGE from RCC_CSR applies */
msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U;
}
else
{ /* MSIRANGE from RCC_CR applies */
msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U;
}
/*MSI frequency range in HZ*/
msirange = MSIRangeTable[msirange];
/* Get SYSCLK source -------------------------------------------------------*/
switch (RCC->CFGR & RCC_CFGR_SWS)
{
case 0x00: /* MSI used as system clock source */
SystemCoreClock = msirange;
break;
case 0x04: /* HSI used as system clock source */
SystemCoreClock = HSI_VALUE;
break;
case 0x08: /* HSE used as system clock source */
SystemCoreClock = HSE_VALUE;
break;
case 0x0C: /* PLL used as system clock source */
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
SYSCLK = PLL_VCO / PLLR
*/
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U ;
switch (pllsource)
{
case 0x02: /* HSI used as PLL clock source */
pllvco = (HSI_VALUE / pllm);
break;
case 0x03: /* HSE used as PLL clock source */
pllvco = (HSE_VALUE / pllm);
break;
default: /* MSI used as PLL clock source */
pllvco = (msirange / pllm);
break;
}
pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U);
pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U;
SystemCoreClock = pllvco/pllr;
break;
default:
SystemCoreClock = msirange;
break;
}
/* Compute HCLK clock frequency --------------------------------------------*/
/* Get HCLK prescaler */
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
/* HCLK clock frequency */
SystemCoreClock >>= tmp;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,447 @@
/**
******************************************************************************
* @file startup_stm32l432xx.s
* @author MCD Application Team
* @brief STM32L432xx devices vector table for GCC toolchain.
* This module performs:
* - Set the initial SP
* - Set the initial PC == Reset_Handler,
* - Set the vector table entries with the exceptions ISR address,
* - Configure the clock system
* - Branches to main in the C library (which eventually
* calls main()).
* After Reset the Cortex-M4 processor is in Thread mode,
* priority is Privileged, and the Stack is set to Main.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Apache License, Version 2.0,
* 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/Apache-2.0
*
******************************************************************************
*/
.syntax unified
.cpu cortex-m4
.fpu softvfp
.thumb
.global g_pfnVectors
.global Default_Handler
/* start address for the initialization values of the .data section.
defined in linker script */
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
.equ BootRAM, 0xF1E0F85F
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
.section .text.Reset_Handler
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
ldr sp, =_estack /* Set stack pointer */
/* Call the clock system initialization function.*/
bl SystemInit
/* Copy the data segment initializers from flash to SRAM */
movs r1, #0
b LoopCopyDataInit
CopyDataInit:
ldr r3, =_sidata
ldr r3, [r3, r1]
str r3, [r0, r1]
adds r1, r1, #4
LoopCopyDataInit:
ldr r0, =_sdata
ldr r3, =_edata
adds r2, r0, r1
cmp r2, r3
bcc CopyDataInit
ldr r2, =_sbss
b LoopFillZerobss
/* Zero fill the bss segment. */
FillZerobss:
movs r3, #0
str r3, [r2], #4
LoopFillZerobss:
ldr r3, = _ebss
cmp r2, r3
bcc FillZerobss
/* Call static constructors */
bl __libc_init_array
/* Call the application's entry point.*/
bl main
LoopForever:
b LoopForever
.size Reset_Handler, .-Reset_Handler
/**
* @brief This is the code that gets called when the processor receives an
* unexpected interrupt. This simply enters an infinite loop, preserving
* the system state for examination by a debugger.
*
* @param None
* @retval : None
*/
.section .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
b Infinite_Loop
.size Default_Handler, .-Default_Handler
/******************************************************************************
*
* The minimal vector table for a Cortex-M4. Note that the proper constructs
* must be placed on this to ensure that it ends up at physical address
* 0x0000.0000.
*
******************************************************************************/
.section .isr_vector,"a",%progbits
.type g_pfnVectors, %object
.size g_pfnVectors, .-g_pfnVectors
g_pfnVectors:
.word _estack
.word Reset_Handler
.word NMI_Handler
.word HardFault_Handler
.word MemManage_Handler
.word BusFault_Handler
.word UsageFault_Handler
.word 0
.word 0
.word 0
.word 0
.word SVC_Handler
.word DebugMon_Handler
.word 0
.word PendSV_Handler
.word SysTick_Handler
.word WWDG_IRQHandler
.word PVD_PVM_IRQHandler
.word TAMP_STAMP_IRQHandler
.word RTC_WKUP_IRQHandler
.word FLASH_IRQHandler
.word RCC_IRQHandler
.word EXTI0_IRQHandler
.word EXTI1_IRQHandler
.word EXTI2_IRQHandler
.word EXTI3_IRQHandler
.word EXTI4_IRQHandler
.word DMA1_Channel1_IRQHandler
.word DMA1_Channel2_IRQHandler
.word DMA1_Channel3_IRQHandler
.word DMA1_Channel4_IRQHandler
.word DMA1_Channel5_IRQHandler
.word DMA1_Channel6_IRQHandler
.word DMA1_Channel7_IRQHandler
.word ADC1_IRQHandler
.word CAN1_TX_IRQHandler
.word CAN1_RX0_IRQHandler
.word CAN1_RX1_IRQHandler
.word CAN1_SCE_IRQHandler
.word EXTI9_5_IRQHandler
.word TIM1_BRK_TIM15_IRQHandler
.word TIM1_UP_TIM16_IRQHandler
.word TIM1_TRG_COM_IRQHandler
.word TIM1_CC_IRQHandler
.word TIM2_IRQHandler
.word 0
.word 0
.word I2C1_EV_IRQHandler
.word I2C1_ER_IRQHandler
.word 0
.word 0
.word SPI1_IRQHandler
.word 0
.word USART1_IRQHandler
.word USART2_IRQHandler
.word 0
.word EXTI15_10_IRQHandler
.word RTC_Alarm_IRQHandler
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word SPI3_IRQHandler
.word 0
.word 0
.word TIM6_DAC_IRQHandler
.word TIM7_IRQHandler
.word DMA2_Channel1_IRQHandler
.word DMA2_Channel2_IRQHandler
.word DMA2_Channel3_IRQHandler
.word DMA2_Channel4_IRQHandler
.word DMA2_Channel5_IRQHandler
.word 0
.word 0
.word 0
.word COMP_IRQHandler
.word LPTIM1_IRQHandler
.word LPTIM2_IRQHandler
.word USB_IRQHandler
.word DMA2_Channel6_IRQHandler
.word DMA2_Channel7_IRQHandler
.word LPUART1_IRQHandler
.word QUADSPI_IRQHandler
.word I2C3_EV_IRQHandler
.word I2C3_ER_IRQHandler
.word SAI1_IRQHandler
.word 0
.word SWPMI1_IRQHandler
.word TSC_IRQHandler
.word 0
.word 0
.word RNG_IRQHandler
.word FPU_IRQHandler
.word CRS_IRQHandler
/*******************************************************************************
*
* Provide weak aliases for each Exception handler to the Default_Handler.
* As they are weak aliases, any function with the same name will override
* this definition.
*
*******************************************************************************/
.weak NMI_Handler
.thumb_set NMI_Handler,Default_Handler
.weak HardFault_Handler
.thumb_set HardFault_Handler,Default_Handler
.weak MemManage_Handler
.thumb_set MemManage_Handler,Default_Handler
.weak BusFault_Handler
.thumb_set BusFault_Handler,Default_Handler
.weak UsageFault_Handler
.thumb_set UsageFault_Handler,Default_Handler
.weak SVC_Handler
.thumb_set SVC_Handler,Default_Handler
.weak DebugMon_Handler
.thumb_set DebugMon_Handler,Default_Handler
.weak PendSV_Handler
.thumb_set PendSV_Handler,Default_Handler
.weak SysTick_Handler
.thumb_set SysTick_Handler,Default_Handler
.weak WWDG_IRQHandler
.thumb_set WWDG_IRQHandler,Default_Handler
.weak PVD_PVM_IRQHandler
.thumb_set PVD_PVM_IRQHandler,Default_Handler
.weak TAMP_STAMP_IRQHandler
.thumb_set TAMP_STAMP_IRQHandler,Default_Handler
.weak RTC_WKUP_IRQHandler
.thumb_set RTC_WKUP_IRQHandler,Default_Handler
.weak FLASH_IRQHandler
.thumb_set FLASH_IRQHandler,Default_Handler
.weak RCC_IRQHandler
.thumb_set RCC_IRQHandler,Default_Handler
.weak EXTI0_IRQHandler
.thumb_set EXTI0_IRQHandler,Default_Handler
.weak EXTI1_IRQHandler
.thumb_set EXTI1_IRQHandler,Default_Handler
.weak EXTI2_IRQHandler
.thumb_set EXTI2_IRQHandler,Default_Handler
.weak EXTI3_IRQHandler
.thumb_set EXTI3_IRQHandler,Default_Handler
.weak EXTI4_IRQHandler
.thumb_set EXTI4_IRQHandler,Default_Handler
.weak DMA1_Channel1_IRQHandler
.thumb_set DMA1_Channel1_IRQHandler,Default_Handler
.weak DMA1_Channel2_IRQHandler
.thumb_set DMA1_Channel2_IRQHandler,Default_Handler
.weak DMA1_Channel3_IRQHandler
.thumb_set DMA1_Channel3_IRQHandler,Default_Handler
.weak DMA1_Channel4_IRQHandler
.thumb_set DMA1_Channel4_IRQHandler,Default_Handler
.weak DMA1_Channel5_IRQHandler
.thumb_set DMA1_Channel5_IRQHandler,Default_Handler
.weak DMA1_Channel6_IRQHandler
.thumb_set DMA1_Channel6_IRQHandler,Default_Handler
.weak DMA1_Channel7_IRQHandler
.thumb_set DMA1_Channel7_IRQHandler,Default_Handler
.weak ADC1_IRQHandler
.thumb_set ADC1_IRQHandler,Default_Handler
.weak CAN1_TX_IRQHandler
.thumb_set CAN1_TX_IRQHandler,Default_Handler
.weak CAN1_RX0_IRQHandler
.thumb_set CAN1_RX0_IRQHandler,Default_Handler
.weak CAN1_RX1_IRQHandler
.thumb_set CAN1_RX1_IRQHandler,Default_Handler
.weak CAN1_SCE_IRQHandler
.thumb_set CAN1_SCE_IRQHandler,Default_Handler
.weak EXTI9_5_IRQHandler
.thumb_set EXTI9_5_IRQHandler,Default_Handler
.weak TIM1_BRK_TIM15_IRQHandler
.thumb_set TIM1_BRK_TIM15_IRQHandler,Default_Handler
.weak TIM1_UP_TIM16_IRQHandler
.thumb_set TIM1_UP_TIM16_IRQHandler,Default_Handler
.weak TIM1_TRG_COM_IRQHandler
.thumb_set TIM1_TRG_COM_IRQHandler,Default_Handler
.weak TIM1_CC_IRQHandler
.thumb_set TIM1_CC_IRQHandler,Default_Handler
.weak TIM2_IRQHandler
.thumb_set TIM2_IRQHandler,Default_Handler
.weak I2C1_EV_IRQHandler
.thumb_set I2C1_EV_IRQHandler,Default_Handler
.weak I2C1_ER_IRQHandler
.thumb_set I2C1_ER_IRQHandler,Default_Handler
.weak SPI1_IRQHandler
.thumb_set SPI1_IRQHandler,Default_Handler
.weak USART1_IRQHandler
.thumb_set USART1_IRQHandler,Default_Handler
.weak USART2_IRQHandler
.thumb_set USART2_IRQHandler,Default_Handler
.weak EXTI15_10_IRQHandler
.thumb_set EXTI15_10_IRQHandler,Default_Handler
.weak RTC_Alarm_IRQHandler
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
.weak SPI3_IRQHandler
.thumb_set SPI3_IRQHandler,Default_Handler
.weak TIM6_DAC_IRQHandler
.thumb_set TIM6_DAC_IRQHandler,Default_Handler
.weak TIM7_IRQHandler
.thumb_set TIM7_IRQHandler,Default_Handler
.weak DMA2_Channel1_IRQHandler
.thumb_set DMA2_Channel1_IRQHandler,Default_Handler
.weak DMA2_Channel2_IRQHandler
.thumb_set DMA2_Channel2_IRQHandler,Default_Handler
.weak DMA2_Channel3_IRQHandler
.thumb_set DMA2_Channel3_IRQHandler,Default_Handler
.weak DMA2_Channel4_IRQHandler
.thumb_set DMA2_Channel4_IRQHandler,Default_Handler
.weak DMA2_Channel5_IRQHandler
.thumb_set DMA2_Channel5_IRQHandler,Default_Handler
.weak COMP_IRQHandler
.thumb_set COMP_IRQHandler,Default_Handler
.weak LPTIM1_IRQHandler
.thumb_set LPTIM1_IRQHandler,Default_Handler
.weak LPTIM2_IRQHandler
.thumb_set LPTIM2_IRQHandler,Default_Handler
.weak USB_IRQHandler
.thumb_set USB_IRQHandler,Default_Handler
.weak DMA2_Channel6_IRQHandler
.thumb_set DMA2_Channel6_IRQHandler,Default_Handler
.weak DMA2_Channel7_IRQHandler
.thumb_set DMA2_Channel7_IRQHandler,Default_Handler
.weak LPUART1_IRQHandler
.thumb_set LPUART1_IRQHandler,Default_Handler
.weak QUADSPI_IRQHandler
.thumb_set QUADSPI_IRQHandler,Default_Handler
.weak I2C3_EV_IRQHandler
.thumb_set I2C3_EV_IRQHandler,Default_Handler
.weak I2C3_ER_IRQHandler
.thumb_set I2C3_ER_IRQHandler,Default_Handler
.weak SAI1_IRQHandler
.thumb_set SAI1_IRQHandler,Default_Handler
.weak SWPMI1_IRQHandler
.thumb_set SWPMI1_IRQHandler,Default_Handler
.weak TSC_IRQHandler
.thumb_set TSC_IRQHandler,Default_Handler
.weak RNG_IRQHandler
.thumb_set RNG_IRQHandler,Default_Handler
.weak FPU_IRQHandler
.thumb_set FPU_IRQHandler,Default_Handler
.weak CRS_IRQHandler
.thumb_set CRS_IRQHandler,Default_Handler
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

136
Core/TMPL_Template.c Normal file
View File

@ -0,0 +1,136 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: SCS-3000
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Template source file
// Filename: TMPL_Template.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: Source file template
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "TMPL_Template.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
typedef enum
{
eX = 0,
eY
} EnExample;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
typedef struct
{
U32 u32X;
BOOL boY;
} StExample;
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: TMPL_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL TMPL_boInitializeModule( VOID )
{
return( FALSE );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================

105
Core/TMPL_Template.h Normal file
View File

@ -0,0 +1,105 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: SCS-3000
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Header File Template
// Filename: TMPL_Template.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
#ifndef TMPL_TEMPLATE_H
#define TMPL_TEMPLATE_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "SDEF_StandardDefinitions.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
typedef enum
{
TMPL_eX = 0,
TMPL_eY
} TMPL_EnExample;
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
typedef struct
{
U32 u32X;
BOOL boY;
} TMPL_StExample;
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
BOOL TMPL_boInitializeModule( VOID );
#ifdef __cplusplus
}
#endif
#endif

432
Core/Toolbox/UTIL_Utility.c Normal file
View File

@ -0,0 +1,432 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: High Stability Current Source
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Utility
// Filename: "UTIL_Utility.h".c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: Source file utility
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "UTIL_Utility.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
// defines the registers for the debug printf via trace
#define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
#define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
#define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
#define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
#define TRCENA 0x01000000
#define DBGMCU_IDCOE 0xE0042000
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u16StringLength
// Description: Returns the length of the string without zero termination
// Parameters: PSZ pszString
// Returns: U16, string length
//-------------------------------------------------------------------------------------------------
U16 UTIL_u16StringLength( PSZ pszString )
{
U16 u16Cnt = 0;
while( *pszString++ != '\0' )
{
u16Cnt++;
}
return( u16Cnt );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u16CheckStringLength
// Description: Returns TRUE, if the string leght (withouth zero termination) is less or equal the u16MaxLength
// Parameters: PSZ pszString
// U16 u16MaxLength
// Returns: U16, string length
//-------------------------------------------------------------------------------------------------
BOOL UTIL_boCheckStringLength( PSZ pszString, U16 u16MaxLength )
{
while( *pszString++ != '\0' )
{
if( u16MaxLength == 0 )
{
return( FALSE );
}
u16MaxLength--;
}
return( TRUE );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_vPuts
// Description: Prints a string
// Parameters: PSZ pszString
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID UTIL_vPuts( PSZ pszString )
{
while( *pszString != '\0' )
{
putchar( *pszString++ );
}
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u8FindMajority
// Description: Finds the majority element of a given data set
// Parameters: PU8 pu8Data
// U16 u16Length
// Returns: U8
//-------------------------------------------------------------------------------------------------
U8 UTIL_u8FindMajority( PU8 pu8Data, U16 u16Length )
{
U32 u32MaxCount = 0;
S32 s32Index = -1;
for( U32 i = 0; i < u16Length; i++)
{
U32 u32Count = 0;
for( int j = 0; j < u16Length; j++ )
{
if(pu8Data[i] == pu8Data[j])
u32Count++;
}
// update maxCount if count of
// current element is greater
if( u32Count > u32MaxCount )
{
u32MaxCount = u32Count;
s32Index = i;
}
}
// if maxCount is greater than n/2
// return the corresponding element
if( u32MaxCount > u16Length/2 && s32Index >= 0 )
{
return( pu8Data[s32Index] );
}
else
{
return( 0 );
}
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_vMemCopy
// Description: Copies a set of data.
// Parameters: PVOID pvSource pointer to the source data
// VOID pvDest pointer destination data
// U16 u16Length number of bytes to copy
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID UTIL_vMemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length )
{
// use memcpy for better performance
memcpy( pvDest, pvSource, u16Length );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u32MemCopy
// Description: Copies a set of data.
// Parameters: PVOID pvSource pointer to the source data
// PVOID pvDest pointer destination data
// U16 u16Length number of bytes to copy
// SDEF_EnByteOrder enByteOrder byte order
// Returns: U32 Number of Bytes copied
//-------------------------------------------------------------------------------------------------
U32 UTIL_u32MemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length, SDEF_EnByteOrder enByteOrder )
{
if( enByteOrder == SDEF_eNormalByteOrder )
{
UTIL_vMemCopy( pvSource, pvDest, u16Length );
}
else
{
// copy the bytes in reverse order
PU8 pu8Source = pvSource;
PU8 pu8Dest = pvDest;
for( U16 u16Cnt = 0; u16Cnt < (u16Length+1)/2; u16Cnt++ )
{
pu8Dest[u16Cnt] = pu8Source[u16Length - 1 - u16Cnt];
pu8Dest[u16Length - 1 - u16Cnt] = pu8Source[u16Cnt];
}
}
return( u16Length );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_vMemCopyU32
// Description: Copies a set of four byte data types.
// Parameters: PU32 pu32Source pointer to the source data
// PU32 pu32Dest pointer destination data
// U16 u16Length number of bytes to copy
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID UTIL_vMemCopyU32( PU32 pu32Source, PU32 pu32Dest, U16 u16Length )
{
while( u16Length-- > 0 )
{
*pu32Dest++ = *pu32Source++;
}
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_boMemCompare
// Description: Compares a set of data to equality
// Parameters: PU8 pu8Data1 pointer to first data set
// PU8 pu8Data2 pointer to second data set
// U32 u32Length number of bytes to compare
// Returns: BOOL TRUE, if compared data is equal, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL UTIL_boMemCompare( PU8 pu8Data1, PU8 pu8Data2, U32 u32Length )
{
while( u32Length-- > 0 )
{
if( *pu8Data1++ != *pu8Data2++ )
{
return( FALSE );
}
}
return( TRUE );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_boMemCompareVal
// Description: Compares if the all the data has the value specifed with u8Value.
// Parameters: PU8 pu8Data pointer to data set
// U8 u8Value value to compare
// U32 u32Length number of bytes to compare
// Returns: BOOL TRUE, if compared data is equal, otherwise FALSE
//-------------------------------------------------------------------------------------------------
BOOL UTIL_boMemCompareVal( PU8 pu8Data, U8 u8Value, U32 u32Length )
{
while( u32Length-- > 0 )
{
if( *pu8Data != u8Value)
{
return( FALSE );
}
pu8Data++;
}
return( TRUE );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u8DecToBCD
// Description: Converts decimal encoded byte to bcd value
// Parameters: decimal value to convert to bcd
// Returns: None
//-------------------------------------------------------------------------------------------------
U8 UTIL_u8DecToBCD( U8 u8Value )
{
return ( (u8Value/10*16) + (u8Value%10) );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u8BCDToDec
// Description: Converts bcd to decimal
// Parameters: bcd value to convert to decimal
// Returns: None
//-------------------------------------------------------------------------------------------------
U8 UTIL_u8BCDToDec( U8 u8Value )
{
return ( (u8Value/16*10) + (u8Value%16) );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_vReverseBytes
// Description: Reverses the byte order
// Parameters: PU8 pu8Data data
// U16 u16NumberOfBytes number of bytes
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID UTIL_vReverseBytes( PU8 pu8Data, U16 u16NumberOfBytes )
{
U8 u8Tmp;
for( U16 u16Cnt = 0; u16Cnt < u16NumberOfBytes/2; u16Cnt++ )
{
u8Tmp = pu8Data[u16Cnt];
pu8Data[u16Cnt] = pu8Data[u16NumberOfBytes - 1 - u16Cnt];
pu8Data[u16NumberOfBytes - 1 - u16Cnt] = u8Tmp;
}
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u32RevU32
// Description: Reverses the bytes of an U32
// Parameters: U32 u32Data
// Returns: U32 reversed data
//-------------------------------------------------------------------------------------------------
U32 UTIL_u32RevU32( U32 u32Data )
{
return( __REV(u32Data) );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u32RevFLOAT
// Description: Reverses the bytes of an FLOAT
// Parameters: FLOAT flData
// Returns: U32 reversed data
//-------------------------------------------------------------------------------------------------
U32 UTIL_u32RevFLOAT( FLOAT flData )
{
U32 u32Data = *(PU32)&flData;
return( __REV(u32Data) );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_u16RevU16
// Description: Reverses the bytes of an U16
// Parameters: U16 u16Data
// Returns: U16 reversed data
//-------------------------------------------------------------------------------------------------
U16 UTIL_u16RevU16( U16 u16Data )
{
return( (U16)__REV16(u16Data) );
}
//-------------------------------------------------------------------------------------------------
// Function: UTIL_cGetDeviceRevision
// Description: Gets the silicon revision of the STM32F437
// Parameters: None
// Returns: CHAR
//-------------------------------------------------------------------------------------------------
CHAR UTIL_cGetDeviceRevision( VOID )
{
U16 u16DeviceID = (*(PU32)DBGMCU_IDCOE) >> 16;
switch( u16DeviceID )
{
case 0x100:
return( 'A' );
case 0x1001:
return( 'Z' );
case 0x1003:
return( 'Y' );
case 0x1007:
return( '1' );
case 0x2001:
return( '3' );
default:
return( '0' );
}
}
//-------------------------------------------------------------------------------------------------
// Function: fputc
// Description: Prototype for printf
//-------------------------------------------------------------------------------------------------
int fputc( int ch, FILE *f )
{
UNUSED( f ); // file stream not used
if( DEMCR & TRCENA )
{
while( ITM_Port32(0) == 0 );
ITM_Port8(0) = (U8)ch;
}
return( ch );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Description: Definition (implementation) of local functions.
//=================================================================================================

205
Core/Toolbox/UTIL_Utility.h Normal file
View File

@ -0,0 +1,205 @@
//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: High Stability Current Source
// Author: Lukas Kuenzi (lukas.kuenzi@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Utility
// Filename: UTIL_Utility.h
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: Header file utility
//
//=================================================================================================
#ifndef UTIL_UTILITY_H
#define UTIL_UTILITY_H
#ifdef __cplusplus
extern "C" {
#endif
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files (visible by all modules).
//=================================================================================================
#include "string.h"
#include "stdio.h"
#include "../SDEF_StandardDefinitions.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of global macros (visible by all modules).
//=================================================================================================
//macro for filename without path
//#define _FILE_ ((PSZ)(strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : \
// (strrchr(__FILE__, '\\') ? (strrchr(__FILE__, '\\') + 1) : __FILE__)))
#define _FILE_ __FILE__
#define _LINE_ __LINE__
//checks if a pointer is valid
#define UTIL_IS_FUNC( pfnFoo ) ( pfnFoo != NULL )
#define UTIL_32BitAlign( u32Address ) ((((U32)((u32Address)+4UL)/4UL))*4UL)
#define UTIL_IS_POWER_OF_TWO( u32Numb ) ((u32Numb & (u32Numb - 1)) == 0)
#define UTIL_u16ConcatenateBytes( u8UpperByte, u8LowerByte) ( (U16)((U16)u8UpperByte << 8) | (U16)u8LowerByte )
// approx delay of 1us
#define DELAY_US( u32Us ) do{\
for( U32 u32Cnt = (SystemCoreClock >> 24U) * (u32Us); u32Cnt > 0U; u32Cnt-- ) \
{ \
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); \
}\
}while(0)
#define DELAY_MS( u32Ms ) do{\
for( U32 u32Cnt = (SystemCoreClock >> 14U) * (u32Ms); u32Cnt > 0U; u32Cnt-- ) \
{ \
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();\
__NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP();\
}\
}while(0)
#ifndef UNUSED
#define UNUSED(x) ((void)(x))
#endif
#define UTIL_SET_BIT( u32Add, u32BitMask ) ( *(VOLATILE PU32)u32Add |= (u32BitMask) )
#define UTIL_CLEAR_BIT( u32Add, u32BitMask ) ( *(VOLATILE PU32)u32Add &= ~(u32BitMask) )
#define UTIL_DEFINE_CRITICAL() U32 u32PRIMASK
// Enter Critical:
// implements a memory barrier to ensure memory operations completed before
// stores the interrupt status register
// disables interrupts
#define UTIL_ENTER_CRITICAL() do{ \
__DMB(); \
u32PRIMASK = __get_PRIMASK(); \
__disable_irq(); \
}while(0)
// Exit Critical:
// implements a memory barrier to ensure memory operations completed before
// restores the interrupt status register
#define UTIL_EXIT_CRITICAL() do{ \
__DMB(); \
__set_PRIMASK( u32PRIMASK ); \
}while(0)
// bit band definitions
#define UTIL_BB_SRAM( Address, BitNumber ) (*(VOLATILE PU32)(SRAM_BB_BASE + ((U32)Address - SRAM_BASE)*32 + BitNumber*4 ) )
#define UTIL_BB_BKRAM( Address, BitNumber ) (*(VOLATILE PU32)(BKPSRAM_BB_BASE + ((U32)Address - BKPSRAM_BASE)*32 + BitNumber*4 ) )
#define UTIL_BB_PERI( Address, BitNumber ) (*(VOLATILE PU32)(PERIPH_BB_BASE + ((U32)Address - PERIPH_BASE)*32 + BitNumber*4 ) )
// Basic bit band function definitions
#define UTIL_BB_SRAM_ClearBit( Address, BitNumber) (UTIL_BB_SRAM( Address, BitNumber ) = 0)
#define UTIL_BB_SRAM_SetBit( Address, BitNumber) (UTIL_BB_SRAM( Address, BitNumber ) = 1)
#define UTIL_BB_SRAM_GetBit( Address, BitNumber) UTIL_BB_SRAM( Address, BitNumber )
#define UTIL_BB_PERI_ClearBit( Address, BitNumber) (UTIL_BB_PERI( Address, BitNumber ) = 0)
#define UTIL_BB_PERI_SetBit( Address, BitNumber) (UTIL_BB_PERI( Address, BitNumber ) = 1)
#define UTIL_BB_PERI_GetBit( Address, BitNumber) UTIL_BB_PERI( Address, BitNumber )
#define UTIL_BB_BKRAM_ClearBit( Address, BitNumber) (UTIL_BB_BKRAM( Address, BitNumber ) = 0)
#define UTIL_BB_BKRAM_SetBit( Address, BitNumber) (UTIL_BB_BKRAM( Address, BitNumber ) = 1)
#define UTIL_BB_BKRMA_GetBit( Address, BitNumber) UTIL_BB_BKRAM( Address, BitNumber )
// Checks, if the core is in debug mode
#define UTIL_IS_DEBUGGER_ATTACHED() (CoreDebug_DHCSR_C_DEBUGEN_Msk & CoreDebug->DHCSR)
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of global enumerations (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of global Structures (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL VARIABLES
// Description: Definition of global variables (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL CONSTANTS
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
//=================================================================================================
// Section: GLOBAL FUNCTIONS (PROTOTYPES)
// Description: Definition of global functions (visible by all modules).
//=================================================================================================
U16 UTIL_u16StringLength( PSZ pszString );
BOOL UTIL_boCheckStringLength( PSZ pszString, U16 u16MaxLength );
VOID UTIL_vPuts( PSZ pszString );
VOID UTIL_vMemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length );
U32 UTIL_u32MemCopy( PVOID pvSource, PVOID pvDest, U16 u16Length, SDEF_EnByteOrder enByteOrder );
VOID UTIL_vMemCopyU32( PU32 pu32Source, PU32 pu32Dest, U16 u16Length );
BOOL UTIL_boMemCompare( PU8 pu8Data1, PU8 pu8Data2, U32 u32Length );
BOOL UTIL_boMemCompareVal( PU8 pu8Data1, U8 u8Value, U32 u32Length );
U8 UTIL_u8GetPinSource( U16 u16GIPO_Pin );
U8 UTIL_u8DecToBCD( U8 u8Value );
U8 UTIL_u8BCDToDec( U8 u8Value );
VOID UTIL_vReverseBytes( PU8 pu8Data, U16 u16NumberOfBytes );
U32 UTIL_u32RevU32( U32 u32Data );
U32 UTIL_u32RevFLOAT( FLOAT flData );
U16 UTIL_u16RevU16( U16 u16Data );
U8 UTIL_u8GetNumberOfClkCycles( DOUBLE dtime );
CHAR UTIL_cGetDeviceRevision( VOID );
U8 UTIL_u8FindMajority( PU8 pu8Data, U16 u16Length );
// printf prototype for debug printf
int fputc( int ch, FILE *f );
#ifdef __cplusplus
}
#endif
#endif