2020-06-06 14:35:55 +02:00
/** global definitions and methods
2020-02-11 12:15:31 +01:00
* @ file
2016-08-14 20:30:16 +02:00
* @ author King Kévin < kingkevin @ cuvoodoo . info >
2020-06-06 14:35:55 +02:00
* @ copyright SPDX - License - Identifier : GPL - 3.0 - or - later
2020-02-11 12:15:31 +01:00
* @ date 2016 - 2020
2016-08-14 20:30:16 +02:00
*/
2016-02-18 10:39:08 +01:00
# pragma once
2016-10-23 17:42:27 +02:00
/** enable debugging functionalities */
2018-04-06 19:56:57 +02:00
# define DEBUG true
2016-01-29 11:25:30 +01:00
2020-11-27 16:38:32 +01:00
/** Data Synchronization Barrier, ensure all data is written */
# define __DSB() __asm__("dsb")
/** Instruction Synchronization Barrier, ensure all instruction are run */
# define __ISB() __asm__("isb")
2016-08-14 20:30:16 +02:00
/** get the length of an array */
2016-01-28 21:21:50 +01:00
# define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
2017-02-06 17:32:49 +01:00
/** concatenate 2 arguments */
2016-10-23 17:42:27 +02:00
# define CAT2(x,y) x##y
2017-02-06 17:32:49 +01:00
/** concatenate 3 arguments */
2016-10-23 17:42:27 +02:00
# define CAT3(x,y,z) x##y##z
2017-02-06 17:32:49 +01:00
/** concatenate 4 arguments */
# define CAT4(w,x,y,z) w##x##y##z
2019-03-27 18:40:16 +01:00
/** integer underflow/overflow safe uint8_t addition (result to min/max on underflow/overflow) */
# define ADDU8_SAFE(a,b) {__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); a = (_b > 0 ? ((_a > UINT8_MAX - _b) ? UINT8_MAX : (_a + _b)) : ((_a < _b) ? 0 : (_a - _b)));}
/** integer underflow/overflow safe uint16_t addition (result to min/max on underflow/overflow) */
# define ADDU16_SAFE(a,b) {__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); a = (_b > 0 ? ((_a > UINT16_MAX - _b) ? UINT16_MAX : (_a + _b)) : ((_a < _b) ? 0 : (_a - _b)));}
/** integer underflow/overflow safe uint32_t addition (result to min/max on underflow/overflow) */
# define ADDU32_SAFE(a,b) {__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); a = (_b > 0 ? ((_a > UINT32_MAX - _b) ? UINT32_MAX : (_a + _b)) : ((_a < _b) ? 0 : (_a - _b)));}
/** integer underflow/overflow safe int8_t addition (result to min/max on underflow/overflow) */
2020-12-07 19:10:04 +01:00
# define ADDS8_SAFE(a,b) {__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); a = (_b > 0 ? ((_a > INT8_MAX - _b) ? INT8_MAX : (_a + _b)) : ((_a < INT8_MAX + _b) ? INT8_MAX : (_a + _b)));}
2019-03-27 18:40:16 +01:00
/** integer underflow/overflow safe int16_t addition (result to min/max on underflow/overflow) */
2020-12-07 19:10:04 +01:00
# define ADDS16_SAFE(a,b) {__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); a = (_b > 0 ? ((_a > INT16_MAX - _b) ? INT16_MAX : (_a + _b)) : ((_a < INT16_MIN + _b) ? INT16_MIN : (_a + _b)));}
2019-03-27 18:40:16 +01:00
/** integer underflow/overflow safe int32_t addition (result to min/max on underflow/overflow) */
2020-12-07 19:10:04 +01:00
# define ADDS32_SAFE(a,b) {__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); a = (_b > 0 ? ((_a > INT32_MAX - _b) ? INT32_MAX : (_a + _b)) : ((_a < INT32_MIN + _b) ? INT32_MIN : (_a + _b)));}
/** unsigned 8-bit integer overflow safe addition
* @ param [ in ] a first part of addition
* @ param [ in ] b second part of addition
* return result of addition , or type max on overflow
*/
uint8_t addu8_safe ( uint8_t a , uint8_t b ) ;
/** unsigned 16-bit integer overflow safe addition
* @ param [ in ] a first part of addition
* @ param [ in ] b second part of addition
* return result of addition , or type max on overflow
*/
uint16_t addu16_safe ( uint16_t a , uint16_t b ) ;
/** unsigned 8-bit integer overflow safe addition
* @ param [ in ] a first part of addition
* @ param [ in ] b second part of addition
* return result of addition , or type max on overflow
*/
uint32_t addu32_safe ( uint32_t a , uint32_t b ) ;
/** signed 8-bit integer underflow/overflow safe addition
* @ param [ in ] a first part of addition
* @ param [ in ] b second part of addition
* return result of addition , or type max on overflow
*/
int8_t adds8_safe ( int8_t a , int8_t b ) ;
/** signed 16-bit integer underflow/overflow safe addition
* @ param [ in ] a first part of addition
* @ param [ in ] b second part of addition
* return result of addition , or type max on overflow
*/
int16_t adds16_safe ( int16_t a , int16_t b ) ;
/** signed 32-bit integer underflow/overflow safe addition
* @ param [ in ] a first part of addition
* @ param [ in ] b second part of addition
* return result of addition , or type max on overflow
*/
int32_t adds32_safe ( int32_t a , int32_t b ) ;
2017-02-06 17:32:49 +01:00
2018-02-18 15:21:18 +01:00
/** build year as number */
# define COMPUTE_BUILD_YEAR \
( \
( __DATE__ [ 7 ] - ' 0 ' ) * 1000 + \
( __DATE__ [ 8 ] - ' 0 ' ) * 100 + \
( __DATE__ [ 9 ] - ' 0 ' ) * 10 + \
( __DATE__ [ 10 ] - ' 0 ' ) \
)
/** build day as number */
# define COMPUTE_BUILD_DAY \
( \
( ( __DATE__ [ 4 ] > = ' 0 ' ) ? ( __DATE__ [ 4 ] - ' 0 ' ) * 10 : 0 ) + \
( __DATE__ [ 5 ] - ' 0 ' ) \
)
/** check if build month is January */
# define BUILD_MONTH_IS_JAN (__DATE__[0] == 'J' && __DATE__[1] == 'a' && __DATE__[2] == 'n')
/** check if build month is February */
# define BUILD_MONTH_IS_FEB (__DATE__[0] == 'F')
/** check if build month is March */
# define BUILD_MONTH_IS_MAR (__DATE__[0] == 'M' && __DATE__[1] == 'a' && __DATE__[2] == 'r')
/** check if build month is April */
# define BUILD_MONTH_IS_APR (__DATE__[0] == 'A' && __DATE__[1] == 'p')
/** check if build month is May */
# define BUILD_MONTH_IS_MAY (__DATE__[0] == 'M' && __DATE__[1] == 'a' && __DATE__[2] == 'y')
/** check if build month is June */
# define BUILD_MONTH_IS_JUN (__DATE__[0] == 'J' && __DATE__[1] == 'u' && __DATE__[2] == 'n')
/** check if build month is July */
# define BUILD_MONTH_IS_JUL (__DATE__[0] == 'J' && __DATE__[1] == 'u' && __DATE__[2] == 'l')
/** check if build month is August */
# define BUILD_MONTH_IS_AUG (__DATE__[0] == 'A' && __DATE__[1] == 'u')
/** check if build month is September */
# define BUILD_MONTH_IS_SEP (__DATE__[0] == 'S')
/** check if build month is October */
# define BUILD_MONTH_IS_OCT (__DATE__[0] == 'O')
/** check if build month is November */
# define BUILD_MONTH_IS_NOV (__DATE__[0] == 'N')
/** check if build month is December */
# define BUILD_MONTH_IS_DEC (__DATE__[0] == 'D')
/** build month as number */
# define COMPUTE_BUILD_MONTH \
( \
( BUILD_MONTH_IS_JAN ) ? 1 : \
( BUILD_MONTH_IS_FEB ) ? 2 : \
( BUILD_MONTH_IS_MAR ) ? 3 : \
( BUILD_MONTH_IS_APR ) ? 4 : \
( BUILD_MONTH_IS_MAY ) ? 5 : \
( BUILD_MONTH_IS_JUN ) ? 6 : \
( BUILD_MONTH_IS_JUL ) ? 7 : \
( BUILD_MONTH_IS_AUG ) ? 8 : \
( BUILD_MONTH_IS_SEP ) ? 9 : \
( BUILD_MONTH_IS_OCT ) ? 10 : \
( BUILD_MONTH_IS_NOV ) ? 11 : \
( BUILD_MONTH_IS_DEC ) ? 12 : \
/* error default */ 99 \
)
/** check if build date is unknown */
# define BUILD_DATE_IS_BAD (__DATE__[0] == '?')
/** build year as number if known, or 0 if unknown */
# define BUILD_YEAR ((BUILD_DATE_IS_BAD) ? 0 : COMPUTE_BUILD_YEAR)
/** build month as number if known, or 0 if unknown */
# define BUILD_MONTH ((BUILD_DATE_IS_BAD) ? 99 : COMPUTE_BUILD_MONTH)
/** build day as number if known, or 0 if unknown */
# define BUILD_DAY ((BUILD_DATE_IS_BAD) ? 99 : COMPUTE_BUILD_DAY)
2016-10-23 17:42:27 +02:00
/** @defgroup reg_macro macros to define values based on other defines values
* @ note used when the value is calculated or isn ' t a value
* @ {
*/
2019-06-18 13:46:57 +02:00
/** get GPIO based on GPIO port or pin identifier */
2016-10-23 17:42:27 +02:00
# define GPIO(x) CAT2(GPIO,x)
2019-06-18 13:46:57 +02:00
/** get GPIO port identifier based on GPIO port and pin identifier */
# define GPIO_PORT_ID(x) CAT2(x,_PORT)
/** get GPIO port based on GPIO port and pin identifier */
# define GPIO_PORT(x) GPIO(GPIO_PORT_ID(x))
# define PA0_PORT A /**< GPIO port pin A0 is on port A */
# define PA1_PORT A /**< GPIO port pin A1 is on port A */
# define PA2_PORT A /**< GPIO port pin A2 is on port A */
# define PA3_PORT A /**< GPIO port pin A3 is on port A */
# define PA4_PORT A /**< GPIO port pin A4 is on port A */
# define PA5_PORT A /**< GPIO port pin A5 is on port A */
# define PA6_PORT A /**< GPIO port pin A6 is on port A */
# define PA7_PORT A /**< GPIO port pin A7 is on port A */
# define PA8_PORT A /**< GPIO port pin A8 is on port A */
# define PA9_PORT A /**< GPIO port pin A9 is on port A */
# define PA10_PORT A /**< GPIO port pin A10 is on port A */
# define PA11_PORT A /**< GPIO port pin A11 is on port A */
# define PA12_PORT A /**< GPIO port pin A12 is on port A */
# define PA13_PORT A /**< GPIO port pin A13 is on port A */
# define PA14_PORT A /**< GPIO port pin A14 is on port A */
# define PA15_PORT A /**< GPIO port pin A15 is on port A */
# define PB0_PORT B /**< GPIO port pin B0 is on port B */
# define PB1_PORT B /**< GPIO port pin B1 is on port B */
# define PB2_PORT B /**< GPIO port pin B2 is on port B */
# define PB3_PORT B /**< GPIO port pin B3 is on port B */
# define PB4_PORT B /**< GPIO port pin B4 is on port B */
# define PB5_PORT B /**< GPIO port pin B5 is on port B */
# define PB6_PORT B /**< GPIO port pin B6 is on port B */
# define PB7_PORT B /**< GPIO port pin B7 is on port B */
# define PB8_PORT B /**< GPIO port pin B8 is on port B */
# define PB9_PORT B /**< GPIO port pin B9 is on port B */
# define PB10_PORT B /**< GPIO port pin B10 is on port B */
# define PB11_PORT B /**< GPIO port pin B11 is on port B */
# define PB12_PORT B /**< GPIO port pin B12 is on port B */
# define PB13_PORT B /**< GPIO port pin B13 is on port B */
# define PB14_PORT B /**< GPIO port pin B14 is on port B */
# define PB15_PORT B /**< GPIO port pin B15 is on port B */
# define PC0_PORT C /**< GPIO port pin C0 is on port C */
# define PC1_PORT C /**< GPIO port pin C1 is on port C */
# define PC2_PORT C /**< GPIO port pin C2 is on port C */
# define PC3_PORT C /**< GPIO port pin C3 is on port C */
# define PC4_PORT C /**< GPIO port pin C4 is on port C */
# define PC5_PORT C /**< GPIO port pin C5 is on port C */
# define PC6_PORT C /**< GPIO port pin C6 is on port C */
# define PC7_PORT C /**< GPIO port pin C7 is on port C */
# define PC8_PORT C /**< GPIO port pin C8 is on port C */
# define PC9_PORT C /**< GPIO port pin C9 is on port C */
# define PC10_PORT C /**< GPIO port pin C10 is on port C */
# define PC11_PORT C /**< GPIO port pin C11 is on port C */
# define PC12_PORT C /**< GPIO port pin C12 is on port C */
# define PC13_PORT C /**< GPIO port pin C13 is on port C */
# define PC14_PORT C /**< GPIO port pin C14 is on port C */
# define PC15_PORT C /**< GPIO port pin C15 is on port C */
# define PD0_PORT D /**< GPIO port pin D0 is on port D */
# define PD1_PORT D /**< GPIO port pin D1 is on port D */
# define PD2_PORT D /**< GPIO port pin D2 is on port D */
# define PD3_PORT D /**< GPIO port pin D3 is on port D */
# define PD4_PORT D /**< GPIO port pin D4 is on port D */
# define PD5_PORT D /**< GPIO port pin D5 is on port D */
# define PD6_PORT D /**< GPIO port pin D6 is on port D */
# define PD7_PORT D /**< GPIO port pin D7 is on port D */
# define PD8_PORT D /**< GPIO port pin D8 is on port D */
# define PD9_PORT D /**< GPIO port pin D9 is on port D */
# define PD10_PORT D /**< GPIO port pin D10 is on port D */
# define PD11_PORT D /**< GPIO port pin D11 is on port D */
# define PD12_PORT D /**< GPIO port pin D12 is on port D */
# define PD13_PORT D /**< GPIO port pin D13 is on port D */
# define PD14_PORT D /**< GPIO port pin D14 is on port D */
# define PD15_PORT D /**< GPIO port pin D15 is on port D */
# define PE0_PORT E /**< GPIO port pin E0 is on port E */
# define PE1_PORT E /**< GPIO port pin E1 is on port E */
# define PE2_PORT E /**< GPIO port pin E2 is on port E */
# define PE3_PORT E /**< GPIO port pin E3 is on port E */
# define PE4_PORT E /**< GPIO port pin E4 is on port E */
# define PE5_PORT E /**< GPIO port pin E5 is on port E */
# define PE6_PORT E /**< GPIO port pin E6 is on port E */
# define PE7_PORT E /**< GPIO port pin E7 is on port E */
# define PE8_PORT E /**< GPIO port pin E8 is on port E */
# define PE9_PORT E /**< GPIO port pin E9 is on port E */
# define PE10_PORT E /**< GPIO port pin E10 is on port E */
# define PE11_PORT E /**< GPIO port pin E11 is on port E */
# define PE12_PORT E /**< GPIO port pin E12 is on port E */
# define PE13_PORT E /**< GPIO port pin E13 is on port E */
# define PE14_PORT E /**< GPIO port pin E14 is on port E */
# define PE15_PORT E /**< GPIO port pin E15 is on port E */
# define PF0_PORT F /**< GPIO port pin F0 is on port F */
# define PF1_PORT F /**< GPIO port pin F1 is on port F */
# define PF2_PORT F /**< GPIO port pin F2 is on port F */
# define PF3_PORT F /**< GPIO port pin F3 is on port F */
# define PF4_PORT F /**< GPIO port pin F4 is on port F */
# define PF5_PORT F /**< GPIO port pin F5 is on port F */
# define PF6_PORT F /**< GPIO port pin F6 is on port F */
# define PF7_PORT F /**< GPIO port pin F7 is on port F */
# define PF8_PORT F /**< GPIO port pin F8 is on port F */
# define PF9_PORT F /**< GPIO port pin F9 is on port F */
# define PF10_PORT F /**< GPIO port pin F10 is on port F */
# define PF11_PORT F /**< GPIO port pin F11 is on port F */
# define PF12_PORT F /**< GPIO port pin F12 is on port F */
# define PF13_PORT F /**< GPIO port pin F13 is on port F */
# define PF14_PORT F /**< GPIO port pin F14 is on port F */
# define PF15_PORT F /**< GPIO port pin F15 is on port F */
# define PG0_PORT G /**< GPIO port pin G0 is on port G */
# define PG1_PORT G /**< GPIO port pin G1 is on port G */
# define PG2_PORT G /**< GPIO port pin G2 is on port G */
# define PG3_PORT G /**< GPIO port pin G3 is on port G */
# define PG4_PORT G /**< GPIO port pin G4 is on port G */
# define PG5_PORT G /**< GPIO port pin G5 is on port G */
# define PG6_PORT G /**< GPIO port pin G6 is on port G */
# define PG7_PORT G /**< GPIO port pin G7 is on port G */
# define PG8_PORT G /**< GPIO port pin G8 is on port G */
# define PG9_PORT G /**< GPIO port pin G9 is on port G */
# define PG10_PORT G /**< GPIO port pin G10 is on port G */
# define PG11_PORT G /**< GPIO port pin G11 is on port G */
# define PG12_PORT G /**< GPIO port pin G12 is on port G */
# define PG13_PORT G /**< GPIO port pin G13 is on port G */
# define PG14_PORT G /**< GPIO port pin G14 is on port G */
# define PG15_PORT G /**< GPIO port pin G15 is on port G */
/** get GPIO port identifier based on GPIO port and pin identifier */
# define GPIO_PIN_ID(x) CAT2(x,_PIN)
/** get GPIO pin based on GPIO port and pin identifier */
# define GPIO_PIN(x) GPIO(GPIO_PIN_ID(x))
# define PA0_PIN 0 /**< GPIO port pin A0 is on pin 0 */
# define PA1_PIN 1 /**< GPIO port pin A1 is on pin 1 */
# define PA2_PIN 2 /**< GPIO port pin A2 is on pin 2 */
# define PA3_PIN 3 /**< GPIO port pin A3 is on pin 3 */
# define PA4_PIN 4 /**< GPIO port pin A4 is on pin 4 */
# define PA5_PIN 5 /**< GPIO port pin A5 is on pin 5 */
# define PA6_PIN 6 /**< GPIO port pin A6 is on pin 6 */
# define PA7_PIN 7 /**< GPIO port pin A7 is on pin 7 */
# define PA8_PIN 8 /**< GPIO port pin A8 is on pin 8 */
# define PA9_PIN 9 /**< GPIO port pin A9 is on pin 9 */
# define PA10_PIN 10 /**< GPIO port pin A10 is on pin 10 */
# define PA11_PIN 11 /**< GPIO port pin A11 is on pin 11 */
# define PA12_PIN 12 /**< GPIO port pin A12 is on pin 12 */
# define PA13_PIN 13 /**< GPIO port pin A13 is on pin 13 */
# define PA14_PIN 14 /**< GPIO port pin A14 is on pin 14 */
# define PA15_PIN 15 /**< GPIO port pin A15 is on pin 15 */
# define PB0_PIN 0 /**< GPIO port pin B0 is on pin 0 */
# define PB1_PIN 1 /**< GPIO port pin B1 is on pin 1 */
# define PB2_PIN 2 /**< GPIO port pin B2 is on pin 2 */
# define PB3_PIN 3 /**< GPIO port pin B3 is on pin 3 */
# define PB4_PIN 4 /**< GPIO port pin B4 is on pin 4 */
# define PB5_PIN 5 /**< GPIO port pin B5 is on pin 5 */
# define PB6_PIN 6 /**< GPIO port pin B6 is on pin 6 */
# define PB7_PIN 7 /**< GPIO port pin B7 is on pin 7 */
# define PB8_PIN 8 /**< GPIO port pin B8 is on pin 8 */
# define PB9_PIN 9 /**< GPIO port pin B9 is on pin 9 */
# define PB10_PIN 10 /**< GPIO port pin B10 is on pin 10 */
# define PB11_PIN 11 /**< GPIO port pin B11 is on pin 11 */
# define PB12_PIN 12 /**< GPIO port pin B12 is on pin 12 */
# define PB13_PIN 13 /**< GPIO port pin B13 is on pin 13 */
# define PB14_PIN 14 /**< GPIO port pin B14 is on pin 14 */
# define PB15_PIN 15 /**< GPIO port pin B15 is on pin 15 */
# define PC0_PIN 0 /**< GPIO port pin C0 is on pin 0 */
# define PC1_PIN 1 /**< GPIO port pin C1 is on pin 1 */
# define PC2_PIN 2 /**< GPIO port pin C2 is on pin 2 */
# define PC3_PIN 3 /**< GPIO port pin C3 is on pin 3 */
# define PC4_PIN 4 /**< GPIO port pin C4 is on pin 4 */
# define PC5_PIN 5 /**< GPIO port pin C5 is on pin 5 */
# define PC6_PIN 6 /**< GPIO port pin C6 is on pin 6 */
# define PC7_PIN 7 /**< GPIO port pin C7 is on pin 7 */
# define PC8_PIN 8 /**< GPIO port pin C8 is on pin 8 */
# define PC9_PIN 9 /**< GPIO port pin C9 is on pin 9 */
# define PC10_PIN 10 /**< GPIO port pin C10 is on pin 10 */
# define PC11_PIN 11 /**< GPIO port pin C11 is on pin 11 */
# define PC12_PIN 12 /**< GPIO port pin C12 is on pin 12 */
# define PC13_PIN 13 /**< GPIO port pin C13 is on pin 13 */
# define PC14_PIN 14 /**< GPIO port pin C14 is on pin 14 */
# define PC15_PIN 15 /**< GPIO port pin C15 is on pin 15 */
# define PD0_PIN 0 /**< GPIO port pin D0 is on pin 0 */
# define PD1_PIN 1 /**< GPIO port pin D1 is on pin 1 */
# define PD2_PIN 2 /**< GPIO port pin D2 is on pin 2 */
# define PD3_PIN 3 /**< GPIO port pin D3 is on pin 3 */
# define PD4_PIN 4 /**< GPIO port pin D4 is on pin 4 */
# define PD5_PIN 5 /**< GPIO port pin D5 is on pin 5 */
# define PD6_PIN 6 /**< GPIO port pin D6 is on pin 6 */
# define PD7_PIN 7 /**< GPIO port pin D7 is on pin 7 */
# define PD8_PIN 8 /**< GPIO port pin D8 is on pin 8 */
# define PD9_PIN 9 /**< GPIO port pin D9 is on pin 9 */
# define PD10_PIN 10 /**< GPIO port pin D10 is on pin 10 */
# define PD11_PIN 11 /**< GPIO port pin D11 is on pin 11 */
# define PD12_PIN 12 /**< GPIO port pin D12 is on pin 12 */
# define PD13_PIN 13 /**< GPIO port pin D13 is on pin 13 */
# define PD14_PIN 14 /**< GPIO port pin D14 is on pin 14 */
# define PD15_PIN 15 /**< GPIO port pin D15 is on pin 15 */
# define PE0_PIN 0 /**< GPIO port pin E0 is on pin 0 */
# define PE1_PIN 1 /**< GPIO port pin E1 is on pin 1 */
# define PE2_PIN 2 /**< GPIO port pin E2 is on pin 2 */
# define PE3_PIN 3 /**< GPIO port pin E3 is on pin 3 */
# define PE4_PIN 4 /**< GPIO port pin E4 is on pin 4 */
# define PE5_PIN 5 /**< GPIO port pin E5 is on pin 5 */
# define PE6_PIN 6 /**< GPIO port pin E6 is on pin 6 */
# define PE7_PIN 7 /**< GPIO port pin E7 is on pin 7 */
# define PE8_PIN 8 /**< GPIO port pin E8 is on pin 8 */
# define PE9_PIN 9 /**< GPIO port pin E9 is on pin 9 */
# define PE10_PIN 10 /**< GPIO port pin E10 is on pin 10 */
# define PE11_PIN 11 /**< GPIO port pin E11 is on pin 11 */
# define PE12_PIN 12 /**< GPIO port pin E12 is on pin 12 */
# define PE13_PIN 13 /**< GPIO port pin E13 is on pin 13 */
# define PE14_PIN 14 /**< GPIO port pin E14 is on pin 14 */
# define PE15_PIN 15 /**< GPIO port pin E15 is on pin 15 */
# define PF0_PIN 0 /**< GPIO port pin F0 is on pin 0 */
# define PF1_PIN 1 /**< GPIO port pin F1 is on pin 1 */
# define PF2_PIN 2 /**< GPIO port pin F2 is on pin 2 */
# define PF3_PIN 3 /**< GPIO port pin F3 is on pin 3 */
# define PF4_PIN 4 /**< GPIO port pin F4 is on pin 4 */
# define PF5_PIN 5 /**< GPIO port pin F5 is on pin 5 */
# define PF6_PIN 6 /**< GPIO port pin F6 is on pin 6 */
# define PF7_PIN 7 /**< GPIO port pin F7 is on pin 7 */
# define PF8_PIN 8 /**< GPIO port pin F8 is on pin 8 */
# define PF9_PIN 9 /**< GPIO port pin F9 is on pin 9 */
# define PF10_PIN 10 /**< GPIO port pin F10 is on pin 10 */
# define PF11_PIN 11 /**< GPIO port pin F11 is on pin 11 */
# define PF12_PIN 12 /**< GPIO port pin F12 is on pin 12 */
# define PF13_PIN 13 /**< GPIO port pin F13 is on pin 13 */
# define PF14_PIN 14 /**< GPIO port pin F14 is on pin 14 */
# define PF15_PIN 15 /**< GPIO port pin F15 is on pin 15 */
# define PG0_PIN 0 /**< GPIO port pin G0 is on pin 0 */
# define PG1_PIN 1 /**< GPIO port pin G1 is on pin 1 */
# define PG2_PIN 2 /**< GPIO port pin G2 is on pin 2 */
# define PG3_PIN 3 /**< GPIO port pin G3 is on pin 3 */
# define PG4_PIN 4 /**< GPIO port pin G4 is on pin 4 */
# define PG5_PIN 5 /**< GPIO port pin G5 is on pin 5 */
# define PG6_PIN 6 /**< GPIO port pin G6 is on pin 6 */
# define PG7_PIN 7 /**< GPIO port pin G7 is on pin 7 */
# define PG8_PIN 8 /**< GPIO port pin G8 is on pin 8 */
# define PG9_PIN 9 /**< GPIO port pin G9 is on pin 9 */
# define PG10_PIN 10 /**< GPIO port pin G10 is on pin 10 */
# define PG11_PIN 11 /**< GPIO port pin G11 is on pin 11 */
# define PG12_PIN 12 /**< GPIO port pin G12 is on pin 12 */
# define PG13_PIN 13 /**< GPIO port pin G13 is on pin 13 */
# define PG14_PIN 14 /**< GPIO port pin G14 is on pin 14 */
# define PG15_PIN 15 /**< GPIO port pin G15 is on pin 15 */
2016-10-23 17:42:27 +02:00
/** get RCC for GPIO based on GPIO identifier */
# define RCC_GPIO(x) CAT2(RCC_GPIO,x)
2019-06-18 13:46:57 +02:00
/** get RCC for GPIO based on GPIO identifier */
# define GPIO_RCC(x) RCC_GPIO(GPIO_PORT_ID(x))
2020-06-14 19:01:29 +02:00
/** get RST for GPIO based on GPIO identifier */
# define RST_GPIO(x) CAT2(RST_GPIO,x)
/** get RST for GPIO based on GPIO identifier */
# define GPIO_RST(x) RST_GPIO(GPIO_PORT_ID(x))
2016-10-23 17:42:27 +02:00
/** get TIM based on TIM identifier */
# define TIM(x) CAT2(TIM,x)
/** get RCC for timer based on TIM identifier */
# define RCC_TIM(x) CAT2(RCC_TIM,x)
2020-02-17 13:59:49 +01:00
/** get RST for timer based on TIM identifier */
# define RST_TIM(x) CAT2(RST_TIM,x)
2016-10-23 17:42:27 +02:00
/** get NVIC IRQ for timer base on TIM identifier */
# define NVIC_TIM_IRQ(x) CAT3(NVIC_TIM,x,_IRQ)
2020-12-10 23:53:08 +01:00
/** NVIC IRQ for timer 9 */
# define NVIC_TIM9_IRQ NVIC_TIM1_BRK_TIM9_IRQ
/** NVIC IRQ for timer 10 */
# define NVIC_TIM10_IRQ NVIC_TIM1_UP_TIM10_IRQ
/** NVIC IRQ for timer 11 */
# define NVIC_TIM11_IRQ NVIC_TIM1_TRG_COM_TIM11_IRQ
2016-10-23 17:42:27 +02:00
/** get interrupt service routine for timer base on TIM identifier */
# define TIM_ISR(x) CAT3(tim,x,_isr)
2020-12-10 23:53:08 +01:00
/** interrupt service routine for timer 9 */
# define tim9_isr tim1_brk_tim9_isr
/** interrupt service routine for timer 10 */
# define tim10_isr tim1_up_tim10_isr
/** interrupt service routine for timer 11 */
# define tim11_isr tim1_trg_com_tim11_isr
2022-06-03 10:10:49 +02:00
/** get TIM_OC based on CHx identifier */
# define TIM_OC(x) CAT2(TIM_OC,x)
2017-02-06 17:32:49 +01:00
/** get TIM_IC based on CHx identifier */
# define TIM_IC(x) CAT2(TIM_IC,x)
/** get TIM_IC_IN_TI based on CHx identifier */
# define TIM_IC_IN_TI(x) CAT2(TIM_IC_IN_TI,x)
/** get TIM_SR_CCxIF based on CHx identifier */
# define TIM_SR_CCIF(x) CAT3(TIM_SR_CC,x,IF)
2018-06-14 13:17:01 +02:00
/** get TIM_SR_CCxOF based on CHx identifier */
# define TIM_SR_CCOF(x) CAT3(TIM_SR_CC,x,OF)
2017-02-06 17:32:49 +01:00
/** get TIM_DIER_CCxIE based on CHx identifier */
# define TIM_DIER_CCIE(x) CAT3(TIM_DIER_CC,x,IE)
/** get TIM_CCRy register based on TIMx_CHy identifier */
# define TIM_CCR(x,y) CAT2(TIM_CCR,y)(TIM(x))
2016-10-23 17:42:27 +02:00
/** get external interrupt based on pin identifier */
# define EXTI(x) CAT2(EXTI,x)
2019-06-18 13:46:57 +02:00
/** get external interrupt based on GPIO port and pin identifier */
# define GPIO_EXTI(x) EXTI(GPIO_PIN_ID(x))
/** get NVIC IRQ for external interrupt based on external interrupt/pin */
2016-10-23 17:42:27 +02:00
# define NVIC_EXTI_IRQ(x) CAT3(NVIC_EXTI,x,_IRQ)
2019-06-18 13:46:57 +02:00
/** get NVIC IRQ for external interrupt based on GPIO port and pin identifier */
# define GPIO_NVIC_EXTI_IRQ(x) NVIC_EXTI_IRQ(GPIO_PIN_ID(x))
2016-10-23 17:42:27 +02:00
# define NVIC_EXTI5_IRQ NVIC_EXTI9_5_IRQ /**< IRQ for line 9 to 5 for pin 5 */
# define NVIC_EXTI6_IRQ NVIC_EXTI9_5_IRQ /**< IRQ for line 9 to 5 for pin 6 */
# define NVIC_EXTI7_IRQ NVIC_EXTI9_5_IRQ /**< IRQ for line 9 to 5 for pin 7 */
# define NVIC_EXTI8_IRQ NVIC_EXTI9_5_IRQ /**< IRQ for line 9 to 5 for pin 8 */
# define NVIC_EXTI9_IRQ NVIC_EXTI9_5_IRQ /**< IRQ for line 9 to 5 for pin 9 */
# define NVIC_EXTI10_IRQ NVIC_EXTI15_10_IRQ /**< IRQ for line 15 to 10 for pin 10 */
# define NVIC_EXTI11_IRQ NVIC_EXTI15_10_IRQ /**< IRQ for line 15 to 10 for pin 11 */
# define NVIC_EXTI12_IRQ NVIC_EXTI15_10_IRQ /**< IRQ for line 15 to 10 for pin 12 */
# define NVIC_EXTI13_IRQ NVIC_EXTI15_10_IRQ /**< IRQ for line 15 to 10 for pin 13 */
# define NVIC_EXTI14_IRQ NVIC_EXTI15_10_IRQ /**< IRQ for line 15 to 10 for pin 14 */
# define NVIC_EXTI15_IRQ NVIC_EXTI15_10_IRQ /**< IRQ for line 15 to 10 for pin 15 */
/** get interrupt service routine for timer base on external interrupt/pin */
# define EXTI_ISR(x) CAT3(exti,x,_isr)
2019-06-18 13:46:57 +02:00
/** get external interrupt based on GPIO port and pin identifier */
# define GPIO_EXTI_ISR(x) EXTI_ISR(GPIO_PIN_ID(x))
# define exti5_isr exti9_5_isr /**< ISR for line 9 to 5 for pin 5 */
# define exti6_isr exti9_5_isr /**< ISR for line 9 to 5 for pin 6 */
# define exti7_isr exti9_5_isr /**< ISR for line 9 to 5 for pin 7 */
# define exti8_isr exti9_5_isr /**< ISR for line 9 to 5 for pin 8 */
# define exti9_isr exti9_5_isr /**< ISR for line 9 to 5 for pin 9 */
# define exti10_isr exti15_10_isr /**< ISR for line 15 to 10 for pin 10 */
# define exti11_isr exti15_10_isr /**< ISR for line 15 to 10 for pin 11 */
# define exti12_isr exti15_10_isr /**< ISR for line 15 to 10 for pin 12 */
# define exti13_isr exti15_10_isr /**< ISR for line 15 to 10 for pin 13 */
# define exti14_isr exti15_10_isr /**< ISR for line 15 to 10 for pin 14 */
# define exti15_isr exti15_10_isr /**< ISR for line 15 to 10 for pin 15 */
2016-10-23 17:42:27 +02:00
/** get USART based on USART identifier */
# define USART(x) CAT2(USART,x)
/** get RCC for USART based on USART identifier */
2018-04-03 16:59:02 +02:00
# define RCC_USART(x) CAT2(RCC_USART,x)
2018-06-14 13:17:01 +02:00
/** get RST for USART based on USART identifier */
# define RST_USART(x) CAT2(RST_USART,x)
2016-10-23 17:42:27 +02:00
/** get NVIC IRQ for USART based on USART identifier */
# define USART_IRQ(x) CAT3(NVIC_USART,x,_IRQ)
/** get interrupt service routine for USART based on USART identifier */
# define USART_ISR(x) CAT3(usart,x,_isr)
2020-12-14 13:34:52 +01:00
/** get channel based on ADC1_IN identifier */
2017-02-06 17:32:49 +01:00
# define ADC_CHANNEL(x) CAT2(ADC_CHANNEL,x)
2017-04-03 13:03:07 +02:00
/** get SPI based on SPI identifier */
# define SPI(x) CAT2(SPI,x)
/** get RCC for SPI based on SPI identifier */
# define RCC_SPI(x) CAT2(RCC_SPI,x)
2017-06-28 10:27:53 +02:00
/** get SPI CRC polynomial register based on SPI identifier */
# define SPI_CRC_PR(x) CAT3(SPI,x,_CRCPR)
/** get SPI CRC transmit register based on SPI identifier */
# define SPI_CRC_TXR(x) CAT3(SPI,x,_TXCRCR)
/** get SPI CRC receive register based on SPI identifier */
# define SPI_CRC_RXR(x) CAT3(SPI,x,_RXCRCR)
2020-02-09 18:56:22 +01:00
/** get SPI IRQ based on SPI identifier */
# define SPI_IRQ(x) CAT3(NVIC_SPI,x,_IRQ)
/** get SPI ISR based on SPI identifier */
# define SPI_ISR(x) CAT3(spi,x,_isr)
2020-12-12 14:05:41 +01:00
/** get I²C based on I²C identifier */
# define I2C(x) CAT2(I2C,x)
/** get RCC for I²C based on I²C identifier */
# define RCC_I2C(x) CAT2(RCC_I2C,x)
2020-12-14 13:34:52 +01:00
/** get port based on ADC1_IN identifier */
# define ADC1_IN_PORT(x) CAT3(ADC1_IN,x,_PORT)
# define ADC1_IN0_PORT GPIOA /**< ADC1_IN0 is on PA0 */
# define ADC1_IN1_PORT GPIOA /**< ADC1_IN1 is on PA1 */
# define ADC1_IN2_PORT GPIOA /**< ADC1_IN2 is on PA2 */
# define ADC1_IN3_PORT GPIOA /**< ADC1_IN3 is on PA3 */
# define ADC1_IN4_PORT GPIOA /**< ADC1_IN4 is on PA4 */
# define ADC1_IN5_PORT GPIOA /**< ADC1_IN5 is on PA5 */
# define ADC1_IN6_PORT GPIOA /**< ADC1_IN6 is on PA6 */
# define ADC1_IN7_PORT GPIOA /**< ADC1_IN7 is on PA7 */
# define ADC1_IN8_PORT GPIOB /**< ADC1_IN8 is on PB0 */
# define ADC1_IN9_PORT GPIOB /**< ADC1_IN9 is on PB1 */
# define ADC1_IN10_PORT GPIOC /**< ADC1_IN10 is on PC0 */
# define ADC1_IN11_PORT GPIOC /**< ADC1_IN11 is on PC1 */
# define ADC1_IN12_PORT GPIOC /**< ADC1_IN12 is on PC2 */
# define ADC1_IN13_PORT GPIOC /**< ADC1_IN13 is on PC3 */
# define ADC1_IN14_PORT GPIOC /**< ADC1_IN14 is on PC4 */
# define ADC1_IN15_PORT GPIOC /**< ADC1_IN15 is on PC5 */
/** get pin based on ADC1_IN identifier */
# define ADC1_IN_PIN(x) CAT3(ADC1_IN,x,_PIN)
# define ADC1_IN0_PIN GPIO0 /**< ADC1_IN0 is on PA0 */
# define ADC1_IN1_PIN GPIO1 /**< ADC1_IN1 is on PA1 */
# define ADC1_IN2_PIN GPIO2 /**< ADC1_IN2 is on PA2 */
# define ADC1_IN3_PIN GPIO3 /**< ADC1_IN3 is on PA3 */
# define ADC1_IN4_PIN GPIO4 /**< ADC1_IN4 is on PA4 */
# define ADC1_IN5_PIN GPIO5 /**< ADC1_IN5 is on PA5 */
# define ADC1_IN6_PIN GPIO6 /**< ADC1_IN6 is on PA6 */
# define ADC1_IN7_PIN GPIO7 /**< ADC1_IN7 is on PA7 */
# define ADC1_IN8_PIN GPIO0 /**< ADC1_IN8 is on PB0 */
# define ADC1_IN9_PIN GPIO1 /**< ADC1_IN9 is on PB1 */
# define ADC1_IN10_PIN GPIO0 /**< ADC1_IN10 is on PC0 */
# define ADC1_IN11_PIN GPIO1 /**< ADC1_IN11 is on PC1 */
# define ADC1_IN12_PIN GPIO2 /**< ADC1_IN12 is on PC2 */
# define ADC1_IN13_PIN GPIO3 /**< ADC1_IN13 is on PC3 */
# define ADC1_IN14_PIN GPIO4 /**< ADC1_IN14 is on PC4 */
# define ADC1_IN15_PIN GPIO5 /**< ADC1_IN15 is on PC5 */
/** get RCC based on ADC1_IN identifier */
# define RCC_ADC1_IN(x) CAT2(RCC_ADC1_IN,x)
# define RCC_ADC1_IN0 RCC_GPIOA /**< ADC1_IN0 is on PA0 */
# define RCC_ADC1_IN1 RCC_GPIOA /**< ADC1_IN1 is on PA1 */
# define RCC_ADC1_IN2 RCC_GPIOA /**< ADC1_IN2 is on PA2 */
# define RCC_ADC1_IN3 RCC_GPIOA /**< ADC1_IN3 is on PA3 */
# define RCC_ADC1_IN4 RCC_GPIOA /**< ADC1_IN4 is on PA4 */
# define RCC_ADC1_IN5 RCC_GPIOA /**< ADC1_IN5 is on PA5 */
# define RCC_ADC1_IN6 RCC_GPIOA /**< ADC1_IN6 is on PA6 */
# define RCC_ADC1_IN7 RCC_GPIOA /**< ADC1_IN7 is on PA7 */
# define RCC_ADC1_IN8 RCC_GPIOB /**< ADC1_IN8 is on PB0 */
# define RCC_ADC1_IN9 RCC_GPIOB /**< ADC1_IN9 is on PB1 */
# define RCC_ADC1_IN10 RCC_GPIOC /**< ADC1_IN10 is on PC0 */
# define RCC_ADC1_IN11 RCC_GPIOC /**< ADC1_IN11 is on PC1 */
# define RCC_ADC1_IN12 RCC_GPIOC /**< ADC1_IN12 is on PC2 */
# define RCC_ADC1_IN13 RCC_GPIOC /**< ADC1_IN13 is on PC3 */
# define RCC_ADC1_IN14 RCC_GPIOC /**< ADC1_IN14 is on PC4 */
# define RCC_ADC1_IN15 RCC_GPIOC /**< ADC1_IN15 is on PC5 */
/** get channel based on ADC1_IN identifier */
# define ADC_CHANNEL(x) CAT2(ADC_CHANNEL,x)
2016-10-23 17:42:27 +02:00
/** @} */
2016-01-28 21:21:50 +01:00
2016-08-14 20:30:16 +02:00
/** @defgroup board_led board LED GPIO
* @ {
*/
2020-11-24 15:59:42 +01:00
# if defined(MINIF401)
2020-02-02 21:18:28 +01:00
# define LED_PIN PC13 /**< GPIO pin */
# define LED_ON 0 /**< LED is on when pin is low */
2016-01-29 00:24:14 +01:00
# endif
2016-08-14 20:30:16 +02:00
/** @} */
2016-01-17 14:54:54 +01:00
2016-08-14 20:30:16 +02:00
/** @defgroup board_button board user button GPIO
* @ {
*/
2020-11-24 15:59:42 +01:00
# if defined(MINIF401)
# define BUTTON_PIN PA0 /**< GPIO pin */
2018-02-18 15:18:42 +01:00
# define BUTTON_PRESSED 0 /**< pin is low when button is pressed */
2016-01-29 11:25:30 +01:00
# endif
2016-08-14 20:30:16 +02:00
/** @} */
2016-01-29 11:25:30 +01:00
2017-04-15 13:51:24 +02:00
/** @defgroup input to force DFU mode on low, even if application is valid
* @ {
*/
2020-03-02 15:32:32 +01:00
# if defined(BUTTON_PIN) && defined(BUTTON_PRESSED)
2017-04-15 13:51:24 +02:00
# define DFU_FORCE_PIN BUTTON_PIN /**< button pin */
2020-03-02 15:32:32 +01:00
# define DFU_FORCE_VALUE BUTTON_PRESSED /**< start DFU when button is pressed on boot */
2017-04-15 13:51:24 +02:00
# endif
/** @} */
2018-02-18 15:20:47 +01:00
/** flag set when board user button has been pressed/released */
extern volatile bool button_flag ;
2020-11-24 15:59:42 +01:00
2019-12-21 19:48:00 +01:00
/** symbol for the DFU magic word
* @ note this symbol will be provided by the linker script
*/
extern char __dfu_magic [ 4 ] ;
2018-02-18 15:20:47 +01:00
/** flag set when user input is available */
extern volatile bool user_input_available ;
2016-10-23 17:42:27 +02:00
2016-08-14 20:30:16 +02:00
/** get binary representation of a number
* @ param [ in ] binary number to represent in binary
* @ param [ in ] rjust justify representation with leading zeros
* @ return string with binary representation of the number
*/
char * b2s ( uint64_t binary , uint8_t rjust ) ;
2016-10-23 17:42:27 +02:00
/** switch on board LED */
void led_on ( void ) ;
/** switch off board LED */
void led_off ( void ) ;
/** toggle board LED */
void led_toggle ( void ) ;
2017-08-02 13:44:16 +02:00
/** go to sleep for some microseconds
* @ param [ in ] duration sleep duration in us
*/
void sleep_us ( uint32_t duration ) ;
/** go to sleep for some milliseconds
* @ param [ in ] duration sleep duration in ms
*/
void sleep_ms ( uint32_t duration ) ;
2018-02-18 15:20:47 +01:00
/** get user input
* @ note verify availability using user_input_available
* @ warning blocks and sleeps until user input is available
* @ return user input character
*/
char user_input_get ( void ) ;
/** store user input
* @ param [ in ] c user input character to store
* @ note old data will be overwritten when buffer is full
*/
void user_input_store ( char c ) ;
2016-10-23 17:42:27 +02:00
/** setup board peripherals */
void board_setup ( void ) ;
2020-11-27 16:37:52 +01:00
/** start embedded bootloader (e.g. system memory)
* @ warning the USB DFU bootloader does not start
* @ note after jumping to the bootloader , the USB device is detected , but does not enumerate . I have no idea about the cause . Not configuring the USB did not solve the issue . Re - initializing RCC did not help . Even the STM32CodeMX generated code was not able to have a working USB DFU reboot . Calibrating HSI according to https : //community.st.com/s/question/0D50X0000BG0TfH/stm32f4-usb-dfu-bootloader-not-working-reliably did not solve the issue. Maybe there is something with the board. Booting the embedded USB DFU bootloader by hand by pressing the BOOT0 button works.
* @ note the USART bootloader works fine though
*/
void system_memory ( void ) ;
/** start DFU bootloader */
void dfu_bootloader ( void ) ;