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_GENERAL_Functions

Library Functions. More...

Macros

#define TM_GENERAL_IsIRQMode()    (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
 Checks if code execution is inside active IRQ. More...
 
#define TM_GENERAL_GetSystemClockMHz()    ((uint16_t)(SystemCoreClock * (float)0.000001))
 Gets system clock speed in units of MHz. More...
 
#define TM_GENERAL_DWTCounterDisable()    (DWT->CTRL &= ~0x00000001)
 Disables DWT counter in Cortex-M4 core. More...
 
#define TM_GENERAL_DWTCounterGetValue()    (DWT->CYCCNT)
 Gets current DWT counter value. More...
 
#define TM_GENERAL_DWTCounterSetValue(x)    (DWT->CYCCNT = (x))
 Sets DWT counter value. More...
 
#define TM_GENERAL_IsNumberEven(number)    ((number & 1) == 0)
 Checks if number is odd or even. More...
 
#define TM_GENERAL_IsNumberPowerOfTwo(number)    (number && !(number & (number - 1)))
 Checks if number is power of 2. More...
 

Functions

void TM_GENERAL_SystemReset (void)
 Performs a system reset. More...
 
TM_GENERAL_ResetSource_t TM_GENERAL_GetResetSource (uint8_t reset_flags)
 Gets reset source why system was reset. More...
 
void TM_GENERAL_DisableInterrupts (void)
 Disables all interrupts in system. More...
 
uint8_t TM_GENERAL_EnableInterrupts (void)
 Enables interrupts in system. More...
 
uint32_t TM_GENERAL_GetClockSpeed (TM_GENERAL_Clock_t clock)
 Gets specific clock speed value from STM32F4xx device. More...
 
uint8_t TM_GENERAL_DWTCounterEnable (void)
 Enables DWT counter in Cortex-M4 core. More...
 
static __INLINE void TM_GENERAL_DWTCounterDelayus (uint32_t micros)
 Delays for amount of microseconds using DWT counter. More...
 
static __INLINE void TM_GENERAL_DWTCounterDelayms (uint32_t millis)
 Delays for amount of milliseconds using DWT counter. More...
 
void TM_GENERAL_ConvertFloat (TM_GENERAL_Float_t *Float_Struct, float Number, uint8_t decimals)
 Converts float coded number into integer and decimal part. More...
 
float TM_GENERAL_RoundFloat (float Number, uint8_t decimals)
 Round float number to nearest number with custom number of decimal places. More...
 
uint32_t TM_GENERAL_NextPowerOf2 (uint32_t number)
 Calculates next power of 2 from given number. More...
 
void TM_GENERAL_ForceHardFaultError (void)
 Forces processor to jump to Hard-fault handler. More...
 
void TM_GENERAL_SystemResetCallback (void)
 System reset callback. More...
 

Detailed Description

Library Functions.

Macro Definition Documentation

#define TM_GENERAL_DWTCounterDisable ( )    (DWT->CTRL &= ~0x00000001)

Disables DWT counter in Cortex-M4 core.

Parameters
None
Return values
None
Note
Defined as macro for faster execution
#define TM_GENERAL_DWTCounterGetValue ( )    (DWT->CYCCNT)

Gets current DWT counter value.

Parameters
None
Return values
DWTcounter value
Note
Defined as macro for faster execution
#define TM_GENERAL_DWTCounterSetValue (   x)    (DWT->CYCCNT = (x))

Sets DWT counter value.

Parameters
xValue to be set to DWT counter
Return values
None
Note
Defined as macro for faster execution
#define TM_GENERAL_GetSystemClockMHz ( )    ((uint16_t)(SystemCoreClock * (float)0.000001))

Gets system clock speed in units of MHz.

Parameters
None
Return values
None
Note
Defined as macro for faster execution
#define TM_GENERAL_IsIRQMode ( )    (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)

Checks if code execution is inside active IRQ.

Parameters
None
Return values
IRQExecution status:
  • 0: Code execution is not inside IRQ, thread mode
  • > 0: Code execution is inside IRQ, IRQ mode
Note
Defines as macro for faster execution
#define TM_GENERAL_IsNumberEven (   number)    ((number & 1) == 0)

Checks if number is odd or even.

Parameters
numberNumber to check if it is odd or even
Return values
Isnumber even status:
  • 0: Number is odd
  • > 0: Number is even
Note
Defined as macro for faster execution
#define TM_GENERAL_IsNumberPowerOfTwo (   number)    (number && !(number & (number - 1)))

Checks if number is power of 2.

