STM32F0xx Standard Peripherals Firmware Library
|
I2C_TwoBoards/stm32f0xx_i2c_cpal_conf.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file I2C/I2C_TwoBoards/stm32f0xx_i2c_cpal_conf.h 00004 * @author MCD Application Team 00005 * @version V1.4.0 00006 * @date 24-July-2014 00007 * @brief Library configuration file 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 /* Define to prevent recursive inclusion -------------------------------------*/ 00029 #ifndef __STM32F0XX_I2C_CPAL_CONF_H 00030 #define __STM32F0XX_I2C_CPAL_CONF_H 00031 00032 #ifdef __cplusplus 00033 extern "C" { 00034 #endif 00035 00036 /* Includes ------------------------------------------------------------------*/ 00037 /* Exported types ------------------------------------------------------------*/ 00038 /* Exported constants --------------------------------------------------------*/ 00039 00040 /*======================================================================================================================================= 00041 User NOTES 00042 ========================================================================================================================================= 00043 00044 ------------------------------- 00045 1. How To use the CPAL Library: 00046 ------------------------------- 00047 00048 ------- Refer to the user manual of the library and (eventually) the example to check if 00049 this firmware is appropriate for your hardware (device and (eventually) evaluation board) 00050 00051 - Section 1 : Select the Device instances to be used and the total number of devices 00052 00053 - Section 2 : Configure Transfer Options 00054 00055 - Section 3 : Select and configure transfer and error user Callbacks 00056 00057 - Section 4 : Configure Timeout mechanism and TimeoutCallback 00058 00059 - Section 5 : Configure Interrupt Priority Offset 00060 00061 - Section 6 : Configure CPAL_LOG Macro 00062 00063 ------ After configuring CPAL firmware functionality , You should proceed by configuring hardware used with CPAL 00064 (please refer to stm32f0xx_i2c_cpal_hal.h file). 00065 00066 ------ After configuring CPAL Firmware Library, you should follow these steps to use the Firmware correctly : 00067 00068 -1- STRUCTURE INITIALIZATION 00069 Start by initializing the Device. To perform this action, the global variable PPPx_DevStructure declared 00070 in CPAL Firmware as CPAL_InitTypeDef (I2C1_DevStructure for I2C1, I2C2_DevStructure for I2C2 ...) must be used. 00071 There are two ways to proceed : 00072 00073 ** Call the function CPAL_PPP_StructInit() using as parameter PPPx_DevStructure (where PPP = device type (ie. I2C...) 00074 and where x could be 1 for PPP1, 2 for PPP2 ...). This function sets the default values for all fields of this structure. 00075 00076 Default values for I2C devices are : 00077 I2Cx_DevStructure.CPAL_Direction = CPAL_DIRECTION_TXRX 00078 I2Cx_DevStructure.CPAL_Mode = CPAL_MODE_MASTER 00079 I2Cx_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA 00080 I2Cx_DevStructure.pCPAL_TransferTx = pNULL 00081 I2Cx_DevStructure.pCPAL_TransferRx = pNULL 00082 I2Cx_DevStructure.CPAL_State = CPAL_STATE_DISABLED 00083 I2Cx_DevStructure.wCPAL_DevError = CPAL_I2C_ERR_NONE 00084 I2Cx_DevStructure.wCPAL_Options = 0 (all options disabled) 00085 I2Cx_DevStructure.wCPAL_Timeout = CPAL_TIMEOUT_DEFAULT 00086 I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_Mode = I2C_Mode_I2C 00087 I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_AnalogFilter = I2C_AnalogFilter_Enable 00088 I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_DigitalFilter = 0x00 00089 I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_OwnAddress1 = 0 00090 I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_Ack = I2C_Ack_Enable 00091 I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit 00092 00093 00094 pCPAL_TransferTx and pCPAL_TransferRx fields have to be updated in order to point to valid structures 00095 (these structures should be local/global variables in the user application). 00096 00097 ** Another way of configuration is without calling CPAL_PPP_StructInit() function. 00098 Declare the following structures: 00099 - A PPP_InitTypeDef structure for the device configuration (ie. I2C_InitTypeDef structure) 00100 - One or two CPAL_TransferTypeDef variables (one for Tx and one for Rx). 00101 - Use the extern structure provided by the CPAL library: PPPx_InitStructure (ie. I2C1_DevStructure). 00102 Fill in all the fields for these structures (one by one). 00103 Use the pointers to these structures to fill in the fields pCPAL_PPP_Struct and pCPAL_TransferTx and/or 00104 pCPAL_TransferRx of the PPPx_DevStructure. 00105 After that CPAL_State must be set to CPAL_STATE_DISABLED. 00106 Finally, call the CPAL_PPP_Init() with pointer to the PPPx_DevStructure as argument. 00107 00108 Example: 00109 // Declare local structures 00110 I2C_InitTypeDef I2C1_InitStructure; 00111 CPAL_TransferTypeDef TX_Transfer, RX_Transfer; 00112 // Fill in all the fields of to these structures 00113 I2Cx_InitStructure.I2C_Timing = 0X50321312; 00114 I2Cx_InitStructure.I2C_Mode = I2C_Mode_I2C; 00115 I2Cx_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Disable; 00116 ..... 00117 TX_Transfer.pbBuffer = 0; 00118 TX_Transfer.wNumData = 0; 00119 ..... 00120 RX_Transfer.pbBuffer = 0; 00121 RX_Transfer.wNumData = 0; 00122 ..... 00123 // Use these structures and fill all fields of I2C1_DevStructure. 00124 I2C1_DevStructure.CPAL_Dev = CPAL_I2C1; 00125 I2C1_DevStructure.CPAL_Direction = CPAL_DIRECTION_TXRX; 00126 I2C1_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE; 00127 I2C1_DevStructure.wCPAL_Options = CPAL_OPT_DMATX_TCIT | CPAL_OPT_DMATX_HTIT ; 00128 ..... 00129 I2C1_DevStructure.pCPAL_TransferTx = &TX_Transfer; 00130 I2C1_DevStructure.pCPAL_TransferRx = &RX_Transfer; 00131 I2C1_DevStructure.pCPAL_I2C_Struct = &I2C1_InitStructure; 00132 ... 00133 I2C1_DevStructure.wCPAL_State = CPAL_STATE_DISABLED; 00134 .... 00135 CPAL_I2C_Init(&I2C1_DevStructure); 00136 00137 -2- DEVICE CONFIGURATION 00138 Call the function CPAL_PPP_Init() to configure the selected device with the selected configuration by calling 00139 CPAL_PPP_Init(). This function also enables device clock and initialize all related peripherals ( GPIO, DMA , IT and NVIC ). 00140 This function tests on CPAL_State, if it is equal to CPAL_STATE_BUSY it exit, otherwise device initialization is 00141 performed and CPAL_State is set to CPAL_STATE_READY. 00142 This function returns CPAL_PASS state when the operation is correctly performed, or CPAL_FAIL when the current state of the 00143 device doesn't allow configuration (ie. state different from READY, DISABLED or ERROR). 00144 After calling this function, you may check on the new state of device, when it is equal to CPAL_STATE_READY, Transfer operations 00145 can be started, otherwise you can call CPAL_PPP_DeInit() to deinitialize device and call CPAL_PPP_Init() once again. 00146 00147 -3- READ / WRITE OPERATIONS 00148 Call the function CPAL_PPP_Write() or CPAL_PPP_Read() to perform transfer operations. 00149 These functions handle communication events using device event interrupts (independently of programming model used: DMA, 00150 Interrupt). These functions start preparing communication (send start condition, send salve address in case of 00151 master mode ...) if connection is established between devices CPAL_State is set CPAL_STATE_BUSY_XX and data transfer starts. 00152 By default, Error interrupts are enabled to manage device errors (Error interrupts can be disabled by affecting 00153 CPAL_OPT_I2C_ERRIT_DISABLE to wCPAL_Options). When transfer is completed successfully, CPAL_State is set to CPAL_STATE_READY 00154 and another operation can be started. 00155 These functions return CPAL_PASS if the current state of the device allows starting a new operation and the operation is correctly 00156 started (but not finished). It returns CPAL_FAIL when the state of the device doesn't allow starting a new communication (ie. 00157 BUSY, DISABLED, ERROR) or when an error occurs during operation start. 00158 Once operation is started, user application may perform other tasks while CPAL is sending/receiving data on device through interrupt 00159 or DMA. 00160 00161 -4- DEVICE DEINITIALIZATION 00162 When transfer operations are finished, you may call CPAL_PPP_DeInit() to disable PPPx device and related resources 00163 ( GPIO, DMA , IT and NVIC). CPAL_State is then set to CPAL_STATE_DISABLED by this function. 00164 00165 00166 00167 ------ Callbacks are routines that let you insert your own code in different stages of communication and for handling 00168 device errors. Their prototypes are declared by the CPAL library (if the relative define in this stm32f0xx_i2c_cpal_conf.h is enabled) 00169 but their body is not implemented by CPAL library. It may be done by user when needed. 00170 There are three types of Callbacks: Transfer User Callbacks, Error User Callbacks and Timeout User Callbacks: 00171 00172 -a- Transfer User Callbacks : 00173 00174 ** CPAL_I2C_TX_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00175 This function is called before sending data when Interrupt Programming Model is selected. 00176 00177 ** CPAL_I2C_RX_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00178 This function is called after receiving data when Interrupt Programming Model is selected. 00179 00180 ** CPAL_I2C_TXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00181 ** CPAL_I2C_RXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00182 These functions are called when a transfer is complete when using Interrupt programming model or DMA 00183 programming model. 00184 00185 ** CPAL_I2C_DMATXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00186 ** CPAL_I2C_DMATXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00187 These functions are called when Transfer complete Interrupt occurred in transmission/reception operation 00188 if DMA Programming Model is selected 00189 00190 ** CPAL_I2C_DMATXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00191 ** CPAL_I2C_DMARXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00192 These functions are called when Half transfer Interrupt occurred in transmission/reception operation 00193 if DMA Programming Model is selected. 00194 00195 ** CPAL_I2C_DMATXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00196 ** CPAL_I2C_DMARXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00197 These functions are called when a transfer error Interrupt occurred in transmission/reception operation 00198 if DMA Programming Model is selected. 00199 00200 ** CPAL_I2C_GENCALL_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00201 This function is called when an Address Event interrupt occurred and General Call Address Flag is set 00202 (available in Slave mode only and when the option CPAL_OPT_I2C_GENCALL is enabled). 00203 00204 ** CPAL_I2C_DUALF_UserCallback(CPAL_InitTypeDef* pDevInitStruct) 00205 This function is called when an Address Event interrupt occurred and Dual Address Flag is set 00206 (available in Slave mode only and when the option CPAL_OPT_I2C_DUALADDR is enabled). 00207 00208 00209 -b- Error User Callbacks : 00210 00211 ** CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t Device_Error) 00212 This function is called either when an Error Interrupt occurred (If Error Interrupts enabled) or after 00213 a read or write operations to handle device errors (If Error Interrupts disabled). This callback 00214 can be used to handle all device errors. It is available only when the define USE_SINGLE_ERROR_CALLBACK 00215 is enabled (Section 5). 00216 00217 ** CPAL_I2C_BERR_UserCallback(CPAL_DevTypeDef pDevInstance) 00218 This function is called either when a Bus Error Interrupt occurred (If Error Interrupts enabled) or 00219 after a read or write operations to handle this error (If Error Interrupts disabled). This callback is 00220 available only when USE_MULTIPLE_ERROR_CALLBACK is enabled (Section 5). 00221 00222 ** CPAL_I2C_ARLO_UserCallback(CPAL_DevTypeDef pDevInstance) 00223 This function is called either when an Arbitration Lost Interrupt occurred (If Error Interrupts 00224 enabled) or after a read or write operations to handle this error (If Error Interrupts disabled). 00225 00226 ** CPAL_I2C_OVR_UserCallback(CPAL_DevTypeDef pDevInstance) 00227 This function is called either when an Overrun Interrupt occurred (If Error Interrupts enabled) or 00228 after a read or write operations to handle this error (If Error Interrupts disabled). This callback is 00229 available only when USE_MULTIPLE_ERROR_CALLBACK is enabled (Section 5). 00230 00231 ** CPAL_I2C_AF_UserCallback(CPAL_DevTypeDef pDevInstance) 00232 This function is called either when an Acknowledge Failure Interrupt occurred (If Error Interrupts 00233 enabled) or after a read or write operations to handle this error (If Error Interrupts disabled). 00234 This callback is available only when USE_MULTIPLE_ERROR_CALLBACK is enabled (Section 5). 00235 00236 00237 -c- Timeout User Callbacks : 00238 ** CPAL_TIMEOUT_UserCallback(void) 00239 This function is called when a Timeout occurred in communication. 00240 00241 ** CPAL_TIMEOUT_INIT() 00242 This function allows to configure and enable the counting peripheral/function (ie. SysTick Timer) 00243 It is called into all CPAL_PPP_Init() functions. 00244 00245 ** CPAL_TIMEOUT_DEINIT() 00246 This function allow to free the resources of counting peripheral/function and stop the count. 00247 (ie. disable the SysTick timer and its interrupt). 00248 00249 ** CPAL_PPP_TIMEOUT_Manager() 00250 WARNING: DO NOT IMPLEMENT THIS FUNCTION (already implemented in CPAL drivers) 00251 This function is already implemented in the CPAL drivers (stm32f0xx_i2c_cpal.c file). It should be called periodically 00252 (using the count mechanism interrupt for example). This function checks all PPP devices and 00253 manages timeout conditions. In case of timeout occurring, this function calls the 00254 CPAL_TIMEOUT_UserCallback() function that may be implemented by user to manage the cases of 00255 timeout errors (ie. reset the device/microcontroller...). 00256 In order to facilitate implementation, this function (instead to be called periodically by user 00257 application), may be mapped directly to a periodic event/interrupt: 00258 Example: 00259 #define CPAL_I2C_TIMEOUT_Manager SysTick_Handler 00260 00261 ** Note ** : when mapping CPAL_I2C_TIMEOUT_Manager to a periodic event/interrupt, the prototype 00262 of this event/interrupt should be added. Here below an example when SysTick_Handler 00263 is used to handle timeout mechanism : 00264 #ifndef CPAL_I2C_TIMEOUT_Manager 00265 void CPAL_I2C_TIMEOUT_Manager(void); 00266 #else 00267 void SysTick_Handler(void); 00268 #endif 00269 00270 To implement Transfer and Error Callbacks, you should comment relative defines in Section 4 and implement Callback function (body) into 00271 your application (their prototypes are declared in stm32f0xx_i2c_cpal.h file). 00272 00273 Example: How to implement CPAL_I2C_TX_UserCallback() callback: 00274 00275 -1- Comment the relative define in this file : 00276 //#define CPAL_I2C_TX_UserCallback (void) 00277 00278 -2- Add CPAL_I2C_TX_UserCallback code source in application file ( example : main.c ) 00279 void CPAL_I2C_TX_UserCallback (CPAL_InitTypeDef* pDevInitStruct) 00280 { 00281 // 00282 // user code 00283 // 00284 } 00285 00286 There are two types of Error Callbacks : 00287 -1- Single Error Callback : Only one Callback is used to manage all device errors. 00288 -2- Multiple Error Callback : Each device error is managed by its own separate Callback. 00289 00290 Example of using CPAL_I2C_BERR_UserCallback : 00291 00292 -1- Select Multiple Error Callback type : 00293 //#define USE_SINGLE_ERROR_CALLBACK 00294 #define USE_MULTIPLE_ERROR_CALLBACK 00295 00296 -2- Comment define relative to CPAL_I2C_BERR_UserCallback in stm32f0xx_i2c_cpal_conf.h file: 00297 //#define CPAL_I2C_BERR_UserCallback (void) 00298 00299 -3- Add CPAL_I2C_BERR_UserCallback code source in application file ( example: main.c ) 00300 void CPAL_I2C_BERR_UserCallback (CPAL_DevTypeDef pDevInstance) 00301 { 00302 // 00303 // user code 00304 // 00305 } 00306 00307 ------ The driver API functions Prototypes are in stm32f0xx_i2c_cpal.h file. 00308 00309 *********END OF User Notes***************************************************************************************************************/ 00310 00311 00312 00313 00314 /*======================================================================================================================================= 00315 CPAL Firmware Functionality Configuration 00316 =========================================================================================================================================*/ 00317 00318 /*-----------------------------------------------------------------------------------------------------------------------*/ 00319 /*-----------------------------------------------------------------------------------------------------------------------*/ 00320 00321 /* -- Section 1 : **** I2Cx Device Selection **** 00322 00323 Description: This section provide an easy way to select I2Cx devices in user application. 00324 Choosing device allows to save memory resources. 00325 If you need I2C1 device, uncomment relative define: #define CPAL_USE_I2C1. 00326 All available I2Cx device can be used at the same time. 00327 At least one I2C device should be selected.*/ 00328 00329 #define CPAL_USE_I2C1 /*<! Uncomment to use I2C1 device */ 00330 /*#define CPAL_USE_I2C2*/ /*<! Uncomment to use I2C2 device */ 00331 00332 /*-----------------------------------------------------------------------------------------------------------------------*/ 00333 /*-----------------------------------------------------------------------------------------------------------------------*/ 00334 00335 /* -- Section 2 : **** Transfer Options Configuration **** 00336 00337 Description: This section allows user to enable/disable some Transfer Options. The benefits of these 00338 defines is to minimize the size of the source code */ 00339 00340 /* Enable the use of Master Mode */ 00341 #define CPAL_I2C_MASTER_MODE 00342 /* This define must be uncommented for this example. In this example I2C1 device 00343 can be used as master to communicate other Board (Slave)*/ 00344 00345 /* Enable the use of Slave Mode */ 00346 #define CPAL_I2C_SLAVE_MODE 00347 /* This define must be uncommented for this example. In this example I2C1 device 00348 can be used as slave to communicate other Board (Master)*/ 00349 00350 /* Enable the use of DMA Programming Model */ 00351 #define CPAL_I2C_DMA_PROGMODEL 00352 /* Uncomment this define and keep "CPAL_I2C_IT_PROGMODEL" define commented to use DMA 00353 Programming Model */ 00354 00355 /* Enable the use of IT Programming Model */ 00356 //#define CPAL_I2C_IT_PROGMODEL 00357 /* Uncomment this define and keep "CPAL_I2C_DMA_PROGMODEL" define commented to use Interrupt 00358 Programming Model */ 00359 00360 /* !!!! These following defines are available only when CPAL_I2C_MASTER_MODE is enabled !!!! */ 00361 00362 /* Enable the use of 10Bit Addressing Mode */ 00363 #define CPAL_I2C_10BIT_ADDR_MODE 00364 00365 /* Enable the use of Memory Addressing Mode */ 00366 /*#define CPAL_I2C_MEM_ADDR*/ 00367 00368 /* Enable the use of 16Bit Address memory register option */ 00369 /*#define CPAL_16BIT_REG_OPTION*/ 00370 00371 00372 /*------------------------------------------------------------------------------------------------------------------------------*/ 00373 /*------------------------------------------------------------------------------------------------------------------------------*/ 00374 00375 /* -- Section 3 : **** UserCallbacks Selection and Configuration **** 00376 00377 Description: This section provides an easy way to enable UserCallbacks and select type of Error UserCallbacks. 00378 By default, All UserCallbacks are disabled (UserCallbacks are defined as void functions). 00379 To implement a UserCallbacks in your application, comment the relative define and 00380 implement the callback body in your application file.*/ 00381 00382 00383 /* Error UserCallbacks Type : Uncomment to select UserCallbacks type. One type must be selected */ 00384 /* Note : if Error UserCallbacks are not used the two following defines must be commented 00385 00386 WARNING: These two defines are EXCLUSIVE, only one define should be uncommented ! 00387 */ 00388 #define USE_SINGLE_ERROR_CALLBACK /*<! select single UserCallbacks type */ 00389 //#define USE_MULTIPLE_ERROR_CALLBACK /*<! select multiple UserCallbacks type */ 00390 00391 /* Error UserCallbacks : To use an Error UserCallback comment the relative define */ 00392 00393 /* Single Error Callback */ 00394 /*#define CPAL_I2C_ERR_UserCallback (void)*/ 00395 00396 /* Multiple Error Callback */ 00397 #define CPAL_I2C_BERR_UserCallback (void) 00398 #define CPAL_I2C_ARLO_UserCallback (void) 00399 #define CPAL_I2C_OVR_UserCallback (void) 00400 #define CPAL_I2C_AF_UserCallback (void) 00401 00402 /* Transfer UserCallbacks : To use a Transfer callback comment the relative define */ 00403 #define CPAL_I2C_TX_UserCallback (void) 00404 #define CPAL_I2C_RX_UserCallback (void) 00405 /*#define CPAL_I2C_TXTC_UserCallback (void)*/ 00406 /*#define CPAL_I2C_RXTC_UserCallback (void)*/ 00407 00408 /* DMA Transfer UserCallbacks : To use a DMA Transfer UserCallbacks comment the relative define */ 00409 #define CPAL_I2C_DMATXTC_UserCallback (void) 00410 #define CPAL_I2C_DMATXHT_UserCallback (void) 00411 #define CPAL_I2C_DMATXTE_UserCallback (void) 00412 #define CPAL_I2C_DMARXTC_UserCallback (void) 00413 #define CPAL_I2C_DMARXHT_UserCallback (void) 00414 #define CPAL_I2C_DMARXTE_UserCallback (void) 00415 00416 /* Address Mode UserCallbacks : To use an Address Mode UserCallbacks comment the relative define */ 00417 #define CPAL_I2C_GENCALL_UserCallback (void) 00418 #define CPAL_I2C_DUALF_UserCallback (void) 00419 00420 /* CriticalSectionCallback : Call User callback for critical section (should typically disable interrupts) */ 00421 #define CPAL_EnterCriticalSection_UserCallback __disable_irq 00422 #define CPAL_ExitCriticalSection_UserCallback __enable_irq 00423 00424 /*------------------------------------------------------------------------------------------------------------------------------------------------*/ 00425 /*------------------------------------------------------------------------------------------------------------------------------------------------*/ 00426 00427 /* -- Section 4 : **** Configure Timeout method, TimeoutCallback **** 00428 00429 Description: This section allows you to implement your own Timeout Procedure. 00430 By default Timeout procedure is implemented with Systick timer and 00431 CPAL_I2C_TIMEOUT_Manager is defined as SysTick_Handler. 00432 */ 00433 00434 00435 #define _CPAL_TIMEOUT_INIT() SysTick_Config((SystemCoreClock / 1000));\ 00436 NVIC_SetPriority (SysTick_IRQn, 0) 00437 /*<! Configure and enable the systick timer 00438 to generate an interrupt when counter value 00439 reaches 0. In the Systick interrupt handler 00440 the Timeout Error function is called. Time base is 1 ms */ 00441 00442 #define _CPAL_TIMEOUT_DEINIT() SysTick->CTRL = 0 /*<! Disable the systick timer */ 00443 00444 00445 #define CPAL_I2C_TIMEOUT_Manager SysTick_Handler /*<! This callback is used to handle Timeout error. 00446 When a timeout occurs CPAL_TIMEOUT_UserCallback 00447 is called to handle this error */ 00448 #ifndef CPAL_I2C_TIMEOUT_Manager 00449 void CPAL_I2C_TIMEOUT_Manager(void); 00450 #else 00451 void SysTick_Handler(void); 00452 #endif /* CPAL_I2C_TIMEOUT_Manager */ 00453 00454 /*#define CPAL_TIMEOUT_UserCallback (void) */ /*<! Comment this line and implement the callback body in your 00455 application in order to use the Timeout Callback. 00456 It is strongly advised to implement this callback, since it 00457 is the only way to manage timeout errors.*/ 00458 00459 /* Maximum Timeout values for each communication operation (preferably, Time base should be 1 Millisecond). 00460 The exact maximum value is the sum of event timeout value and the CPAL_I2C_TIMEOUT_MIN value defined below */ 00461 #define CPAL_I2C_TIMEOUT_TC 5 00462 #define CPAL_I2C_TIMEOUT_TCR 5 00463 #define CPAL_I2C_TIMEOUT_TXIS 2 00464 #define CPAL_I2C_TIMEOUT_BUSY 2 00465 00466 /* DO NOT MODIFY THESE VALUES ---------------------------------------------------------*/ 00467 #define CPAL_I2C_TIMEOUT_DEFAULT ((uint32_t)0xFFFFFFFF) 00468 #define CPAL_I2C_TIMEOUT_MIN ((uint32_t)0x00000001) 00469 #define CPAL_I2C_TIMEOUT_DETECTED ((uint32_t)0x00000000) 00470 00471 /*-----------------------------------------------------------------------------------------------------------------------*/ 00472 /*-----------------------------------------------------------------------------------------------------------------------*/ 00473 00474 /* -- Section 5 : **** Configure Interrupt Priority Offset **** 00475 00476 Description: This section allows user to configure Interrupt Priority Offset. 00477 By default Priority Offset of I2Cx device (ERR, EVT, DMA) are set to 0 */ 00478 00479 /*-----------Interrupt Priority Offset-------------*/ 00480 00481 /* This defines can be used to decrease the Level of Interrupt Priority for I2Cx Device (ERR, EVT, DMA_TX, DMA_RX). 00482 The value of I2Cx_IT_OFFSET_SUBPRIO is added to I2Cx_IT_XXX_SUBPRIO and the value of I2Cx_IT_OFFSET_PREPRIO 00483 is added to I2Cx_IT_XXX_PREPRIO (XXX: ERR, EVT, DMATX, DMARX). 00484 I2Cx Interrupt Priority are defined in stm32f0xx_i2c_cpal_hal.h file in Section 3 */ 00485 00486 #define I2C1_IT_OFFSET_SUBPRIO 0 /* I2C1 SUB-PRIORITY Offset */ 00487 #define I2C1_IT_OFFSET_PREPRIO 0 /* I2C1 PREEMPTION PRIORITY Offset */ 00488 00489 #define I2C2_IT_OFFSET_SUBPRIO 0 /* I2C2 SUB-PRIORITY Offset */ 00490 #define I2C2_IT_OFFSET_PREPRIO 0 /* I2C2 PREEMPTION PRIORITY Offset */ 00491 00492 /*-----------------------------------------------------------------------------------------------------------------------*/ 00493 /*-----------------------------------------------------------------------------------------------------------------------*/ 00494 00495 /* -- Section 6 : **** CPAL DEBUG Configuration **** 00496 00497 Description: This section allow user to enable or disable CPAL Debug option. Enabling this option provide 00498 to user an easy way to debug the application code. This option use CPAL_LOG Macro that integrate 00499 printf function. User can retarget printf function to USART ( use hyperterminal), LCD Screen 00500 on ST Eval Board or development toolchain debugger. 00501 In this example, the log is managed through printf function routed to USART peripheral and allowing 00502 to display messages on Hyperterminal-like terminals. This is performed through redefining the 00503 function PUTCHAR_PROTOTYPE (depending on the compiler) as follows: 00504 00505 #ifdef __GNUC__ 00506 // With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf 00507 // set to 'Yes') calls __io_putchar() 00508 #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) 00509 #else 00510 #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) 00511 #endif 00512 00513 WARNING Be aware that enabling this feature may slow down the communication process, increase the code size 00514 significantly, and may in some cases cause communication errors (when print/display mechanism is too slow)*/ 00515 00516 00517 /* To Enable CPAL_DEBUG Option Uncomment the define below */ 00518 /* #define CPAL_DEBUG */ 00519 00520 #ifdef CPAL_DEBUG 00521 #define CPAL_LOG(Str) printf(Str) 00522 #include <stdio.h> /* This header file must be included when using CPAL_DEBUG option */ 00523 #else 00524 #define CPAL_LOG(Str) ((void)0) 00525 #endif /* CPAL_DEBUG */ 00526 00527 00528 /*-----------------------------------------------------------------------------------------------------------------------*/ 00529 /*-----------------------------------------------------------------------------------------------------------------------*/ 00530 00531 /*********END OF CPAL Firmware Functionality Configuration****************************************************************/ 00532 00533 /* Exported macro ------------------------------------------------------------*/ 00534 /* Exported functions ------------------------------------------------------- */ 00535 00536 #ifdef __cplusplus 00537 } 00538 #endif 00539 00540 #endif /* __STM32F0XX_I2C_CPAL_CONF_H */ 00541 00542 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/