├── .gitignore
├── CC3000_Host_Driver
├── build.mk
├── cc3000_common.c
├── cc3000_common.h
├── data_types.h
├── evnt_handler.c
├── evnt_handler.h
├── hci.c
├── hci.h
├── host_driver_version.h
├── netapp.c
├── netapp.h
├── nvmem.c
├── nvmem.h
├── security.c
├── security.h
├── socket.c
├── socket.h
├── wlan.c
└── wlan.h
├── CMSIS
├── Device
│ └── ST
│ │ └── STM32F10x
│ │ └── Include
│ │ ├── stm32f10x.h
│ │ └── system_stm32f10x.h
└── Include
│ ├── arm_common_tables.h
│ ├── arm_math.h
│ ├── core_cm3.h
│ ├── core_cmFunc.h
│ └── core_cmInstr.h
├── README.md
├── SPARK_Firmware_Driver
├── inc
│ ├── cc3000_spi.h
│ ├── config.h
│ ├── debug.h
│ ├── hw_config.h
│ ├── panic.h
│ ├── panic_codes.h
│ ├── platform_config.h
│ ├── spark_macros.h
│ ├── spi.h
│ ├── spi_bus.h
│ ├── sst25vf_spi.h
│ ├── stm32f10x_conf.h
│ └── usb_pwr.h
└── src
│ ├── build.mk
│ ├── cc3000_spi.c
│ ├── debug.c
│ ├── hw_config.c
│ ├── panic.c
│ ├── spi_bus.c
│ ├── sst25vf_spi.c
│ ├── system_stm32f10x.c
│ └── usb_pwr.c
├── SPARK_Services
├── inc
│ └── rgbled.h
├── readme.md
└── src
│ ├── build.mk
│ └── rgbled.c
├── STM32F10x_StdPeriph_Driver
├── inc
│ ├── misc.h
│ ├── stm32f10x_adc.h
│ ├── stm32f10x_bkp.h
│ ├── stm32f10x_can.h
│ ├── stm32f10x_cec.h
│ ├── stm32f10x_crc.h
│ ├── stm32f10x_dac.h
│ ├── stm32f10x_dbgmcu.h
│ ├── stm32f10x_dma.h
│ ├── stm32f10x_exti.h
│ ├── stm32f10x_flash.h
│ ├── stm32f10x_fsmc.h
│ ├── stm32f10x_gpio.h
│ ├── stm32f10x_i2c.h
│ ├── stm32f10x_iwdg.h
│ ├── stm32f10x_pwr.h
│ ├── stm32f10x_rcc.h
│ ├── stm32f10x_rtc.h
│ ├── stm32f10x_sdio.h
│ ├── stm32f10x_spi.h
│ ├── stm32f10x_tim.h
│ ├── stm32f10x_usart.h
│ └── stm32f10x_wwdg.h
└── src
│ ├── build.mk
│ ├── misc.c
│ ├── stm32f10x_adc.c
│ ├── stm32f10x_bkp.c
│ ├── stm32f10x_can.c
│ ├── stm32f10x_cec.c
│ ├── stm32f10x_crc.c
│ ├── stm32f10x_dac.c
│ ├── stm32f10x_dbgmcu.c
│ ├── stm32f10x_dma.c
│ ├── stm32f10x_exti.c
│ ├── stm32f10x_flash.c
│ ├── stm32f10x_fsmc.c
│ ├── stm32f10x_gpio.c
│ ├── stm32f10x_i2c.c
│ ├── stm32f10x_iwdg.c
│ ├── stm32f10x_pwr.c
│ ├── stm32f10x_rcc.c
│ ├── stm32f10x_rtc.c
│ ├── stm32f10x_sdio.c
│ ├── stm32f10x_spi.c
│ ├── stm32f10x_tim.c
│ ├── stm32f10x_usart.c
│ └── stm32f10x_wwdg.c
├── STM32_USB-FS-Device_Driver
├── inc
│ ├── usb_core.h
│ ├── usb_def.h
│ ├── usb_init.h
│ ├── usb_int.h
│ ├── usb_lib.h
│ ├── usb_mem.h
│ ├── usb_regs.h
│ ├── usb_sil.h
│ └── usb_type.h
└── src
│ ├── build.mk
│ ├── usb_core.c
│ ├── usb_init.c
│ ├── usb_int.c
│ ├── usb_mem.c
│ ├── usb_regs.c
│ └── usb_sil.c
├── build
├── .gitignore
└── makefile
└── license.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | # Object files
2 | *.o
3 |
4 | # Libraries
5 | *.lib
6 | *.a
7 |
8 | # Shared objects (inc. Windows DLLs)
9 | *.dll
10 | *.so
11 | *.so.*
12 | *.dylib
13 |
14 | # Executables
15 | *.exe
16 | *.out
17 | *.app
18 |
19 | # Debug folder
20 | Debug/*
21 |
22 | # Release folder
23 | Release/*
24 |
25 | # build folder
26 | *.map
27 | *.lst
28 | *.d
29 | *.o
30 |
31 | # Platform-specific settings
32 | .settings/*
33 | .cproject
34 | .project
35 |
--------------------------------------------------------------------------------
/CC3000_Host_Driver/build.mk:
--------------------------------------------------------------------------------
1 | # This file is a makefile included from the top level makefile which
2 | # defines the sources built for the target.
3 |
4 | # Define the prefix to this directory.
5 | # Note: The name must be unique within this build and should be
6 | # based on the root of the project
7 | TARGET_CC3000_PATH = CC3000_Host_Driver
8 |
9 | # Add tropicssl include to all objects built for this target
10 | INCLUDE_DIRS += $(TARGET_CC3000_PATH)
11 |
12 | # C source files included in this build.
13 | CSRC += $(TARGET_CC3000_PATH)/cc3000_common.c
14 | CSRC += $(TARGET_CC3000_PATH)/evnt_handler.c
15 | CSRC += $(TARGET_CC3000_PATH)/hci.c
16 | CSRC += $(TARGET_CC3000_PATH)/netapp.c
17 | CSRC += $(TARGET_CC3000_PATH)/nvmem.c
18 | CSRC += $(TARGET_CC3000_PATH)/security.c
19 | CSRC += $(TARGET_CC3000_PATH)/socket.c
20 | CSRC += $(TARGET_CC3000_PATH)/wlan.c
21 |
22 | # C++ source files included in this build.
23 | CPPSRC +=
24 |
25 | # ASM source files included in this build.
26 | ASRC +=
27 |
28 |
--------------------------------------------------------------------------------
/CC3000_Host_Driver/cc3000_common.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * cc3000_common.c.c - CC3000 Host Driver Implementation.
4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the
16 | * distribution.
17 | *
18 | * Neither the name of Texas Instruments Incorporated nor the names of
19 | * its contributors may be used to endorse or promote products derived
20 | * from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | *
34 | *****************************************************************************/
35 | //*****************************************************************************
36 | //
37 | //! \addtogroup common_api
38 | //! @{
39 | //
40 | //*****************************************************************************
41 | /******************************************************************************
42 | *
43 | * Include files
44 | *
45 | *****************************************************************************/
46 | #include "cc3000_common.h"
47 | #include "socket.h"
48 | #include "wlan.h"
49 | #include "evnt_handler.h"
50 |
51 | //*****************************************************************************
52 | //
53 | //! __error__
54 | //!
55 | //! @param pcFilename - file name, where error occurred
56 | //! @param ulLine - line number, where error occurred
57 | //!
58 | //! @return none
59 | //!
60 | //! @brief stub function for ASSERT macro
61 | //
62 | //*****************************************************************************
63 | void __error__(CHAR *pcFilename, UINT32 ulLine)
64 | {
65 | //TODO full up function
66 | }
67 |
68 |
69 |
70 | //*****************************************************************************
71 | //
72 | //! UINT32_TO_STREAM_f
73 | //!
74 | //! @param p pointer to the new stream
75 | //! @param u32 pointer to the 32 bit
76 | //!
77 | //! @return pointer to the new stream
78 | //!
79 | //! @brief This function is used for copying 32 bit to stream
80 | //! while converting to little endian format.
81 | //
82 | //*****************************************************************************
83 |
84 | UINT8* UINT32_TO_STREAM_f (UINT8 *p, UINT32 u32)
85 | {
86 | *(p)++ = (UINT8)(u32);
87 | *(p)++ = (UINT8)((u32) >> 8);
88 | *(p)++ = (UINT8)((u32) >> 16);
89 | *(p)++ = (UINT8)((u32) >> 24);
90 | return p;
91 | }
92 |
93 | //*****************************************************************************
94 | //
95 | //! UINT16_TO_STREAM_f
96 | //!
97 | //! @param p pointer to the new stream
98 | //! @param u32 pointer to the 16 bit
99 | //!
100 | //! @return pointer to the new stream
101 | //!
102 | //! @brief This function is used for copying 16 bit to stream
103 | //! while converting to little endian format.
104 | //
105 | //*****************************************************************************
106 |
107 | UINT8* UINT16_TO_STREAM_f (UINT8 *p, UINT16 u16)
108 | {
109 | *(p)++ = (UINT8)(u16);
110 | *(p)++ = (UINT8)((u16) >> 8);
111 | return p;
112 | }
113 |
114 | //*****************************************************************************
115 | //
116 | //! STREAM_TO_UINT16_f
117 | //!
118 | //! @param p pointer to the stream
119 | //! @param offset offset in the stream
120 | //!
121 | //! @return pointer to the new 16 bit
122 | //!
123 | //! @brief This function is used for copying received stream to
124 | //! 16 bit in little endian format.
125 | //
126 | //*****************************************************************************
127 |
128 | UINT16 STREAM_TO_UINT16_f(CHAR* p, UINT16 offset)
129 | {
130 | return (UINT16)((UINT16)((UINT16)
131 | (*(p + offset + 1)) << 8) + (UINT16)(*(p + offset)));
132 | }
133 |
134 | //*****************************************************************************
135 | //
136 | //! STREAM_TO_UINT32_f
137 | //!
138 | //! @param p pointer to the stream
139 | //! @param offset offset in the stream
140 | //!
141 | //! @return pointer to the new 32 bit
142 | //!
143 | //! @brief This function is used for copying received stream to
144 | //! 32 bit in little endian format.
145 | //
146 | //*****************************************************************************
147 |
148 | UINT32 STREAM_TO_UINT32_f(CHAR* p, UINT16 offset)
149 | {
150 | return (UINT32)((UINT32)((UINT32)
151 | (*(p + offset + 3)) << 24) + (UINT32)((UINT32)
152 | (*(p + offset + 2)) << 16) + (UINT32)((UINT32)
153 | (*(p + offset + 1)) << 8) + (UINT32)(*(p + offset)));
154 | }
155 |
156 |
157 |
158 | //*****************************************************************************
159 | //
160 | // Close the Doxygen group.
161 | //! @}
162 | //
163 | //*****************************************************************************
164 |
--------------------------------------------------------------------------------
/CC3000_Host_Driver/data_types.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * data_types.h - CC3000 Host Driver Implementation.
4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the
16 | * distribution.
17 | *
18 | * Neither the name of Texas Instruments Incorporated nor the names of
19 | * its contributors may be used to endorse or promote products derived
20 | * from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | *
34 | *****************************************************************************/
35 | #ifndef __DATA_TYPES__
36 | #define __DATA_TYPES__
37 |
38 | //*****************************************************************************
39 | //
40 | // If building with a C++ compiler, make all of the definitions in this header
41 | // have a C binding.
42 | //
43 | //*****************************************************************************
44 | #ifdef __cplusplus
45 | extern "C" {
46 | #endif
47 |
48 | #ifndef NULL
49 | #define NULL (0)
50 | #endif
51 |
52 | #ifndef FALSE
53 | #define FALSE (0)
54 | #endif
55 |
56 | #ifndef TRUE
57 | #define TRUE (!FALSE)
58 | #endif
59 |
60 | #ifndef _INT8
61 | #define _INT8
62 | typedef signed char INT8;
63 | #endif
64 |
65 | #ifndef _UINT8
66 | #define _UINT8
67 | typedef unsigned char UINT8;
68 | #endif
69 |
70 | #ifndef _INT16
71 | #define _INT16
72 | typedef signed short INT16;
73 | #endif
74 |
75 | #ifndef _UINT16
76 | #define _UINT16
77 | typedef unsigned short UINT16;
78 | #endif
79 |
80 | #ifndef _INT32
81 | #define _INT32
82 | typedef signed long INT32;
83 | #endif
84 |
85 | #ifndef _UINT32
86 | #define _UINT32
87 | typedef unsigned long UINT32;
88 | #endif
89 |
90 | typedef char CHAR;
91 |
92 | #ifdef __cplusplus
93 | }
94 | #endif /* __cplusplus */
95 |
96 | #endif /* __DATA_TYPE__ */
97 |
--------------------------------------------------------------------------------
/CC3000_Host_Driver/evnt_handler.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * evnt_handler.h - CC3000 Host Driver Implementation.
4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the
16 | * distribution.
17 | *
18 | * Neither the name of Texas Instruments Incorporated nor the names of
19 | * its contributors may be used to endorse or promote products derived
20 | * from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | *
34 | *****************************************************************************/
35 | #ifndef __EVENT_HANDLER_H__
36 | #define __EVENT_HANDLER_H__
37 | #include "hci.h"
38 | #include "socket.h"
39 |
40 | //*****************************************************************************
41 | //
42 | // If building with a C++ compiler, make all of the definitions in this header
43 | // have a C binding.
44 | //
45 | //*****************************************************************************
46 | #ifdef __cplusplus
47 | extern "C" {
48 | #endif
49 |
50 | //*****************************************************************************
51 | //
52 | // Prototypes for the APIs.
53 | //
54 | //*****************************************************************************
55 |
56 | //*****************************************************************************
57 | //
58 | //! hci_event_handler
59 | //!
60 | //! @param pRetParams incoming data buffer
61 | //! @param from from information (in case of data received)
62 | //! @param fromlen from information length (in case of data received)
63 | //!
64 | //! @return none
65 | //!
66 | //! @brief Parse the incoming events packets and issues corresponding
67 | //! event handler from global array of handlers pointers
68 | //
69 | //*****************************************************************************
70 | extern UINT8 *hci_event_handler(void *pRetParams, UINT8 *from, INT32 *fromlen);
71 |
72 | //*****************************************************************************
73 | //
74 | //! hci_unsol_event_handler
75 | //!
76 | //! @param event_hdr event header
77 | //!
78 | //! @return 1 if event supported and handled
79 | //! 0 if event is not supported
80 | //!
81 | //! @brief Handle unsolicited events
82 | //
83 | //*****************************************************************************
84 | extern INT32 hci_unsol_event_handler(CHAR *event_hdr);
85 |
86 | //*****************************************************************************
87 | //
88 | //! hci_unsolicited_event_handler
89 | //!
90 | //! @param None
91 | //!
92 | //! @return ESUCCESS if successful, EFAIL if an error occurred
93 | //!
94 | //! @brief Parse the incoming unsolicited event packets and issues
95 | //! corresponding event handler.
96 | //
97 | //*****************************************************************************
98 | extern INT32 hci_unsolicited_event_handler(void);
99 |
100 | #define M_BSD_RESP_PARAMS_OFFSET(hci_event_hdr)((CHAR *)(hci_event_hdr) + HCI_EVENT_HEADER_SIZE)
101 |
102 | #define SOCKET_STATUS_ACTIVE 0
103 | #define SOCKET_STATUS_INACTIVE 1
104 | /* Init socket_active_status = 'all ones': init all sockets with SOCKET_STATUS_INACTIVE.
105 | Will be changed by 'set_socket_active_status' upon 'connect' and 'accept' calls */
106 | #define SOCKET_STATUS_INIT_VAL 0xFFFF
107 | #define M_IS_VALID_SD(sd) ((0 <= (sd)) && ((sd) <= 7))
108 | #define M_IS_VALID_STATUS(status) (((status) == SOCKET_STATUS_ACTIVE)||((status) == SOCKET_STATUS_INACTIVE))
109 |
110 | extern void set_socket_active_status(INT32 Sd, INT32 Status);
111 | extern INT32 get_socket_active_status(INT32 Sd);
112 |
113 | typedef struct _bsd_accept_return_t
114 | {
115 | INT32 iSocketDescriptor;
116 | INT32 iStatus;
117 | sockaddr tSocketAddress;
118 |
119 | } tBsdReturnParams;
120 |
121 |
122 | typedef struct _bsd_read_return_t
123 | {
124 | INT32 iSocketDescriptor;
125 | INT32 iNumberOfBytes;
126 | UINT32 uiFlags;
127 | } tBsdReadReturnParams;
128 |
129 | #define BSD_RECV_FROM_FROMLEN_OFFSET (4)
130 | #define BSD_RECV_FROM_FROM_OFFSET (16)
131 |
132 |
133 | typedef struct _bsd_select_return_t
134 | {
135 | INT32 iStatus;
136 | UINT32 uiRdfd;
137 | UINT32 uiWrfd;
138 | UINT32 uiExfd;
139 | } tBsdSelectRecvParams;
140 |
141 |
142 | typedef struct _bsd_getsockopt_return_t
143 | {
144 | UINT8 ucOptValue[4];
145 | CHAR iStatus;
146 | } tBsdGetSockOptReturnParams;
147 |
148 | typedef struct _bsd_gethostbyname_return_t
149 | {
150 | INT32 retVal;
151 | INT32 outputAddress;
152 | } tBsdGethostbynameParams;
153 |
154 | extern uint32_t cc3000__event_timeout_ms;
155 | //*****************************************************************************
156 | //
157 | // Mark the end of the C bindings section for C++ compilers.
158 | //
159 | //*****************************************************************************
160 | #ifdef __cplusplus
161 | }
162 | #endif // __cplusplus
163 |
164 | #endif // __EVENT_HANDLER_H__
165 |
166 |
--------------------------------------------------------------------------------
/CC3000_Host_Driver/hci.c:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * hci.c - CC3000 Host Driver Implementation.
4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the
16 | * distribution.
17 | *
18 | * Neither the name of Texas Instruments Incorporated nor the names of
19 | * its contributors may be used to endorse or promote products derived
20 | * from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | *
34 | *****************************************************************************/
35 |
36 | //*****************************************************************************
37 | //
38 | //! \addtogroup hci_app
39 | //! @{
40 | //
41 | //*****************************************************************************
42 |
43 | #include "cc3000_common.h"
44 | #include "hci.h"
45 | #include "spi.h"
46 | #include "evnt_handler.h"
47 | #include "wlan.h"
48 |
49 | #define SL_PATCH_PORTION_SIZE (1000)
50 |
51 |
52 | //*****************************************************************************
53 | //
54 | //! hci_command_send
55 | //!
56 | //! @param usOpcode command operation code
57 | //! @param pucBuff pointer to the command's arguments buffer
58 | //! @param ucArgsLength length of the arguments
59 | //!
60 | //! @return none
61 | //!
62 | //! @brief Initiate an HCI command.
63 | //
64 | //*****************************************************************************
65 | UINT16 hci_command_send(UINT16 usOpcode, UINT8 *pucBuff, UINT8 ucArgsLength)
66 | {
67 | UINT8 *stream;
68 |
69 | stream = (pucBuff + SPI_HEADER_SIZE);
70 |
71 | UINT8_TO_STREAM(stream, HCI_TYPE_CMND);
72 | stream = UINT16_TO_STREAM(stream, usOpcode);
73 | UINT8_TO_STREAM(stream, ucArgsLength);
74 |
75 | //Update the opcode of the event we will be waiting for
76 | SpiWrite(pucBuff, ucArgsLength + SIMPLE_LINK_HCI_CMND_HEADER_SIZE);
77 |
78 | return(0);
79 | }
80 |
81 | //*****************************************************************************
82 | //
83 | //! hci_data_send
84 | //!
85 | //! @param usOpcode command operation code
86 | //! @param ucArgs pointer to the command's arguments buffer
87 | //! @param usArgsLength length of the arguments
88 | //! @param ucTail pointer to the data buffer
89 | //! @param usTailLength buffer length
90 | //!
91 | //! @return none
92 | //!
93 | //! @brief Initiate an HCI data write operation
94 | //
95 | //*****************************************************************************
96 | INT32 hci_data_send(UINT8 ucOpcode,
97 | UINT8 *ucArgs,
98 | UINT16 usArgsLength,
99 | UINT16 usDataLength,
100 | const UINT8 *ucTail,
101 | UINT16 usTailLength)
102 | {
103 | UINT8 *stream;
104 |
105 | stream = ((ucArgs) + SPI_HEADER_SIZE);
106 |
107 | UINT8_TO_STREAM(stream, HCI_TYPE_DATA);
108 | UINT8_TO_STREAM(stream, ucOpcode);
109 | UINT8_TO_STREAM(stream, usArgsLength);
110 | stream = UINT16_TO_STREAM(stream, usArgsLength + usDataLength + usTailLength);
111 |
112 | // Send the packet over the SPI
113 | SpiWrite(ucArgs, SIMPLE_LINK_HCI_DATA_HEADER_SIZE + usArgsLength + usDataLength + usTailLength);
114 |
115 | return(ESUCCESS);
116 | }
117 |
118 |
119 | //*****************************************************************************
120 | //
121 | //! hci_data_command_send
122 | //!
123 | //! @param usOpcode command operation code
124 | //! @param pucBuff pointer to the data buffer
125 | //! @param ucArgsLength arguments length
126 | //! @param ucDataLength data length
127 | //!
128 | //! @return none
129 | //!
130 | //! @brief Prepeare HCI header and initiate an HCI data write operation
131 | //
132 | //*****************************************************************************
133 | void hci_data_command_send(UINT16 usOpcode, UINT8 *pucBuff, UINT8 ucArgsLength,UINT16 ucDataLength)
134 | {
135 | UINT8 *stream = (pucBuff + SPI_HEADER_SIZE);
136 |
137 | UINT8_TO_STREAM(stream, HCI_TYPE_DATA);
138 | UINT8_TO_STREAM(stream, usOpcode);
139 | UINT8_TO_STREAM(stream, ucArgsLength);
140 | stream = UINT16_TO_STREAM(stream, ucArgsLength + ucDataLength);
141 |
142 | // Send the command over SPI on data channel
143 | SpiWrite(pucBuff, ucArgsLength + ucDataLength + SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE);
144 |
145 | return;
146 | }
147 |
148 | //*****************************************************************************
149 | //
150 | //! hci_patch_send
151 | //!
152 | //! @param usOpcode command operation code
153 | //! @param pucBuff pointer to the command's arguments buffer
154 | //! @param patch pointer to patch content buffer
155 | //! @param usDataLength data length
156 | //!
157 | //! @return none
158 | //!
159 | //! @brief Prepeare HCI header and initiate an HCI patch write operation
160 | //
161 | //*****************************************************************************
162 | void hci_patch_send(UINT8 ucOpcode, UINT8 *pucBuff, CHAR *patch, UINT16 usDataLength)
163 | {
164 | UINT8 *data_ptr = (pucBuff + SPI_HEADER_SIZE);
165 | UINT16 usTransLength;
166 | UINT8 *stream = (pucBuff + SPI_HEADER_SIZE);
167 |
168 | UINT8_TO_STREAM(stream, HCI_TYPE_PATCH);
169 | UINT8_TO_STREAM(stream, ucOpcode);
170 | stream = UINT16_TO_STREAM(stream, usDataLength + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE);
171 |
172 | if (usDataLength <= SL_PATCH_PORTION_SIZE)
173 | {
174 | UINT16_TO_STREAM(stream, usDataLength);
175 | stream = UINT16_TO_STREAM(stream, usDataLength);
176 | memcpy((pucBuff + SPI_HEADER_SIZE) + HCI_PATCH_HEADER_SIZE, patch, usDataLength);
177 |
178 | // Update the opcode of the event we will be waiting for
179 | SpiWrite(pucBuff, usDataLength + HCI_PATCH_HEADER_SIZE);
180 | }
181 | else
182 | {
183 |
184 | usTransLength = (usDataLength/SL_PATCH_PORTION_SIZE);
185 | UINT16_TO_STREAM(stream, usDataLength + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE + usTransLength*SIMPLE_LINK_HCI_PATCH_HEADER_SIZE);
186 | stream = UINT16_TO_STREAM(stream, SL_PATCH_PORTION_SIZE);
187 | memcpy(pucBuff + SPI_HEADER_SIZE + HCI_PATCH_HEADER_SIZE, patch, SL_PATCH_PORTION_SIZE);
188 | usDataLength -= SL_PATCH_PORTION_SIZE;
189 | patch += SL_PATCH_PORTION_SIZE;
190 |
191 | // Update the opcode of the event we will be waiting for
192 | SpiWrite(pucBuff, SL_PATCH_PORTION_SIZE + HCI_PATCH_HEADER_SIZE);
193 |
194 | while (usDataLength)
195 | {
196 | if (usDataLength <= SL_PATCH_PORTION_SIZE)
197 | {
198 | usTransLength = usDataLength;
199 | usDataLength = 0;
200 |
201 | }
202 | else
203 | {
204 | usTransLength = SL_PATCH_PORTION_SIZE;
205 | usDataLength -= usTransLength;
206 | }
207 |
208 | *(UINT16 *)data_ptr = usTransLength;
209 | memcpy(data_ptr + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE, patch, usTransLength);
210 | patch += usTransLength;
211 |
212 | // Update the opcode of the event we will be waiting for
213 | SpiWrite((UINT8 *)data_ptr, usTransLength + sizeof(usTransLength));
214 | }
215 | }
216 | }
217 |
218 | //*****************************************************************************
219 | //
220 | // Close the Doxygen group.
221 | //! @}
222 | //
223 | //
224 | //*****************************************************************************
225 |
--------------------------------------------------------------------------------
/CC3000_Host_Driver/host_driver_version.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * host_driver_version.h - CC3000 Host Driver Implementation.
4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the
16 | * distribution.
17 | *
18 | * Neither the name of Texas Instruments Incorporated nor the names of
19 | * its contributors may be used to endorse or promote products derived
20 | * from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | *
34 | *****************************************************************************/
35 | #ifndef __HOST_DRIVER_VERSION_H__
36 | #define __HOST_DRIVER_VERSION_H__
37 |
38 | #define DRIVER_VERSION_NUMBER 15
39 |
40 |
41 |
42 | #endif // __VERSION_H__
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/CC3000_Host_Driver/security.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | *
3 | * security.h - CC3000 Host Driver Implementation.
4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in the
15 | * documentation and/or other materials provided with the
16 | * distribution.
17 | *
18 | * Neither the name of Texas Instruments Incorporated nor the names of
19 | * its contributors may be used to endorse or promote products derived
20 | * from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 | *
34 | *****************************************************************************/
35 | #ifndef __SECURITY__
36 | #define __SECURITY__
37 |
38 | #include "nvmem.h"
39 |
40 | //*****************************************************************************
41 | //
42 | // If building with a C++ compiler, make all of the definitions in this header
43 | // have a C binding.
44 | //
45 | //*****************************************************************************
46 | #ifdef __cplusplus
47 | extern "C" {
48 | #endif
49 |
50 |
51 | #define AES128_KEY_SIZE 16
52 |
53 | #ifndef CC3000_UNENCRYPTED_SMART_CONFIG
54 |
55 |
56 | //*****************************************************************************
57 | //
58 | //! aes_encrypt
59 | //!
60 | //! @param[in] key AES128 key of size 16 bytes
61 | //! @param[in\out] state 16 bytes of plain text and cipher text
62 | //! @param[in] expandedKey temporary buffer for key
63 | //!
64 | //! @return none
65 | //!
66 | //! @brief AES128 encryption:
67 | //! Given AES128 key and 16 bytes plain text, cipher text of 16 bytes
68 | //! is computed. The AES implementation is in mode ECB (Electronic
69 | //! Code Book).
70 | //!
71 | //!
72 | //*****************************************************************************
73 | extern void aes_encrypt(UINT8 *state, UINT8 *key, UINT8 expandedKey[176]);
74 |
75 | //*****************************************************************************
76 | //
77 | //! aes_decrypt
78 | //!
79 | //! @param[in] key AES128 key of size 16 bytes
80 | //! @param[in\out] state 16 bytes of cipher text and plain text
81 | //! @param[in] expandedKey temporary buffer for key
82 | //!
83 | //! @return none
84 | //!
85 | //! @brief AES128 decryption:
86 | //! Given AES128 key and 16 bytes cipher text, plain text of 16 bytes
87 | //! is computed The AES implementation is in mode ECB
88 | //! (Electronic Code Book).
89 | //!
90 | //!
91 | //*****************************************************************************
92 | extern void aes_decrypt(UINT8 *state, UINT8 *key, UINT8 expandedKey[176]);
93 |
94 |
95 | //*****************************************************************************
96 | //
97 | //! aes_read_key
98 | //!
99 | //! @param[out] key AES128 key of size 16 bytes
100 | //!
101 | //! @return on success 0, error otherwise.
102 | //!
103 | //! @brief Reads AES128 key from EEPROM
104 | //! Reads the AES128 key from fileID #12 in EEPROM
105 | //! returns an error if the key does not exist.
106 | //!
107 | //!
108 | //*****************************************************************************
109 | extern INT32 aes_read_key(UINT8 *key);
110 |
111 | //*****************************************************************************
112 | //
113 | //! aes_write_key
114 | //!
115 | //! @param[out] key AES128 key of size 16 bytes
116 | //!
117 | //! @return on success 0, error otherwise.
118 | //!
119 | //! @brief writes AES128 key from EEPROM
120 | //! Writes the AES128 key to fileID #12 in EEPROM
121 | //!
122 | //!
123 | //*****************************************************************************
124 | extern INT32 aes_write_key(UINT8 *key);
125 |
126 | #endif //CC3000_UNENCRYPTED_SMART_CONFIG
127 |
128 | #ifdef __cplusplus
129 | }
130 | #endif // __cplusplus
131 |
132 | #endif
133 |
--------------------------------------------------------------------------------
/CMSIS/Device/ST/STM32F10x/Include/system_stm32f10x.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | Released into the public domain.
4 | This work is free: you can redistribute it and/or modify it under the terms of
5 | Creative Commons Zero license v1.0
6 |
7 | This work is licensed under the Creative Commons Zero 1.0 United States License.
8 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
9 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
10 | California, 94105, USA.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 | or FITNESS FOR A PARTICULAR PURPOSE.
15 | ******************************************************************************
16 | */
17 |
18 |
19 | /** @addtogroup CMSIS
20 | * @{
21 | */
22 |
23 | /** @addtogroup stm32f10x_system
24 | * @{
25 | */
26 |
27 | /**
28 | * @brief Define to prevent recursive inclusion
29 | */
30 | #ifndef __SYSTEM_STM32F10X_H
31 | #define __SYSTEM_STM32F10X_H
32 |
33 | #ifdef __cplusplus
34 | extern "C" {
35 | #endif
36 |
37 | /** @addtogroup STM32F10x_System_Includes
38 | * @{
39 | */
40 |
41 | /**
42 | * @}
43 | */
44 |
45 |
46 | /** @addtogroup STM32F10x_System_Exported_types
47 | * @{
48 | */
49 |
50 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
51 |
52 | /**
53 | * @}
54 | */
55 |
56 | /** @addtogroup STM32F10x_System_Exported_Constants
57 | * @{
58 | */
59 |
60 | /**
61 | * @}
62 | */
63 |
64 | /** @addtogroup STM32F10x_System_Exported_Macros
65 | * @{
66 | */
67 |
68 | /**
69 | * @}
70 | */
71 |
72 | /** @addtogroup STM32F10x_System_Exported_Functions
73 | * @{
74 | */
75 |
76 | extern void SystemInit(void);
77 | extern void SystemCoreClockUpdate(void);
78 | /**
79 | * @}
80 | */
81 |
82 | #ifdef __cplusplus
83 | }
84 | #endif
85 |
86 | #endif /*__SYSTEM_STM32F10X_H */
87 |
88 | /**
89 | * @}
90 | */
91 |
92 | /**
93 | * @}
94 | */
95 |
--------------------------------------------------------------------------------
/CMSIS/Include/arm_common_tables.h:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------
2 | * Copyright (C) 2010 ARM Limited. All rights reserved.
3 | *
4 | * $Date: 11. November 2010
5 | * $Revision: V1.0.2
6 | *
7 | * Project: CMSIS DSP Library
8 | * Title: arm_common_tables.h
9 | *
10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions
11 | *
12 | * Target Processor: Cortex-M4/Cortex-M3
13 | *
14 | * Version 1.0.2 2010/11/11
15 | * Documentation updated.
16 | *
17 | * Version 1.0.1 2010/10/05
18 | * Production release and review comments incorporated.
19 | *
20 | * Version 1.0.0 2010/09/20
21 | * Production release and review comments incorporated.
22 | * -------------------------------------------------------------------- */
23 |
24 | #ifndef _ARM_COMMON_TABLES_H
25 | #define _ARM_COMMON_TABLES_H
26 |
27 | #include "arm_math.h"
28 |
29 | extern const uint16_t armBitRevTable[1024];
30 | extern const q15_t armRecipTableQ15[64];
31 | extern const q31_t armRecipTableQ31[64];
32 | extern const q31_t realCoefAQ31[1024];
33 | extern const q31_t realCoefBQ31[1024];
34 | extern const float32_t twiddleCoef[6144];
35 | extern const q31_t twiddleCoefQ31[6144];
36 | extern const q15_t twiddleCoefQ15[6144];
37 |
38 | #endif /* ARM_COMMON_TABLES_H */
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # core-common-lib
2 |
3 | This repository holds all the common firmware libraries used by the Spark's main core firmware.
4 |
5 | Follow [this link](https://github.com/spark/core-firmware/blob/master/README.md) to find out how to build and use this repository.
6 |
7 | #### CREDITS AND ATTRIBUTIONS
8 |
9 | The Spark application team: Zachary Crockett, Satish Nair, Zach Supalla, David Middlecamp and Mohit Bhoite.
10 |
11 | The core-common-lib uses the GNU GCC toolchain for ARM Cortex-M processors, ARM's CMSIS libraries, TI's CC3000 host driver libraries and STM32 standard peripheral libraries.
12 |
13 | #### LICENSE
14 | Unless stated elsewhere, file headers or otherwise, the license as stated in the LICENSE file.
15 |
16 | #### CONTRIBUTE
17 |
18 | Want to contribute to the Spark Core project? Follow [this link]() to find out how.
19 |
20 | #### CONNECT
21 |
22 | Having problems or have awesome suggestions? Connect with us [here.](https://community.sparkdevices.com/)
23 |
24 | #### VERSION HISTORY
25 |
26 | Latest Version: v1.0.0
27 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/cc3000_spi.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file cc3000_spi.h
4 | * @author Satish Nair, Zachary Crockett and Mohit Bhoite
5 | * @version V1.0.0
6 | * @date 29-March-2013
7 | * @brief This file contains all the functions prototypes for the
8 | * CC3000 SPI firmware driver.
9 | ******************************************************************************
10 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved.
11 |
12 | This library is free software; you can redistribute it and/or
13 | modify it under the terms of the GNU Lesser General Public
14 | License as published by the Free Software Foundation, either
15 | version 3 of the License, or (at your option) any later version.
16 |
17 | This library is distributed in the hope that it will be useful,
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | Lesser General Public License for more details.
21 |
22 | You should have received a copy of the GNU Lesser General Public
23 | License along with this library; if not, see .
24 | ******************************************************************************
25 | */
26 |
27 | /* Define to prevent recursive inclusion -------------------------------------*/
28 | #ifndef __CC3000_SPI_H
29 | #define __CC3000_SPI_H
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include
33 | #include "hw_config.h"
34 | #include "cc3000_common.h"
35 | #include "hci.h"
36 | #include "wlan.h"
37 |
38 | #ifndef FALSE
39 | #define FALSE 0x00
40 | #endif
41 | #ifndef TRUE
42 | #define TRUE !FALSE
43 | #endif
44 |
45 | #define READ 0x03
46 | #define WRITE 0x01
47 |
48 | #define HI(value) (((value) & 0xFF00) >> 8)
49 | #define LO(value) ((value) & 0x00FF)
50 |
51 | #define ASSERT_CS() CC3000_CS_LOW()
52 | #define DEASSERT_CS() CC3000_CS_HIGH()
53 |
54 |
55 | #define HEADERS_SIZE_EVNT (SPI_HEADER_SIZE + 5)
56 | #define MAX_PACKET_PAYLOAD_SIZE 1014
57 | #define RX_SPI_BUFFER_SIZE (MAX_PACKET_PAYLOAD_SIZE+HEADERS_SIZE_EVNT)
58 | #define TX_SPI_BUFFER_SIZE (MAX_PACKET_PAYLOAD_SIZE+HEADERS_SIZE_EVNT)
59 |
60 | typedef void (*gcSpiHandleRx)(void *p);
61 | typedef void (*gcSpiHandleTx)(void);
62 |
63 | extern unsigned char wlan_rx_buffer[RX_SPI_BUFFER_SIZE];
64 | extern unsigned char wlan_tx_buffer[TX_SPI_BUFFER_SIZE];
65 |
66 | /* CC3000 SPI Protocol API */
67 | extern void SpiOpen(gcSpiHandleRx pfRxHandler);
68 | extern void SpiClose(void);
69 | extern long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength);
70 | extern void SpiResumeSpi(void);
71 | extern void SPI_DMA_IntHandler(void);
72 | extern void SPI_EXTI_IntHandler(void);
73 |
74 | extern void handle_spi_request();
75 |
76 | #endif /* __CC3000_SPI_H */
77 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * config.h
3 | *
4 | * Created on: Jan 31, 2014
5 | * Author: david_s5
6 | */
7 |
8 | #ifndef CONFIG_H_
9 | #define CONFIG_H_
10 |
11 | #if !defined(RELEASE_BUILD) && !defined(DEBUG_BUILD)
12 | #warning "Defaulting to Release Build"
13 | #define RELEASE_BUILD
14 | #undef DEBUG_BUILD
15 | #endif
16 |
17 |
18 | #if defined(DEBUG_BUILD)
19 | #define DBGMCU_SETTINGS (DBGMCU_CR_DBG_SLEEP|DBGMCU_CR_DBG_STOP|DBGMCU_CR_DBG_STANDBY|DBGMCU_CR_DBG_IWDG_STOP|DBGMCU_CR_DBG_WWDG_STOP)
20 | #else
21 | #define USE_ONLY_PANIC // Define to remove all Logging and only have Panic
22 | #define DBGMCU_SETTINGS (DBGMCU_CR_DBG_IWDG_STOP|DBGMCU_CR_DBG_WWDG_STOP)
23 | #endif
24 | // define to include __FILE__ information within the debug output
25 | #define INCLUDE_FILE_INFO_IN_DEBUG
26 | #define MAX_DEBUG_MESSAGE_LENGTH 120
27 |
28 | #define RESET_ON_CFOD 1 // 1 Will do reset 0 will not
29 | #define MAX_SEC_WAIT_CONNECT 8 // Number of second a TCP, spark will wait
30 | #define MAX_FAILED_CONNECTS 2 // Number of time a connect can fail
31 | #define DEFAULT_SEC_INACTIVITY 0
32 | #define DEFAULT_SEC_NETOPS 20
33 |
34 | #endif /* CONFIG_H_ */
35 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/debug.h:
--------------------------------------------------------------------------------
1 | /*
2 | * debug.h
3 | *
4 | * Created on: Jan 31, 2014
5 | * Author: david_s5
6 | */
7 | #ifndef DEBUG_H_
8 | #define DEBUG_H_
9 |
10 | #include "config.h"
11 |
12 | /*
13 | * This module supports runtime and compile time message filtering.
14 | *
15 | * For a message be compiled in the message type has to be >= to then the LOG_LEVEL_AT_COMPILE_TIME
16 | * For a message to be output the message type has to be >= then the LOG_LEVEL_AT_RUN_TIME
17 | *
18 | * This module assumes one of two #defines RELEASE_BUILD or DEBUG_BUILD exist
19 | * Then the LOG_LEVEL_AT_COMPILE_TIME and LOG_LEVEL_AT_RUN_TIME are set based on RELEASE or DEBUG
20 | * For a release build
21 | * LOG_LEVEL_AT_COMPILE_TIME = WARN_LEVEL
22 | * LOG_LEVEL_AT_RUN_TIME = WARN_LEVEL
23 | * For a debug build:
24 | * LOG_LEVEL_AT_COMPILE_TIME = LOG_LEVEL
25 | * LOG_LEVEL_AT_RUN_TIME = LOG_LEVEL
26 | * The API
27 | * LOG(fmt,...)
28 | * DEBUG(fmt,...)
29 | * WARN(fmt,...)
30 | * ERROR(fmt,...)
31 | * PANIC(code,fmt,...)
32 | */
33 |
34 | #include
35 | #include
36 | #include "panic.h"
37 |
38 | // Debug Levels
39 | #define LOG_LEVEL 1
40 | #define DEBUG_LEVEL 2
41 | #define WARN_LEVEL 3
42 | #define ERROR_LEVEL 4
43 | #define PANIC_LEVEL 5
44 |
45 | #if !defined(INCLUDE_FILE_INFO_IN_DEBUG)
46 | #define _FILE_PATH __FILE__
47 | #else
48 | #define _FILE_PATH NULL
49 | #endif //
50 |
51 | #if defined(DEBUG_BUILD)
52 | #define LOG_LEVEL_AT_COMPILE_TIME LOG_LEVEL
53 | #define LOG_LEVEL_AT_RUN_TIME LOG_LEVEL // Set to allow all LOG_LEVEL and above messages to be displayed conditionally by levels.
54 | #endif
55 |
56 | #if defined(RELEASE_BUILD)
57 | #define LOG_LEVEL_AT_COMPILE_TIME ERROR_LEVEL
58 | #define LOG_LEVEL_AT_RUN_TIME ERROR_LEVEL
59 | #endif
60 |
61 | #ifdef __cplusplus
62 | extern "C" {
63 | #endif
64 | // Must be provided by main if wanted as extern C definitions
65 | extern uint32_t log_level_at_run_time __attribute__ ((weak));;
66 | void log_print_(int level, int line, const char *func, const char *file, const char *msg, ...);
67 | void debug_output_(const char *) __attribute__ ((weak));
68 | #ifdef __cplusplus
69 | }
70 | #endif
71 |
72 | // Short Cuts
73 | #define __LOG_LEVEL_TEST(level) (level >= LOG_LEVEL_AT_COMPILE_TIME && level >= LOG_LEVEL_AT_RUN_TIME)
74 |
75 | #if defined(USE_ONLY_PANIC)
76 | #define LOG(fmt, ...)
77 | #define DEBUG(fmt, ...)
78 | #define WARN(fmt, ...)
79 | #define ERROR(fmt, ...)
80 | #define PANIC(code,fmt, ...) do {panic_(code);}while(0)
81 | #else
82 | // Macros to use
83 | #define LOG(fmt, ...) do { if ( __LOG_LEVEL_TEST(LOG_LEVEL) ) {log_print_(LOG_LEVEL,__LINE__,__PRETTY_FUNCTION__,_FILE_PATH,fmt, ##__VA_ARGS__);}}while(0)
84 | #define DEBUG(fmt, ...) do { if ( __LOG_LEVEL_TEST(DEBUG_LEVEL)) {log_print_(DEBUG_LEVEL,__LINE__,__PRETTY_FUNCTION__,_FILE_PATH,fmt,##__VA_ARGS__);}}while(0)
85 | #define WARN(fmt, ...) do { if ( __LOG_LEVEL_TEST(WARN_LEVEL) ) {log_print_(WARN_LEVEL,__LINE__,__PRETTY_FUNCTION__,_FILE_PATH,fmt,##__VA_ARGS__);}}while(0)
86 | #define ERROR(fmt, ...) do { if ( __LOG_LEVEL_TEST(ERROR_LEVEL) ) {log_print_(ERROR_LEVEL,__LINE__,__PRETTY_FUNCTION__,_FILE_PATH,fmt,##__VA_ARGS__);}}while(0)
87 | #define PANIC(code,fmt, ...) do { if ( __LOG_LEVEL_TEST(PANIC_LEVEL) ) {log_print_(PANIC_LEVEL,__LINE__,__PRETTY_FUNCTION__,_FILE_PATH,fmt,##__VA_ARGS__);} panic_(code);}while(0)
88 | #endif
89 | #define SPARK_ASSERT(predicate) do { if (!(predicate)) PANIC(AssertionFailure,"AssertionFailure "#predicate);} while(0);
90 |
91 | #endif /* DEBUG_H_ */
92 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/panic.h:
--------------------------------------------------------------------------------
1 | /*
2 | * panic.h
3 | *
4 | * Created on: Jan 31, 2014
5 | * Author: david_s5
6 | */
7 | // The panic module will send SOS followed by 900 ms delay
8 | // followed by 300 blinks of the value of code
9 | /// ...---... code ...---...
10 |
11 |
12 | #ifndef PANIC_H_
13 | #define PANIC_H_
14 | #ifdef __cplusplus
15 | extern "C" {
16 | #endif
17 |
18 | #define def_panic_codes(_class,led,code) code,
19 | typedef enum {
20 | NotUsedPanicCode = 0, // Not used
21 | #include "panic_codes.h"
22 | } ePanicCode;
23 | #undef def_panic_codes
24 |
25 | void panic_(ePanicCode code);
26 |
27 | #ifdef __cplusplus
28 | }
29 | #endif
30 |
31 | #endif /* PANIC_H_ */
32 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/panic_codes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * panic.h
3 | *
4 | * Created on: Jan 31, 2014
5 | * Author: david_s5
6 | */
7 | // Add a panic code def_panic_codes(_class, led, code)
8 | // the panic module will send SOS followed by 900 ms delay
9 | // followed by 300 blinks of the value of code
10 | /// ...---... code ...---...
11 |
12 | def_panic_codes(Faults,RGB_COLOR_RED,HardFault)
13 | def_panic_codes(Faults,RGB_COLOR_RED,NMIFault)
14 | def_panic_codes(Faults,RGB_COLOR_RED,MemManage)
15 | def_panic_codes(Faults,RGB_COLOR_RED,BusFault)
16 | def_panic_codes(Faults,RGB_COLOR_RED,UsageFault)
17 |
18 | def_panic_codes(Cloud,RGB_COLOR_RED,InvalidLenth)
19 |
20 | def_panic_codes(System,RGB_COLOR_RED,Exit)
21 | def_panic_codes(System,RGB_COLOR_RED,OutOfHeap)
22 |
23 | def_panic_codes(System,RGB_COLOR_RED,SPIOverRun)
24 |
25 | def_panic_codes(Software,RGB_COLOR_RED,AssertionFailure)
26 | def_panic_codes(Software,RGB_COLOR_RED,InvalidCase)
27 | def_panic_codes(Software,RGB_COLOR_RED,PureVirtualCall)
28 |
29 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/spark_macros.h:
--------------------------------------------------------------------------------
1 | /*
2 | * spark_macros.h
3 | *
4 | * Created on: Jan 31, 2014
5 | * Author: david_s5
6 | */
7 |
8 | #ifndef SPARK_MACROS_H_
9 | #define SPARK_MACROS_H_
10 |
11 | #if !defined(arraySize)
12 | # define arraySize(a) (sizeof((a))/sizeof((a[0])))
13 | #endif
14 |
15 | #define INVALID_CASE(c) PANIC(InvalidCase,"Invalid Case %d",(c))
16 | #define UNUSED(var) (void)(var)
17 |
18 | #define _CAT(a, b) a ## b
19 | #define CAT(a, b) _CAT(a, b)
20 |
21 | #define CCASSERT(predicate) _x_CCASSERT_LINE(predicate, __LINE__)
22 | #define _x_CCASSERT_LINE(predicate, line) typedef char CAT(constraint_violated_on_line_,line)[2*((predicate)!=0)-1];
23 |
24 | // Seconds to Us
25 | #define S2u(s) ((s)*1000000)
26 | // Mili Seconds to Us
27 | #define MS2u(m) ((m)*1000)
28 |
29 | // Seconds to Ms
30 | #define S2M(s) ((s)*1000)
31 |
32 | #endif /* SPARK_MACROS_H_ */
33 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/spi.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file spi.h
4 | * @authors Zac
5 | * @version V1.0.0
6 | * @date 28-April-2013
7 | * @brief SPI
8 | ******************************************************************************
9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved.
10 |
11 | This library is free software; you can redistribute it and/or
12 | modify it under the terms of the GNU Lesser General Public
13 | License as published by the Free Software Foundation, either
14 | version 3 of the License, or (at your option) any later version.
15 |
16 | This library is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 | Lesser General Public License for more details.
20 |
21 | You should have received a copy of the GNU Lesser General Public
22 | License along with this library; if not, see .
23 | ******************************************************************************
24 | */
25 |
26 |
27 | #ifndef SPI_H_
28 | #define SPI_H_
29 |
30 | #include "cc3000_spi.h"
31 |
32 | #endif /* SPI_H_ */
33 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/spi_bus.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: spi_bus.h
3 | * Author: mat
4 | *
5 | * Created on 30 June 2014, 14:25
6 | */
7 |
8 | #ifndef SPI_BUS_H
9 | #define SPI_BUS_H
10 |
11 | #ifdef __cplusplus
12 | extern "C" {
13 | #endif
14 |
15 | void reset_bus();
16 |
17 | int try_acquire_spi_bus(int owner);
18 |
19 | void acquire_spi_bus(int owner);
20 |
21 | void release_spi_bus(int owner);
22 |
23 | int current_bus_owner();
24 |
25 | #ifdef __cplusplus
26 | }
27 | #endif
28 |
29 | #endif /* SPI_BUS_H */
30 |
31 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/sst25vf_spi.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file sst25vf_spi.h
4 | * @author Satish Nair, Zachary Crockett and Mohit Bhoite
5 | * @version V1.0.0
6 | * @date 15-May-2013
7 | * @brief This file contains all the functions prototypes for the
8 | * sst25vf_spi Flash firmware driver.
9 | ******************************************************************************
10 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved.
11 |
12 | This library is free software; you can redistribute it and/or
13 | modify it under the terms of the GNU Lesser General Public
14 | License as published by the Free Software Foundation, either
15 | version 3 of the License, or (at your option) any later version.
16 |
17 | This library is distributed in the hope that it will be useful,
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | Lesser General Public License for more details.
21 |
22 | You should have received a copy of the GNU Lesser General Public
23 | License along with this library; if not, see .
24 | ******************************************************************************
25 | */
26 |
27 | /* Define to prevent recursive inclusion -------------------------------------*/
28 | #ifndef __SST25VF_SPI_H
29 | #define __SST25VF_SPI_H
30 |
31 | /* Includes ------------------------------------------------------------------*/
32 | #include "hw_config.h"
33 |
34 | /* SST25 SPI Flash supported commands */
35 | #define sFLASH_CMD_RDSR 0x05 /* Read Status Register */
36 | #define sFLASH_CMD_WRSR 0x01 /* Write Status Register */
37 | #define sFLASH_CMD_EWSR 0x50 /* Write Enable Status */
38 | #define sFLASH_CMD_WRDI 0x04 /* Write Disable */
39 | #define sFLASH_CMD_WREN 0x06 /* Write Enable */
40 | #define sFLASH_CMD_READ 0x03 /* Read Data Bytes */
41 | #define sFLASH_CMD_WRITE 0x02 /* Byte Program */
42 | #define sFLASH_CMD_AAIP 0xAD /* Auto Address Increment */
43 | #define sFLASH_CMD_SE 0x20 /* 4KB Sector Erase instruction */
44 | #define sFLASH_CMD_BE 0xC7 /* Bulk Chip Erase instruction */
45 | #define sFLASH_CMD_RDID 0x9F /* JEDEC ID Read */
46 | #define sFLASH_CMD_EBSY 0x70 /* Enable SO RY/BY# Status */
47 | #define sFLASH_CMD_DBSY 0x80 /* Disable SO RY/BY# Status */
48 |
49 | #define sFLASH_WIP_FLAG 0x01 /* Write In Progress (WIP) flag */
50 |
51 | #define sFLASH_DUMMY_BYTE 0xFF
52 | #define sFLASH_PAGESIZE 0x1000 /* 4096 bytes */
53 |
54 | #define sFLASH_SST25VF040_ID 0xBF258D /* JEDEC Read-ID Data */
55 | #define sFLASH_SST25VF016_ID 0xBF2541 /* JEDEC Read-ID Data */
56 |
57 | #ifdef __cplusplus
58 | extern "C" {
59 | #endif /* __cplusplus */
60 |
61 | /* High level functions. */
62 | void sFLASH_Init(void);
63 | void sFLASH_EraseSector(uint32_t SectorAddr);
64 | void sFLASH_EraseBulk(void);
65 | void sFLASH_WriteBuffer(const uint8_t *pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite);
66 | void sFLASH_ReadBuffer(uint8_t *pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead);
67 | uint32_t sFLASH_ReadID(void);
68 |
69 | /* Flash Self Test Routine */
70 | int sFLASH_SelfTest(void);
71 |
72 | #ifdef __cplusplus
73 | } /* extern "C" */
74 | #endif /* __cplusplus */
75 |
76 | #endif /* __SST25VF_SPI_H */
77 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/stm32f10x_conf.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_conf.h
4 | * @author Satish Nair, Zachary Crockett and Mohit Bhoite
5 | * @version V1.0.0
6 | * @date 21-January-2013
7 | * @brief Library configuration file.
8 | ******************************************************************************
9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved.
10 |
11 | This library is free software; you can redistribute it and/or
12 | modify it under the terms of the GNU Lesser General Public
13 | License as published by the Free Software Foundation, either
14 | version 3 of the License, or (at your option) any later version.
15 |
16 | This library is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 | Lesser General Public License for more details.
20 |
21 | You should have received a copy of the GNU Lesser General Public
22 | License along with this library; if not, see .
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_CONF_H
28 | #define __STM32F10x_CONF_H
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | /* Uncomment the line below to enable peripheral header file inclusion */
32 | #include "stm32f10x_adc.h"
33 | #include "stm32f10x_bkp.h"
34 | //#include "stm32f10x_can.h"
35 | #include "stm32f10x_crc.h"
36 | //#include "stm32f10x_dac.h"
37 | //#include "stm32f10x_dbgmcu.h"
38 | #include "stm32f10x_dma.h"
39 | #include "stm32f10x_exti.h"
40 | #include "stm32f10x_flash.h"
41 | //#include "stm32f10x_fsmc.h"
42 | #include "stm32f10x_gpio.h"
43 | #include "stm32f10x_i2c.h"
44 | #include "stm32f10x_iwdg.h"
45 | #include "stm32f10x_pwr.h"
46 | #include "stm32f10x_rcc.h"
47 | #include "stm32f10x_rtc.h"
48 | //#include "stm32f10x_sdio.h"
49 | #include "stm32f10x_spi.h"
50 | #include "stm32f10x_tim.h"
51 | #include "stm32f10x_usart.h"
52 | //#include "stm32f10x_wwdg.h"
53 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
54 |
55 | /* Exported types ------------------------------------------------------------*/
56 | /* Exported constants --------------------------------------------------------*/
57 | /* Uncomment the line below to expanse the "assert_param" macro in the
58 | Standard Peripheral Library drivers code */
59 | /* #define USE_FULL_ASSERT 1 */
60 |
61 | /* Exported macro ------------------------------------------------------------*/
62 | #ifdef USE_FULL_ASSERT
63 |
64 | /*******************************************************************************
65 | * Macro Name : assert_param
66 | * Description : The assert_param macro is used for function's parameters check.
67 | * Input : - expr: If expr is false, it calls assert_failed function
68 | * which reports the name of the source file and the source
69 | * line number of the call that failed.
70 | * If expr is true, it returns no value.
71 | * Return : None
72 | *******************************************************************************/
73 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
74 | /* Exported functions ------------------------------------------------------- */
75 | void assert_failed(uint8_t* file, uint32_t line);
76 | #else
77 | #define assert_param(expr) ((void)0)
78 | #endif /* USE_FULL_ASSERT */
79 |
80 | #endif /* __STM32F10x_CONF_H */
81 |
82 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/inc/usb_pwr.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_pwr.h
4 | * @author Satish Nair, Zachary Crockett and Mohit Bhoite
5 | * @version V1.0.0
6 | * @date 24-April-2013
7 | * @brief Connection/disconnection & power management header
8 | ******************************************************************************
9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved.
10 |
11 | This library is free software; you can redistribute it and/or
12 | modify it under the terms of the GNU Lesser General Public
13 | License as published by the Free Software Foundation, either
14 | version 3 of the License, or (at your option) any later version.
15 |
16 | This library is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 | Lesser General Public License for more details.
20 |
21 | You should have received a copy of the GNU Lesser General Public
22 | License along with this library; if not, see .
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __USB_PWR_H
28 | #define __USB_PWR_H
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | /* Exported types ------------------------------------------------------------*/
32 | typedef enum _RESUME_STATE
33 | {
34 | RESUME_EXTERNAL,
35 | RESUME_INTERNAL,
36 | RESUME_LATER,
37 | RESUME_WAIT,
38 | RESUME_START,
39 | RESUME_ON,
40 | RESUME_OFF,
41 | RESUME_ESOF
42 | } RESUME_STATE;
43 |
44 | typedef enum _DEVICE_STATE
45 | {
46 | UNCONNECTED,
47 | ATTACHED,
48 | POWERED,
49 | SUSPENDED,
50 | ADDRESSED,
51 | CONFIGURED
52 | } DEVICE_STATE;
53 |
54 | /* Exported constants --------------------------------------------------------*/
55 | /* Exported macro ------------------------------------------------------------*/
56 | /* Exported functions ------------------------------------------------------- */
57 | void Suspend(void);
58 | void Resume_Init(void);
59 | void Resume(RESUME_STATE eResumeSetVal);
60 | RESULT PowerOn(void);
61 | RESULT PowerOff(void);
62 |
63 | /* External variables --------------------------------------------------------*/
64 | extern __IO uint32_t bDeviceState; /* USB device status */
65 | extern __IO bool fSuspendEnabled; /* true when suspend is possible */
66 |
67 | #endif /*__USB_PWR_H*/
68 |
69 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/src/build.mk:
--------------------------------------------------------------------------------
1 | # This file is a makefile included from the top level makefile which
2 | # defines the sources built for the target.
3 |
4 | # Define the prefix to this directory.
5 | # Note: The name must be unique within this build and should be
6 | # based on the root of the project
7 | TARGET_SPARK_PATH = SPARK_Firmware_Driver
8 | TARGET_SPARK_SRC_PATH = $(TARGET_SPARK_PATH)/src
9 |
10 | # Add tropicssl include to all objects built for this target
11 | INCLUDE_DIRS += $(TARGET_SPARK_PATH)/inc
12 | INCLUDE_DIRS += SPARK_Services/inc
13 |
14 | # C source files included in this build.
15 | CSRC += $(TARGET_SPARK_SRC_PATH)/cc3000_spi.c
16 | CSRC += $(TARGET_SPARK_SRC_PATH)/hw_config.c
17 | CSRC += $(TARGET_SPARK_SRC_PATH)/sst25vf_spi.c
18 | CSRC += $(TARGET_SPARK_SRC_PATH)/system_stm32f10x.c
19 | CSRC += $(TARGET_SPARK_SRC_PATH)/usb_pwr.c
20 | CSRC += $(TARGET_SPARK_SRC_PATH)/debug.c
21 | CSRC += $(TARGET_SPARK_SRC_PATH)/panic.c
22 | CSRC += $(TARGET_SPARK_SRC_PATH)/spi_bus.c
23 |
24 | # C++ source files included in this build.
25 | CPPSRC +=
26 |
27 | # ASM source files included in this build.
28 | ASRC +=
29 |
30 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/src/debug.c:
--------------------------------------------------------------------------------
1 | /*
2 | * debug.c
3 | *
4 | * Created on: Jan 31, 2014
5 | * Author: david_s5
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include "config.h"
13 | #include "hw_config.h"
14 | #include "spark_macros.h"
15 | #include "debug.h"
16 |
17 |
18 | uint32_t log_level_at_run_time = LOG_LEVEL_AT_RUN_TIME;
19 |
20 | void log_print_(int level, int line, const char *func, const char *file, const char *msg, ...)
21 | {
22 | char _buffer[MAX_DEBUG_MESSAGE_LENGTH];
23 | static char * levels[] = {
24 | "",
25 | "LOG ",
26 | "DEBUG",
27 | "WARN ",
28 | "ERROR",
29 | "PANIC",
30 | };
31 | va_list args;
32 | va_start(args, msg);
33 | file = file ? strrchr(file,'/') + 1 : "";
34 | int trunc = snprintf(_buffer, arraySize(_buffer), "%010lu:<%s> %s %s(%d):", GetSystem1MsTick(), levels[level], func, file, line);
35 | if (debug_output_)
36 | {
37 | debug_output_(_buffer);
38 | if (trunc > arraySize(_buffer))
39 | {
40 | debug_output_("...");
41 | }
42 | }
43 | trunc = vsnprintf(_buffer,arraySize(_buffer), msg, args);
44 | if (debug_output_)
45 | {
46 | debug_output_(_buffer);
47 | if (trunc > arraySize(_buffer))
48 | {
49 | debug_output_("...");
50 | }
51 | debug_output_("\r\n");
52 | }
53 | }
54 |
55 |
56 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/src/panic.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pnaic.c
3 | *
4 | * Created on: Jan 31, 2014
5 | * Author: david_s5
6 | */
7 |
8 | #include
9 | #include "hw_config.h"
10 | #include "spark_macros.h"
11 | #include "panic.h"
12 | #include "debug.h"
13 |
14 |
15 | #define LOOPSPERMSEC 5483
16 |
17 | typedef struct {
18 | uint32_t led;
19 | uint16_t count;
20 | } flash_codes_t;
21 |
22 |
23 | #define def_panic_codes(_class,led,code) {led, code},
24 | static const flash_codes_t flash_codes[] = {
25 | {0,0}, //NotUsedPanicCode
26 | #include "panic_codes.h"
27 | };
28 | #undef def_panic_codes
29 |
30 | /****************************************************************************
31 | * Public Functions
32 | ****************************************************************************/
33 |
34 | void panic_(ePanicCode code)
35 | {
36 | __disable_irq();
37 | // Flush any serial message to help the poor bugger debug this;
38 | flash_codes_t pcd = flash_codes[code];
39 | LED_SetRGBColor(RGB_COLOR_RED);
40 | LED_On(LED_RGB);
41 | uint16_t c;
42 | int loops = 2;
43 | if (debug_output_)(debug_output_("!"));
44 | LED_Off(LED_RGB);
45 | while(loops) {
46 | // preamble
47 | KICK_WDT();
48 | for (c = 3; c; c--) {
49 | LED_SetRGBColor(pcd.led);
50 | LED_On(LED_RGB);
51 | Delay_Microsecond(MS2u(150));
52 | LED_Off(LED_RGB);
53 | Delay_Microsecond(MS2u(100));
54 | }
55 |
56 | Delay_Microsecond(MS2u(100));
57 | for (c = 3; c; c--) {
58 | LED_SetRGBColor(pcd.led);
59 | LED_On(LED_RGB);
60 | Delay_Microsecond(MS2u(300));
61 | LED_Off(LED_RGB);
62 | Delay_Microsecond(MS2u(100));
63 | }
64 | Delay_Microsecond(MS2u(100));
65 |
66 | for (c = 3; c; c--) {
67 | LED_SetRGBColor(pcd.led);
68 | LED_On(LED_RGB);
69 | Delay_Microsecond(MS2u(150));
70 | LED_Off(LED_RGB);
71 | Delay_Microsecond(MS2u(100));
72 | }
73 |
74 | // pause
75 | Delay_Microsecond(MS2u(900));
76 | // play code
77 | for (c = code; c; c--) {
78 | LED_SetRGBColor(pcd.led);
79 | LED_On(LED_RGB);
80 | Delay_Microsecond(MS2u(300));
81 | LED_Off(LED_RGB);
82 | Delay_Microsecond(MS2u(300));
83 | }
84 | // pause
85 | Delay_Microsecond(MS2u(800));
86 | #ifdef RELEASE_BUILD
87 | if (--loops == 0) NVIC_SystemReset();
88 | #endif
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/src/spi_bus.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "spi_bus.h"
4 | #include "debug.h"
5 | #include "hw_config.h"
6 |
7 | #ifndef SPI_BUS_ARBITER
8 | #define SPI_BUS_ARBITER 1
9 | #endif
10 |
11 | volatile int spi_bus_lock = 0;
12 |
13 | void reset_bus() { spi_bus_lock = 0; }
14 |
15 | int try_acquire_spi_bus(int owner) {
16 | #if SPI_BUS_ARBITER
17 | __sync_synchronize();
18 | return spi_bus_lock==owner || __sync_bool_compare_and_swap(&spi_bus_lock, 0, owner);
19 | #else
20 | return 1;
21 | #endif
22 | }
23 |
24 | void acquire_spi_bus(int owner) {
25 | #if SPI_BUS_ARBITER
26 | while (!try_acquire_spi_bus(owner));
27 | #endif
28 | }
29 |
30 | int try_release_spi_bus(int owner) {
31 | #if SPI_BUS_ARBITER
32 | __sync_synchronize();
33 | return spi_bus_lock==0 || __sync_bool_compare_and_swap(&spi_bus_lock, owner, 0);
34 | #else
35 | return 1;
36 | #endif
37 | }
38 |
39 | void release_spi_bus(int owner) {
40 | #if SPI_BUS_ARBITER
41 | while (!try_release_spi_bus(owner));
42 | #endif
43 | }
44 |
45 | int current_bus_owner() { return spi_bus_lock; }
46 |
--------------------------------------------------------------------------------
/SPARK_Firmware_Driver/src/usb_pwr.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_pwr.c
4 | * @author Satish Nair, Zachary Crockett and Mohit Bhoite
5 | * @version V1.0.0
6 | * @date 24-April-2013
7 | * @brief Connection/disconnection & power management
8 | ******************************************************************************
9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved.
10 |
11 | This program is free software; you can redistribute it and/or
12 | modify it under the terms of the GNU Lesser General Public
13 | License as published by the Free Software Foundation, either
14 | version 3 of the License, or (at your option) any later version.
15 |
16 | This program is distributed in the hope that it will be useful,
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 | Lesser General Public License for more details.
20 |
21 | You should have received a copy of the GNU Lesser General Public
22 | License along with this program; if not, see .
23 | ******************************************************************************
24 | */
25 |
26 | /* Includes ------------------------------------------------------------------*/
27 |
28 | #include "hw_config.h"
29 | #include "usb_lib.h"
30 | #include "usb_pwr.h"
31 |
32 |
33 | /* Private typedef -----------------------------------------------------------*/
34 | /* Private define ------------------------------------------------------------*/
35 | /* Private macro -------------------------------------------------------------*/
36 | /* Private variables ---------------------------------------------------------*/
37 | __IO uint32_t bDeviceState = UNCONNECTED; /* USB device status */
38 | __IO bool fSuspendEnabled = true; /* true when suspend is possible */
39 |
40 | struct
41 | {
42 | __IO RESUME_STATE eState;
43 | __IO uint8_t bESOFcnt;
44 | }ResumeS;
45 |
46 | /* Extern variables ----------------------------------------------------------*/
47 | /* Private function prototypes -----------------------------------------------*/
48 | /* Extern function prototypes ------------------------------------------------*/
49 | /* Private functions ---------------------------------------------------------*/
50 |
51 | /*******************************************************************************
52 | * Function Name : PowerOn
53 | * Description :
54 | * Input : None.
55 | * Output : None.
56 | * Return : USB_SUCCESS.
57 | *******************************************************************************/
58 | RESULT PowerOn(void)
59 | {
60 | uint16_t wRegVal;
61 |
62 | /*** cable plugged-in ? ***/
63 | USB_Cable_Config(ENABLE);
64 |
65 | /*** CNTR_PWDN = 0 ***/
66 | wRegVal = CNTR_FRES;
67 | _SetCNTR(wRegVal);
68 |
69 | /*** CNTR_FRES = 0 ***/
70 | wInterrupt_Mask = 0;
71 | _SetCNTR(wInterrupt_Mask);
72 | /*** Clear pending interrupts ***/
73 | _SetISTR(0);
74 | /*** Set interrupt mask ***/
75 | wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;
76 | _SetCNTR(wInterrupt_Mask);
77 |
78 | return USB_SUCCESS;
79 | }
80 |
81 | /*******************************************************************************
82 | * Function Name : PowerOff
83 | * Description : handles switch-off conditions
84 | * Input : None.
85 | * Output : None.
86 | * Return : USB_SUCCESS.
87 | *******************************************************************************/
88 | RESULT PowerOff()
89 | {
90 | /* disable all interrupts and force USB reset */
91 | _SetCNTR(CNTR_FRES);
92 | /* clear interrupt status register */
93 | _SetISTR(0);
94 | /* Disable the Pull-Up*/
95 | USB_Cable_Config(DISABLE);
96 | /* switch-off device */
97 | _SetCNTR(CNTR_FRES + CNTR_PDWN);
98 |
99 | /* sw variables reset */
100 | /* ... */
101 |
102 | return USB_SUCCESS;
103 | }
104 |
105 | /*******************************************************************************
106 | * Function Name : Suspend
107 | * Description : sets suspend mode operating conditions
108 | * Input : None.
109 | * Output : None.
110 | * Return : USB_SUCCESS.
111 | *******************************************************************************/
112 | void Suspend(void)
113 | {
114 | uint16_t wCNTR;
115 | /* suspend preparation */
116 | /* ... */
117 |
118 | /* macrocell enters suspend mode */
119 | wCNTR = _GetCNTR();
120 | wCNTR |= CNTR_FSUSP;
121 | _SetCNTR(wCNTR);
122 |
123 | /* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
124 | /* power reduction */
125 | /* ... on connected devices */
126 |
127 | /* force low-power mode in the macrocell */
128 | wCNTR = _GetCNTR();
129 | wCNTR |= CNTR_LPMODE;
130 | _SetCNTR(wCNTR);
131 |
132 | /* switch-off the clocks */
133 | /* ... */
134 | Enter_LowPowerMode();
135 |
136 | }
137 |
138 | /*******************************************************************************
139 | * Function Name : Resume_Init
140 | * Description : Handles wake-up restoring normal operations
141 | * Input : None.
142 | * Output : None.
143 | * Return : USB_SUCCESS.
144 | *******************************************************************************/
145 | void Resume_Init(void)
146 | {
147 | uint16_t wCNTR;
148 |
149 | /* ------------------ ONLY WITH BUS-POWERED DEVICES ---------------------- */
150 | /* restart the clocks */
151 | /* ... */
152 |
153 | /* CNTR_LPMODE = 0 */
154 | wCNTR = _GetCNTR();
155 | wCNTR &= (~CNTR_LPMODE);
156 | _SetCNTR(wCNTR);
157 |
158 | /* restore full power */
159 | /* ... on connected devices */
160 | Leave_LowPowerMode();
161 |
162 | /* reset FSUSP bit */
163 | _SetCNTR(IMR_MSK);
164 |
165 | /* reverse suspend preparation */
166 | /* ... */
167 |
168 | }
169 |
170 | /*******************************************************************************
171 | * Function Name : Resume
172 | * Description : This is the state machine handling resume operations and
173 | * timing sequence. The control is based on the Resume structure
174 | * variables and on the ESOF interrupt calling this subroutine
175 | * without changing machine state.
176 | * Input : a state machine value (RESUME_STATE)
177 | * RESUME_ESOF doesn't change ResumeS.eState allowing
178 | * decrementing of the ESOF counter in different states.
179 | * Output : None.
180 | * Return : None.
181 | *******************************************************************************/
182 | void Resume(RESUME_STATE eResumeSetVal)
183 | {
184 | uint16_t wCNTR;
185 |
186 | if (eResumeSetVal != RESUME_ESOF)
187 | ResumeS.eState = eResumeSetVal;
188 |
189 | switch (ResumeS.eState)
190 | {
191 | case RESUME_EXTERNAL:
192 | Resume_Init();
193 | ResumeS.eState = RESUME_OFF;
194 | break;
195 | case RESUME_INTERNAL:
196 | Resume_Init();
197 | ResumeS.eState = RESUME_START;
198 | break;
199 | case RESUME_LATER:
200 | ResumeS.bESOFcnt = 2;
201 | ResumeS.eState = RESUME_WAIT;
202 | break;
203 | case RESUME_WAIT:
204 | ResumeS.bESOFcnt--;
205 | if (ResumeS.bESOFcnt == 0)
206 | ResumeS.eState = RESUME_START;
207 | break;
208 | case RESUME_START:
209 | wCNTR = _GetCNTR();
210 | wCNTR |= CNTR_RESUME;
211 | _SetCNTR(wCNTR);
212 | ResumeS.eState = RESUME_ON;
213 | ResumeS.bESOFcnt = 10;
214 | break;
215 | case RESUME_ON:
216 | ResumeS.bESOFcnt--;
217 | if (ResumeS.bESOFcnt == 0)
218 | {
219 | wCNTR = _GetCNTR();
220 | wCNTR &= (~CNTR_RESUME);
221 | _SetCNTR(wCNTR);
222 | ResumeS.eState = RESUME_OFF;
223 | }
224 | break;
225 | case RESUME_OFF:
226 | case RESUME_ESOF:
227 | default:
228 | ResumeS.eState = RESUME_OFF;
229 | break;
230 | }
231 | }
232 |
233 |
--------------------------------------------------------------------------------
/SPARK_Services/inc/rgbled.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef RGBLED_H
3 | #define RGBLED_H
4 |
5 | typedef enum
6 | {
7 | LED1 = 0, LED2 = 1, LED3 = 2, LED4 = 3, LED3_LED4_LED2 = 231
8 | } Led_TypeDef;
9 |
10 |
11 | //Extended LED Types
12 | #define LED_RGB LED3_LED4_LED2
13 | #define LED_USER LED1
14 |
15 | //RGB Basic Colors
16 | #define RGB_COLOR_RED 0xFF0000
17 | #define RGB_COLOR_GREEN 0x00FF00
18 | #define RGB_COLOR_BLUE 0x0000FF
19 | #define RGB_COLOR_YELLOW 0xFFFF00
20 | #define RGB_COLOR_CYAN 0x00FFFF
21 | #define RGB_COLOR_MAGENTA 0xFF00FF
22 | #define RGB_COLOR_WHITE 0xFFFFFF
23 | #define RGB_COLOR_ORANGE 0xFF6000
24 |
25 |
26 | void LED_SetRGBColor(uint32_t RGB_Color);
27 | void LED_SetSignalingColor(uint32_t RGB_Color);
28 | void LED_Signaling_Start(void);
29 | void LED_Signaling_Stop(void);
30 | void LED_Signaling_Override(void) __attribute__ ((weak));
31 | void LED_SetBrightness(uint8_t brightness); /* 0 = off, 255 = full brightness */
32 | void LED_RGB_Get(uint8_t* rgb);
33 | void LED_Init(Led_TypeDef Led);
34 | void LED_On(Led_TypeDef Led);
35 | void LED_Off(Led_TypeDef Led);
36 | void LED_Toggle(Led_TypeDef Led);
37 | void LED_Fade(Led_TypeDef Led);
38 |
39 | uint8_t Get_LED_Brightness();
40 | // Hardware interface
41 |
42 | /**
43 | * Directly set the color of the RGB led.
44 | */
45 | void Set_RGB_LED(uint16_t* data);
46 | extern void Set_RGB_LED_Values(uint16_t r, uint16_t g, uint16_t b);
47 |
48 | extern void Get_RGB_LED_Values(uint16_t* rgb);
49 |
50 | extern void Set_User_LED(uint8_t state);
51 | extern void Toggle_User_LED();
52 |
53 | extern uint16_t Get_RGB_LED_Max_Value();
54 |
55 |
56 | #endif /* RGBLED_H */
57 |
58 |
--------------------------------------------------------------------------------
/SPARK_Services/readme.md:
--------------------------------------------------------------------------------
1 | This folder contains hardware-neutral services. In principle these could be part of a separate repo, but are kept here to avoid users needing to clone another repo.
--------------------------------------------------------------------------------
/SPARK_Services/src/build.mk:
--------------------------------------------------------------------------------
1 | # This file is a makefile included from the top level makefile which
2 | # defines the sources built for the target.
3 |
4 | # Define the prefix to this directory.
5 | # Note: The name must be unique within this build and should be
6 | # based on the root of the project
7 | TARGET_SPARK_SERVICES_PATH = SPARK_Services
8 | TARGET_SPARK_SERVICES_SRC_PATH = $(TARGET_SPARK_SERVICES_PATH)/src
9 |
10 | INCLUDE_DIRS += $(TARGET_SPARK_SERVICES_SRC_PATH)/inc
11 |
12 | CSRC += $(TARGET_SPARK_SERVICES_SRC_PATH)/rgbled.c
13 |
14 | # C++ source files included in this build.
15 | CPPSRC +=
16 |
17 | # ASM source files included in this build.
18 | ASRC +=
19 |
20 |
--------------------------------------------------------------------------------
/SPARK_Services/src/rgbled.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include "rgbled.h"
4 |
5 | uint8_t LED_RGB_OVERRIDE = 0;
6 | uint8_t LED_RGB_BRIGHTNESS = 96;
7 | uint32_t lastSignalColor = 0;
8 | uint32_t lastRGBColor = 0;
9 |
10 | /* Led Fading. */
11 | #define NUM_LED_FADE_STEPS 100 /* Called at 100Hz, fade over 1 second. */
12 | static uint8_t led_fade_step = NUM_LED_FADE_STEPS - 1;
13 | static uint8_t led_fade_direction = -1; /* 1 = rising, -1 = falling. */
14 |
15 | uint16_t ccr_scale(uint8_t color) {
16 | return (uint16_t)((((uint32_t)(color)) * LED_RGB_BRIGHTNESS * Get_RGB_LED_Max_Value()) >> 16);
17 | }
18 |
19 | void Set_CCR_Color(uint32_t RGB_Color, uint16_t* ccr) {
20 | ccr[0] = ccr_scale((RGB_Color>>16) & 0xFF);
21 | ccr[1] = ccr_scale((RGB_Color>>8) & 0xFF);
22 | ccr[2] = ccr_scale(RGB_Color & 0xFF);
23 | }
24 |
25 | void LED_SetRGBColor(uint32_t RGB_Color)
26 | {
27 | lastRGBColor = RGB_Color;
28 | }
29 |
30 | void LED_SetSignalingColor(uint32_t RGB_Color)
31 | {
32 | lastSignalColor = RGB_Color;
33 | }
34 |
35 | void LED_Signaling_Start(void)
36 | {
37 | LED_RGB_OVERRIDE = 1;
38 |
39 | LED_Off(LED_RGB);
40 | }
41 |
42 | void LED_Signaling_Stop(void)
43 | {
44 | LED_RGB_OVERRIDE = 0;
45 |
46 | LED_On(LED_RGB);
47 | }
48 |
49 | void LED_SetBrightness(uint8_t brightness)
50 | {
51 | LED_RGB_BRIGHTNESS = brightness;
52 | }
53 |
54 | uint8_t Get_LED_Brightness()
55 | {
56 | return LED_RGB_BRIGHTNESS;
57 | }
58 |
59 | /**
60 | * Sets the color on the RGB led. The color is adjusted for brightness.
61 | * @param color
62 | */
63 |
64 | void Set_RGB_LED_Color(uint32_t color) {
65 | uint16_t ccr[3];
66 | Set_CCR_Color(color, ccr);
67 | Set_RGB_LED(ccr);
68 | }
69 |
70 | uint16_t scale_fade(uint8_t step, uint16_t value) {
71 | return (uint16_t)((((uint32_t) value) * step) / (NUM_LED_FADE_STEPS - 1));
72 | }
73 |
74 | void Set_RGB_LED_Scale(uint8_t step, uint32_t color) {
75 | int i;
76 | uint16_t ccr[3];
77 | Set_CCR_Color(color, ccr);
78 | for (i=0; i<3; i++)
79 | ccr[i] = scale_fade(step, ccr[i]);
80 | Set_RGB_LED(ccr);
81 | }
82 |
83 |
84 | /**
85 | * @brief Turns selected LED On.
86 | * @param Led: Specifies the Led to be set on.
87 | * This parameter can be one of following parameters:
88 | * @arg LED1, LED2, LED_USER, LED_RGB
89 | * @retval None
90 | */
91 | void LED_On(Led_TypeDef Led)
92 | {
93 | switch(Led)
94 | {
95 | case LED_USER:
96 | Set_User_LED(1);
97 | break;
98 |
99 | case LED_RGB: //LED_SetRGBColor() should be called first for this Case
100 | Set_RGB_LED_Color(LED_RGB_OVERRIDE ? lastSignalColor : lastRGBColor);
101 | led_fade_step = NUM_LED_FADE_STEPS - 1;
102 | led_fade_direction = -1; /* next fade is falling */
103 | break;
104 | default:
105 | break;
106 | }
107 | }
108 |
109 | /**
110 | * @brief Turns selected LED Off.
111 | * @param Led: Specifies the Led to be set off.
112 | * This parameter can be one of following parameters:
113 | * @arg LED1, LED2, LED_USER, LED_RGB
114 | * @retval None
115 | */
116 | void LED_Off(Led_TypeDef Led)
117 | {
118 | switch(Led)
119 | {
120 | case LED_USER:
121 | Set_User_LED(0);
122 | break;
123 |
124 | case LED_RGB:
125 | Set_RGB_LED_Values(0,0,0);
126 | led_fade_step = 0;
127 | led_fade_direction = 1; /* next fade is rising. */
128 | break;
129 | default:
130 | break;
131 | }
132 | }
133 |
134 |
135 |
136 | /**
137 | * @brief Toggles the selected LED.
138 | * @param Led: Specifies the Led to be toggled.
139 | * This parameter can be one of following parameters:
140 | * @arg LED1, LED2, LED_USER, LED_RGB
141 | * @retval None
142 | */
143 | void LED_Toggle(Led_TypeDef Led)
144 | {
145 | uint32_t color;
146 | uint16_t rgb[3];
147 | switch(Led)
148 | {
149 | case LED_USER:
150 | Toggle_User_LED();
151 | break;
152 | default:
153 | break;
154 |
155 | case LED_RGB://LED_SetRGBColor() and LED_On() should be called first for this Case
156 |
157 | color = LED_RGB_OVERRIDE ? lastSignalColor : lastRGBColor;
158 | Get_RGB_LED_Values(rgb);
159 | if (rgb[0] | rgb[1] | rgb[2])
160 | Set_RGB_LED_Values(0,0,0);
161 | else
162 | Set_RGB_LED_Color(color);
163 | break;
164 | }
165 | }
166 |
167 |
168 | /**
169 | * @brief Fades selected LED.
170 | * @param Led: Specifies the Led to be set on.
171 | * This parameter can be one of following parameters:
172 | * @arg LED1, LED2, LED_RGB
173 | * @retval None
174 | */
175 | void LED_Fade(Led_TypeDef Led)
176 | {
177 | /* Update position in fade. */
178 | if (led_fade_step == 0)
179 | led_fade_direction = 1; /* Switch to fade growing. */
180 | else if (led_fade_step == NUM_LED_FADE_STEPS - 1)
181 | led_fade_direction = -1; /* Switch to fade falling. */
182 |
183 | led_fade_step += led_fade_direction;
184 |
185 | if(Led == LED_RGB)
186 | {
187 | Set_RGB_LED_Scale(led_fade_step, LED_RGB_OVERRIDE ? lastSignalColor : lastRGBColor);
188 | }
189 | }
190 |
191 |
192 | void LED_RGB_Get(uint8_t* rgb) {
193 | int i=0;
194 | uint16_t values[3];
195 | Get_RGB_LED_Values(values);
196 | for (i=0; i<3; i++) {
197 | rgb[i] = (uint8_t)(((uint32_t)(values[i])<<8)/(Get_RGB_LED_Max_Value()));
198 | }
199 | }
200 |
201 | void Set_RGB_LED(uint16_t* data) {
202 | Set_RGB_LED_Values(data[0], data[1], data[2]);
203 | }
204 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_bkp.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_bkp.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the BKP firmware
8 | * library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_BKP_H
28 | #define __STM32F10x_BKP_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup BKP
42 | * @{
43 | */
44 |
45 | /** @defgroup BKP_Exported_Types
46 | * @{
47 | */
48 |
49 | /**
50 | * @}
51 | */
52 |
53 | /** @defgroup BKP_Exported_Constants
54 | * @{
55 | */
56 |
57 | /** @defgroup Tamper_Pin_active_level
58 | * @{
59 | */
60 |
61 | #define BKP_TamperPinLevel_High ((uint16_t)0x0000)
62 | #define BKP_TamperPinLevel_Low ((uint16_t)0x0001)
63 | #define IS_BKP_TAMPER_PIN_LEVEL(LEVEL) (((LEVEL) == BKP_TamperPinLevel_High) || \
64 | ((LEVEL) == BKP_TamperPinLevel_Low))
65 | /**
66 | * @}
67 | */
68 |
69 | /** @defgroup RTC_output_source_to_output_on_the_Tamper_pin
70 | * @{
71 | */
72 |
73 | #define BKP_RTCOutputSource_None ((uint16_t)0x0000)
74 | #define BKP_RTCOutputSource_CalibClock ((uint16_t)0x0080)
75 | #define BKP_RTCOutputSource_Alarm ((uint16_t)0x0100)
76 | #define BKP_RTCOutputSource_Second ((uint16_t)0x0300)
77 | #define IS_BKP_RTC_OUTPUT_SOURCE(SOURCE) (((SOURCE) == BKP_RTCOutputSource_None) || \
78 | ((SOURCE) == BKP_RTCOutputSource_CalibClock) || \
79 | ((SOURCE) == BKP_RTCOutputSource_Alarm) || \
80 | ((SOURCE) == BKP_RTCOutputSource_Second))
81 | /**
82 | * @}
83 | */
84 |
85 | /** @defgroup Data_Backup_Register
86 | * @{
87 | */
88 |
89 | #define BKP_DR1 ((uint16_t)0x0004)
90 | #define BKP_DR2 ((uint16_t)0x0008)
91 | #define BKP_DR3 ((uint16_t)0x000C)
92 | #define BKP_DR4 ((uint16_t)0x0010)
93 | #define BKP_DR5 ((uint16_t)0x0014)
94 | #define BKP_DR6 ((uint16_t)0x0018)
95 | #define BKP_DR7 ((uint16_t)0x001C)
96 | #define BKP_DR8 ((uint16_t)0x0020)
97 | #define BKP_DR9 ((uint16_t)0x0024)
98 | #define BKP_DR10 ((uint16_t)0x0028)
99 | #define BKP_DR11 ((uint16_t)0x0040)
100 | #define BKP_DR12 ((uint16_t)0x0044)
101 | #define BKP_DR13 ((uint16_t)0x0048)
102 | #define BKP_DR14 ((uint16_t)0x004C)
103 | #define BKP_DR15 ((uint16_t)0x0050)
104 | #define BKP_DR16 ((uint16_t)0x0054)
105 | #define BKP_DR17 ((uint16_t)0x0058)
106 | #define BKP_DR18 ((uint16_t)0x005C)
107 | #define BKP_DR19 ((uint16_t)0x0060)
108 | #define BKP_DR20 ((uint16_t)0x0064)
109 | #define BKP_DR21 ((uint16_t)0x0068)
110 | #define BKP_DR22 ((uint16_t)0x006C)
111 | #define BKP_DR23 ((uint16_t)0x0070)
112 | #define BKP_DR24 ((uint16_t)0x0074)
113 | #define BKP_DR25 ((uint16_t)0x0078)
114 | #define BKP_DR26 ((uint16_t)0x007C)
115 | #define BKP_DR27 ((uint16_t)0x0080)
116 | #define BKP_DR28 ((uint16_t)0x0084)
117 | #define BKP_DR29 ((uint16_t)0x0088)
118 | #define BKP_DR30 ((uint16_t)0x008C)
119 | #define BKP_DR31 ((uint16_t)0x0090)
120 | #define BKP_DR32 ((uint16_t)0x0094)
121 | #define BKP_DR33 ((uint16_t)0x0098)
122 | #define BKP_DR34 ((uint16_t)0x009C)
123 | #define BKP_DR35 ((uint16_t)0x00A0)
124 | #define BKP_DR36 ((uint16_t)0x00A4)
125 | #define BKP_DR37 ((uint16_t)0x00A8)
126 | #define BKP_DR38 ((uint16_t)0x00AC)
127 | #define BKP_DR39 ((uint16_t)0x00B0)
128 | #define BKP_DR40 ((uint16_t)0x00B4)
129 | #define BKP_DR41 ((uint16_t)0x00B8)
130 | #define BKP_DR42 ((uint16_t)0x00BC)
131 |
132 | #define IS_BKP_DR(DR) (((DR) == BKP_DR1) || ((DR) == BKP_DR2) || ((DR) == BKP_DR3) || \
133 | ((DR) == BKP_DR4) || ((DR) == BKP_DR5) || ((DR) == BKP_DR6) || \
134 | ((DR) == BKP_DR7) || ((DR) == BKP_DR8) || ((DR) == BKP_DR9) || \
135 | ((DR) == BKP_DR10) || ((DR) == BKP_DR11) || ((DR) == BKP_DR12) || \
136 | ((DR) == BKP_DR13) || ((DR) == BKP_DR14) || ((DR) == BKP_DR15) || \
137 | ((DR) == BKP_DR16) || ((DR) == BKP_DR17) || ((DR) == BKP_DR18) || \
138 | ((DR) == BKP_DR19) || ((DR) == BKP_DR20) || ((DR) == BKP_DR21) || \
139 | ((DR) == BKP_DR22) || ((DR) == BKP_DR23) || ((DR) == BKP_DR24) || \
140 | ((DR) == BKP_DR25) || ((DR) == BKP_DR26) || ((DR) == BKP_DR27) || \
141 | ((DR) == BKP_DR28) || ((DR) == BKP_DR29) || ((DR) == BKP_DR30) || \
142 | ((DR) == BKP_DR31) || ((DR) == BKP_DR32) || ((DR) == BKP_DR33) || \
143 | ((DR) == BKP_DR34) || ((DR) == BKP_DR35) || ((DR) == BKP_DR36) || \
144 | ((DR) == BKP_DR37) || ((DR) == BKP_DR38) || ((DR) == BKP_DR39) || \
145 | ((DR) == BKP_DR40) || ((DR) == BKP_DR41) || ((DR) == BKP_DR42))
146 |
147 | #define IS_BKP_CALIBRATION_VALUE(VALUE) ((VALUE) <= 0x7F)
148 | /**
149 | * @}
150 | */
151 |
152 | /**
153 | * @}
154 | */
155 |
156 | /** @defgroup BKP_Exported_Macros
157 | * @{
158 | */
159 |
160 | /**
161 | * @}
162 | */
163 |
164 | /** @defgroup BKP_Exported_Functions
165 | * @{
166 | */
167 |
168 | void BKP_DeInit(void);
169 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel);
170 | void BKP_TamperPinCmd(FunctionalState NewState);
171 | void BKP_ITConfig(FunctionalState NewState);
172 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource);
173 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue);
174 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data);
175 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR);
176 | FlagStatus BKP_GetFlagStatus(void);
177 | void BKP_ClearFlag(void);
178 | ITStatus BKP_GetITStatus(void);
179 | void BKP_ClearITPendingBit(void);
180 |
181 | #ifdef __cplusplus
182 | }
183 | #endif
184 |
185 | #endif /* __STM32F10x_BKP_H */
186 | /**
187 | * @}
188 | */
189 |
190 | /**
191 | * @}
192 | */
193 |
194 | /**
195 | * @}
196 | */
197 |
198 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_cec.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_cec.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the CEC firmware
8 | * library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_CEC_H
28 | #define __STM32F10x_CEC_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup CEC
42 | * @{
43 | */
44 |
45 |
46 | /** @defgroup CEC_Exported_Types
47 | * @{
48 | */
49 |
50 | /**
51 | * @brief CEC Init structure definition
52 | */
53 | typedef struct
54 | {
55 | uint16_t CEC_BitTimingMode; /*!< Configures the CEC Bit Timing Error Mode.
56 | This parameter can be a value of @ref CEC_BitTiming_Mode */
57 | uint16_t CEC_BitPeriodMode; /*!< Configures the CEC Bit Period Error Mode.
58 | This parameter can be a value of @ref CEC_BitPeriod_Mode */
59 | }CEC_InitTypeDef;
60 |
61 | /**
62 | * @}
63 | */
64 |
65 | /** @defgroup CEC_Exported_Constants
66 | * @{
67 | */
68 |
69 | /** @defgroup CEC_BitTiming_Mode
70 | * @{
71 | */
72 | #define CEC_BitTimingStdMode ((uint16_t)0x00) /*!< Bit timing error Standard Mode */
73 | #define CEC_BitTimingErrFreeMode CEC_CFGR_BTEM /*!< Bit timing error Free Mode */
74 |
75 | #define IS_CEC_BIT_TIMING_ERROR_MODE(MODE) (((MODE) == CEC_BitTimingStdMode) || \
76 | ((MODE) == CEC_BitTimingErrFreeMode))
77 | /**
78 | * @}
79 | */
80 |
81 | /** @defgroup CEC_BitPeriod_Mode
82 | * @{
83 | */
84 | #define CEC_BitPeriodStdMode ((uint16_t)0x00) /*!< Bit period error Standard Mode */
85 | #define CEC_BitPeriodFlexibleMode CEC_CFGR_BPEM /*!< Bit period error Flexible Mode */
86 |
87 | #define IS_CEC_BIT_PERIOD_ERROR_MODE(MODE) (((MODE) == CEC_BitPeriodStdMode) || \
88 | ((MODE) == CEC_BitPeriodFlexibleMode))
89 | /**
90 | * @}
91 | */
92 |
93 |
94 | /** @defgroup CEC_interrupts_definition
95 | * @{
96 | */
97 | #define CEC_IT_TERR CEC_CSR_TERR
98 | #define CEC_IT_TBTRF CEC_CSR_TBTRF
99 | #define CEC_IT_RERR CEC_CSR_RERR
100 | #define CEC_IT_RBTF CEC_CSR_RBTF
101 | #define IS_CEC_GET_IT(IT) (((IT) == CEC_IT_TERR) || ((IT) == CEC_IT_TBTRF) || \
102 | ((IT) == CEC_IT_RERR) || ((IT) == CEC_IT_RBTF))
103 | /**
104 | * @}
105 | */
106 |
107 |
108 | /** @defgroup CEC_Own_Address
109 | * @{
110 | */
111 | #define IS_CEC_ADDRESS(ADDRESS) ((ADDRESS) < 0x10)
112 | /**
113 | * @}
114 | */
115 |
116 | /** @defgroup CEC_Prescaler
117 | * @{
118 | */
119 | #define IS_CEC_PRESCALER(PRESCALER) ((PRESCALER) <= 0x3FFF)
120 |
121 | /**
122 | * @}
123 | */
124 |
125 | /** @defgroup CEC_flags_definition
126 | * @{
127 | */
128 |
129 | /**
130 | * @brief ESR register flags
131 | */
132 | #define CEC_FLAG_BTE ((uint32_t)0x10010000)
133 | #define CEC_FLAG_BPE ((uint32_t)0x10020000)
134 | #define CEC_FLAG_RBTFE ((uint32_t)0x10040000)
135 | #define CEC_FLAG_SBE ((uint32_t)0x10080000)
136 | #define CEC_FLAG_ACKE ((uint32_t)0x10100000)
137 | #define CEC_FLAG_LINE ((uint32_t)0x10200000)
138 | #define CEC_FLAG_TBTFE ((uint32_t)0x10400000)
139 |
140 | /**
141 | * @brief CSR register flags
142 | */
143 | #define CEC_FLAG_TEOM ((uint32_t)0x00000002)
144 | #define CEC_FLAG_TERR ((uint32_t)0x00000004)
145 | #define CEC_FLAG_TBTRF ((uint32_t)0x00000008)
146 | #define CEC_FLAG_RSOM ((uint32_t)0x00000010)
147 | #define CEC_FLAG_REOM ((uint32_t)0x00000020)
148 | #define CEC_FLAG_RERR ((uint32_t)0x00000040)
149 | #define CEC_FLAG_RBTF ((uint32_t)0x00000080)
150 |
151 | #define IS_CEC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF03) == 0x00) && ((FLAG) != 0x00))
152 |
153 | #define IS_CEC_GET_FLAG(FLAG) (((FLAG) == CEC_FLAG_BTE) || ((FLAG) == CEC_FLAG_BPE) || \
154 | ((FLAG) == CEC_FLAG_RBTFE) || ((FLAG)== CEC_FLAG_SBE) || \
155 | ((FLAG) == CEC_FLAG_ACKE) || ((FLAG) == CEC_FLAG_LINE) || \
156 | ((FLAG) == CEC_FLAG_TBTFE) || ((FLAG) == CEC_FLAG_TEOM) || \
157 | ((FLAG) == CEC_FLAG_TERR) || ((FLAG) == CEC_FLAG_TBTRF) || \
158 | ((FLAG) == CEC_FLAG_RSOM) || ((FLAG) == CEC_FLAG_REOM) || \
159 | ((FLAG) == CEC_FLAG_RERR) || ((FLAG) == CEC_FLAG_RBTF))
160 |
161 | /**
162 | * @}
163 | */
164 |
165 | /**
166 | * @}
167 | */
168 |
169 | /** @defgroup CEC_Exported_Macros
170 | * @{
171 | */
172 |
173 | /**
174 | * @}
175 | */
176 |
177 | /** @defgroup CEC_Exported_Functions
178 | * @{
179 | */
180 | void CEC_DeInit(void);
181 | void CEC_Init(CEC_InitTypeDef* CEC_InitStruct);
182 | void CEC_Cmd(FunctionalState NewState);
183 | void CEC_ITConfig(FunctionalState NewState);
184 | void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress);
185 | void CEC_SetPrescaler(uint16_t CEC_Prescaler);
186 | void CEC_SendDataByte(uint8_t Data);
187 | uint8_t CEC_ReceiveDataByte(void);
188 | void CEC_StartOfMessage(void);
189 | void CEC_EndOfMessageCmd(FunctionalState NewState);
190 | FlagStatus CEC_GetFlagStatus(uint32_t CEC_FLAG);
191 | void CEC_ClearFlag(uint32_t CEC_FLAG);
192 | ITStatus CEC_GetITStatus(uint8_t CEC_IT);
193 | void CEC_ClearITPendingBit(uint16_t CEC_IT);
194 |
195 | #ifdef __cplusplus
196 | }
197 | #endif
198 |
199 | #endif /* __STM32F10x_CEC_H */
200 |
201 | /**
202 | * @}
203 | */
204 |
205 | /**
206 | * @}
207 | */
208 |
209 | /**
210 | * @}
211 | */
212 |
213 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_crc.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the CRC firmware
8 | * library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_CRC_H
28 | #define __STM32F10x_CRC_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup CRC
42 | * @{
43 | */
44 |
45 | /** @defgroup CRC_Exported_Types
46 | * @{
47 | */
48 |
49 | /**
50 | * @}
51 | */
52 |
53 | /** @defgroup CRC_Exported_Constants
54 | * @{
55 | */
56 |
57 | /**
58 | * @}
59 | */
60 |
61 | /** @defgroup CRC_Exported_Macros
62 | * @{
63 | */
64 |
65 | /**
66 | * @}
67 | */
68 |
69 | /** @defgroup CRC_Exported_Functions
70 | * @{
71 | */
72 |
73 | void CRC_ResetDR(void);
74 | uint32_t CRC_CalcCRC(uint32_t Data);
75 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength);
76 | uint32_t CRC_GetCRC(void);
77 | void CRC_SetIDRegister(uint8_t IDValue);
78 | uint8_t CRC_GetIDRegister(void);
79 |
80 | #ifdef __cplusplus
81 | }
82 | #endif
83 |
84 | #endif /* __STM32F10x_CRC_H */
85 | /**
86 | * @}
87 | */
88 |
89 | /**
90 | * @}
91 | */
92 |
93 | /**
94 | * @}
95 | */
96 |
97 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_dbgmcu.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the DBGMCU
8 | * firmware library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_DBGMCU_H
28 | #define __STM32F10x_DBGMCU_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup DBGMCU
42 | * @{
43 | */
44 |
45 | /** @defgroup DBGMCU_Exported_Types
46 | * @{
47 | */
48 |
49 | /**
50 | * @}
51 | */
52 |
53 | /** @defgroup DBGMCU_Exported_Constants
54 | * @{
55 | */
56 |
57 | #define DBGMCU_SLEEP ((uint32_t)0x00000001)
58 | #define DBGMCU_STOP ((uint32_t)0x00000002)
59 | #define DBGMCU_STANDBY ((uint32_t)0x00000004)
60 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100)
61 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200)
62 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400)
63 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800)
64 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000)
65 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000)
66 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000)
67 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000)
68 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000)
69 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000)
70 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000)
71 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000)
72 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000)
73 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000)
74 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000)
75 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000)
76 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000)
77 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000)
78 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000)
79 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000)
80 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000)
81 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000)
82 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000)
83 |
84 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00))
85 | /**
86 | * @}
87 | */
88 |
89 | /** @defgroup DBGMCU_Exported_Macros
90 | * @{
91 | */
92 |
93 | /**
94 | * @}
95 | */
96 |
97 | /** @defgroup DBGMCU_Exported_Functions
98 | * @{
99 | */
100 |
101 | uint32_t DBGMCU_GetREVID(void);
102 | uint32_t DBGMCU_GetDEVID(void);
103 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState);
104 |
105 | #ifdef __cplusplus
106 | }
107 | #endif
108 |
109 | #endif /* __STM32F10x_DBGMCU_H */
110 | /**
111 | * @}
112 | */
113 |
114 | /**
115 | * @}
116 | */
117 |
118 | /**
119 | * @}
120 | */
121 |
122 |
123 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_exti.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_exti.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the EXTI firmware
8 | * library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_EXTI_H
28 | #define __STM32F10x_EXTI_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup EXTI
42 | * @{
43 | */
44 |
45 | /** @defgroup EXTI_Exported_Types
46 | * @{
47 | */
48 |
49 | /**
50 | * @brief EXTI mode enumeration
51 | */
52 |
53 | typedef enum
54 | {
55 | EXTI_Mode_Interrupt = 0x00,
56 | EXTI_Mode_Event = 0x04
57 | }EXTIMode_TypeDef;
58 |
59 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event))
60 |
61 | /**
62 | * @brief EXTI Trigger enumeration
63 | */
64 |
65 | typedef enum
66 | {
67 | EXTI_Trigger_Rising = 0x08,
68 | EXTI_Trigger_Falling = 0x0C,
69 | EXTI_Trigger_Rising_Falling = 0x10
70 | }EXTITrigger_TypeDef;
71 |
72 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \
73 | ((TRIGGER) == EXTI_Trigger_Falling) || \
74 | ((TRIGGER) == EXTI_Trigger_Rising_Falling))
75 | /**
76 | * @brief EXTI Init Structure definition
77 | */
78 |
79 | typedef struct
80 | {
81 | uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled.
82 | This parameter can be any combination of @ref EXTI_Lines */
83 |
84 | EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines.
85 | This parameter can be a value of @ref EXTIMode_TypeDef */
86 |
87 | EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines.
88 | This parameter can be a value of @ref EXTITrigger_TypeDef */
89 |
90 | FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines.
91 | This parameter can be set either to ENABLE or DISABLE */
92 | }EXTI_InitTypeDef;
93 |
94 | /**
95 | * @}
96 | */
97 |
98 | /** @defgroup EXTI_Exported_Constants
99 | * @{
100 | */
101 |
102 | /** @defgroup EXTI_Lines
103 | * @{
104 | */
105 |
106 | #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */
107 | #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */
108 | #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */
109 | #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */
110 | #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */
111 | #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */
112 | #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */
113 | #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */
114 | #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */
115 | #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */
116 | #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */
117 | #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */
118 | #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */
119 | #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */
120 | #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */
121 | #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */
122 | #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */
123 | #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */
124 | #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB Device/USB OTG FS
125 | Wakeup from suspend event */
126 | #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */
127 |
128 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF00000) == 0x00) && ((LINE) != (uint16_t)0x00))
129 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \
130 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \
131 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \
132 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \
133 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \
134 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \
135 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \
136 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \
137 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \
138 | ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19))
139 |
140 |
141 | /**
142 | * @}
143 | */
144 |
145 | /**
146 | * @}
147 | */
148 |
149 | /** @defgroup EXTI_Exported_Macros
150 | * @{
151 | */
152 |
153 | /**
154 | * @}
155 | */
156 |
157 | /** @defgroup EXTI_Exported_Functions
158 | * @{
159 | */
160 |
161 | void EXTI_DeInit(void);
162 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct);
163 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct);
164 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line);
165 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line);
166 | void EXTI_ClearFlag(uint32_t EXTI_Line);
167 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line);
168 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line);
169 |
170 | #ifdef __cplusplus
171 | }
172 | #endif
173 |
174 | #endif /* __STM32F10x_EXTI_H */
175 | /**
176 | * @}
177 | */
178 |
179 | /**
180 | * @}
181 | */
182 |
183 | /**
184 | * @}
185 | */
186 |
187 |
188 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_iwdg.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_iwdg.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the IWDG
8 | * firmware library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_IWDG_H
28 | #define __STM32F10x_IWDG_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup IWDG
42 | * @{
43 | */
44 |
45 | /** @defgroup IWDG_Exported_Types
46 | * @{
47 | */
48 |
49 | /**
50 | * @}
51 | */
52 |
53 | /** @defgroup IWDG_Exported_Constants
54 | * @{
55 | */
56 |
57 | /** @defgroup IWDG_WriteAccess
58 | * @{
59 | */
60 |
61 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555)
62 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000)
63 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \
64 | ((ACCESS) == IWDG_WriteAccess_Disable))
65 | /**
66 | * @}
67 | */
68 |
69 | /** @defgroup IWDG_prescaler
70 | * @{
71 | */
72 |
73 | #define IWDG_Prescaler_4 ((uint8_t)0x00)
74 | #define IWDG_Prescaler_8 ((uint8_t)0x01)
75 | #define IWDG_Prescaler_16 ((uint8_t)0x02)
76 | #define IWDG_Prescaler_32 ((uint8_t)0x03)
77 | #define IWDG_Prescaler_64 ((uint8_t)0x04)
78 | #define IWDG_Prescaler_128 ((uint8_t)0x05)
79 | #define IWDG_Prescaler_256 ((uint8_t)0x06)
80 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \
81 | ((PRESCALER) == IWDG_Prescaler_8) || \
82 | ((PRESCALER) == IWDG_Prescaler_16) || \
83 | ((PRESCALER) == IWDG_Prescaler_32) || \
84 | ((PRESCALER) == IWDG_Prescaler_64) || \
85 | ((PRESCALER) == IWDG_Prescaler_128)|| \
86 | ((PRESCALER) == IWDG_Prescaler_256))
87 | /**
88 | * @}
89 | */
90 |
91 | /** @defgroup IWDG_Flag
92 | * @{
93 | */
94 |
95 | #define IWDG_FLAG_PVU ((uint16_t)0x0001)
96 | #define IWDG_FLAG_RVU ((uint16_t)0x0002)
97 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU))
98 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF)
99 | /**
100 | * @}
101 | */
102 |
103 | /**
104 | * @}
105 | */
106 |
107 | /** @defgroup IWDG_Exported_Macros
108 | * @{
109 | */
110 |
111 | /**
112 | * @}
113 | */
114 |
115 | /** @defgroup IWDG_Exported_Functions
116 | * @{
117 | */
118 |
119 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess);
120 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler);
121 | void IWDG_SetReload(uint16_t Reload);
122 | void IWDG_ReloadCounter(void);
123 | void IWDG_Enable(void);
124 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG);
125 |
126 | #ifdef __cplusplus
127 | }
128 | #endif
129 |
130 | #endif /* __STM32F10x_IWDG_H */
131 | /**
132 | * @}
133 | */
134 |
135 | /**
136 | * @}
137 | */
138 |
139 | /**
140 | * @}
141 | */
142 |
143 |
144 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_pwr.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_pwr.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the PWR firmware
8 | * library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_PWR_H
28 | #define __STM32F10x_PWR_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup PWR
42 | * @{
43 | */
44 |
45 | /** @defgroup PWR_Exported_Types
46 | * @{
47 | */
48 |
49 | /**
50 | * @}
51 | */
52 |
53 | /** @defgroup PWR_Exported_Constants
54 | * @{
55 | */
56 |
57 | /** @defgroup PVD_detection_level
58 | * @{
59 | */
60 |
61 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000)
62 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020)
63 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040)
64 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060)
65 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080)
66 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0)
67 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0)
68 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0)
69 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \
70 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \
71 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \
72 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9))
73 | /**
74 | * @}
75 | */
76 |
77 | /** @defgroup Regulator_state_is_STOP_mode
78 | * @{
79 | */
80 |
81 | #define PWR_Regulator_ON ((uint32_t)0x00000000)
82 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001)
83 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \
84 | ((REGULATOR) == PWR_Regulator_LowPower))
85 | /**
86 | * @}
87 | */
88 |
89 | /** @defgroup STOP_mode_entry
90 | * @{
91 | */
92 |
93 | #define PWR_STOPEntry_WFI ((uint8_t)0x01)
94 | #define PWR_STOPEntry_WFE ((uint8_t)0x02)
95 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE))
96 |
97 | /**
98 | * @}
99 | */
100 |
101 | /** @defgroup PWR_Flag
102 | * @{
103 | */
104 |
105 | #define PWR_FLAG_WU ((uint32_t)0x00000001)
106 | #define PWR_FLAG_SB ((uint32_t)0x00000002)
107 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004)
108 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \
109 | ((FLAG) == PWR_FLAG_PVDO))
110 |
111 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB))
112 | /**
113 | * @}
114 | */
115 |
116 | /**
117 | * @}
118 | */
119 |
120 | /** @defgroup PWR_Exported_Macros
121 | * @{
122 | */
123 |
124 | /**
125 | * @}
126 | */
127 |
128 | /** @defgroup PWR_Exported_Functions
129 | * @{
130 | */
131 |
132 | void PWR_DeInit(void);
133 | void PWR_BackupAccessCmd(FunctionalState NewState);
134 | void PWR_PVDCmd(FunctionalState NewState);
135 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel);
136 | void PWR_WakeUpPinCmd(FunctionalState NewState);
137 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry);
138 | void PWR_EnterSTANDBYMode(void);
139 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG);
140 | void PWR_ClearFlag(uint32_t PWR_FLAG);
141 |
142 | #ifdef __cplusplus
143 | }
144 | #endif
145 |
146 | #endif /* __STM32F10x_PWR_H */
147 | /**
148 | * @}
149 | */
150 |
151 | /**
152 | * @}
153 | */
154 |
155 | /**
156 | * @}
157 | */
158 |
159 |
160 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rtc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_rtc.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the RTC firmware
8 | * library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_RTC_H
28 | #define __STM32F10x_RTC_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup RTC
42 | * @{
43 | */
44 |
45 | /** @defgroup RTC_Exported_Types
46 | * @{
47 | */
48 |
49 | /**
50 | * @}
51 | */
52 |
53 | /** @defgroup RTC_Exported_Constants
54 | * @{
55 | */
56 |
57 | /** @defgroup RTC_interrupts_define
58 | * @{
59 | */
60 |
61 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */
62 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */
63 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */
64 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00))
65 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \
66 | ((IT) == RTC_IT_SEC))
67 | /**
68 | * @}
69 | */
70 |
71 | /** @defgroup RTC_interrupts_flags
72 | * @{
73 | */
74 |
75 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */
76 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */
77 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */
78 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */
79 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */
80 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00))
81 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \
82 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \
83 | ((FLAG) == RTC_FLAG_SEC))
84 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF)
85 |
86 | /**
87 | * @}
88 | */
89 |
90 | /**
91 | * @}
92 | */
93 |
94 | /** @defgroup RTC_Exported_Macros
95 | * @{
96 | */
97 |
98 | /**
99 | * @}
100 | */
101 |
102 | /** @defgroup RTC_Exported_Functions
103 | * @{
104 | */
105 |
106 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState);
107 | void RTC_EnterConfigMode(void);
108 | void RTC_ExitConfigMode(void);
109 | uint32_t RTC_GetCounter(void);
110 | void RTC_SetCounter(uint32_t CounterValue);
111 | void RTC_SetPrescaler(uint32_t PrescalerValue);
112 | void RTC_SetAlarm(uint32_t AlarmValue);
113 | uint32_t RTC_GetDivider(void);
114 | void RTC_WaitForLastTask(void);
115 | void RTC_WaitForSynchro(void);
116 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG);
117 | void RTC_ClearFlag(uint16_t RTC_FLAG);
118 | ITStatus RTC_GetITStatus(uint16_t RTC_IT);
119 | void RTC_ClearITPendingBit(uint16_t RTC_IT);
120 |
121 | #ifdef __cplusplus
122 | }
123 | #endif
124 |
125 | #endif /* __STM32F10x_RTC_H */
126 | /**
127 | * @}
128 | */
129 |
130 | /**
131 | * @}
132 | */
133 |
134 | /**
135 | * @}
136 | */
137 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_wwdg.h
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file contains all the functions prototypes for the WWDG firmware
8 | * library.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __STM32F10x_WWDG_H
28 | #define __STM32F10x_WWDG_H
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | /* Includes ------------------------------------------------------------------*/
35 | #include "stm32f10x.h"
36 |
37 | /** @addtogroup STM32F10x_StdPeriph_Driver
38 | * @{
39 | */
40 |
41 | /** @addtogroup WWDG
42 | * @{
43 | */
44 |
45 | /** @defgroup WWDG_Exported_Types
46 | * @{
47 | */
48 |
49 | /**
50 | * @}
51 | */
52 |
53 | /** @defgroup WWDG_Exported_Constants
54 | * @{
55 | */
56 |
57 | /** @defgroup WWDG_Prescaler
58 | * @{
59 | */
60 |
61 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000)
62 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080)
63 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100)
64 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180)
65 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \
66 | ((PRESCALER) == WWDG_Prescaler_2) || \
67 | ((PRESCALER) == WWDG_Prescaler_4) || \
68 | ((PRESCALER) == WWDG_Prescaler_8))
69 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F)
70 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F))
71 |
72 | /**
73 | * @}
74 | */
75 |
76 | /**
77 | * @}
78 | */
79 |
80 | /** @defgroup WWDG_Exported_Macros
81 | * @{
82 | */
83 | /**
84 | * @}
85 | */
86 |
87 | /** @defgroup WWDG_Exported_Functions
88 | * @{
89 | */
90 |
91 | void WWDG_DeInit(void);
92 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler);
93 | void WWDG_SetWindowValue(uint8_t WindowValue);
94 | void WWDG_EnableIT(void);
95 | void WWDG_SetCounter(uint8_t Counter);
96 | void WWDG_Enable(uint8_t Counter);
97 | FlagStatus WWDG_GetFlagStatus(void);
98 | void WWDG_ClearFlag(void);
99 |
100 | #ifdef __cplusplus
101 | }
102 | #endif
103 |
104 | #endif /* __STM32F10x_WWDG_H */
105 |
106 | /**
107 | * @}
108 | */
109 |
110 | /**
111 | * @}
112 | */
113 |
114 | /**
115 | * @}
116 | */
117 |
118 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/build.mk:
--------------------------------------------------------------------------------
1 | # This file is a makefile included from the top level makefile which
2 | # defines the sources built for the target.
3 |
4 | # Define the prefix to this directory.
5 | # Note: The name must be unique within this build and should be
6 | # based on the root of the project
7 | TARGET_STDPERIPH_PATH = STM32F10x_StdPeriph_Driver
8 | TARGET_STDPERIPH_SRC_PATH = $(TARGET_STDPERIPH_PATH)/src
9 |
10 | # Add tropicssl include to all objects built for this target
11 | INCLUDE_DIRS += $(TARGET_STDPERIPH_PATH)/inc
12 |
13 | # C source files included in this build.
14 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/misc.c
15 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_adc.c
16 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_bkp.c
17 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_crc.c
18 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_dma.c
19 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_exti.c
20 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_flash.c
21 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_gpio.c
22 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_i2c.c
23 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_iwdg.c
24 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_pwr.c
25 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_rcc.c
26 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_rtc.c
27 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_spi.c
28 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_tim.c
29 | CSRC += $(TARGET_STDPERIPH_SRC_PATH)/stm32f10x_usart.c
30 |
31 | # C++ source files included in this build.
32 | CPPSRC +=
33 |
34 | # ASM source files included in this build.
35 | ASRC +=
36 |
37 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/misc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file misc.c
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file provides all the miscellaneous firmware functions (add-on
8 | * to CMSIS functions).
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 | /* Includes ------------------------------------------------------------------*/
27 | #include "misc.h"
28 |
29 | /** @addtogroup STM32F10x_StdPeriph_Driver
30 | * @{
31 | */
32 |
33 | /** @defgroup MISC
34 | * @brief MISC driver modules
35 | * @{
36 | */
37 |
38 | /** @defgroup MISC_Private_TypesDefinitions
39 | * @{
40 | */
41 |
42 | /**
43 | * @}
44 | */
45 |
46 | /** @defgroup MISC_Private_Defines
47 | * @{
48 | */
49 |
50 | #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
51 | /**
52 | * @}
53 | */
54 |
55 | /** @defgroup MISC_Private_Macros
56 | * @{
57 | */
58 |
59 | /**
60 | * @}
61 | */
62 |
63 | /** @defgroup MISC_Private_Variables
64 | * @{
65 | */
66 |
67 | /**
68 | * @}
69 | */
70 |
71 | /** @defgroup MISC_Private_FunctionPrototypes
72 | * @{
73 | */
74 |
75 | /**
76 | * @}
77 | */
78 |
79 | /** @defgroup MISC_Private_Functions
80 | * @{
81 | */
82 |
83 | /**
84 | * @brief Configures the priority grouping: pre-emption priority and subpriority.
85 | * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
86 | * This parameter can be one of the following values:
87 | * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
88 | * 4 bits for subpriority
89 | * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
90 | * 3 bits for subpriority
91 | * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
92 | * 2 bits for subpriority
93 | * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
94 | * 1 bits for subpriority
95 | * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
96 | * 0 bits for subpriority
97 | * @retval None
98 | */
99 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
100 | {
101 | /* Check the parameters */
102 | assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
103 |
104 | /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
105 | SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
106 | }
107 |
108 | /**
109 | * @brief Initializes the NVIC peripheral according to the specified
110 | * parameters in the NVIC_InitStruct.
111 | * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
112 | * the configuration information for the specified NVIC peripheral.
113 | * @retval None
114 | */
115 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
116 | {
117 | uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
118 |
119 | /* Check the parameters */
120 | assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
121 | assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
122 | assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
123 |
124 | if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
125 | {
126 | /* Compute the Corresponding IRQ Priority --------------------------------*/
127 | tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
128 | tmppre = (0x4 - tmppriority);
129 | tmpsub = tmpsub >> tmppriority;
130 |
131 | tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
132 | tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
133 | tmppriority = tmppriority << 0x04;
134 |
135 | NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
136 |
137 | /* Enable the Selected IRQ Channels --------------------------------------*/
138 | NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
139 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
140 | }
141 | else
142 | {
143 | /* Disable the Selected IRQ Channels -------------------------------------*/
144 | NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
145 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
146 | }
147 | }
148 |
149 | /**
150 | * @brief Sets the vector table location and Offset.
151 | * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
152 | * This parameter can be one of the following values:
153 | * @arg NVIC_VectTab_RAM
154 | * @arg NVIC_VectTab_FLASH
155 | * @param Offset: Vector Table base offset field. This value must be a multiple
156 | * of 0x200.
157 | * @retval None
158 | */
159 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
160 | {
161 | /* Check the parameters */
162 | assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
163 | assert_param(IS_NVIC_OFFSET(Offset));
164 |
165 | SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
166 | }
167 |
168 | /**
169 | * @brief Selects the condition for the system to enter low power mode.
170 | * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
171 | * This parameter can be one of the following values:
172 | * @arg NVIC_LP_SEVONPEND
173 | * @arg NVIC_LP_SLEEPDEEP
174 | * @arg NVIC_LP_SLEEPONEXIT
175 | * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
176 | * @retval None
177 | */
178 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
179 | {
180 | /* Check the parameters */
181 | assert_param(IS_NVIC_LP(LowPowerMode));
182 | assert_param(IS_FUNCTIONAL_STATE(NewState));
183 |
184 | if (NewState != DISABLE)
185 | {
186 | SCB->SCR |= LowPowerMode;
187 | }
188 | else
189 | {
190 | SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
191 | }
192 | }
193 |
194 | /**
195 | * @brief Configures the SysTick clock source.
196 | * @param SysTick_CLKSource: specifies the SysTick clock source.
197 | * This parameter can be one of the following values:
198 | * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
199 | * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
200 | * @retval None
201 | */
202 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
203 | {
204 | /* Check the parameters */
205 | assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
206 | if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
207 | {
208 | SysTick->CTRL |= SysTick_CLKSource_HCLK;
209 | }
210 | else
211 | {
212 | SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
213 | }
214 | }
215 |
216 | /**
217 | * @}
218 | */
219 |
220 | /**
221 | * @}
222 | */
223 |
224 | /**
225 | * @}
226 | */
227 |
228 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_bkp.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_bkp.c
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file provides all the BKP firmware functions.
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "stm32f10x_bkp.h"
26 | #include "stm32f10x_rcc.h"
27 |
28 | /** @addtogroup STM32F10x_StdPeriph_Driver
29 | * @{
30 | */
31 |
32 | /** @defgroup BKP
33 | * @brief BKP driver modules
34 | * @{
35 | */
36 |
37 | /** @defgroup BKP_Private_TypesDefinitions
38 | * @{
39 | */
40 |
41 | /**
42 | * @}
43 | */
44 |
45 | /** @defgroup BKP_Private_Defines
46 | * @{
47 | */
48 |
49 | /* ------------ BKP registers bit address in the alias region --------------- */
50 | #define BKP_OFFSET (BKP_BASE - PERIPH_BASE)
51 |
52 | /* --- CR Register ----*/
53 |
54 | /* Alias word address of TPAL bit */
55 | #define CR_OFFSET (BKP_OFFSET + 0x30)
56 | #define TPAL_BitNumber 0x01
57 | #define CR_TPAL_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPAL_BitNumber * 4))
58 |
59 | /* Alias word address of TPE bit */
60 | #define TPE_BitNumber 0x00
61 | #define CR_TPE_BB (PERIPH_BB_BASE + (CR_OFFSET * 32) + (TPE_BitNumber * 4))
62 |
63 | /* --- CSR Register ---*/
64 |
65 | /* Alias word address of TPIE bit */
66 | #define CSR_OFFSET (BKP_OFFSET + 0x34)
67 | #define TPIE_BitNumber 0x02
68 | #define CSR_TPIE_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TPIE_BitNumber * 4))
69 |
70 | /* Alias word address of TIF bit */
71 | #define TIF_BitNumber 0x09
72 | #define CSR_TIF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TIF_BitNumber * 4))
73 |
74 | /* Alias word address of TEF bit */
75 | #define TEF_BitNumber 0x08
76 | #define CSR_TEF_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEF_BitNumber * 4))
77 |
78 | /* ---------------------- BKP registers bit mask ------------------------ */
79 |
80 | /* RTCCR register bit mask */
81 | #define RTCCR_CAL_MASK ((uint16_t)0xFF80)
82 | #define RTCCR_MASK ((uint16_t)0xFC7F)
83 |
84 | /**
85 | * @}
86 | */
87 |
88 |
89 | /** @defgroup BKP_Private_Macros
90 | * @{
91 | */
92 |
93 | /**
94 | * @}
95 | */
96 |
97 | /** @defgroup BKP_Private_Variables
98 | * @{
99 | */
100 |
101 | /**
102 | * @}
103 | */
104 |
105 | /** @defgroup BKP_Private_FunctionPrototypes
106 | * @{
107 | */
108 |
109 | /**
110 | * @}
111 | */
112 |
113 | /** @defgroup BKP_Private_Functions
114 | * @{
115 | */
116 |
117 | /**
118 | * @brief Deinitializes the BKP peripheral registers to their default reset values.
119 | * @param None
120 | * @retval None
121 | */
122 | void BKP_DeInit(void)
123 | {
124 | RCC_BackupResetCmd(ENABLE);
125 | RCC_BackupResetCmd(DISABLE);
126 | }
127 |
128 | /**
129 | * @brief Configures the Tamper Pin active level.
130 | * @param BKP_TamperPinLevel: specifies the Tamper Pin active level.
131 | * This parameter can be one of the following values:
132 | * @arg BKP_TamperPinLevel_High: Tamper pin active on high level
133 | * @arg BKP_TamperPinLevel_Low: Tamper pin active on low level
134 | * @retval None
135 | */
136 | void BKP_TamperPinLevelConfig(uint16_t BKP_TamperPinLevel)
137 | {
138 | /* Check the parameters */
139 | assert_param(IS_BKP_TAMPER_PIN_LEVEL(BKP_TamperPinLevel));
140 | *(__IO uint32_t *) CR_TPAL_BB = BKP_TamperPinLevel;
141 | }
142 |
143 | /**
144 | * @brief Enables or disables the Tamper Pin activation.
145 | * @param NewState: new state of the Tamper Pin activation.
146 | * This parameter can be: ENABLE or DISABLE.
147 | * @retval None
148 | */
149 | void BKP_TamperPinCmd(FunctionalState NewState)
150 | {
151 | /* Check the parameters */
152 | assert_param(IS_FUNCTIONAL_STATE(NewState));
153 | *(__IO uint32_t *) CR_TPE_BB = (uint32_t)NewState;
154 | }
155 |
156 | /**
157 | * @brief Enables or disables the Tamper Pin Interrupt.
158 | * @param NewState: new state of the Tamper Pin Interrupt.
159 | * This parameter can be: ENABLE or DISABLE.
160 | * @retval None
161 | */
162 | void BKP_ITConfig(FunctionalState NewState)
163 | {
164 | /* Check the parameters */
165 | assert_param(IS_FUNCTIONAL_STATE(NewState));
166 | *(__IO uint32_t *) CSR_TPIE_BB = (uint32_t)NewState;
167 | }
168 |
169 | /**
170 | * @brief Select the RTC output source to output on the Tamper pin.
171 | * @param BKP_RTCOutputSource: specifies the RTC output source.
172 | * This parameter can be one of the following values:
173 | * @arg BKP_RTCOutputSource_None: no RTC output on the Tamper pin.
174 | * @arg BKP_RTCOutputSource_CalibClock: output the RTC clock with frequency
175 | * divided by 64 on the Tamper pin.
176 | * @arg BKP_RTCOutputSource_Alarm: output the RTC Alarm pulse signal on
177 | * the Tamper pin.
178 | * @arg BKP_RTCOutputSource_Second: output the RTC Second pulse signal on
179 | * the Tamper pin.
180 | * @retval None
181 | */
182 | void BKP_RTCOutputConfig(uint16_t BKP_RTCOutputSource)
183 | {
184 | uint16_t tmpreg = 0;
185 | /* Check the parameters */
186 | assert_param(IS_BKP_RTC_OUTPUT_SOURCE(BKP_RTCOutputSource));
187 | tmpreg = BKP->RTCCR;
188 | /* Clear CCO, ASOE and ASOS bits */
189 | tmpreg &= RTCCR_MASK;
190 |
191 | /* Set CCO, ASOE and ASOS bits according to BKP_RTCOutputSource value */
192 | tmpreg |= BKP_RTCOutputSource;
193 | /* Store the new value */
194 | BKP->RTCCR = tmpreg;
195 | }
196 |
197 | /**
198 | * @brief Sets RTC Clock Calibration value.
199 | * @param CalibrationValue: specifies the RTC Clock Calibration value.
200 | * This parameter must be a number between 0 and 0x7F.
201 | * @retval None
202 | */
203 | void BKP_SetRTCCalibrationValue(uint8_t CalibrationValue)
204 | {
205 | uint16_t tmpreg = 0;
206 | /* Check the parameters */
207 | assert_param(IS_BKP_CALIBRATION_VALUE(CalibrationValue));
208 | tmpreg = BKP->RTCCR;
209 | /* Clear CAL[6:0] bits */
210 | tmpreg &= RTCCR_CAL_MASK;
211 | /* Set CAL[6:0] bits according to CalibrationValue value */
212 | tmpreg |= CalibrationValue;
213 | /* Store the new value */
214 | BKP->RTCCR = tmpreg;
215 | }
216 |
217 | /**
218 | * @brief Writes user data to the specified Data Backup Register.
219 | * @param BKP_DR: specifies the Data Backup Register.
220 | * This parameter can be BKP_DRx where x:[1, 42]
221 | * @param Data: data to write
222 | * @retval None
223 | */
224 | void BKP_WriteBackupRegister(uint16_t BKP_DR, uint16_t Data)
225 | {
226 | __IO uint32_t tmp = 0;
227 |
228 | /* Check the parameters */
229 | assert_param(IS_BKP_DR(BKP_DR));
230 |
231 | tmp = (uint32_t)BKP_BASE;
232 | tmp += BKP_DR;
233 |
234 | *(__IO uint32_t *) tmp = Data;
235 | }
236 |
237 | /**
238 | * @brief Reads data from the specified Data Backup Register.
239 | * @param BKP_DR: specifies the Data Backup Register.
240 | * This parameter can be BKP_DRx where x:[1, 42]
241 | * @retval The content of the specified Data Backup Register
242 | */
243 | uint16_t BKP_ReadBackupRegister(uint16_t BKP_DR)
244 | {
245 | __IO uint32_t tmp = 0;
246 |
247 | /* Check the parameters */
248 | assert_param(IS_BKP_DR(BKP_DR));
249 |
250 | tmp = (uint32_t)BKP_BASE;
251 | tmp += BKP_DR;
252 |
253 | return (*(__IO uint16_t *) tmp);
254 | }
255 |
256 | /**
257 | * @brief Checks whether the Tamper Pin Event flag is set or not.
258 | * @param None
259 | * @retval The new state of the Tamper Pin Event flag (SET or RESET).
260 | */
261 | FlagStatus BKP_GetFlagStatus(void)
262 | {
263 | return (FlagStatus)(*(__IO uint32_t *) CSR_TEF_BB);
264 | }
265 |
266 | /**
267 | * @brief Clears Tamper Pin Event pending flag.
268 | * @param None
269 | * @retval None
270 | */
271 | void BKP_ClearFlag(void)
272 | {
273 | /* Set CTE bit to clear Tamper Pin Event flag */
274 | BKP->CSR |= BKP_CSR_CTE;
275 | }
276 |
277 | /**
278 | * @brief Checks whether the Tamper Pin Interrupt has occurred or not.
279 | * @param None
280 | * @retval The new state of the Tamper Pin Interrupt (SET or RESET).
281 | */
282 | ITStatus BKP_GetITStatus(void)
283 | {
284 | return (ITStatus)(*(__IO uint32_t *) CSR_TIF_BB);
285 | }
286 |
287 | /**
288 | * @brief Clears Tamper Pin Interrupt pending bit.
289 | * @param None
290 | * @retval None
291 | */
292 | void BKP_ClearITPendingBit(void)
293 | {
294 | /* Set CTI bit to clear Tamper Pin Interrupt pending bit */
295 | BKP->CSR |= BKP_CSR_CTI;
296 | }
297 |
298 | /**
299 | * @}
300 | */
301 |
302 | /**
303 | * @}
304 | */
305 |
306 | /**
307 | * @}
308 | */
309 |
310 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_crc.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_crc.c
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file provides all the CRC firmware functions.
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "stm32f10x_crc.h"
26 |
27 | /** @addtogroup STM32F10x_StdPeriph_Driver
28 | * @{
29 | */
30 |
31 | /** @defgroup CRC
32 | * @brief CRC driver modules
33 | * @{
34 | */
35 |
36 | /** @defgroup CRC_Private_TypesDefinitions
37 | * @{
38 | */
39 |
40 | /**
41 | * @}
42 | */
43 |
44 | /** @defgroup CRC_Private_Defines
45 | * @{
46 | */
47 |
48 | /**
49 | * @}
50 | */
51 |
52 | /** @defgroup CRC_Private_Macros
53 | * @{
54 | */
55 |
56 | /**
57 | * @}
58 | */
59 |
60 | /** @defgroup CRC_Private_Variables
61 | * @{
62 | */
63 |
64 | /**
65 | * @}
66 | */
67 |
68 | /** @defgroup CRC_Private_FunctionPrototypes
69 | * @{
70 | */
71 |
72 | /**
73 | * @}
74 | */
75 |
76 | /** @defgroup CRC_Private_Functions
77 | * @{
78 | */
79 |
80 | /**
81 | * @brief Resets the CRC Data register (DR).
82 | * @param None
83 | * @retval None
84 | */
85 | void CRC_ResetDR(void)
86 | {
87 | /* Reset CRC generator */
88 | CRC->CR = CRC_CR_RESET;
89 | }
90 |
91 | /**
92 | * @brief Computes the 32-bit CRC of a given data word(32-bit).
93 | * @param Data: data word(32-bit) to compute its CRC
94 | * @retval 32-bit CRC
95 | */
96 | uint32_t CRC_CalcCRC(uint32_t Data)
97 | {
98 | CRC->DR = Data;
99 |
100 | return (CRC->DR);
101 | }
102 |
103 | /**
104 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
105 | * @param pBuffer: pointer to the buffer containing the data to be computed
106 | * @param BufferLength: length of the buffer to be computed
107 | * @retval 32-bit CRC
108 | */
109 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
110 | {
111 | uint32_t index = 0;
112 |
113 | for(index = 0; index < BufferLength; index++)
114 | {
115 | CRC->DR = pBuffer[index];
116 | }
117 | return (CRC->DR);
118 | }
119 |
120 | /**
121 | * @brief Returns the current CRC value.
122 | * @param None
123 | * @retval 32-bit CRC
124 | */
125 | uint32_t CRC_GetCRC(void)
126 | {
127 | return (CRC->DR);
128 | }
129 |
130 | /**
131 | * @brief Stores a 8-bit data in the Independent Data(ID) register.
132 | * @param IDValue: 8-bit value to be stored in the ID register
133 | * @retval None
134 | */
135 | void CRC_SetIDRegister(uint8_t IDValue)
136 | {
137 | CRC->IDR = IDValue;
138 | }
139 |
140 | /**
141 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register
142 | * @param None
143 | * @retval 8-bit value of the ID register
144 | */
145 | uint8_t CRC_GetIDRegister(void)
146 | {
147 | return (CRC->IDR);
148 | }
149 |
150 | /**
151 | * @}
152 | */
153 |
154 | /**
155 | * @}
156 | */
157 |
158 | /**
159 | * @}
160 | */
161 |
162 |
163 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_dbgmcu.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_dbgmcu.c
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file provides all the DBGMCU firmware functions.
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "stm32f10x_dbgmcu.h"
26 |
27 | /** @addtogroup STM32F10x_StdPeriph_Driver
28 | * @{
29 | */
30 |
31 | /** @defgroup DBGMCU
32 | * @brief DBGMCU driver modules
33 | * @{
34 | */
35 |
36 | /** @defgroup DBGMCU_Private_TypesDefinitions
37 | * @{
38 | */
39 |
40 | /**
41 | * @}
42 | */
43 |
44 | /** @defgroup DBGMCU_Private_Defines
45 | * @{
46 | */
47 |
48 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
49 | /**
50 | * @}
51 | */
52 |
53 | /** @defgroup DBGMCU_Private_Macros
54 | * @{
55 | */
56 |
57 | /**
58 | * @}
59 | */
60 |
61 | /** @defgroup DBGMCU_Private_Variables
62 | * @{
63 | */
64 |
65 | /**
66 | * @}
67 | */
68 |
69 | /** @defgroup DBGMCU_Private_FunctionPrototypes
70 | * @{
71 | */
72 |
73 | /**
74 | * @}
75 | */
76 |
77 | /** @defgroup DBGMCU_Private_Functions
78 | * @{
79 | */
80 |
81 | /**
82 | * @brief Returns the device revision identifier.
83 | * @param None
84 | * @retval Device revision identifier
85 | */
86 | uint32_t DBGMCU_GetREVID(void)
87 | {
88 | return(DBGMCU->IDCODE >> 16);
89 | }
90 |
91 | /**
92 | * @brief Returns the device identifier.
93 | * @param None
94 | * @retval Device identifier
95 | */
96 | uint32_t DBGMCU_GetDEVID(void)
97 | {
98 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK);
99 | }
100 |
101 | /**
102 | * @brief Configures the specified peripheral and low power mode behavior
103 | * when the MCU under Debug mode.
104 | * @param DBGMCU_Periph: specifies the peripheral and low power mode.
105 | * This parameter can be any combination of the following values:
106 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode
107 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode
108 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode
109 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted
110 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted
111 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted
112 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted
113 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted
114 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted
115 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted
116 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted
117 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted
118 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted
119 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted
120 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted
121 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted
122 | * @arg DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted
123 | * @arg DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted
124 | * @arg DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted
125 | * @arg DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted
126 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted
127 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted
128 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted
129 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted
130 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted
131 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted
132 | * @param NewState: new state of the specified peripheral in Debug mode.
133 | * This parameter can be: ENABLE or DISABLE.
134 | * @retval None
135 | */
136 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState)
137 | {
138 | /* Check the parameters */
139 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph));
140 | assert_param(IS_FUNCTIONAL_STATE(NewState));
141 |
142 | if (NewState != DISABLE)
143 | {
144 | DBGMCU->CR |= DBGMCU_Periph;
145 | }
146 | else
147 | {
148 | DBGMCU->CR &= ~DBGMCU_Periph;
149 | }
150 | }
151 |
152 | /**
153 | * @}
154 | */
155 |
156 | /**
157 | * @}
158 | */
159 |
160 | /**
161 | * @}
162 | */
163 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_exti.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_exti.c
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file provides all the EXTI firmware functions.
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "stm32f10x_exti.h"
26 |
27 | /** @addtogroup STM32F10x_StdPeriph_Driver
28 | * @{
29 | */
30 |
31 | /** @defgroup EXTI
32 | * @brief EXTI driver modules
33 | * @{
34 | */
35 |
36 | /** @defgroup EXTI_Private_TypesDefinitions
37 | * @{
38 | */
39 |
40 | /**
41 | * @}
42 | */
43 |
44 | /** @defgroup EXTI_Private_Defines
45 | * @{
46 | */
47 |
48 | #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
49 |
50 | /**
51 | * @}
52 | */
53 |
54 | /** @defgroup EXTI_Private_Macros
55 | * @{
56 | */
57 |
58 | /**
59 | * @}
60 | */
61 |
62 | /** @defgroup EXTI_Private_Variables
63 | * @{
64 | */
65 |
66 | /**
67 | * @}
68 | */
69 |
70 | /** @defgroup EXTI_Private_FunctionPrototypes
71 | * @{
72 | */
73 |
74 | /**
75 | * @}
76 | */
77 |
78 | /** @defgroup EXTI_Private_Functions
79 | * @{
80 | */
81 |
82 | /**
83 | * @brief Deinitializes the EXTI peripheral registers to their default reset values.
84 | * @param None
85 | * @retval None
86 | */
87 | void EXTI_DeInit(void)
88 | {
89 | EXTI->IMR = 0x00000000;
90 | EXTI->EMR = 0x00000000;
91 | EXTI->RTSR = 0x00000000;
92 | EXTI->FTSR = 0x00000000;
93 | EXTI->PR = 0x000FFFFF;
94 | }
95 |
96 | /**
97 | * @brief Initializes the EXTI peripheral according to the specified
98 | * parameters in the EXTI_InitStruct.
99 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
100 | * that contains the configuration information for the EXTI peripheral.
101 | * @retval None
102 | */
103 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
104 | {
105 | uint32_t tmp = 0;
106 |
107 | /* Check the parameters */
108 | assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
109 | assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
110 | assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
111 | assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
112 |
113 | tmp = (uint32_t)EXTI_BASE;
114 |
115 | if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
116 | {
117 | /* Clear EXTI line configuration */
118 | EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
119 | EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
120 |
121 | tmp += EXTI_InitStruct->EXTI_Mode;
122 |
123 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
124 |
125 | /* Clear Rising Falling edge configuration */
126 | EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
127 | EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
128 |
129 | /* Select the trigger for the selected external interrupts */
130 | if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
131 | {
132 | /* Rising Falling edge */
133 | EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
134 | EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
135 | }
136 | else
137 | {
138 | tmp = (uint32_t)EXTI_BASE;
139 | tmp += EXTI_InitStruct->EXTI_Trigger;
140 |
141 | *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
142 | }
143 | }
144 | else
145 | {
146 | tmp += EXTI_InitStruct->EXTI_Mode;
147 |
148 | /* Disable the selected external lines */
149 | *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
150 | }
151 | }
152 |
153 | /**
154 | * @brief Fills each EXTI_InitStruct member with its reset value.
155 | * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
156 | * be initialized.
157 | * @retval None
158 | */
159 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
160 | {
161 | EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
162 | EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
163 | EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
164 | EXTI_InitStruct->EXTI_LineCmd = DISABLE;
165 | }
166 |
167 | /**
168 | * @brief Generates a Software interrupt.
169 | * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled.
170 | * This parameter can be any combination of EXTI_Linex where x can be (0..19).
171 | * @retval None
172 | */
173 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
174 | {
175 | /* Check the parameters */
176 | assert_param(IS_EXTI_LINE(EXTI_Line));
177 |
178 | EXTI->SWIER |= EXTI_Line;
179 | }
180 |
181 | /**
182 | * @brief Checks whether the specified EXTI line flag is set or not.
183 | * @param EXTI_Line: specifies the EXTI line flag to check.
184 | * This parameter can be:
185 | * @arg EXTI_Linex: External interrupt line x where x(0..19)
186 | * @retval The new state of EXTI_Line (SET or RESET).
187 | */
188 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
189 | {
190 | FlagStatus bitstatus = RESET;
191 | /* Check the parameters */
192 | assert_param(IS_GET_EXTI_LINE(EXTI_Line));
193 |
194 | if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
195 | {
196 | bitstatus = SET;
197 | }
198 | else
199 | {
200 | bitstatus = RESET;
201 | }
202 | return bitstatus;
203 | }
204 |
205 | /**
206 | * @brief Clears the EXTI's line pending flags.
207 | * @param EXTI_Line: specifies the EXTI lines flags to clear.
208 | * This parameter can be any combination of EXTI_Linex where x can be (0..19).
209 | * @retval None
210 | */
211 | void EXTI_ClearFlag(uint32_t EXTI_Line)
212 | {
213 | /* Check the parameters */
214 | assert_param(IS_EXTI_LINE(EXTI_Line));
215 |
216 | EXTI->PR = EXTI_Line;
217 | }
218 |
219 | /**
220 | * @brief Checks whether the specified EXTI line is asserted or not.
221 | * @param EXTI_Line: specifies the EXTI line to check.
222 | * This parameter can be:
223 | * @arg EXTI_Linex: External interrupt line x where x(0..19)
224 | * @retval The new state of EXTI_Line (SET or RESET).
225 | */
226 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
227 | {
228 | ITStatus bitstatus = RESET;
229 | uint32_t enablestatus = 0;
230 | /* Check the parameters */
231 | assert_param(IS_GET_EXTI_LINE(EXTI_Line));
232 |
233 | enablestatus = EXTI->IMR & EXTI_Line;
234 | if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
235 | {
236 | bitstatus = SET;
237 | }
238 | else
239 | {
240 | bitstatus = RESET;
241 | }
242 | return bitstatus;
243 | }
244 |
245 | /**
246 | * @brief Clears the EXTI's line pending bits.
247 | * @param EXTI_Line: specifies the EXTI lines to clear.
248 | * This parameter can be any combination of EXTI_Linex where x can be (0..19).
249 | * @retval None
250 | */
251 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
252 | {
253 | /* Check the parameters */
254 | assert_param(IS_EXTI_LINE(EXTI_Line));
255 |
256 | EXTI->PR = EXTI_Line;
257 | }
258 |
259 | /**
260 | * @}
261 | */
262 |
263 | /**
264 | * @}
265 | */
266 |
267 | /**
268 | * @}
269 | */
270 |
271 |
272 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/particle-iot-archived/core-common-lib/3cdaed3ca40949a466027942c4b253adebc2ccf0/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/particle-iot-archived/core-common-lib/3cdaed3ca40949a466027942c4b253adebc2ccf0/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_iwdg.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_iwdg.c
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file provides all the IWDG firmware functions.
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "stm32f10x_iwdg.h"
26 |
27 | /** @addtogroup STM32F10x_StdPeriph_Driver
28 | * @{
29 | */
30 |
31 | /** @defgroup IWDG
32 | * @brief IWDG driver modules
33 | * @{
34 | */
35 |
36 | /** @defgroup IWDG_Private_TypesDefinitions
37 | * @{
38 | */
39 |
40 | /**
41 | * @}
42 | */
43 |
44 | /** @defgroup IWDG_Private_Defines
45 | * @{
46 | */
47 |
48 | /* ---------------------- IWDG registers bit mask ----------------------------*/
49 |
50 | /* KR register bit mask */
51 | #define KR_KEY_Reload ((uint16_t)0xAAAA)
52 | #define KR_KEY_Enable ((uint16_t)0xCCCC)
53 |
54 | /**
55 | * @}
56 | */
57 |
58 | /** @defgroup IWDG_Private_Macros
59 | * @{
60 | */
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | /** @defgroup IWDG_Private_Variables
67 | * @{
68 | */
69 |
70 | /**
71 | * @}
72 | */
73 |
74 | /** @defgroup IWDG_Private_FunctionPrototypes
75 | * @{
76 | */
77 |
78 | /**
79 | * @}
80 | */
81 |
82 | /** @defgroup IWDG_Private_Functions
83 | * @{
84 | */
85 |
86 | /**
87 | * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
88 | * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
89 | * This parameter can be one of the following values:
90 | * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
91 | * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
92 | * @retval None
93 | */
94 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
95 | {
96 | /* Check the parameters */
97 | assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
98 | IWDG->KR = IWDG_WriteAccess;
99 | }
100 |
101 | /**
102 | * @brief Sets IWDG Prescaler value.
103 | * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
104 | * This parameter can be one of the following values:
105 | * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
106 | * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
107 | * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
108 | * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
109 | * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
110 | * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
111 | * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
112 | * @retval None
113 | */
114 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
115 | {
116 | /* Check the parameters */
117 | assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
118 | IWDG->PR = IWDG_Prescaler;
119 | }
120 |
121 | /**
122 | * @brief Sets IWDG Reload value.
123 | * @param Reload: specifies the IWDG Reload value.
124 | * This parameter must be a number between 0 and 0x0FFF.
125 | * @retval None
126 | */
127 | void IWDG_SetReload(uint16_t Reload)
128 | {
129 | /* Check the parameters */
130 | assert_param(IS_IWDG_RELOAD(Reload));
131 | IWDG->RLR = Reload;
132 | }
133 |
134 | /**
135 | * @brief Reloads IWDG counter with value defined in the reload register
136 | * (write access to IWDG_PR and IWDG_RLR registers disabled).
137 | * @param None
138 | * @retval None
139 | */
140 | void IWDG_ReloadCounter(void)
141 | {
142 | IWDG->KR = KR_KEY_Reload;
143 | }
144 |
145 | /**
146 | * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
147 | * @param None
148 | * @retval None
149 | */
150 | void IWDG_Enable(void)
151 | {
152 | IWDG->KR = KR_KEY_Enable;
153 | }
154 |
155 | /**
156 | * @brief Checks whether the specified IWDG flag is set or not.
157 | * @param IWDG_FLAG: specifies the flag to check.
158 | * This parameter can be one of the following values:
159 | * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
160 | * @arg IWDG_FLAG_RVU: Reload Value Update on going
161 | * @retval The new state of IWDG_FLAG (SET or RESET).
162 | */
163 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
164 | {
165 | FlagStatus bitstatus = RESET;
166 | /* Check the parameters */
167 | assert_param(IS_IWDG_FLAG(IWDG_FLAG));
168 | if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
169 | {
170 | bitstatus = SET;
171 | }
172 | else
173 | {
174 | bitstatus = RESET;
175 | }
176 | /* Return the flag status */
177 | return bitstatus;
178 | }
179 |
180 | /**
181 | * @}
182 | */
183 |
184 | /**
185 | * @}
186 | */
187 |
188 | /**
189 | * @}
190 | */
191 |
192 |
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/particle-iot-archived/core-common-lib/3cdaed3ca40949a466027942c4b253adebc2ccf0/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c
--------------------------------------------------------------------------------
/STM32F10x_StdPeriph_Driver/src/stm32f10x_wwdg.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f10x_wwdg.c
4 | * @author MCD Application Team
5 | * @version V3.6.1
6 | * @date 05-March-2012
7 | * @brief This file provides all the WWDG firmware functions.
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | ******************************************************************************
22 | */
23 |
24 | /* Includes ------------------------------------------------------------------*/
25 | #include "stm32f10x_wwdg.h"
26 | #include "stm32f10x_rcc.h"
27 |
28 | /** @addtogroup STM32F10x_StdPeriph_Driver
29 | * @{
30 | */
31 |
32 | /** @defgroup WWDG
33 | * @brief WWDG driver modules
34 | * @{
35 | */
36 |
37 | /** @defgroup WWDG_Private_TypesDefinitions
38 | * @{
39 | */
40 |
41 | /**
42 | * @}
43 | */
44 |
45 | /** @defgroup WWDG_Private_Defines
46 | * @{
47 | */
48 |
49 | /* ----------- WWDG registers bit address in the alias region ----------- */
50 | #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE)
51 |
52 | /* Alias word address of EWI bit */
53 | #define CFR_OFFSET (WWDG_OFFSET + 0x04)
54 | #define EWI_BitNumber 0x09
55 | #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
56 |
57 | /* --------------------- WWDG registers bit mask ------------------------ */
58 |
59 | /* CR register bit mask */
60 | #define CR_WDGA_Set ((uint32_t)0x00000080)
61 |
62 | /* CFR register bit mask */
63 | #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F)
64 | #define CFR_W_Mask ((uint32_t)0xFFFFFF80)
65 | #define BIT_Mask ((uint8_t)0x7F)
66 |
67 | /**
68 | * @}
69 | */
70 |
71 | /** @defgroup WWDG_Private_Macros
72 | * @{
73 | */
74 |
75 | /**
76 | * @}
77 | */
78 |
79 | /** @defgroup WWDG_Private_Variables
80 | * @{
81 | */
82 |
83 | /**
84 | * @}
85 | */
86 |
87 | /** @defgroup WWDG_Private_FunctionPrototypes
88 | * @{
89 | */
90 |
91 | /**
92 | * @}
93 | */
94 |
95 | /** @defgroup WWDG_Private_Functions
96 | * @{
97 | */
98 |
99 | /**
100 | * @brief Deinitializes the WWDG peripheral registers to their default reset values.
101 | * @param None
102 | * @retval None
103 | */
104 | void WWDG_DeInit(void)
105 | {
106 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
107 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
108 | }
109 |
110 | /**
111 | * @brief Sets the WWDG Prescaler.
112 | * @param WWDG_Prescaler: specifies the WWDG Prescaler.
113 | * This parameter can be one of the following values:
114 | * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
115 | * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
116 | * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
117 | * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
118 | * @retval None
119 | */
120 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
121 | {
122 | uint32_t tmpreg = 0;
123 | /* Check the parameters */
124 | assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
125 | /* Clear WDGTB[1:0] bits */
126 | tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
127 | /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
128 | tmpreg |= WWDG_Prescaler;
129 | /* Store the new value */
130 | WWDG->CFR = tmpreg;
131 | }
132 |
133 | /**
134 | * @brief Sets the WWDG window value.
135 | * @param WindowValue: specifies the window value to be compared to the downcounter.
136 | * This parameter value must be lower than 0x80.
137 | * @retval None
138 | */
139 | void WWDG_SetWindowValue(uint8_t WindowValue)
140 | {
141 | __IO uint32_t tmpreg = 0;
142 |
143 | /* Check the parameters */
144 | assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
145 | /* Clear W[6:0] bits */
146 |
147 | tmpreg = WWDG->CFR & CFR_W_Mask;
148 |
149 | /* Set W[6:0] bits according to WindowValue value */
150 | tmpreg |= WindowValue & (uint32_t) BIT_Mask;
151 |
152 | /* Store the new value */
153 | WWDG->CFR = tmpreg;
154 | }
155 |
156 | /**
157 | * @brief Enables the WWDG Early Wakeup interrupt(EWI).
158 | * @param None
159 | * @retval None
160 | */
161 | void WWDG_EnableIT(void)
162 | {
163 | *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE;
164 | }
165 |
166 | /**
167 | * @brief Sets the WWDG counter value.
168 | * @param Counter: specifies the watchdog counter value.
169 | * This parameter must be a number between 0x40 and 0x7F.
170 | * @retval None
171 | */
172 | void WWDG_SetCounter(uint8_t Counter)
173 | {
174 | /* Check the parameters */
175 | assert_param(IS_WWDG_COUNTER(Counter));
176 | /* Write to T[6:0] bits to configure the counter value, no need to do
177 | a read-modify-write; writing a 0 to WDGA bit does nothing */
178 | WWDG->CR = Counter & BIT_Mask;
179 | }
180 |
181 | /**
182 | * @brief Enables WWDG and load the counter value.
183 | * @param Counter: specifies the watchdog counter value.
184 | * This parameter must be a number between 0x40 and 0x7F.
185 | * @retval None
186 | */
187 | void WWDG_Enable(uint8_t Counter)
188 | {
189 | /* Check the parameters */
190 | assert_param(IS_WWDG_COUNTER(Counter));
191 | WWDG->CR = CR_WDGA_Set | Counter;
192 | }
193 |
194 | /**
195 | * @brief Checks whether the Early Wakeup interrupt flag is set or not.
196 | * @param None
197 | * @retval The new state of the Early Wakeup interrupt flag (SET or RESET)
198 | */
199 | FlagStatus WWDG_GetFlagStatus(void)
200 | {
201 | return (FlagStatus)(WWDG->SR);
202 | }
203 |
204 | /**
205 | * @brief Clears Early Wakeup interrupt flag.
206 | * @param None
207 | * @retval None
208 | */
209 | void WWDG_ClearFlag(void)
210 | {
211 | WWDG->SR = (uint32_t)RESET;
212 | }
213 |
214 | /**
215 | * @}
216 | */
217 |
218 | /**
219 | * @}
220 | */
221 |
222 | /**
223 | * @}
224 | */
225 |
226 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/inc/usb_def.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | Released into the public domain.
4 | This work is free: you can redistribute it and/or modify it under the terms of
5 | Creative Commons Zero license v1.0
6 |
7 | This work is licensed under the Creative Commons Zero 1.0 United States License.
8 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
9 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
10 | California, 94105, USA.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 | or FITNESS FOR A PARTICULAR PURPOSE.
15 | ******************************************************************************
16 | */
17 |
18 | /* Define to prevent recursive inclusion -------------------------------------*/
19 | #ifndef __USB_DEF_H
20 | #define __USB_DEF_H
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | /* Exported types ------------------------------------------------------------*/
24 | typedef enum _RECIPIENT_TYPE
25 | {
26 | DEVICE_RECIPIENT, /* Recipient device */
27 | INTERFACE_RECIPIENT, /* Recipient interface */
28 | ENDPOINT_RECIPIENT, /* Recipient endpoint */
29 | OTHER_RECIPIENT
30 | } RECIPIENT_TYPE;
31 |
32 |
33 | typedef enum _STANDARD_REQUESTS
34 | {
35 | GET_STATUS = 0,
36 | CLEAR_FEATURE,
37 | RESERVED1,
38 | SET_FEATURE,
39 | RESERVED2,
40 | SET_ADDRESS,
41 | GET_DESCRIPTOR,
42 | SET_DESCRIPTOR,
43 | GET_CONFIGURATION,
44 | SET_CONFIGURATION,
45 | GET_INTERFACE,
46 | SET_INTERFACE,
47 | TOTAL_sREQUEST, /* Total number of Standard request */
48 | SYNCH_FRAME = 12
49 | } STANDARD_REQUESTS;
50 |
51 | /* Definition of "USBwValue" */
52 | typedef enum _DESCRIPTOR_TYPE
53 | {
54 | DEVICE_DESCRIPTOR = 1,
55 | CONFIG_DESCRIPTOR,
56 | STRING_DESCRIPTOR,
57 | INTERFACE_DESCRIPTOR,
58 | ENDPOINT_DESCRIPTOR
59 | } DESCRIPTOR_TYPE;
60 |
61 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */
62 | typedef enum _FEATURE_SELECTOR
63 | {
64 | ENDPOINT_STALL,
65 | DEVICE_REMOTE_WAKEUP
66 | } FEATURE_SELECTOR;
67 |
68 | /* Exported constants --------------------------------------------------------*/
69 | /* Definition of "USBbmRequestType" */
70 | #define REQUEST_TYPE 0x60 /* Mask to get request type */
71 | #define STANDARD_REQUEST 0x00 /* Standard request */
72 | #define CLASS_REQUEST 0x20 /* Class request */
73 | #define VENDOR_REQUEST 0x40 /* Vendor request */
74 |
75 | #define RECIPIENT 0x1F /* Mask to get recipient */
76 |
77 | /* Exported macro ------------------------------------------------------------*/
78 | /* Exported functions ------------------------------------------------------- */
79 |
80 | #endif /* __USB_DEF_H */
81 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/inc/usb_init.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_init.h
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Initialization routines & global variables
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | ******************************************************************************
22 | */
23 |
24 |
25 | /* Define to prevent recursive inclusion -------------------------------------*/
26 | #ifndef __USB_INIT_H
27 | #define __USB_INIT_H
28 |
29 | /* Includes ------------------------------------------------------------------*/
30 | /* Exported types ------------------------------------------------------------*/
31 | /* Exported constants --------------------------------------------------------*/
32 | /* Exported macro ------------------------------------------------------------*/
33 | /* Exported functions ------------------------------------------------------- */
34 | void USB_Init(void);
35 |
36 | /* External variables --------------------------------------------------------*/
37 | /* The number of current endpoint, it will be used to specify an endpoint */
38 | extern uint8_t EPindex;
39 | /* The number of current device, it is an index to the Device_Table */
40 | /*extern uint8_t Device_no; */
41 | /* Points to the DEVICE_INFO structure of current device */
42 | /* The purpose of this register is to speed up the execution */
43 | extern DEVICE_INFO* pInformation;
44 | /* Points to the DEVICE_PROP structure of current device */
45 | /* The purpose of this register is to speed up the execution */
46 | extern DEVICE_PROP* pProperty;
47 | /* Temporary save the state of Rx & Tx status. */
48 | /* Whenever the Rx or Tx state is changed, its value is saved */
49 | /* in this variable first and will be set to the EPRB or EPRA */
50 | /* at the end of interrupt process */
51 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests;
52 |
53 | extern uint16_t SaveState ;
54 | extern uint16_t wInterrupt_Mask;
55 |
56 | #endif /* __USB_INIT_H */
57 |
58 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/inc/usb_int.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_int.h
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Endpoint CTR (Low and High) interrupt's service routines prototypes
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | *
22 | ******************************************************************************
23 | */
24 |
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __USB_INT_H
28 | #define __USB_INT_H
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | /* Exported types ------------------------------------------------------------*/
32 | /* Exported constants --------------------------------------------------------*/
33 | /* Exported macro ------------------------------------------------------------*/
34 | /* Exported functions ------------------------------------------------------- */
35 | void CTR_LP(void);
36 | void CTR_HP(void);
37 |
38 | /* External variables --------------------------------------------------------*/
39 |
40 | #endif /* __USB_INT_H */
41 |
42 |
43 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/inc/usb_lib.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_lib.h
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief USB library include files
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | *
22 | ******************************************************************************
23 | */
24 |
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __USB_LIB_H
28 | #define __USB_LIB_H
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | #include "hw_config.h"
32 | #include "usb_type.h"
33 | #include "usb_regs.h"
34 | #include "usb_def.h"
35 | #include "usb_core.h"
36 | #include "usb_init.h"
37 | #include "usb_sil.h"
38 | #include "usb_mem.h"
39 | #include "usb_int.h"
40 |
41 | /* Exported types ------------------------------------------------------------*/
42 | /* Exported constants --------------------------------------------------------*/
43 | /* Exported macro ------------------------------------------------------------*/
44 | /* Exported functions ------------------------------------------------------- */
45 | /* External variables --------------------------------------------------------*/
46 |
47 | #endif /* __USB_LIB_H */
48 |
49 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/inc/usb_mem.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_mem.h
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Utility prototypes functions for memory/PMA transfers
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | *
22 | ******************************************************************************
23 | */
24 |
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __USB_MEM_H
28 | #define __USB_MEM_H
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | /* Exported types ------------------------------------------------------------*/
32 | /* Exported constants --------------------------------------------------------*/
33 | /* Exported macro ------------------------------------------------------------*/
34 | /* Exported functions ------------------------------------------------------- */
35 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
36 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
37 |
38 | /* External variables --------------------------------------------------------*/
39 |
40 | #endif /*__USB_MEM_H*/
41 |
42 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/inc/usb_sil.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_sil.h
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Simplified Interface Layer function prototypes.
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | *
22 | ******************************************************************************
23 | */
24 |
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __USB_SIL_H
28 | #define __USB_SIL_H
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | /* Exported types ------------------------------------------------------------*/
32 | /* Exported constants --------------------------------------------------------*/
33 | /* Exported macro ------------------------------------------------------------*/
34 | /* Exported functions ------------------------------------------------------- */
35 |
36 | uint32_t USB_SIL_Init(void);
37 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize);
38 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer);
39 |
40 | /* External variables --------------------------------------------------------*/
41 |
42 | #endif /* __USB_SIL_H */
43 |
44 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/inc/usb_type.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_type.h
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Type definitions used by the USB Library
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | *
22 | ******************************************************************************
23 | */
24 |
25 |
26 | /* Define to prevent recursive inclusion -------------------------------------*/
27 | #ifndef __USB_TYPE_H
28 | #define __USB_TYPE_H
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 |
32 | /* Exported types ------------------------------------------------------------*/
33 | /* Exported constants --------------------------------------------------------*/
34 | #ifndef NULL
35 | #define NULL ((void *)0)
36 | #endif
37 |
38 | #ifndef __cplusplus
39 | typedef enum
40 | {
41 | false = 0, true = !false
42 | }
43 | bool;
44 | #endif
45 |
46 | /* Exported macro ------------------------------------------------------------*/
47 | /* Exported functions ------------------------------------------------------- */
48 | /* External variables --------------------------------------------------------*/
49 |
50 | #endif /* __USB_TYPE_H */
51 |
52 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/src/build.mk:
--------------------------------------------------------------------------------
1 | # This file is a makefile included from the top level makefile which
2 | # defines the sources built for the target.
3 |
4 | # Define the prefix to this directory.
5 | # Note: The name must be unique within this build and should be
6 | # based on the root of the project
7 | TARGET_USB_FS_PATH = STM32_USB-FS-Device_Driver
8 | TARGET_USB_FS_SRC_PATH = $(TARGET_USB_FS_PATH)/src
9 |
10 | # Add tropicssl include to all objects built for this target
11 | INCLUDE_DIRS += $(TARGET_USB_FS_PATH)/inc
12 |
13 | # C source files included in this build.
14 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_core.c
15 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_init.c
16 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_int.c
17 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_mem.c
18 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_regs.c
19 | CSRC += $(TARGET_USB_FS_SRC_PATH)/usb_sil.c
20 |
21 | # C++ source files included in this build.
22 | CPPSRC +=
23 |
24 | # ASM source files included in this build.
25 | ASRC +=
26 |
27 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/src/usb_init.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_init.c
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Initialization routines & global variables
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | *
22 | ******************************************************************************
23 | */
24 |
25 |
26 | /* Includes ------------------------------------------------------------------*/
27 | #include "usb_lib.h"
28 |
29 | /* Private typedef -----------------------------------------------------------*/
30 | /* Private define ------------------------------------------------------------*/
31 | /* Private macro -------------------------------------------------------------*/
32 | /* Private variables ---------------------------------------------------------*/
33 | /* The number of current endpoint, it will be used to specify an endpoint */
34 | uint8_t EPindex;
35 | /* The number of current device, it is an index to the Device_Table */
36 | /* uint8_t Device_no; */
37 | /* Points to the DEVICE_INFO structure of current device */
38 | /* The purpose of this register is to speed up the execution */
39 | DEVICE_INFO *pInformation;
40 | /* Points to the DEVICE_PROP structure of current device */
41 | /* The purpose of this register is to speed up the execution */
42 | DEVICE_PROP *pProperty;
43 | /* Temporary save the state of Rx & Tx status. */
44 | /* Whenever the Rx or Tx state is changed, its value is saved */
45 | /* in this variable first and will be set to the EPRB or EPRA */
46 | /* at the end of interrupt process */
47 | uint16_t SaveState ;
48 | uint16_t wInterrupt_Mask;
49 | DEVICE_INFO Device_Info;
50 | USER_STANDARD_REQUESTS *pUser_Standard_Requests;
51 |
52 | /* Extern variables ----------------------------------------------------------*/
53 | /* Private function prototypes -----------------------------------------------*/
54 | /* Private functions ---------------------------------------------------------*/
55 |
56 | /*******************************************************************************
57 | * Function Name : USB_Init
58 | * Description : USB system initialization
59 | * Input : None.
60 | * Output : None.
61 | * Return : None.
62 | *******************************************************************************/
63 | void USB_Init(void)
64 | {
65 | pInformation = &Device_Info;
66 | pInformation->ControlState = 2;
67 | pProperty = &Device_Property;
68 | pUser_Standard_Requests = &User_Standard_Requests;
69 | /* Initialize devices one by one */
70 | pProperty->Init();
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/src/usb_int.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_int.c
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Endpoint CTR (Low and High) interrupt's service routines
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | *
22 | ******************************************************************************
23 | */
24 |
25 | /* Includes ------------------------------------------------------------------*/
26 | #include "usb_lib.h"
27 |
28 | /* Private typedef -----------------------------------------------------------*/
29 | /* Private define ------------------------------------------------------------*/
30 | /* Private macro -------------------------------------------------------------*/
31 | /* Private variables ---------------------------------------------------------*/
32 | __IO uint16_t SaveRState;
33 | __IO uint16_t SaveTState;
34 |
35 | /* Extern variables ----------------------------------------------------------*/
36 | extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */
37 | extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */
38 |
39 | /* Private function prototypes -----------------------------------------------*/
40 | /* Private functions ---------------------------------------------------------*/
41 |
42 | /*******************************************************************************
43 | * Function Name : CTR_LP.
44 | * Description : Low priority Endpoint Correct Transfer interrupt's service
45 | * routine.
46 | * Input : None.
47 | * Output : None.
48 | * Return : None.
49 | *******************************************************************************/
50 | void CTR_LP(void)
51 | {
52 | __IO uint16_t wEPVal = 0;
53 | /* stay in loop while pending interrupts */
54 | while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
55 | {
56 | /* extract highest priority endpoint number */
57 | EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
58 | if (EPindex == 0)
59 | {
60 | /* Decode and service control endpoint interrupt */
61 | /* calling related service routine */
62 | /* (Setup0_Process, In0_Process, Out0_Process) */
63 |
64 | /* save RX & TX status */
65 | /* and set both to NAK */
66 |
67 | SaveRState = _GetENDPOINT(ENDP0);
68 | SaveTState = SaveRState & EPTX_STAT;
69 | SaveRState &= EPRX_STAT;
70 |
71 | _SetEPRxTxStatus(ENDP0,EP_RX_NAK,EP_TX_NAK);
72 |
73 | /* DIR bit = origin of the interrupt */
74 |
75 | if ((wIstr & ISTR_DIR) == 0)
76 | {
77 | /* DIR = 0 */
78 |
79 | /* DIR = 0 => IN int */
80 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */
81 |
82 | _ClearEP_CTR_TX(ENDP0);
83 | In0_Process();
84 |
85 | /* before terminate set Tx & Rx status */
86 |
87 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
88 | return;
89 | }
90 | else
91 | {
92 | /* DIR = 1 */
93 |
94 | /* DIR = 1 & CTR_RX => SETUP or OUT int */
95 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
96 |
97 | wEPVal = _GetENDPOINT(ENDP0);
98 |
99 | if ((wEPVal &EP_SETUP) != 0)
100 | {
101 | _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
102 | Setup0_Process();
103 | /* before terminate set Tx & Rx status */
104 |
105 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
106 | return;
107 | }
108 |
109 | else if ((wEPVal & EP_CTR_RX) != 0)
110 | {
111 | _ClearEP_CTR_RX(ENDP0);
112 | Out0_Process();
113 | /* before terminate set Tx & Rx status */
114 |
115 | _SetEPRxTxStatus(ENDP0,SaveRState,SaveTState);
116 | return;
117 | }
118 | }
119 | }/* if(EPindex == 0) */
120 | else
121 | {
122 | /* Decode and service non control endpoints interrupt */
123 |
124 | /* process related endpoint register */
125 | wEPVal = _GetENDPOINT(EPindex);
126 | if ((wEPVal & EP_CTR_RX) != 0)
127 | {
128 | /* clear int flag */
129 | _ClearEP_CTR_RX(EPindex);
130 |
131 | /* call OUT service function */
132 | (*pEpInt_OUT[EPindex-1])();
133 |
134 | } /* if((wEPVal & EP_CTR_RX) */
135 |
136 | if ((wEPVal & EP_CTR_TX) != 0)
137 | {
138 | /* clear int flag */
139 | _ClearEP_CTR_TX(EPindex);
140 |
141 | /* call IN service function */
142 | (*pEpInt_IN[EPindex-1])();
143 | } /* if((wEPVal & EP_CTR_TX) != 0) */
144 |
145 | }/* if(EPindex == 0) else */
146 |
147 | }/* while(...) */
148 | }
149 |
150 | /*******************************************************************************
151 | * Function Name : CTR_HP.
152 | * Description : High Priority Endpoint Correct Transfer interrupt's service
153 | * routine.
154 | * Input : None.
155 | * Output : None.
156 | * Return : None.
157 | *******************************************************************************/
158 | void CTR_HP(void)
159 | {
160 | uint32_t wEPVal = 0;
161 |
162 | while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
163 | {
164 | _SetISTR((uint16_t)CLR_CTR); /* clear CTR flag */
165 | /* extract highest priority endpoint number */
166 | EPindex = (uint8_t)(wIstr & ISTR_EP_ID);
167 | /* process related endpoint register */
168 | wEPVal = _GetENDPOINT(EPindex);
169 | if ((wEPVal & EP_CTR_RX) != 0)
170 | {
171 | /* clear int flag */
172 | _ClearEP_CTR_RX(EPindex);
173 |
174 | /* call OUT service function */
175 | (*pEpInt_OUT[EPindex-1])();
176 |
177 | } /* if((wEPVal & EP_CTR_RX) */
178 | else if ((wEPVal & EP_CTR_TX) != 0)
179 | {
180 | /* clear int flag */
181 | _ClearEP_CTR_TX(EPindex);
182 |
183 | /* call IN service function */
184 | (*pEpInt_IN[EPindex-1])();
185 |
186 |
187 | } /* if((wEPVal & EP_CTR_TX) != 0) */
188 |
189 | }/* while(...) */
190 | }
191 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/src/usb_mem.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_mem.c
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Utility functions for memory transfers to/from PMA
8 | ******************************************************************************
9 | Released into the public domain.
10 | This work is free: you can redistribute it and/or modify it under the terms of
11 | Creative Commons Zero license v1.0
12 |
13 | This work is licensed under the Creative Commons Zero 1.0 United States License.
14 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
15 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
16 | California, 94105, USA.
17 |
18 | This program is distributed in the hope that it will be useful,
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 | or FITNESS FOR A PARTICULAR PURPOSE.
21 | *
22 | ******************************************************************************
23 | */
24 |
25 | /* Includes ------------------------------------------------------------------*/
26 | #include "usb_lib.h"
27 |
28 | /* Private typedef -----------------------------------------------------------*/
29 | /* Private define ------------------------------------------------------------*/
30 | /* Private macro -------------------------------------------------------------*/
31 | /* Private variables ---------------------------------------------------------*/
32 | /* Extern variables ----------------------------------------------------------*/
33 | /* Private function prototypes -----------------------------------------------*/
34 | /* Private functions ---------------------------------------------------------*/
35 |
36 | /*******************************************************************************
37 | * Function Name : UserToPMABufferCopy
38 | * Description : Copy a buffer from user memory area to packet memory area (PMA)
39 | * Input : - pbUsrBuf: pointer to user memory area.
40 | * - wPMABufAddr: address into PMA.
41 | * - wNBytes: no. of bytes to be copied.
42 | * Output : None.
43 | * Return : None .
44 | *******************************************************************************/
45 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
46 | {
47 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
48 | uint32_t i, temp1, temp2;
49 | uint16_t *pdwVal;
50 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr);
51 | for (i = n; i != 0; i--)
52 | {
53 | temp1 = (uint16_t) * pbUsrBuf;
54 | pbUsrBuf++;
55 | temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
56 | *pdwVal++ = temp2;
57 | pdwVal++;
58 | pbUsrBuf++;
59 | }
60 | }
61 |
62 | /*******************************************************************************
63 | * Function Name : PMAToUserBufferCopy
64 | * Description : Copy a buffer from user memory area to packet memory area (PMA)
65 | * Input : - pbUsrBuf = pointer to user memory area.
66 | * - wPMABufAddr = address into PMA.
67 | * - wNBytes = no. of bytes to be copied.
68 | * Output : None.
69 | * Return : None.
70 | *******************************************************************************/
71 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
72 | {
73 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/
74 | uint32_t i;
75 | uint32_t *pdwVal;
76 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr);
77 | for (i = n; i != 0; i--)
78 | {
79 | *(uint16_t*)pbUsrBuf++ = *pdwVal++;
80 | pbUsrBuf++;
81 | }
82 | }
83 |
84 |
--------------------------------------------------------------------------------
/STM32_USB-FS-Device_Driver/src/usb_sil.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_sil.c
4 | * @author MCD Application Team
5 | * @version V4.0.0
6 | * @date 28-August-2012
7 | * @brief Simplified Interface Layer for Global Initialization and Endpoint
8 | * Rea/Write operations.
9 | ******************************************************************************
10 | Released into the public domain.
11 | This work is free: you can redistribute it and/or modify it under the terms of
12 | Creative Commons Zero license v1.0
13 |
14 | This work is licensed under the Creative Commons Zero 1.0 United States License.
15 | To view a copy of this license, visit http://creativecommons.org/publicdomain/zero/1.0/
16 | or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco,
17 | California, 94105, USA.
18 |
19 | This program is distributed in the hope that it will be useful,
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 | or FITNESS FOR A PARTICULAR PURPOSE.
22 | *
23 | ******************************************************************************
24 | */
25 |
26 |
27 | /* Includes ------------------------------------------------------------------*/
28 | #include "usb_lib.h"
29 |
30 | /* Private typedef -----------------------------------------------------------*/
31 | /* Private define ------------------------------------------------------------*/
32 | /* Private macro -------------------------------------------------------------*/
33 | /* Private variables ---------------------------------------------------------*/
34 | /* Extern variables ----------------------------------------------------------*/
35 | /* Private function prototypes -----------------------------------------------*/
36 | /* Private functions ---------------------------------------------------------*/
37 |
38 | /*******************************************************************************
39 | * Function Name : USB_SIL_Init
40 | * Description : Initialize the USB Device IP and the Endpoint 0.
41 | * Input : None.
42 | * Output : None.
43 | * Return : Status.
44 | *******************************************************************************/
45 | uint32_t USB_SIL_Init(void)
46 | {
47 | /* USB interrupts initialization */
48 | /* clear pending interrupts */
49 | _SetISTR(0);
50 | wInterrupt_Mask = IMR_MSK;
51 | /* set interrupts mask */
52 | _SetCNTR(wInterrupt_Mask);
53 | return 0;
54 | }
55 |
56 | /*******************************************************************************
57 | * Function Name : USB_SIL_Write
58 | * Description : Write a buffer of data to a selected endpoint.
59 | * Input : - bEpAddr: The address of the non control endpoint.
60 | * - pBufferPointer: The pointer to the buffer of data to be written
61 | * to the endpoint.
62 | * - wBufferSize: Number of data to be written (in bytes).
63 | * Output : None.
64 | * Return : Status.
65 | *******************************************************************************/
66 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize)
67 | {
68 | /* Use the memory interface function to write to the selected endpoint */
69 | UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);
70 |
71 | /* Update the data length in the control register */
72 | SetEPTxCount((bEpAddr & 0x7F), wBufferSize);
73 |
74 | return 0;
75 | }
76 |
77 | /*******************************************************************************
78 | * Function Name : USB_SIL_Read
79 | * Description : Write a buffer of data to a selected endpoint.
80 | * Input : - bEpAddr: The address of the non control endpoint.
81 | * - pBufferPointer: The pointer to which will be saved the
82 | * received data buffer.
83 | * Output : None.
84 | * Return : Number of received data (in Bytes).
85 | *******************************************************************************/
86 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer)
87 | {
88 | uint32_t DataLength = 0;
89 |
90 | /* Get the number of received data on the selected Endpoint */
91 | DataLength = GetEPRxCount(bEpAddr & 0x7F);
92 |
93 | /* Use the memory interface function to write to the selected endpoint */
94 | PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength);
95 |
96 | /* Return the number of received data */
97 | return DataLength;
98 | }
99 |
100 |
--------------------------------------------------------------------------------
/build/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled objects and dependancies
2 | obj/
--------------------------------------------------------------------------------
/build/makefile:
--------------------------------------------------------------------------------
1 |
2 | # Define the compiler/tools prefix
3 | GCC_PREFIX ?= arm-none-eabi-
4 |
5 | # Define tools
6 | CC = $(GCC_PREFIX)gcc
7 | AR = $(GCC_PREFIX)ar
8 | OBJCOPY = $(GCC_PREFIX)objcopy
9 |
10 | RM = rm -f
11 | MKDIR = mkdir -p
12 |
13 | # Recursive wildcard function
14 | rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
15 |
16 | # Define the build path, this is where all of the dependancies and
17 | # object files will be placed.
18 | # Note: Currently set to /build/obj directory and set relative to
19 | # the dir which makefile is invoked. If the makefile is moved to the project
20 | # root, BUILD_PATH = build can be used to store the build products in
21 | # the build directory.
22 | BUILD_PATH = obj
23 |
24 | # Path to the root of source files, in this case root of the project to
25 | # inclue ../src and ../lib dirs.
26 | # Note: Consider relocating source files in lib to src, or build a
27 | # seperate library.
28 | SRC_PATH = ..
29 |
30 | # Target this makefile is building.
31 | TARGET = libcore-common-lib.a
32 |
33 | # Find all build.mk makefiles in each source directory in the src tree.
34 | SRC_MAKEFILES := $(call rwildcard,$(SRC_PATH)/,build.mk)
35 |
36 | # Include all build.mk defines source files.
37 | include $(SRC_MAKEFILES)
38 |
39 | # Additional include directories, applied to objects built for this target.
40 | INCLUDE_DIRS += CMSIS/Include
41 | INCLUDE_DIRS += CMSIS/Device/ST/STM32F10x/Include
42 |
43 | # Compiler flags
44 | CFLAGS = -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb
45 | CFLAGS += $(patsubst %,-I$(SRC_PATH)/%,$(INCLUDE_DIRS)) -I.
46 | CFLAGS += -ffunction-sections -Wall -Wno-switch -fmessage-length=0
47 |
48 | # Generate dependancy files automatically.
49 | CFLAGS += -MD -MP -MF $@.d
50 |
51 | # Target specific defines
52 | CFLAGS += -DUSE_STDPERIPH_DRIVER
53 | CFLAGS += -DSTM32F10X_MD
54 |
55 | ifeq ("$(USE_SWD_JTAG)","y")
56 | CFLAGS += -DUSE_SWD_JTAG
57 | endif
58 |
59 | ifeq ("$(DEBUG_BUILD)","y")
60 | CFLAGS += -DDEBUG_BUILD
61 | else
62 | CFLAGS += -DRELEASE_BUILD
63 | endif
64 |
65 | # C++ specific flags
66 | CPPFLAGS = -fno-exceptions -fno-rtti
67 |
68 | # Collect all object and dep files
69 | ALLOBJ += $(addprefix $(BUILD_PATH)/, $(CSRC:.c=.o))
70 | ALLOBJ += $(addprefix $(BUILD_PATH)/, $(CPPSRC:.cpp=.o))
71 | ALLOBJ += $(addprefix $(BUILD_PATH)/, $(ASRC:.S=.o))
72 |
73 | ALLDEPS += $(addprefix $(BUILD_PATH)/, $(CSRC:.c=.o.d))
74 | ALLDEPS += $(addprefix $(BUILD_PATH)/, $(CPPSRC:.cpp=.o.d))
75 | ALLDEPS += $(addprefix $(BUILD_PATH)/, $(ASRC:.S=.o.d))
76 |
77 | # All Target
78 | all: check_external_deps $(TARGET)
79 |
80 | # Check for external dependancies, none in this case.
81 | check_external_deps:
82 |
83 | # Tool invocations
84 | $(TARGET) : $(ALLOBJ)
85 | @echo 'Building target: $@'
86 | @echo 'Invoking: ARM GCC Archiver'
87 | $(AR) -r $@ $^
88 | @echo ' '
89 |
90 | # C compiler to build .o from .c in $(BUILD_DIR)
91 | $(BUILD_PATH)/%.o : $(SRC_PATH)/%.c
92 | @echo Building file: $<
93 | @echo Invoking: ARM GCC C Compiler
94 | $(MKDIR) $(dir $@)
95 | $(CC) $(CFLAGS) -c -o $@ $<
96 | @echo
97 |
98 | # CPP compiler to build .o from .cpp in $(BUILD_DIR)
99 | # Note: Calls standard $(CC) - gcc will invoke g++ as appropriate
100 | $(BUILD_PATH)/%.o : $(SRC_PATH)/%.cpp
101 | @echo Building file: $<
102 | @echo Invoking: ARM GCC CPP Compiler
103 | $(MKDIR) $(dir $@)
104 | $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
105 | @echo
106 |
107 | # Other Targets
108 | clean:
109 | $(RM) $(ALLOBJ) $(ALLDEPS) $(TARGET)
110 | @echo ' '
111 |
112 | .PHONY: all clean
113 | .SECONDARY:
114 |
115 | # Include auto generated dependancy files
116 | -include $(ALLDEPS)
117 |
118 |
--------------------------------------------------------------------------------