43 |
44 | /**
45 | * @ingroup groupMath
46 | */
47 |
48 | /**
49 | * @defgroup BasicAbs Vector Absolute Value
50 | *
51 | * Computes the absolute value of a vector on an element-by-element basis.
52 | *
53 | *
54 | * pDst[n] = abs(pSrc[n]), 0 <= n < blockSize.
55 | *
56 | *
57 | * The functions support in-place computation allowing the source and
58 | * destination pointers to reference the same memory buffer.
59 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
60 | */
61 |
62 | /**
63 | * @addtogroup BasicAbs
64 | * @{
65 | */
66 |
67 | /**
68 | * @brief Floating-point vector absolute value.
69 | * @param[in] *pSrc points to the input buffer
70 | * @param[out] *pDst points to the output buffer
71 | * @param[in] blockSize number of samples in each vector
72 | * @return none.
73 | */
74 |
75 | void arm_abs_f32(
76 | float32_t * pSrc,
77 | float32_t * pDst,
78 | uint32_t blockSize)
79 | {
80 | uint32_t blkCnt; /* loop counter */
81 |
82 | #ifndef ARM_MATH_CM0_FAMILY
83 |
84 | /* Run the below code for Cortex-M4 and Cortex-M3 */
85 | float32_t in1, in2, in3, in4; /* temporary variables */
86 |
87 | /*loop Unrolling */
88 | blkCnt = blockSize >> 2u;
89 |
90 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
91 | ** a second loop below computes the remaining 1 to 3 samples. */
92 | while(blkCnt > 0u)
93 | {
94 | /* C = |A| */
95 | /* Calculate absolute and then store the results in the destination buffer. */
96 | /* read sample from source */
97 | in1 = *pSrc;
98 | in2 = *(pSrc + 1);
99 | in3 = *(pSrc + 2);
100 |
101 | /* find absolute value */
102 | in1 = fabsf(in1);
103 |
104 | /* read sample from source */
105 | in4 = *(pSrc + 3);
106 |
107 | /* find absolute value */
108 | in2 = fabsf(in2);
109 |
110 | /* read sample from source */
111 | *pDst = in1;
112 |
113 | /* find absolute value */
114 | in3 = fabsf(in3);
115 |
116 | /* find absolute value */
117 | in4 = fabsf(in4);
118 |
119 | /* store result to destination */
120 | *(pDst + 1) = in2;
121 |
122 | /* store result to destination */
123 | *(pDst + 2) = in3;
124 |
125 | /* store result to destination */
126 | *(pDst + 3) = in4;
127 |
128 |
129 | /* Update source pointer to process next sampels */
130 | pSrc += 4u;
131 |
132 | /* Update destination pointer to process next sampels */
133 | pDst += 4u;
134 |
135 | /* Decrement the loop counter */
136 | blkCnt--;
137 | }
138 |
139 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
140 | ** No loop unrolling is used. */
141 | blkCnt = blockSize % 0x4u;
142 |
143 | #else
144 |
145 | /* Run the below code for Cortex-M0 */
146 |
147 | /* Initialize blkCnt with number of samples */
148 | blkCnt = blockSize;
149 |
150 | #endif /* #ifndef ARM_MATH_CM0_FAMILY */
151 |
152 | while(blkCnt > 0u)
153 | {
154 | /* C = |A| */
155 | /* Calculate absolute and then store the results in the destination buffer. */
156 | *pDst++ = fabsf(*pSrc++);
157 |
158 | /* Decrement the loop counter */
159 | blkCnt--;
160 | }
161 | }
162 |
163 | /**
164 | * @} end of BasicAbs group
165 | */
166 |
--------------------------------------------------------------------------------
/system/src/cmsis/arm_cos_f32.c:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------
2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3 | *
4 | * $Date: 21. September 2015
5 | * $Revision: V.1.4.5 a
6 | *
7 | * Project: CMSIS DSP Library
8 | * Title: arm_cos_f32.c
9 | *
10 | * Description: Fast cosine calculation for floating-point values.
11 | *
12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 | *
14 | * Redistribution and use in source and binary forms, with or without
15 | * modification, are permitted provided that the following conditions
16 | * are met:
17 | * - Redistributions of source code must retain the above copyright
18 | * notice, this list of conditions and the following disclaimer.
19 | * - Redistributions in binary form must reproduce the above copyright
20 | * notice, this list of conditions and the following disclaimer in
21 | * the documentation and/or other materials provided with the
22 | * distribution.
23 | * - Neither the name of ARM LIMITED nor the names of its contributors
24 | * may be used to endorse or promote products derived from this
25 | * software without specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 | * POSSIBILITY OF SUCH DAMAGE.
39 | * -------------------------------------------------------------------- */
40 |
41 | #include "arm_math.h"
42 | #include "arm_common_tables.h"
43 | /**
44 | * @ingroup groupFastMath
45 | */
46 |
47 | /**
48 | * @defgroup cos Cosine
49 | *
50 | * Computes the trigonometric cosine function using a combination of table lookup
51 | * and linear interpolation. There are separate functions for
52 | * Q15, Q31, and floating-point data types.
53 | * The input to the floating-point version is in radians while the
54 | * fixed-point Q15 and Q31 have a scaled input with the range
55 | * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a
56 | * value of 2*pi wraps around to 0.
57 | *
58 | * The implementation is based on table lookup using 256 values together with linear interpolation.
59 | * The steps used are:
60 | * -# Calculation of the nearest integer table index
61 | * -# Compute the fractional portion (fract) of the table index.
62 | * -# The final result equals (1.0f-fract)*a + fract*b;
63 | *
64 | * where
65 | *
66 | * b=Table[index+0];
67 | * c=Table[index+1];
68 | *
69 | */
70 |
71 | /**
72 | * @addtogroup cos
73 | * @{
74 | */
75 |
76 | /**
77 | * @brief Fast approximation to the trigonometric cosine function for floating-point data.
78 | * @param[in] x input value in radians.
79 | * @return cos(x).
80 | */
81 |
82 | float32_t arm_cos_f32(
83 | float32_t x)
84 | {
85 | float32_t cosVal, fract, in; /* Temporary variables for input, output */
86 | uint16_t index; /* Index variable */
87 | float32_t a, b; /* Two nearest output values */
88 | int32_t n;
89 | float32_t findex;
90 |
91 | /* input x is in radians */
92 | /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi, add 0.25 (pi/2) to read sine table */
93 | in = x * 0.159154943092f + 0.25f;
94 |
95 | /* Calculation of floor value of input */
96 | n = (int32_t) in;
97 |
98 | /* Make negative values towards -infinity */
99 | if(in < 0.0f)
100 | {
101 | n--;
102 | }
103 |
104 | /* Map input value to [0 1] */
105 | in = in - (float32_t) n;
106 |
107 | /* Calculation of index of the table */
108 | findex = (float32_t) FAST_MATH_TABLE_SIZE * in;
109 | index = ((uint16_t)findex) & 0x1ff;
110 |
111 | /* fractional value calculation */
112 | fract = findex - (float32_t) index;
113 |
114 | /* Read two nearest values of input value from the cos table */
115 | a = sinTable_f32[index];
116 | b = sinTable_f32[index+1];
117 |
118 | /* Linear interpolation process */
119 | cosVal = (1.0f-fract)*a + fract*b;
120 |
121 | /* Return the output value */
122 | return (cosVal);
123 | }
124 |
125 | /**
126 | * @} end of cos group
127 | */
128 |
--------------------------------------------------------------------------------
/system/src/cmsis/arm_sin_f32.c:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------
2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3 | *
4 | * $Date: 21. September 2015
5 | * $Revision: V.1.4.5 a
6 | *
7 | * Project: CMSIS DSP Library
8 | * Title: arm_sin_f32.c
9 | *
10 | * Description: Fast sine calculation for floating-point values.
11 | *
12 | * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
13 | *
14 | * Redistribution and use in source and binary forms, with or without
15 | * modification, are permitted provided that the following conditions
16 | * are met:
17 | * - Redistributions of source code must retain the above copyright
18 | * notice, this list of conditions and the following disclaimer.
19 | * - Redistributions in binary form must reproduce the above copyright
20 | * notice, this list of conditions and the following disclaimer in
21 | * the documentation and/or other materials provided with the
22 | * distribution.
23 | * - Neither the name of ARM LIMITED nor the names of its contributors
24 | * may be used to endorse or promote products derived from this
25 | * software without specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 | * POSSIBILITY OF SUCH DAMAGE.
39 | * -------------------------------------------------------------------- */
40 |
41 | #include "arm_math.h"
42 | #include "arm_common_tables.h"
43 | #include
44 |
45 | /**
46 | * @ingroup groupFastMath
47 | */
48 |
49 | /**
50 | * @defgroup sin Sine
51 | *
52 | * Computes the trigonometric sine function using a combination of table lookup
53 | * and linear interpolation. There are separate functions for
54 | * Q15, Q31, and floating-point data types.
55 | * The input to the floating-point version is in radians while the
56 | * fixed-point Q15 and Q31 have a scaled input with the range
57 | * [0 +0.9999] mapping to [0 2*pi). The fixed-point range is chosen so that a
58 | * value of 2*pi wraps around to 0.
59 | *
60 | * The implementation is based on table lookup using 256 values together with linear interpolation.
61 | * The steps used are:
62 | * -# Calculation of the nearest integer table index
63 | * -# Compute the fractional portion (fract) of the table index.
64 | * -# The final result equals (1.0f-fract)*a + fract*b;
65 | *
66 | * where
67 | *
68 | * b=Table[index+0];
69 | * c=Table[index+1];
70 | *
71 | */
72 |
73 | /**
74 | * @addtogroup sin
75 | * @{
76 | */
77 |
78 | /**
79 | * @brief Fast approximation to the trigonometric sine function for floating-point data.
80 | * @param[in] x input value in radians.
81 | * @return sin(x).
82 | */
83 |
84 | float32_t arm_sin_f32(
85 | float32_t x)
86 | {
87 | float32_t sinVal, fract, in; /* Temporary variables for input, output */
88 | uint16_t index; /* Index variable */
89 | float32_t a, b; /* Two nearest output values */
90 | int32_t n;
91 | float32_t findex;
92 |
93 | /* input x is in radians */
94 | /* Scale the input to [0 1] range from [0 2*PI] , divide input by 2*pi */
95 | in = x * 0.159154943092f;
96 |
97 | /* Calculation of floor value of input */
98 | n = (int32_t) in;
99 |
100 | /* Make negative values towards -infinity */
101 | if(x < 0.0f)
102 | {
103 | n--;
104 | }
105 |
106 | /* Map input value to [0 1] */
107 | in = in - (float32_t) n;
108 |
109 | /* Calculation of index of the table */
110 | findex = (float32_t) FAST_MATH_TABLE_SIZE * in;
111 | if (findex >= 512.0f) {
112 | findex -= 512.0f;
113 | }
114 |
115 | index = ((uint16_t)findex) & 0x1ff;
116 |
117 | /* fractional value calculation */
118 | fract = findex - (float32_t) index;
119 |
120 | /* Read two nearest values of input value from the sin table */
121 | a = sinTable_f32[index];
122 | b = sinTable_f32[index+1];
123 |
124 | /* Linear interpolation process */
125 | sinVal = (1.0f-fract)*a + fract*b;
126 |
127 | /* Return the output value */
128 | return (sinVal);
129 | }
130 |
131 | /**
132 | * @} end of sin group
133 | */
134 |
--------------------------------------------------------------------------------
/system/src/cortexm/_initialize_hardware.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include "cmsis_device.h"
9 |
10 | // ----------------------------------------------------------------------------
11 |
12 | extern unsigned int __vectors_start;
13 |
14 | // Forward declarations.
15 |
16 | void
17 | __initialize_hardware_early(void);
18 |
19 | void
20 | __initialize_hardware(void);
21 |
22 | // ----------------------------------------------------------------------------
23 |
24 | // This is the early hardware initialisation routine, it can be
25 | // redefined in the application for more complex cases that
26 | // require early inits (before BSS init).
27 | //
28 | // Called early from _start(), right before data & bss init.
29 | //
30 | // After Reset the Cortex-M processor is in Thread mode,
31 | // priority is Privileged, and the Stack is set to Main.
32 |
33 | void
34 | __attribute__((weak))
35 | __initialize_hardware_early(void)
36 | {
37 | // Call the CSMSIS system initialisation routine.
38 | SystemInit();
39 |
40 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
41 | // Set VTOR to the actual address, provided by the linker script.
42 | // Override the manual, possibly wrong, SystemInit() setting.
43 | SCB->VTOR = (uint32_t)(&__vectors_start);
44 | #endif
45 |
46 | // The current version of SystemInit() leaves the value of the clock
47 | // in a RAM variable (SystemCoreClock), which will be cleared shortly,
48 | // so it needs to be recomputed after the RAM initialisations
49 | // are completed.
50 |
51 | #if defined(OS_INCLUDE_STARTUP_INIT_FP) || (defined (__VFP_FP__) && !defined (__SOFTFP__))
52 |
53 | // Normally FP init is done by SystemInit(). In case this is not done
54 | // there, it is possible to force its inclusion by defining
55 | // OS_INCLUDE_STARTUP_INIT_FP.
56 |
57 | // Enable the Cortex-M4 FPU only when -mfloat-abi=hard.
58 | // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C)
59 |
60 | // Set bits 20-23 to enable CP10 and CP11 coprocessor
61 | SCB->CPACR |= (0xF << 20);
62 |
63 | #endif // (__VFP_FP__) && !(__SOFTFP__)
64 |
65 | #if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
66 | SCB->SHCSR |= SCB_SHCSR_USGFAULTENA_Msk;
67 | #endif
68 | }
69 |
70 | // This is the second hardware initialisation routine, it can be
71 | // redefined in the application for more complex cases that
72 | // require custom inits (before constructors), otherwise these can
73 | // be done in main().
74 | //
75 | // Called from _start(), right after data & bss init, before
76 | // constructors.
77 |
78 | void
79 | __attribute__((weak))
80 | __initialize_hardware(void)
81 | {
82 | // Call the CSMSIS system clock routine to store the clock frequency
83 | // in the SystemCoreClock global RAM location.
84 | SystemCoreClockUpdate();
85 | }
86 |
87 | // ----------------------------------------------------------------------------
88 |
--------------------------------------------------------------------------------
/system/src/cortexm/_reset_hardware.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include "cmsis_device.h"
9 |
10 | // ----------------------------------------------------------------------------
11 |
12 | extern void
13 | __attribute__((noreturn))
14 | NVIC_SystemReset(void);
15 |
16 | // ----------------------------------------------------------------------------
17 |
18 | // Forward declarations
19 |
20 | void
21 | __reset_hardware(void);
22 |
23 | // ----------------------------------------------------------------------------
24 |
25 | // This is the default hardware reset routine; it can be
26 | // redefined in the application for more complex applications.
27 | //
28 | // Called from _exit().
29 |
30 | void
31 | __attribute__((weak,noreturn))
32 | __reset_hardware()
33 | {
34 | NVIC_SystemReset();
35 | }
36 |
37 | // ----------------------------------------------------------------------------
38 |
--------------------------------------------------------------------------------
/system/src/diag/Trace.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #if defined(TRACE)
9 |
10 | #include
11 | #include
12 | #include "diag/Trace.h"
13 | #include "string.h"
14 |
15 | #ifndef OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE
16 | #define OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE (128)
17 | #endif
18 |
19 | // ----------------------------------------------------------------------------
20 |
21 | int
22 | trace_printf(const char* format, ...)
23 | {
24 | int ret;
25 | va_list ap;
26 |
27 | va_start (ap, format);
28 |
29 | // TODO: rewrite it to no longer use newlib, it is way too heavy
30 |
31 | static char buf[OS_INTEGER_TRACE_PRINTF_TMP_ARRAY_SIZE];
32 |
33 | // Print to the local buffer
34 | ret = vsnprintf (buf, sizeof(buf), format, ap);
35 | if (ret > 0)
36 | {
37 | // Transfer the buffer to the device
38 | ret = trace_write (buf, (size_t)ret);
39 | }
40 |
41 | va_end (ap);
42 | return ret;
43 | }
44 |
45 | int
46 | trace_puts(const char *s)
47 | {
48 | trace_write(s, strlen(s));
49 | return trace_write("\n", 1);
50 | }
51 |
52 | int
53 | trace_putchar(int c)
54 | {
55 | trace_write((const char*)&c, 1);
56 | return c;
57 | }
58 |
59 | void
60 | trace_dump_args(int argc, char* argv[])
61 | {
62 | trace_printf("main(argc=%d, argv=[", argc);
63 | for (int i = 0; i < argc; ++i)
64 | {
65 | if (i != 0)
66 | {
67 | trace_printf(", ");
68 | }
69 | trace_printf("\"%s\"", argv[i]);
70 | }
71 | trace_printf("]);\n");
72 | }
73 |
74 | // ----------------------------------------------------------------------------
75 |
76 | #endif // TRACE
77 |
--------------------------------------------------------------------------------
/system/src/diag/trace_impl.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #if defined(TRACE)
9 |
10 | #include "cmsis_device.h"
11 | #include "diag/Trace.h"
12 |
13 | // ----------------------------------------------------------------------------
14 |
15 | // One of these definitions must be passed via the compiler command line
16 | // Note: small Cortex-M0/M0+ might implement a simplified debug interface.
17 |
18 | //#define OS_USE_TRACE_ITM
19 | //#define OS_USE_TRACE_SEMIHOSTING_DEBUG
20 | //#define OS_USE_TRACE_SEMIHOSTING_STDOUT
21 |
22 | #if !(defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
23 | #if defined(OS_USE_TRACE_ITM)
24 | #undef OS_USE_TRACE_ITM
25 | #warning "ITM unavailable"
26 | #endif // defined(OS_USE_TRACE_ITM)
27 | #endif // !(defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__))
28 |
29 | #if defined(OS_DEBUG_SEMIHOSTING_FAULTS)
30 | #if defined(OS_USE_TRACE_SEMIHOSTING_STDOUT) || defined(OS_USE_TRACE_SEMIHOSTING_DEBUG)
31 | #error "Cannot debug semihosting using semihosting trace; use OS_USE_TRACE_ITM"
32 | #endif
33 | #endif
34 |
35 | // ----------------------------------------------------------------------------
36 |
37 | // Forward definitions.
38 |
39 | #if defined(OS_USE_TRACE_ITM)
40 | static ssize_t
41 | _trace_write_itm (const char* buf, size_t nbyte);
42 | #endif
43 |
44 | #if defined(OS_USE_TRACE_SEMIHOSTING_STDOUT)
45 | static ssize_t
46 | _trace_write_semihosting_stdout(const char* buf, size_t nbyte);
47 | #endif
48 |
49 | #if defined(OS_USE_TRACE_SEMIHOSTING_DEBUG)
50 | static ssize_t
51 | _trace_write_semihosting_debug(const char* buf, size_t nbyte);
52 | #endif
53 |
54 | // ----------------------------------------------------------------------------
55 |
56 | void
57 | trace_initialize(void)
58 | {
59 | // For regular ITM / semihosting, no inits required.
60 | }
61 |
62 | // ----------------------------------------------------------------------------
63 |
64 | // This function is called from _write() for fd==1 or fd==2 and from some
65 | // of the trace_* functions.
66 |
67 | ssize_t
68 | trace_write (const char* buf __attribute__((unused)),
69 | size_t nbyte __attribute__((unused)))
70 | {
71 | #if defined(OS_USE_TRACE_ITM)
72 | return _trace_write_itm (buf, nbyte);
73 | #elif defined(OS_USE_TRACE_SEMIHOSTING_STDOUT)
74 | return _trace_write_semihosting_stdout(buf, nbyte);
75 | #elif defined(OS_USE_TRACE_SEMIHOSTING_DEBUG)
76 | return _trace_write_semihosting_debug(buf, nbyte);
77 | #endif
78 |
79 | return -1;
80 | }
81 |
82 | // ----------------------------------------------------------------------------
83 |
84 | #if defined(OS_USE_TRACE_ITM)
85 |
86 | #if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
87 |
88 | // ITM is the ARM standard mechanism, running over SWD/SWO on Cortex-M3/M4
89 | // devices, and is the recommended setting, if available.
90 | //
91 | // The JLink probe and the GDB server fully support SWD/SWO
92 | // and the JLink Debugging plug-in enables it by default.
93 | // The current OpenOCD does not include support to parse the SWO stream,
94 | // so this configuration will not work on OpenOCD (will not crash, but
95 | // nothing will be displayed in the output console).
96 |
97 | #if !defined(OS_INTEGER_TRACE_ITM_STIMULUS_PORT)
98 | #define OS_INTEGER_TRACE_ITM_STIMULUS_PORT (0)
99 | #endif
100 |
101 | static ssize_t
102 | _trace_write_itm (const char* buf, size_t nbyte)
103 | {
104 | for (size_t i = 0; i < nbyte; i++)
105 | {
106 | // Check if ITM or the stimulus port are not enabled
107 | if (((ITM->TCR & ITM_TCR_ITMENA_Msk) == 0)
108 | || ((ITM->TER & (1UL << OS_INTEGER_TRACE_ITM_STIMULUS_PORT)) == 0))
109 | {
110 | return (ssize_t)i; // return the number of sent characters (may be 0)
111 | }
112 |
113 | // Wait until STIMx is ready...
114 | while (ITM->PORT[OS_INTEGER_TRACE_ITM_STIMULUS_PORT].u32 == 0)
115 | ;
116 | // then send data, one byte at a time
117 | ITM->PORT[OS_INTEGER_TRACE_ITM_STIMULUS_PORT].u8 = (uint8_t) (*buf++);
118 | }
119 |
120 | return (ssize_t)nbyte; // all characters successfully sent
121 | }
122 |
123 | #endif // defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
124 |
125 | #endif // OS_USE_TRACE_ITM
126 |
127 | // ----------------------------------------------------------------------------
128 |
129 | #if defined(OS_USE_TRACE_SEMIHOSTING_DEBUG) || defined(OS_USE_TRACE_SEMIHOSTING_STDOUT)
130 |
131 | #include "arm/semihosting.h"
132 |
133 | // Semihosting is the other output channel that can be used for the trace
134 | // messages. It comes in two flavours: STDOUT and DEBUG. The STDOUT channel
135 | // is the equivalent of the stdout in POSIX and in most cases it is forwarded
136 | // to the GDB server stdout stream. The debug channel is a separate
137 | // channel. STDOUT is buffered, so nothing is displayed until a \n;
138 | // DEBUG is not buffered, but can be slow.
139 | //
140 | // Choosing between semihosting stdout and debug depends on the capabilities
141 | // of your GDB server, and also on specific needs. It is recommended to test
142 | // DEBUG first, and if too slow, try STDOUT.
143 | //
144 | // The JLink GDB server fully support semihosting, and both configurations
145 | // are available; to activate it, use "monitor semihosting enable" or check
146 | // the corresponding button in the JLink Debugging plug-in.
147 | // In OpenOCD, support for semihosting can be enabled using
148 | // "monitor arm semihosting enable".
149 | //
150 | // Note: Applications built with semihosting output active normally cannot
151 | // be executed without the debugger connected and active, since they use
152 | // BKPT to communicate with the host. However, with a carefully written
153 | // HardFault_Handler, the semihosting BKPT calls can be processed, making
154 | // possible to run semihosting applications as standalone, without being
155 | // terminated with hardware faults.
156 |
157 | #endif // OS_USE_TRACE_SEMIHOSTING_DEBUG_*
158 |
159 | // ----------------------------------------------------------------------------
160 |
161 | #if defined(OS_USE_TRACE_SEMIHOSTING_STDOUT)
162 |
163 | static ssize_t
164 | _trace_write_semihosting_stdout (const char* buf, size_t nbyte)
165 | {
166 | static int handle;
167 | void* block[3];
168 | int ret;
169 |
170 | if (handle == 0)
171 | {
172 | // On the first call get the file handle from the host
173 | block[0] = ":tt"; // special filename to be used for stdin/out/err
174 | block[1] = (void*) 4; // mode "w"
175 | // length of ":tt", except null terminator
176 | block[2] = (void*) (sizeof(":tt") - 1);
177 |
178 | ret = call_host (SEMIHOSTING_SYS_OPEN, (void*) block);
179 | if (ret == -1)
180 | return -1;
181 |
182 | handle = ret;
183 | }
184 |
185 | block[0] = (void*) handle;
186 | block[1] = (void*) buf;
187 | block[2] = (void*) nbyte;
188 | // send character array to host file/device
189 | ret = call_host (SEMIHOSTING_SYS_WRITE, (void*) block);
190 | // this call returns the number of bytes NOT written (0 if all ok)
191 |
192 | // -1 is not a legal value, but SEGGER seems to return it
193 | if (ret == -1)
194 | return -1;
195 |
196 | // The compliant way of returning errors
197 | if (ret == (int) nbyte)
198 | return -1;
199 |
200 | // Return the number of bytes written
201 | return (ssize_t) (nbyte) - (ssize_t) ret;
202 | }
203 |
204 | #endif // OS_USE_TRACE_SEMIHOSTING_STDOUT
205 |
206 | // ----------------------------------------------------------------------------
207 |
208 | #if defined(OS_USE_TRACE_SEMIHOSTING_DEBUG)
209 |
210 | #define OS_INTEGER_TRACE_TMP_ARRAY_SIZE (16)
211 |
212 | static ssize_t
213 | _trace_write_semihosting_debug (const char* buf, size_t nbyte)
214 | {
215 | // Since the single character debug channel is quite slow, try to
216 | // optimise and send a null terminated string, if possible.
217 | if (buf[nbyte] == '\0')
218 | {
219 | // send string
220 | call_host (SEMIHOSTING_SYS_WRITE0, (void*) buf);
221 | }
222 | else
223 | {
224 | // If not, use a local buffer to speed things up
225 | char tmp[OS_INTEGER_TRACE_TMP_ARRAY_SIZE];
226 | size_t togo = nbyte;
227 | while (togo > 0)
228 | {
229 | unsigned int n = ((togo < sizeof(tmp)) ? togo : sizeof(tmp));
230 | unsigned int i = 0;
231 | for (; i < n; ++i, ++buf)
232 | {
233 | tmp[i] = *buf;
234 | }
235 | tmp[i] = '\0';
236 |
237 | call_host (SEMIHOSTING_SYS_WRITE0, (void*) tmp);
238 |
239 | togo -= n;
240 | }
241 | }
242 |
243 | // All bytes written
244 | return (ssize_t) nbyte;
245 | }
246 |
247 | #endif // OS_USE_TRACE_SEMIHOSTING_DEBUG
248 |
249 | #endif // TRACE
250 |
251 | // ----------------------------------------------------------------------------
252 |
253 |
--------------------------------------------------------------------------------
/system/src/newlib/README.txt:
--------------------------------------------------------------------------------
1 |
2 | The following files extend or replace some of the the newlib functionality:
3 |
4 | _startup.c: a customised startup sequence, written in C
5 |
6 | _exit.c: a customised exit() implementation
7 |
8 | _syscalls.c: local versions of the libnosys/librdimon code
9 |
10 | _sbrk.c: a custom _sbrk() to match the actual linker scripts
11 |
12 | assert.c: implementation for the asserion macros
13 |
14 | _cxx.cpp: local versions of some C++ support, to avoid references to
15 | large functions.
16 |
17 |
--------------------------------------------------------------------------------
/system/src/newlib/_cxx.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | // These functions are redefined locally, to avoid references to some
9 | // heavy implementations in the standard C++ library.
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | #include
14 | #include
15 | #include "diag/Trace.h"
16 |
17 | // ----------------------------------------------------------------------------
18 |
19 | namespace __gnu_cxx
20 | {
21 | void
22 | __attribute__((noreturn))
23 | __verbose_terminate_handler();
24 |
25 | void
26 | __verbose_terminate_handler()
27 | {
28 | trace_puts(__func__);
29 | abort();
30 | }
31 | }
32 |
33 | // ----------------------------------------------------------------------------
34 |
35 | extern "C"
36 | {
37 | void
38 | __attribute__((noreturn))
39 | __cxa_pure_virtual();
40 |
41 | void
42 | __cxa_pure_virtual()
43 | {
44 | trace_puts(__func__);
45 | abort();
46 | }
47 | }
48 |
49 | // ----------------------------------------------------------------------------
50 |
51 |
--------------------------------------------------------------------------------
/system/src/newlib/_exit.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include
9 | #include "diag/Trace.h"
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | extern void
14 | __attribute__((noreturn))
15 | __reset_hardware(void);
16 |
17 | // ----------------------------------------------------------------------------
18 |
19 | // Forward declaration
20 |
21 | void
22 | _exit(int code);
23 |
24 | // ----------------------------------------------------------------------------
25 |
26 | // On Release, call the hardware reset procedure.
27 | // On Debug we just enter an infinite loop, to be used as landmark when halting
28 | // the debugger.
29 | //
30 | // It can be redefined in the application, if more functionality
31 | // is required.
32 |
33 | void
34 | __attribute__((weak))
35 | _exit(int code __attribute__((unused)))
36 | {
37 | #if !defined(DEBUG)
38 | __reset_hardware();
39 | #endif
40 |
41 | // TODO: write on trace
42 | while (1)
43 | ;
44 | }
45 |
46 | // ----------------------------------------------------------------------------
47 |
48 | void
49 | __attribute__((weak,noreturn))
50 | abort(void)
51 | {
52 | trace_puts("abort(), exiting...");
53 |
54 | _exit(1);
55 | }
56 |
57 | // ----------------------------------------------------------------------------
58 |
--------------------------------------------------------------------------------
/system/src/newlib/_sbrk.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | // ----------------------------------------------------------------------------
7 |
8 | #include
9 | #include
10 |
11 | // ----------------------------------------------------------------------------
12 |
13 | caddr_t
14 | _sbrk(int incr);
15 |
16 | // ----------------------------------------------------------------------------
17 |
18 | // The definitions used here should be kept in sync with the
19 | // stack definitions in the linker script.
20 |
21 | caddr_t
22 | _sbrk(int incr)
23 | {
24 | extern char _Heap_Begin; // Defined by the linker.
25 | extern char _Heap_Limit; // Defined by the linker.
26 |
27 | static char* current_heap_end;
28 | char* current_block_address;
29 |
30 | if (current_heap_end == 0)
31 | {
32 | current_heap_end = &_Heap_Begin;
33 | }
34 |
35 | current_block_address = current_heap_end;
36 |
37 | // Need to align heap to word boundary, else will get
38 | // hard faults on Cortex-M0. So we assume that heap starts on
39 | // word boundary, hence make sure we always add a multiple of
40 | // 4 to it.
41 | incr = (incr + 3) & (~3); // align value to 4
42 | if (current_heap_end + incr > &_Heap_Limit)
43 | {
44 | // Some of the libstdc++-v3 tests rely upon detecting
45 | // out of memory errors, so do not abort here.
46 | #if 0
47 | extern void abort (void);
48 |
49 | _write (1, "_sbrk: Heap and stack collision\n", 32);
50 |
51 | abort ();
52 | #else
53 | // Heap has overflowed
54 | errno = ENOMEM;
55 | return (caddr_t) - 1;
56 | #endif
57 | }
58 |
59 | current_heap_end += incr;
60 |
61 | return (caddr_t) current_block_address;
62 | }
63 |
64 | // ----------------------------------------------------------------------------
65 |
66 |
--------------------------------------------------------------------------------
/system/src/newlib/assert.c:
--------------------------------------------------------------------------------
1 | //
2 | // This file is part of the µOS++ III distribution.
3 | // Copyright (c) 2014 Liviu Ionescu.
4 | //
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include "diag/Trace.h"
11 |
12 | // ----------------------------------------------------------------------------
13 |
14 | void
15 | __attribute__((noreturn))
16 | __assert_func (const char *file, int line, const char *func,
17 | const char *failedexpr)
18 | {
19 | trace_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
20 | failedexpr, file, line, func ? ", function: " : "",
21 | func ? func : "");
22 | abort ();
23 | /* NOTREACHED */
24 | }
25 |
26 | // ----------------------------------------------------------------------------
27 |
28 | // This is STM32 specific, but can be used on other platforms too.
29 | // If you need it, add the following to your application header:
30 |
31 | //#ifdef USE_FULL_ASSERT
32 | //#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
33 | //void assert_failed(uint8_t* file, uint32_t line);
34 | //#else
35 | //#define assert_param(expr) ((void)0)
36 | //#endif // USE_FULL_ASSERT
37 |
38 | #if defined(USE_FULL_ASSERT)
39 |
40 | void
41 | assert_failed (uint8_t* file, uint32_t line);
42 |
43 | // Called from the assert_param() macro, usually defined in the stm32f*_conf.h
44 | void
45 | __attribute__((noreturn, weak))
46 | assert_failed (uint8_t* file, uint32_t line)
47 | {
48 | trace_printf ("assert_param() failed: file \"%s\", line %d\n", file, line);
49 | abort ();
50 | /* NOTREACHED */
51 | }
52 |
53 | #endif // defined(USE_FULL_ASSERT)
54 |
55 | // ----------------------------------------------------------------------------
56 |
--------------------------------------------------------------------------------
/system/src/stm32f4-hal/README_HAL.md:
--------------------------------------------------------------------------------
1 | The STM files are from the original `stm32cube_fw_f4_v190.zip`
2 | archive, the folder:
3 |
4 | * `STM32Cube_FW_F4_V1.9.0/Drivers/STM32F4xx_HAL_Driver/Src`
5 |
6 | There should be no changes from the STM originals.
7 |
8 | To disable compilation warnings, the compiler settings were changed
9 | to include `-Wno-*`.
10 |
11 | Files excluded from build can be re-enabled by using:
12 |
13 | * right click -> **Resource Configurations** -> **Exclude from build**
14 | * uncheck Debug and/or Release
15 |
--------------------------------------------------------------------------------
/system/src/stm32f4-hal/stm32f4xx_hal_flash_ramfunc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_flash_ramfunc.c
4 | * @author MCD Application Team
5 | * @version V1.4.1
6 | * @date 09-October-2015
7 | * @brief FLASH RAMFUNC module driver.
8 | * This file provides a FLASH firmware functions which should be
9 | * executed from internal SRAM
10 | * + Stop/Start the flash interface while System Run
11 | * + Enable/Disable the flash sleep while System Run
12 | @verbatim
13 | ==============================================================================
14 | ##### APIs executed from Internal RAM #####
15 | ==============================================================================
16 | [..]
17 | *** ARM Compiler ***
18 | --------------------
19 | [..] RAM functions are defined using the toolchain options.
20 | Functions that are be executed in RAM should reside in a separate
21 | source module. Using the 'Options for File' dialog you can simply change
22 | the 'Code / Const' area of a module to a memory space in physical RAM.
23 | Available memory areas are declared in the 'Target' tab of the
24 | Options for Target' dialog.
25 |
26 | *** ICCARM Compiler ***
27 | -----------------------
28 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".
29 |
30 | *** GNU Compiler ***
31 | --------------------
32 | [..] RAM functions are defined using a specific toolchain attribute
33 | "__attribute__((section(".RamFunc")))".
34 |
35 | @endverbatim
36 | ******************************************************************************
37 | * @attention
38 | *
39 | * © COPYRIGHT(c) 2015 STMicroelectronics
40 | *
41 | * Redistribution and use in source and binary forms, with or without modification,
42 | * are permitted provided that the following conditions are met:
43 | * 1. Redistributions of source code must retain the above copyright notice,
44 | * this list of conditions and the following disclaimer.
45 | * 2. Redistributions in binary form must reproduce the above copyright notice,
46 | * this list of conditions and the following disclaimer in the documentation
47 | * and/or other materials provided with the distribution.
48 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
49 | * may be used to endorse or promote products derived from this software
50 | * without specific prior written permission.
51 | *
52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
53 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
56 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
58 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
59 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
60 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 | *
63 | ******************************************************************************
64 | */
65 |
66 | /* Includes ------------------------------------------------------------------*/
67 | #include "stm32f4xx_hal.h"
68 |
69 | /** @addtogroup STM32F4xx_HAL_Driver
70 | * @{
71 | */
72 |
73 | /** @defgroup FLASHRAMFUNC FLASH RAMFUNC
74 | * @brief FLASH functions executed from RAM
75 | * @{
76 | */
77 | #ifdef HAL_FLASH_MODULE_ENABLED
78 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx)
79 |
80 | /* Private typedef -----------------------------------------------------------*/
81 | /* Private define ------------------------------------------------------------*/
82 | /* Private macro -------------------------------------------------------------*/
83 | /* Private variables ---------------------------------------------------------*/
84 | /* Private function prototypes -----------------------------------------------*/
85 | /* Exported functions --------------------------------------------------------*/
86 | /** @defgroup FLASHRAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions
87 | * @{
88 | */
89 |
90 | /** @defgroup FLASHRAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM
91 | * @brief Peripheral Extended features functions
92 | *
93 | @verbatim
94 |
95 | ===============================================================================
96 | ##### ramfunc functions #####
97 | ===============================================================================
98 | [..]
99 | This subsection provides a set of functions that should be executed from RAM
100 | transfers.
101 |
102 | @endverbatim
103 | * @{
104 | */
105 |
106 | /**
107 | * @brief Stop the flash interface while System Run
108 | * @note This mode is only available for STM32F411xx devices.
109 | * @note This mode couldn't be set while executing with the flash itself.
110 | * It should be done with specific routine executed from RAM.
111 | * @retval None
112 | */
113 | __RAM_FUNC HAL_FLASHEx_StopFlashInterfaceClk(void)
114 | {
115 | /* Enable Power ctrl clock */
116 | __HAL_RCC_PWR_CLK_ENABLE();
117 | /* Stop the flash interface while System Run */
118 | SET_BIT(PWR->CR, PWR_CR_FISSR);
119 |
120 | return HAL_OK;
121 | }
122 |
123 | /**
124 | * @brief Start the flash interface while System Run
125 | * @note This mode is only available for STM32F411xx devices.
126 | * @note This mode couldn't be set while executing with the flash itself.
127 | * It should be done with specific routine executed from RAM.
128 | * @retval None
129 | */
130 | __RAM_FUNC HAL_FLASHEx_StartFlashInterfaceClk(void)
131 | {
132 | /* Enable Power ctrl clock */
133 | __HAL_RCC_PWR_CLK_ENABLE();
134 | /* Start the flash interface while System Run */
135 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR);
136 |
137 | return HAL_OK;
138 | }
139 |
140 | /**
141 | * @brief Enable the flash sleep while System Run
142 | * @note This mode is only available for STM32F411xx devices.
143 | * @note This mode could n't be set while executing with the flash itself.
144 | * It should be done with specific routine executed from RAM.
145 | * @retval None
146 | */
147 | __RAM_FUNC HAL_FLASHEx_EnableFlashSleepMode(void)
148 | {
149 | /* Enable Power ctrl clock */
150 | __HAL_RCC_PWR_CLK_ENABLE();
151 | /* Enable the flash sleep while System Run */
152 | SET_BIT(PWR->CR, PWR_CR_FMSSR);
153 |
154 | return HAL_OK;
155 | }
156 |
157 | /**
158 | * @brief Disable the flash sleep while System Run
159 | * @note This mode is only available for STM32F411xx devices.
160 | * @note This mode couldn't be set while executing with the flash itself.
161 | * It should be done with specific routine executed from RAM.
162 | * @retval None
163 | */
164 | __RAM_FUNC HAL_FLASHEx_DisableFlashSleepMode(void)
165 | {
166 | /* Enable Power ctrl clock */
167 | __HAL_RCC_PWR_CLK_ENABLE();
168 | /* Disable the flash sleep while System Run */
169 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR);
170 |
171 | return HAL_OK;
172 | }
173 |
174 | /**
175 | * @}
176 | */
177 |
178 | /**
179 | * @}
180 | */
181 |
182 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx */
183 | #endif /* HAL_FLASH_MODULE_ENABLED */
184 | /**
185 | * @}
186 | */
187 |
188 | /**
189 | * @}
190 | */
191 |
192 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
193 |
--------------------------------------------------------------------------------
/system/src/stm32f4-hal/stm32f4xx_hal_i2c_ex.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_i2c_ex.c
4 | * @author MCD Application Team
5 | * @version V1.4.1
6 | * @date 09-October-2015
7 | * @brief I2C Extension HAL module driver.
8 | * This file provides firmware functions to manage the following
9 | * functionalities of I2C extension peripheral:
10 | * + Extension features functions
11 | *
12 | @verbatim
13 | ==============================================================================
14 | ##### I2C peripheral extension features #####
15 | ==============================================================================
16 |
17 | [..] Comparing to other previous devices, the I2C interface for STM32F427xx/437xx/
18 | 429xx/439xx devices contains the following additional features :
19 |
20 | (+) Possibility to disable or enable Analog Noise Filter
21 | (+) Use of a configured Digital Noise Filter
22 |
23 | ##### How to use this driver #####
24 | ==============================================================================
25 | [..] This driver provides functions to configure Noise Filter
26 | (#) Configure I2C Analog noise filter using the function HAL_I2C_AnalogFilter_Config()
27 | (#) Configure I2C Digital noise filter using the function HAL_I2C_DigitalFilter_Config()
28 |
29 | @endverbatim
30 | ******************************************************************************
31 | * @attention
32 | *
33 | * © COPYRIGHT(c) 2015 STMicroelectronics
34 | *
35 | * Redistribution and use in source and binary forms, with or without modification,
36 | * are permitted provided that the following conditions are met:
37 | * 1. Redistributions of source code must retain the above copyright notice,
38 | * this list of conditions and the following disclaimer.
39 | * 2. Redistributions in binary form must reproduce the above copyright notice,
40 | * this list of conditions and the following disclaimer in the documentation
41 | * and/or other materials provided with the distribution.
42 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
43 | * may be used to endorse or promote products derived from this software
44 | * without specific prior written permission.
45 | *
46 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
52 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 | *
57 | ******************************************************************************
58 | */
59 |
60 | /* Includes ------------------------------------------------------------------*/
61 | #include "stm32f4xx_hal.h"
62 |
63 | /** @addtogroup STM32F4xx_HAL_Driver
64 | * @{
65 | */
66 |
67 | /** @defgroup I2CEx I2CEx
68 | * @brief I2C HAL module driver
69 | * @{
70 | */
71 |
72 | #ifdef HAL_I2C_MODULE_ENABLED
73 |
74 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
75 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) ||\
76 | defined(STM32F469xx) || defined(STM32F479xx)
77 | /* Private typedef -----------------------------------------------------------*/
78 | /* Private define ------------------------------------------------------------*/
79 | /* Private macro -------------------------------------------------------------*/
80 | /* Private variables ---------------------------------------------------------*/
81 | /* Private function prototypes -----------------------------------------------*/
82 | /* Exported functions --------------------------------------------------------*/
83 | /** @defgroup I2CEx_Exported_Functions I2C Exported Functions
84 | * @{
85 | */
86 |
87 |
88 | /** @defgroup I2CEx_Exported_Functions_Group1 Extension features functions
89 | * @brief Extension features functions
90 | *
91 | @verbatim
92 | ===============================================================================
93 | ##### Extension features functions #####
94 | ===============================================================================
95 | [..] This section provides functions allowing to:
96 | (+) Configure Noise Filters
97 |
98 | @endverbatim
99 | * @{
100 | */
101 |
102 | /**
103 | * @brief Configures I2C Analog noise filter.
104 | * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
105 | * the configuration information for the specified I2Cx peripheral.
106 | * @param AnalogFilter: new state of the Analog filter.
107 | * @retval HAL status
108 | */
109 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
110 | {
111 | uint32_t tmp = 0;
112 |
113 | /* Check the parameters */
114 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
115 | assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
116 |
117 | tmp = hi2c->State;
118 | if((tmp == HAL_I2C_STATE_BUSY) || (tmp == HAL_I2C_STATE_BUSY_TX) || (tmp == HAL_I2C_STATE_BUSY_RX))
119 | {
120 | return HAL_BUSY;
121 | }
122 |
123 | hi2c->State = HAL_I2C_STATE_BUSY;
124 |
125 | /* Disable the selected I2C peripheral */
126 | __HAL_I2C_DISABLE(hi2c);
127 |
128 | /* Reset I2Cx ANOFF bit */
129 | hi2c->Instance->FLTR &= ~(I2C_FLTR_ANOFF);
130 |
131 | /* Disable the analog filter */
132 | hi2c->Instance->FLTR |= AnalogFilter;
133 |
134 | __HAL_I2C_ENABLE(hi2c);
135 |
136 | hi2c->State = HAL_I2C_STATE_READY;
137 |
138 | return HAL_OK;
139 | }
140 |
141 | /**
142 | * @brief Configures I2C Digital noise filter.
143 | * @param hi2c: pointer to a I2C_HandleTypeDef structure that contains
144 | * the configuration information for the specified I2Cx peripheral.
145 | * @param DigitalFilter: Coefficient of digital noise filter between 0x00 and 0x0F.
146 | * @retval HAL status
147 | */
148 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
149 | {
150 | uint16_t tmpreg = 0;
151 | uint32_t tmp = 0;
152 |
153 | /* Check the parameters */
154 | assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
155 | assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
156 |
157 | tmp = hi2c->State;
158 | if((tmp == HAL_I2C_STATE_BUSY) || (tmp == HAL_I2C_STATE_BUSY_TX) || (tmp == HAL_I2C_STATE_BUSY_RX))
159 | {
160 | return HAL_BUSY;
161 | }
162 |
163 | hi2c->State = HAL_I2C_STATE_BUSY;
164 |
165 | /* Disable the selected I2C peripheral */
166 | __HAL_I2C_DISABLE(hi2c);
167 |
168 | /* Get the old register value */
169 | tmpreg = hi2c->Instance->FLTR;
170 |
171 | /* Reset I2Cx DNF bit [3:0] */
172 | tmpreg &= ~(I2C_FLTR_DNF);
173 |
174 | /* Set I2Cx DNF coefficient */
175 | tmpreg |= DigitalFilter;
176 |
177 | /* Store the new register value */
178 | hi2c->Instance->FLTR = tmpreg;
179 |
180 | __HAL_I2C_ENABLE(hi2c);
181 |
182 | hi2c->State = HAL_I2C_STATE_READY;
183 |
184 | return HAL_OK;
185 | }
186 |
187 | /**
188 | * @}
189 | */
190 |
191 | /**
192 | * @}
193 | */
194 | #endif /* STM32F427xx || STM32F429xx || STM32F437xx || STM32F439xx || STM32F401xC ||\
195 | STM32F401xE || STM32F446xx || STM32F469xx || STM32F479xx */
196 |
197 | #endif /* HAL_I2C_MODULE_ENABLED */
198 | /**
199 | * @}
200 | */
201 |
202 | /**
203 | * @}
204 | */
205 |
206 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
207 |
--------------------------------------------------------------------------------
/system/src/stm32f4-hal/stm32f4xx_hal_ltdc_ex.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_ltdc_ex.c
4 | * @author MCD Application Team
5 | * @version V1.4.1
6 | * @date 09-October-2015
7 | * @brief LTDC Extension HAL module driver.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT(c) 2015 STMicroelectronics
12 | *
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | * 1. Redistributions of source code must retain the above copyright notice,
16 | * this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright notice,
18 | * this list of conditions and the following disclaimer in the documentation
19 | * and/or other materials provided with the distribution.
20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software
22 | * without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | *
35 | ******************************************************************************
36 | */
37 |
38 | /* Includes ------------------------------------------------------------------*/
39 | #include "stm32f4xx_hal.h"
40 |
41 | /** @addtogroup STM32F4xx_HAL_Driver
42 | * @{
43 | */
44 | /** @defgroup LTDCEx LTDCEx
45 | * @brief LTDC HAL module driver
46 | * @{
47 | */
48 |
49 | #ifdef HAL_LTDC_MODULE_ENABLED
50 |
51 | /* Private typedef -----------------------------------------------------------*/
52 | /* Private define ------------------------------------------------------------*/
53 | /* Private macro -------------------------------------------------------------*/
54 | /* Private variables ---------------------------------------------------------*/
55 | /* Private function prototypes -----------------------------------------------*/
56 | /* Exported functions --------------------------------------------------------*/
57 |
58 | /** @defgroup LTDCEx_Exported_Functions LTDC Extended Exported Functions
59 | * @{
60 | */
61 |
62 | /** @defgroup LTDCEx_Exported_Functions_Group1 Initialization and Configuration functions
63 | * @brief Initialization and Configuration functions
64 | *
65 | @verbatim
66 | ===============================================================================
67 | ##### Initialization and Configuration functions #####
68 | ===============================================================================
69 | [..] This section provides functions allowing to:
70 | (+) Initialize and configure the LTDC
71 |
72 | @endverbatim
73 | * @{
74 | */
75 | #if defined(STM32F469xx) || defined(STM32F479xx)
76 | /**
77 | * @brief Retrieve common parameters from DSI Video mode configuration structure
78 | * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
79 | * the configuration information for the LTDC.
80 | * @param VidCfg: pointer to a DSI_VidCfgTypeDef structure that contains
81 | * the DSI video mode configuration parameters
82 | * @note The implementation of this function is taking into account the LTDC
83 | * polarities inversion as described in the current LTDC specification
84 | * @retval HAL status
85 | */
86 | HAL_StatusTypeDef HAL_LTDC_StructInitFromVideoConfig(LTDC_HandleTypeDef* hltdc, DSI_VidCfgTypeDef *VidCfg)
87 | {
88 | /* Retrieve signal polarities from DSI */
89 |
90 | /* The following polarities are inverted:
91 | LTDC_DEPOLARITY_AL <-> LTDC_DEPOLARITY_AH
92 | LTDC_VSPOLARITY_AL <-> LTDC_VSPOLARITY_AH
93 | LTDC_HSPOLARITY_AL <-> LTDC_HSPOLARITY_AH)*/
94 |
95 | /* Note 1 : Code in line w/ Current LTDC specification */
96 | hltdc->Init.DEPolarity = (VidCfg->DEPolarity == DSI_DATA_ENABLE_ACTIVE_HIGH) ? LTDC_DEPOLARITY_AL : LTDC_DEPOLARITY_AH;
97 | hltdc->Init.VSPolarity = (VidCfg->VSPolarity == DSI_VSYNC_ACTIVE_HIGH) ? LTDC_VSPOLARITY_AL : LTDC_VSPOLARITY_AH;
98 | hltdc->Init.HSPolarity = (VidCfg->HSPolarity == DSI_HSYNC_ACTIVE_HIGH) ? LTDC_HSPOLARITY_AL : LTDC_HSPOLARITY_AH;
99 |
100 | /* Note 2: Code to be used in case LTDC polarities inversion updated in the specification */
101 | /* hltdc->Init.DEPolarity = VidCfg->DEPolarity << 29;
102 | hltdc->Init.VSPolarity = VidCfg->VSPolarity << 29;
103 | hltdc->Init.HSPolarity = VidCfg->HSPolarity << 29; */
104 |
105 | /* Retrieve vertical timing parameters from DSI */
106 | hltdc->Init.VerticalSync = VidCfg->VerticalSyncActive - 1;
107 | hltdc->Init.AccumulatedVBP = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch - 1;
108 | hltdc->Init.AccumulatedActiveH = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch + VidCfg->VerticalActive - 1;
109 | hltdc->Init.TotalHeigh = VidCfg->VerticalSyncActive + VidCfg->VerticalBackPorch + VidCfg->VerticalActive + VidCfg->VerticalFrontPorch - 1;
110 |
111 | return HAL_OK;
112 | }
113 |
114 | /**
115 | * @brief Retrieve common parameters from DSI Adapted command mode configuration structure
116 | * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
117 | * the configuration information for the LTDC.
118 | * @param CmdCfg: pointer to a DSI_CmdCfgTypeDef structure that contains
119 | * the DSI command mode configuration parameters
120 | * @note The implementation of this function is taking into account the LTDC
121 | * polarities inversion as described in the current LTDC specification
122 | * @retval HAL status
123 | */
124 | HAL_StatusTypeDef HAL_LTDC_StructInitFromAdaptedCommandConfig(LTDC_HandleTypeDef* hltdc, DSI_CmdCfgTypeDef *CmdCfg)
125 | {
126 | /* Retrieve signal polarities from DSI */
127 |
128 | /* The following polarities are inverted:
129 | LTDC_DEPOLARITY_AL <-> LTDC_DEPOLARITY_AH
130 | LTDC_VSPOLARITY_AL <-> LTDC_VSPOLARITY_AH
131 | LTDC_HSPOLARITY_AL <-> LTDC_HSPOLARITY_AH)*/
132 |
133 | /* Note 1 : Code in line w/ Current LTDC specification */
134 | hltdc->Init.DEPolarity = (CmdCfg->DEPolarity == DSI_DATA_ENABLE_ACTIVE_HIGH) ? LTDC_DEPOLARITY_AL : LTDC_DEPOLARITY_AH;
135 | hltdc->Init.VSPolarity = (CmdCfg->VSPolarity == DSI_VSYNC_ACTIVE_HIGH) ? LTDC_VSPOLARITY_AL : LTDC_VSPOLARITY_AH;
136 | hltdc->Init.HSPolarity = (CmdCfg->HSPolarity == DSI_HSYNC_ACTIVE_HIGH) ? LTDC_HSPOLARITY_AL : LTDC_HSPOLARITY_AH;
137 |
138 | /* Note 2: Code to be used in case LTDC polarities inversion updated in the specification */
139 | /* hltdc->Init.DEPolarity = CmdCfg->DEPolarity << 29;
140 | hltdc->Init.VSPolarity = CmdCfg->VSPolarity << 29;
141 | hltdc->Init.HSPolarity = CmdCfg->HSPolarity << 29; */
142 |
143 | return HAL_OK;
144 | }
145 | #endif /* STM32F469xx || STM32F479xx */
146 |
147 | /**
148 | * @}
149 | */
150 |
151 | /**
152 | * @}
153 | */
154 |
155 | #endif /* HAL_DCMI_MODULE_ENABLED */
156 | /**
157 | * @}
158 | */
159 |
160 | /**
161 | * @}
162 | */
163 |
164 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
165 |
--------------------------------------------------------------------------------
/system/src/stm32f4-hal/stm32f4xx_hal_msp_template.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_msp_template.c
4 | * @author MCD Application Team
5 | * @version V1.4.1
6 | * @date 09-October-2015
7 | * @brief This file contains the HAL System and Peripheral (PPP) MSP initialization
8 | * and de-initialization functions.
9 | * It should be copied to the application folder and renamed into 'stm32f4xx_hal_msp.c'.
10 | ******************************************************************************
11 | * @attention
12 | *
13 | * © COPYRIGHT(c) 2015 STMicroelectronics
14 | *
15 | * Redistribution and use in source and binary forms, with or without modification,
16 | * are permitted provided that the following conditions are met:
17 | * 1. Redistributions of source code must retain the above copyright notice,
18 | * this list of conditions and the following disclaimer.
19 | * 2. Redistributions in binary form must reproduce the above copyright notice,
20 | * this list of conditions and the following disclaimer in the documentation
21 | * and/or other materials provided with the distribution.
22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | ******************************************************************************
38 | */
39 |
40 | /* Includes ------------------------------------------------------------------*/
41 | #include "stm32f4xx_hal.h"
42 |
43 | /** @addtogroup STM32F4xx_HAL_Driver
44 | * @{
45 | */
46 |
47 | /** @defgroup HAL_MSP HAL MSP
48 | * @brief HAL MSP module.
49 | * @{
50 | */
51 |
52 | /* Private typedef -----------------------------------------------------------*/
53 | /* Private define ------------------------------------------------------------*/
54 | /* Private macro -------------------------------------------------------------*/
55 | /* Private variables ---------------------------------------------------------*/
56 | /* Private function prototypes -----------------------------------------------*/
57 | /* Private functions ---------------------------------------------------------*/
58 |
59 | /** @defgroup HAL_MSP_Private_Functions HAL MSP Private Functions
60 | * @{
61 | */
62 |
63 | /**
64 | * @brief Initializes the Global MSP.
65 | * @note This function is called from HAL_Init() function to perform system
66 | * level initialization (GPIOs, clock, DMA, interrupt).
67 | * @retval None
68 | */
69 | void HAL_MspInit(void)
70 | {
71 |
72 | }
73 |
74 | /**
75 | * @brief DeInitializes the Global MSP.
76 | * @note This functiona is called from HAL_DeInit() function to perform system
77 | * level de-initialization (GPIOs, clock, DMA, interrupt).
78 | * @retval None
79 | */
80 | void HAL_MspDeInit(void)
81 | {
82 |
83 | }
84 |
85 | /**
86 | * @brief Initializes the PPP MSP.
87 | * @note This functiona is called from HAL_PPP_Init() function to perform
88 | * peripheral(PPP) system level initialization (GPIOs, clock, DMA, interrupt)
89 | * @retval None
90 | */
91 | void HAL_PPP_MspInit(void)
92 | {
93 |
94 | }
95 |
96 | /**
97 | * @brief DeInitializes the PPP MSP.
98 | * @note This functiona is called from HAL_PPP_DeInit() function to perform
99 | * peripheral(PPP) system level de-initialization (GPIOs, clock, DMA, interrupt)
100 | * @retval None
101 | */
102 | void HAL_PPP_MspDeInit(void)
103 | {
104 |
105 | }
106 |
107 | /**
108 | * @}
109 | */
110 |
111 | /**
112 | * @}
113 | */
114 |
115 | /**
116 | * @}
117 | */
118 |
119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
120 |
--------------------------------------------------------------------------------
/system/src/stm32f4-hal/stm32f4xx_hal_pcd_ex.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f4xx_hal_pcd_ex.c
4 | * @author MCD Application Team
5 | * @version V1.4.1
6 | * @date 09-October-2015
7 | * @brief PCD HAL module driver.
8 | * This file provides firmware functions to manage the following
9 | * functionalities of the USB Peripheral Controller:
10 | * + Extended features functions
11 | *
12 | ******************************************************************************
13 | * @attention
14 | *
15 | * © COPYRIGHT(c) 2015 STMicroelectronics
16 | *
17 | * Redistribution and use in source and binary forms, with or without modification,
18 | * are permitted provided that the following conditions are met:
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
25 | * may be used to endorse or promote products derived from this software
26 | * without specific prior written permission.
27 | *
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | ******************************************************************************
40 | */
41 |
42 | /* Includes ------------------------------------------------------------------*/
43 | #include "stm32f4xx_hal.h"
44 |
45 | /** @addtogroup STM32F4xx_HAL_Driver
46 | * @{
47 | */
48 |
49 | /** @defgroup PCDEx PCDEx
50 | * @brief PCD Extended HAL module driver
51 | * @{
52 | */
53 | #ifdef HAL_PCD_MODULE_ENABLED
54 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \
55 | defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
56 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) || \
57 | defined(STM32F469xx) || defined(STM32F479xx)
58 | /* Private types -------------------------------------------------------------*/
59 | /* Private variables ---------------------------------------------------------*/
60 | /* Private constants ---------------------------------------------------------*/
61 | /* Private macros ------------------------------------------------------------*/
62 | /* Private functions ---------------------------------------------------------*/
63 | /* Exported functions --------------------------------------------------------*/
64 |
65 | /** @defgroup PCDEx_Exported_Functions PCD Extended Exported Functions
66 | * @{
67 | */
68 |
69 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
70 | * @brief PCDEx control functions
71 | *
72 | @verbatim
73 | ===============================================================================
74 | ##### Extended features functions #####
75 | ===============================================================================
76 | [..] This section provides functions allowing to:
77 | (+) Update FIFO configuration
78 |
79 | @endverbatim
80 | * @{
81 | */
82 |
83 | /**
84 | * @brief Set Tx FIFO
85 | * @param hpcd: PCD handle
86 | * @param fifo: The number of Tx fifo
87 | * @param size: Fifo size
88 | * @retval HAL status
89 | */
90 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
91 | {
92 | uint8_t i = 0;
93 | uint32_t Tx_Offset = 0;
94 |
95 | /* TXn min size = 16 words. (n : Transmit FIFO index)
96 | When a TxFIFO is not used, the Configuration should be as follows:
97 | case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
98 | --> Txm can use the space allocated for Txn.
99 | case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
100 | --> Txn should be configured with the minimum space of 16 words
101 | The FIFO is used optimally when used TxFIFOs are allocated in the top
102 | of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
103 | When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
104 |
105 | Tx_Offset = hpcd->Instance->GRXFSIZ;
106 |
107 | if(fifo == 0)
108 | {
109 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((uint32_t)size << 16) | Tx_Offset);
110 | }
111 | else
112 | {
113 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
114 | for (i = 0; i < (fifo - 1); i++)
115 | {
116 | Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
117 | }
118 |
119 | /* Multiply Tx_Size by 2 to get higher performance */
120 | hpcd->Instance->DIEPTXF[fifo - 1] = (uint32_t)(((uint32_t)size << 16) | Tx_Offset);
121 | }
122 |
123 | return HAL_OK;
124 | }
125 |
126 | /**
127 | * @brief Set Rx FIFO
128 | * @param hpcd: PCD handle
129 | * @param size: Size of Rx fifo
130 | * @retval HAL status
131 | */
132 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
133 | {
134 | hpcd->Instance->GRXFSIZ = size;
135 |
136 | return HAL_OK;
137 | }
138 |
139 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
140 | /**
141 | * @brief Activate LPM feature
142 | * @param hpcd: PCD handle
143 | * @retval HAL status
144 | */
145 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd)
146 | {
147 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
148 |
149 | hpcd->lpm_active = ENABLE;
150 | hpcd->LPM_State = LPM_L0;
151 | USBx->GINTMSK |= USB_OTG_GINTMSK_LPMINTM;
152 | USBx->GLPMCFG |= (USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
153 |
154 | return HAL_OK;
155 | }
156 |
157 | /**
158 | * @brief Deactivate LPM feature.
159 | * @param hpcd: PCD handle
160 | * @retval HAL status
161 | */
162 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd)
163 | {
164 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
165 |
166 | hpcd->lpm_active = DISABLE;
167 | USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM;
168 | USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
169 |
170 | return HAL_OK;
171 | }
172 |
173 | /**
174 | * @brief Send LPM message to user layer callback.
175 | * @param hpcd: PCD handle
176 | * @param msg: LPM message
177 | * @retval HAL status
178 | */
179 | __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
180 | {
181 | }
182 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
183 |
184 | /**
185 | * @}
186 | */
187 |
188 | /**
189 | * @}
190 | */
191 |
192 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||
193 | STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx */
194 | #endif /* HAL_PCD_MODULE_ENABLED */
195 | /**
196 | * @}
197 | */
198 |
199 | /**
200 | * @}
201 | */
202 |
203 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
204 |
--------------------------------------------------------------------------------
/system/src/stm32f4-hal/stm32f4xx_hal_rcc_ex.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/angst7/stm32_functgen/e142b51e4a9a2bfc9fa5d4bed017f30a9b8dcb84/system/src/stm32f4-hal/stm32f4xx_hal_rcc_ex.c
--------------------------------------------------------------------------------
/system/src/stm32f4-hal/stm32f4xx_hal_wwdg.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/angst7/stm32_functgen/e142b51e4a9a2bfc9fa5d4bed017f30a9b8dcb84/system/src/stm32f4-hal/stm32f4xx_hal_wwdg.c
--------------------------------------------------------------------------------