TM STM32F4xx Libraries  v1.0.0
Libraries for STM32F4xx devices from Tilen Majerle
tm_stm32f4_general.h
1 
30 #ifndef TM_GENERAL_H
31 #define TM_GENERAL_H 140
32 
33 /* C++ detection */
34 #ifdef __cplusplus
35 extern C {
36 #endif
37 
97 #include "stm32f4xx.h"
98 #include "stm32f4xx_rcc.h"
99 #include "defines.h"
100 #include "attributes.h"
101 
111 extern uint16_t GENERAL_SystemSpeedInMHz;
112 
136 typedef enum {
144 
148 typedef enum {
158 
162 typedef struct {
163  int32_t Integer;
164  uint32_t Decimal;
166 
184 void TM_GENERAL_SystemReset(void);
185 
194 
201 
211 uint8_t TM_GENERAL_EnableInterrupts(void);
212 
221 #define TM_GENERAL_IsIRQMode() (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
222 
229 
236 #define TM_GENERAL_GetSystemClockMHz() ((uint16_t)(SystemCoreClock * (float)0.000001))
237 
249 uint8_t TM_GENERAL_DWTCounterEnable(void);
250 
257 #define TM_GENERAL_DWTCounterDisable() (DWT->CTRL &= ~0x00000001)
258 
265 #define TM_GENERAL_DWTCounterGetValue() (DWT->CYCCNT)
266 
273 #define TM_GENERAL_DWTCounterSetValue(x) (DWT->CYCCNT = (x))
274 
281 static __INLINE void TM_GENERAL_DWTCounterDelayus(uint32_t micros) {
282  uint32_t c = TM_GENERAL_DWTCounterGetValue();
283 
284  /* Calculate clock cycles */
285  micros *= (SystemCoreClock / 1000000);
286  micros -= 12;
287 
288  /* Wait till done */
289  while ((TM_GENERAL_DWTCounterGetValue() - c) < micros);
290 }
291 
298 static __INLINE void TM_GENERAL_DWTCounterDelayms(uint32_t millis) {
299  uint32_t c = TM_GENERAL_DWTCounterGetValue();
300 
301  /* Calculate clock cycles */
302  millis *= (SystemCoreClock / 1000);
303  millis -= 12;
304 
305  /* Wait till done */
306  while ((TM_GENERAL_DWTCounterGetValue() - c) < millis);
307 }
308 
317 #define TM_GENERAL_IsNumberEven(number) ((number & 1) == 0)
318 
330 void TM_GENERAL_ConvertFloat(TM_GENERAL_Float_t* Float_Struct, float Number, uint8_t decimals);
331 
338 float TM_GENERAL_RoundFloat(float Number, uint8_t decimals);
339 
350 #define TM_GENERAL_IsNumberPowerOfTwo(number) (number && !(number & (number - 1)))
351 
360 uint32_t TM_GENERAL_NextPowerOf2(uint32_t number);
361 
369 
378 
391 /* C++ detection */
392 #ifdef __cplusplus
393 }
394 #endif
395 
396 #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_stm32f4_general.h:281
Definition: tm_stm32f4_general.h:154
Definition: tm_stm32f4_general.h:149
static __INLINE void TM_GENERAL_DWTCounterDelayms(uint32_t millis)
Delays for amount of milliseconds using DWT counter.
Definition: tm_stm32f4_general.h:298
Definition: tm_stm32f4_general.h:153
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_stm32f4_general.h:137
uint16_t GENERAL_SystemSpeedInMHz
System speed in MHz.
Definition: tm_stm32f4_general.h:156
uint8_t TM_GENERAL_EnableInterrupts(void)
Enables interrupts in system.
Definition: tm_stm32f4_general.h:139
uint32_t Decimal
Definition: tm_stm32f4_general.h:164
void TM_GENERAL_ForceHardFaultError(void)
Forces processor to jump to Hard-fault handler.
Definition: tm_stm32f4_general.h:155
Definition: tm_stm32f4_general.h:150
Definition: tm_stm32f4_general.h:152
Definition: tm_stm32f4_general.h:151
uint32_t TM_GENERAL_GetClockSpeed(TM_GENERAL_Clock_t clock)
Gets specific clock speed value from STM32F4xx device.
Definition: tm_stm32f4_general.h:142
void TM_GENERAL_SystemReset(void)
Performs a system reset.
Definition: tm_stm32f4_general.h:141
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_stm32f4_general.h:162
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_stm32f4_general.h:136
#define TM_GENERAL_DWTCounterGetValue()
Gets current DWT counter value.
Definition: tm_stm32f4_general.h:265
Definition: tm_stm32f4_general.h:140
int32_t Integer
Definition: tm_stm32f4_general.h:163
TM_GENERAL_ResetSource_t
All possible reset sources.
Definition: tm_stm32f4_general.h:148
Definition: tm_stm32f4_general.h:138