Note
It can be used to determine if number has more than just one bit set If only one bit is set, function will return > 0 because this is power of 2.
Parameters
numberNumber to check if it is power of 2
Return values
Ispower of 2 status:
  • 0: Number if not power of 2
  • > 0: Number is power of 2
Note
Defined as macro for faster execution

Function Documentation

void TM_GENERAL_ConvertFloat ( TM_GENERAL_Float_t Float_Struct,
float  Number,
uint8_t  decimals 
)

Converts float coded number into integer and decimal part.

Parameters
*Float_StructPointer to empty TM_GENERAL_Float_t to store result into
NumberFloat number to convert
decimalsNumber of decimal places for conversion, maximum 9 decimal places
Return values
None
Note
Example: You have number 15.002 in float format.
  • You want to split this to integer and decimal part with 6 decimal places.
  • Call TM_GENERAL_ConvertFloat(&Float_Struct, 15.002, 6);
  • Result will be: Integer: 15; Decimal: 2000 (0.002 * 10^6)
void TM_GENERAL_DisableInterrupts ( void  )

Disables all interrupts in system.

Parameters
None
Return values
None
static __INLINE void TM_GENERAL_DWTCounterDelayms ( uint32_t  millis)
static

Delays for amount of milliseconds using DWT counter.

Parameters
millisNumber of micro seconds for delay
Return values
None
Note
DWT Counter HAVE to be initialized first using TM_GENERAL_EnableDWTCounter()
static __INLINE void TM_GENERAL_DWTCounterDelayus ( uint32_t  micros)
static

Delays for amount of microseconds using DWT counter.

Parameters
microsNumber of micro seconds for delay
Return values
None
Note
DWT Counter HAVE to be initialized first using TM_GENERAL_EnableDWTCounter()
uint8_t TM_GENERAL_DWTCounterEnable ( void  )

Enables DWT counter in Cortex-M4 core.

Parameters
None
Return values
DWTStatus:
  • 0: DWT has not started, hardware/software reset is required
  • > 0: DWT has started and is ready to use
Note
It may happen, that DWT counter won't start after reprogramming device. This happened to me when I use onboard ST-Link on Discovery or Nucleo boards. When I used external debugger (J-Link or ULINK2) it worked always without problems. If your DWT doesn't start, you should perform software/hardware reset by yourself.
uint8_t TM_GENERAL_EnableInterrupts ( void  )

Enables interrupts in system.

Note
This function has nesting support. This means that if you call TM_GENERAL_DisableInterrupts() 4 times, then you have to call this function also 4 times to enable interrupts.
Parameters
None
Return values
Interruptenabled status:
  • 0: Interrupts were not enabled
  • > 0: Interrupts were enabled
void TM_GENERAL_ForceHardFaultError ( void  )

Forces processor to jump to Hard-fault handler.

Note
Function tries to call function at zero location in memory which causes hard-fault
Parameters
None
Return values
None
uint32_t TM_GENERAL_GetClockSpeed ( TM_GENERAL_Clock_t  clock)

Gets specific clock speed value from STM32F4xx device.

Parameters
clockClock type you want to know speed for. This parameter can be a value of TM_GENERAL_Clock_t enumeration
Return values
Clockspeed in units of hertz
TM_GENERAL_ResetSource_t TM_GENERAL_GetResetSource ( uint8_t  reset_flags)

Gets reset source why system was reset.

Parameters
reset_flagsAfter read, clear reset flags
  • 0: Flags will stay untouched
  • > 0: All reset flags will reset
Return values
Memberof TM_GENERAL_ResetSource_t containing reset source
uint32_t TM_GENERAL_NextPowerOf2 ( uint32_t  number)

Calculates next power of 2 from given number.

Parameters
numberInput number to be calculated
Return values
Numberwith next power of 2 Example:
  • Input number: 450
  • Next power of 2 is: 512 = 2^9
float TM_GENERAL_RoundFloat ( float  Number,
uint8_t  decimals 
)

Round float number to nearest number with custom number of decimal places.

Parameters
NumberFloat number to round
decimalsNumber of decimal places to round, maximum 9 decimal places
Return values
Roundedfloat number
void TM_GENERAL_SystemReset ( void  )

Performs a system reset.

Note
Before system will be reset, TM_GENERAL_SoftwareResetCallback() will be called, where you can do important stuff if necessary
Parameters
None
Return values
None
void TM_GENERAL_SystemResetCallback ( void  )

System reset callback.

Note
Function is called before software reset occurs.
Parameters
None
Return values
None
Note
With __weak parameter to prevent link errors if not defined by user