TM STM32Fxxx HAL Libraries  v1.0.0
Libraries for STM32Fxxx (F0, F4 and F7 series) devices based on HAL drivers from ST from Tilen Majerle
tm_stm32_general.h
1 
37 #ifndef TM_GENERAL_H
38 #define TM_GENERAL_H 110
39 
40 /* C++ detection */
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
91 #include "stm32fxxx_hal.h"
92 #include "defines.h"
93 #include "attributes.h"
94 
104 extern uint16_t GENERAL_SystemSpeedInMHz;
105 
129 typedef enum {
137 
141 typedef enum {
151 
155 typedef struct {
156  int32_t Integer;
157  uint32_t Decimal;
159 
177 void TM_GENERAL_SystemReset(void);
178 
187 
194 
204 uint8_t TM_GENERAL_EnableInterrupts(void);
205 
214 #define TM_GENERAL_IsIRQMode() (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
215 
222 
229 #define TM_GENERAL_GetSystemClockMHz() ((uint16_t)(SystemCoreClock * (float)0.000001))
230 
242 uint8_t TM_GENERAL_DWTCounterEnable(void);
243 
250 #if !defined(STM32F0xx)
251 #define TM_GENERAL_DWTCounterDisable() (DWT->CTRL &= ~0x00000001)
252 #endif
253 
254 
261 #define TM_GENERAL_DWTCounterGetValue() (DWT->CYCCNT)
262 
269 #define TM_GENERAL_DWTCounterSetValue(x) (DWT->CYCCNT = (x))
270 
277 static __INLINE void TM_GENERAL_DWTCounterDelayus(uint32_t micros) {
278  uint32_t c = TM_GENERAL_DWTCounterGetValue();
279 
280  /* Calculate clock cycles */
281  micros *= (SystemCoreClock / 1000000);
282  micros -= 12;
283 
284  /* Wait till done */
285  while ((TM_GENERAL_DWTCounterGetValue() - c) < micros);
286 }
287 
294 static __INLINE void TM_GENERAL_DWTCounterDelayms(uint32_t millis) {
295  uint32_t c = TM_GENERAL_DWTCounterGetValue();
296 
297  /* Calculate clock cycles */
298  millis *= (SystemCoreClock / 1000);
299  millis -= 12;
300 
301  /* Wait till done */
302  while ((TM_GENERAL_DWTCounterGetValue() - c) < millis);
303 }
304 
313 #define TM_GENERAL_IsNumberEven(number) ((number & 1) == 0)
314 
326 void TM_GENERAL_ConvertFloat(TM_GENERAL_Float_t* Float_Struct, float Number, uint8_t decimals);
327 
334 float TM_GENERAL_RoundFloat(float Number, uint8_t decimals);
335 
346 #define TM_GENERAL_IsNumberPowerOfTwo(number) (number && !(number & (number - 1)))
347 
356 uint32_t TM_GENERAL_NextPowerOf2(uint32_t number);
357 
365 
374 
387 /* C++ detection */
388 #ifdef __cplusplus
389 }
390 #endif
391 
392 #endif
uint8_t TM_GENERAL_DWTCounterEnable(void)
Enables DWT counter in Cortex-M4 core.
uint32_t TM_GENERAL_NextPowerOf2(uint32_t number)
Calculates next power of 2 from given number.
static __INLINE void TM_GENERAL_DWTCounterDelayus(uint32_t micros)
Delays for amount of microseconds using DWT counter.
Definition: tm_stm32_general.h:277
Definition: tm_stm32_general.h:147
Definition: tm_stm32_general.h:142
static __INLINE void TM_GENERAL_DWTCounterDelayms(uint32_t millis)
Delays for amount of milliseconds using DWT counter.
Definition: tm_stm32_general.h:294
Definition: tm_stm32_general.h:146
void TM_GENERAL_DisableInterrupts(void)
Disables all interrupts in system.
TM_GENERAL_ResetSource_t TM_GENERAL_GetResetSource(uint8_t reset_flags)
Gets reset source why system was reset.
void TM_GENERAL_SystemResetCallback(void)
System reset callback.
Definition: tm_stm32_general.h:130
uint16_t GENERAL_SystemSpeedInMHz
System speed in MHz.
Definition: tm_stm32_general.h:149
uint8_t TM_GENERAL_EnableInterrupts(void)
Enables interrupts in system.
Definition: tm_stm32_general.h:132
uint32_t Decimal
Definition: tm_stm32_general.h:157
void TM_GENERAL_ForceHardFaultError(void)
Forces processor to jump to Hard-fault handler.
Definition: tm_stm32_general.h:148
Definition: tm_stm32_general.h:143
Definition: tm_stm32_general.h:145
Definition: tm_stm32_general.h:144
uint32_t TM_GENERAL_GetClockSpeed(TM_GENERAL_Clock_t clock)
Gets specific clock speed value from STM32F4xx device.
Definition: tm_stm32_general.h:135
void TM_GENERAL_SystemReset(void)
Performs a system reset.
Definition: tm_stm32_general.h:134
float TM_GENERAL_RoundFloat(float Number, uint8_t decimals)
Round float number to nearest number with custom number of decimal places.
Float number operation structure.
Definition: tm_stm32_general.h:155
void TM_GENERAL_ConvertFloat(TM_GENERAL_Float_t *Float_Struct, float Number, uint8_t decimals)
Converts float coded number into integer and decimal part.
TM_GENERAL_Clock_t
Clock speed enumeration.
Definition: tm_stm32_general.h:129
#define TM_GENERAL_DWTCounterGetValue()
Gets current DWT counter value.
Definition: tm_stm32_general.h:261
Definition: tm_stm32_general.h:133
int32_t Integer
Definition: tm_stm32_general.h:156
TM_GENERAL_ResetSource_t
All possible reset sources.
Definition: tm_stm32_general.h:141
Definition: tm_stm32_general.h:131