Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 6 | ||
|---|---|---|---|
| Line 225... | Line 225... | ||
| 225 | ============================================= |
225 | ============================================= |
| 226 | [..] |
226 | [..] |
| 227 | 227 | ||
| 228 | The compilation flag USE_HAL_ADC_REGISTER_CALLBACKS, when set to 1, |
228 | The compilation flag USE_HAL_ADC_REGISTER_CALLBACKS, when set to 1, |
| 229 | allows the user to configure dynamically the driver callbacks. |
229 | allows the user to configure dynamically the driver callbacks. |
| 230 | Use Functions @ref HAL_ADC_RegisterCallback() |
230 | Use Functions HAL_ADC_RegisterCallback() |
| 231 | to register an interrupt callback. |
231 | to register an interrupt callback. |
| 232 | [..] |
232 | [..] |
| 233 | 233 | ||
| 234 | Function @ref HAL_ADC_RegisterCallback() allows to register following callbacks: |
234 | Function HAL_ADC_RegisterCallback() allows to register following callbacks: |
| 235 | (+) ConvCpltCallback : ADC conversion complete callback |
235 | (+) ConvCpltCallback : ADC conversion complete callback |
| 236 | (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback |
236 | (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback |
| 237 | (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback |
237 | (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback |
| 238 | (+) ErrorCallback : ADC error callback |
238 | (+) ErrorCallback : ADC error callback |
| 239 | (+) MspInitCallback : ADC Msp Init callback |
239 | (+) MspInitCallback : ADC Msp Init callback |
| 240 | (+) MspDeInitCallback : ADC Msp DeInit callback |
240 | (+) MspDeInitCallback : ADC Msp DeInit callback |
| 241 | This function takes as parameters the HAL peripheral handle, the Callback ID |
241 | This function takes as parameters the HAL peripheral handle, the Callback ID |
| 242 | and a pointer to the user callback function. |
242 | and a pointer to the user callback function. |
| 243 | [..] |
243 | [..] |
| 244 | 244 | ||
| 245 | Use function @ref HAL_ADC_UnRegisterCallback to reset a callback to the default |
245 | Use function HAL_ADC_UnRegisterCallback to reset a callback to the default |
| 246 | weak function. |
246 | weak function. |
| 247 | [..] |
247 | [..] |
| 248 | 248 | ||
| 249 | @ref HAL_ADC_UnRegisterCallback takes as parameters the HAL peripheral handle, |
249 | HAL_ADC_UnRegisterCallback takes as parameters the HAL peripheral handle, |
| 250 | and the Callback ID. |
250 | and the Callback ID. |
| 251 | This function allows to reset following callbacks: |
251 | This function allows to reset following callbacks: |
| 252 | (+) ConvCpltCallback : ADC conversion complete callback |
252 | (+) ConvCpltCallback : ADC conversion complete callback |
| 253 | (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback |
253 | (+) ConvHalfCpltCallback : ADC conversion DMA half-transfer callback |
| 254 | (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback |
254 | (+) LevelOutOfWindowCallback : ADC analog watchdog 1 callback |
| 255 | (+) ErrorCallback : ADC error callback |
255 | (+) ErrorCallback : ADC error callback |
| 256 | (+) MspInitCallback : ADC Msp Init callback |
256 | (+) MspInitCallback : ADC Msp Init callback |
| 257 | (+) MspDeInitCallback : ADC Msp DeInit callback |
257 | (+) MspDeInitCallback : ADC Msp DeInit callback |
| 258 | [..] |
258 | [..] |
| 259 | 259 | ||
| 260 | By default, after the @ref HAL_ADC_Init() and when the state is @ref HAL_ADC_STATE_RESET |
260 | By default, after the HAL_ADC_Init() and when the state is HAL_ADC_STATE_RESET |
| 261 | all callbacks are set to the corresponding weak functions: |
261 | all callbacks are set to the corresponding weak functions: |
| 262 | examples @ref HAL_ADC_ConvCpltCallback(), @ref HAL_ADC_ErrorCallback(). |
262 | examples HAL_ADC_ConvCpltCallback(), HAL_ADC_ErrorCallback(). |
| 263 | Exception done for MspInit and MspDeInit functions that are |
263 | Exception done for MspInit and MspDeInit functions that are |
| 264 | reset to the legacy weak functions in the @ref HAL_ADC_Init()/ @ref HAL_ADC_DeInit() only when |
264 | reset to the legacy weak functions in the HAL_ADC_Init()/ HAL_ADC_DeInit() only when |
| 265 | these callbacks are null (not registered beforehand). |
265 | these callbacks are null (not registered beforehand). |
| 266 | [..] |
266 | [..] |
| 267 | 267 | ||
| 268 | If MspInit or MspDeInit are not null, the @ref HAL_ADC_Init()/ @ref HAL_ADC_DeInit() |
268 | If MspInit or MspDeInit are not null, the HAL_ADC_Init()/ HAL_ADC_DeInit() |
| 269 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state. |
269 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state. |
| 270 | [..] |
270 | [..] |
| 271 | 271 | ||
| 272 | Callbacks can be registered/unregistered in @ref HAL_ADC_STATE_READY state only. |
272 | Callbacks can be registered/unregistered in HAL_ADC_STATE_READY state only. |
| 273 | Exception done MspInit/MspDeInit functions that can be registered/unregistered |
273 | Exception done MspInit/MspDeInit functions that can be registered/unregistered |
| 274 | in @ref HAL_ADC_STATE_READY or @ref HAL_ADC_STATE_RESET state, |
274 | in HAL_ADC_STATE_READY or HAL_ADC_STATE_RESET state, |
| 275 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
275 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
| 276 | [..] |
276 | [..] |
| 277 | 277 | ||
| 278 | Then, the user first registers the MspInit/MspDeInit user callbacks |
278 | Then, the user first registers the MspInit/MspDeInit user callbacks |
| 279 | using @ref HAL_ADC_RegisterCallback() before calling @ref HAL_ADC_DeInit() |
279 | using HAL_ADC_RegisterCallback() before calling HAL_ADC_DeInit() |
| 280 | or @ref HAL_ADC_Init() function. |
280 | or HAL_ADC_Init() function. |
| 281 | [..] |
281 | [..] |
| 282 | 282 | ||
| 283 | When the compilation flag USE_HAL_ADC_REGISTER_CALLBACKS is set to 0 or |
283 | When the compilation flag USE_HAL_ADC_REGISTER_CALLBACKS is set to 0 or |
| 284 | not defined, the callback registration feature is not available and all callbacks |
284 | not defined, the callback registration feature is not available and all callbacks |
| 285 | are set to the corresponding weak functions. |
285 | are set to the corresponding weak functions. |
| Line 1190... | Line 1190... | ||
| 1190 | /* Check if timeout is disabled (set to infinite wait) */ |
1190 | /* Check if timeout is disabled (set to infinite wait) */ |
| 1191 | if(Timeout != HAL_MAX_DELAY) |
1191 | if(Timeout != HAL_MAX_DELAY) |
| 1192 | { |
1192 | { |
| 1193 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
1193 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
| 1194 | { |
1194 | { |
| - | 1195 | /* New check to avoid false timeout detection in case of preemption */ |
|
| - | 1196 | if(HAL_IS_BIT_CLR(hadc->Instance->ISR, tmp_Flag_EOC)) |
|
| - | 1197 | { |
|
| 1195 | /* Update ADC state machine to timeout */ |
1198 | /* Update ADC state machine to timeout */ |
| 1196 | SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT); |
1199 | SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT); |
| 1197 | 1200 | ||
| 1198 | /* Process unlocked */ |
1201 | /* Process unlocked */ |
| 1199 | __HAL_UNLOCK(hadc); |
1202 | __HAL_UNLOCK(hadc); |
| 1200 | 1203 | ||
| 1201 | return HAL_TIMEOUT; |
1204 | return HAL_TIMEOUT; |
| - | 1205 | } |
|
| 1202 | } |
1206 | } |
| 1203 | } |
1207 | } |
| 1204 | } |
1208 | } |
| 1205 | 1209 | ||
| 1206 | /* Update ADC state machine */ |
1210 | /* Update ADC state machine */ |
| Line 1280... | Line 1284... | ||
| 1280 | /* Check if timeout is disabled (set to infinite wait) */ |
1284 | /* Check if timeout is disabled (set to infinite wait) */ |
| 1281 | if(Timeout != HAL_MAX_DELAY) |
1285 | if(Timeout != HAL_MAX_DELAY) |
| 1282 | { |
1286 | { |
| 1283 | if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout)) |
1287 | if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout)) |
| 1284 | { |
1288 | { |
| - | 1289 | /* New check to avoid false timeout detection in case of preemption */ |
|
| - | 1290 | if(__HAL_ADC_GET_FLAG(hadc, EventType) == RESET) |
|
| - | 1291 | { |
|
| 1285 | /* Update ADC state machine to timeout */ |
1292 | /* Update ADC state machine to timeout */ |
| 1286 | SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT); |
1293 | SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT); |
| 1287 | 1294 | ||
| 1288 | /* Process unlocked */ |
1295 | /* Process unlocked */ |
| 1289 | __HAL_UNLOCK(hadc); |
1296 | __HAL_UNLOCK(hadc); |
| 1290 | 1297 | ||
| 1291 | return HAL_TIMEOUT; |
1298 | return HAL_TIMEOUT; |
| - | 1299 | } |
|
| 1292 | } |
1300 | } |
| 1293 | } |
1301 | } |
| 1294 | } |
1302 | } |
| 1295 | 1303 | ||
| 1296 | switch(EventType) |
1304 | switch(EventType) |
| Line 1581... | Line 1589... | ||
| 1581 | /* Disable ADC DMA (ADC DMA configuration ADC_CFGR_DMACFG is kept) */ |
1589 | /* Disable ADC DMA (ADC DMA configuration ADC_CFGR_DMACFG is kept) */ |
| 1582 | hadc->Instance->CFGR1 &= ~ADC_CFGR1_DMAEN; |
1590 | hadc->Instance->CFGR1 &= ~ADC_CFGR1_DMAEN; |
| 1583 | 1591 | ||
| 1584 | /* Disable the DMA channel (in case of DMA in circular mode or stop while */ |
1592 | /* Disable the DMA channel (in case of DMA in circular mode or stop while */ |
| 1585 | /* while DMA transfer is on going) */ |
1593 | /* while DMA transfer is on going) */ |
| 1586 | tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); |
- | |
| 1587 | - | ||
| 1588 | /* Check if DMA channel effectively disabled */ |
- | |
| 1589 | if (tmp_hal_status != HAL_OK) |
1594 | if (hadc->DMA_Handle->State == HAL_DMA_STATE_BUSY) |
| 1590 | { |
1595 | { |
| - | 1596 | tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle); |
|
| - | 1597 | ||
| - | 1598 | /* Check if DMA channel effectively disabled */ |
|
| - | 1599 | if (tmp_hal_status != HAL_OK) |
|
| - | 1600 | { |
|
| 1591 | /* Update ADC state machine to error */ |
1601 | /* Update ADC state machine to error */ |
| 1592 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); |
1602 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_DMA); |
| - | 1603 | } |
|
| 1593 | } |
1604 | } |
| 1594 | 1605 | ||
| 1595 | /* Disable ADC overrun interrupt */ |
1606 | /* Disable ADC overrun interrupt */ |
| 1596 | __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); |
1607 | __HAL_ADC_DISABLE_IT(hadc, ADC_IT_OVR); |
| 1597 | 1608 | ||
| Line 2225... | Line 2236... | ||
| 2225 | /* Wait for ADC effectively enabled */ |
2236 | /* Wait for ADC effectively enabled */ |
| 2226 | while(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_RDY) == RESET) |
2237 | while(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_RDY) == RESET) |
| 2227 | { |
2238 | { |
| 2228 | if((HAL_GetTick() - tickstart) > ADC_ENABLE_TIMEOUT) |
2239 | if((HAL_GetTick() - tickstart) > ADC_ENABLE_TIMEOUT) |
| 2229 | { |
2240 | { |
| - | 2241 | /* New check to avoid false timeout detection in case of preemption */ |
|
| - | 2242 | if(__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_RDY) == RESET) |
|
| - | 2243 | { |
|
| 2230 | /* Update ADC state machine to error */ |
2244 | /* Update ADC state machine to error */ |
| 2231 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); |
2245 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); |
| 2232 | 2246 | ||
| 2233 | /* Set ADC error code to ADC IP internal error */ |
2247 | /* Set ADC error code to ADC IP internal error */ |
| 2234 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); |
2248 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); |
| 2235 | 2249 | ||
| 2236 | return HAL_ERROR; |
2250 | return HAL_ERROR; |
| - | 2251 | } |
|
| 2237 | } |
2252 | } |
| 2238 | } |
- | |
| 2239 | 2253 | } |
|
| 2240 | } |
2254 | } |
| 2241 | 2255 | ||
| 2242 | /* Return HAL status */ |
2256 | /* Return HAL status */ |
| 2243 | return HAL_OK; |
2257 | return HAL_OK; |
| 2244 | } |
2258 | } |
| Line 2282... | Line 2296... | ||
| 2282 | 2296 | ||
| 2283 | while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADEN)) |
2297 | while(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADEN)) |
| 2284 | { |
2298 | { |
| 2285 | if((HAL_GetTick() - tickstart) > ADC_DISABLE_TIMEOUT) |
2299 | if((HAL_GetTick() - tickstart) > ADC_DISABLE_TIMEOUT) |
| 2286 | { |
2300 | { |
| - | 2301 | /* New check to avoid false timeout detection in case of preemption */ |
|
| - | 2302 | if(HAL_IS_BIT_SET(hadc->Instance->CR, ADC_CR_ADEN)) |
|
| - | 2303 | { |
|
| 2287 | /* Update ADC state machine to error */ |
2304 | /* Update ADC state machine to error */ |
| 2288 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); |
2305 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); |
| 2289 | 2306 | ||
| 2290 | /* Set ADC error code to ADC IP internal error */ |
2307 | /* Set ADC error code to ADC IP internal error */ |
| 2291 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); |
2308 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); |
| 2292 | 2309 | ||
| 2293 | return HAL_ERROR; |
2310 | return HAL_ERROR; |
| - | 2311 | } |
|
| 2294 | } |
2312 | } |
| 2295 | } |
2313 | } |
| 2296 | } |
2314 | } |
| 2297 | 2315 | ||
| 2298 | /* Return HAL status */ |
2316 | /* Return HAL status */ |
| Line 2334... | Line 2352... | ||
| 2334 | 2352 | ||
| 2335 | while((hadc->Instance->CR & ADC_CR_ADSTART) != RESET) |
2353 | while((hadc->Instance->CR & ADC_CR_ADSTART) != RESET) |
| 2336 | { |
2354 | { |
| 2337 | if((HAL_GetTick() - tickstart) > ADC_STOP_CONVERSION_TIMEOUT) |
2355 | if((HAL_GetTick() - tickstart) > ADC_STOP_CONVERSION_TIMEOUT) |
| 2338 | { |
2356 | { |
| - | 2357 | /* New check to avoid false timeout detection in case of preemption */ |
|
| - | 2358 | if((hadc->Instance->CR & ADC_CR_ADSTART) != RESET) |
|
| - | 2359 | { |
|
| 2339 | /* Update ADC state machine to error */ |
2360 | /* Update ADC state machine to error */ |
| 2340 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); |
2361 | SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL); |
| 2341 | 2362 | ||
| 2342 | /* Set ADC error code to ADC IP internal error */ |
2363 | /* Set ADC error code to ADC IP internal error */ |
| 2343 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); |
2364 | SET_BIT(hadc->ErrorCode, HAL_ADC_ERROR_INTERNAL); |
| 2344 | 2365 | ||
| 2345 | return HAL_ERROR; |
2366 | return HAL_ERROR; |
| - | 2367 | } |
|
| 2346 | } |
2368 | } |
| 2347 | } |
2369 | } |
| 2348 | - | ||
| 2349 | } |
2370 | } |
| 2350 | 2371 | ||
| 2351 | /* Return HAL status */ |
2372 | /* Return HAL status */ |
| 2352 | return HAL_OK; |
2373 | return HAL_OK; |
| 2353 | } |
2374 | } |