Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_STM/TARGET_STM32L1/spi_api.c@189:f392fc9709a3, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 22:31:08 2019 +0000
- Revision:
- 189:f392fc9709a3
- Parent:
- 187:0387e8f68319
mbed library release version 165
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| <> | 149:156823d33999 | 1 | /* mbed Microcontroller Library | 
| <> | 149:156823d33999 | 2 | ******************************************************************************* | 
| <> | 149:156823d33999 | 3 | * Copyright (c) 2014, STMicroelectronics | 
| <> | 149:156823d33999 | 4 | * All rights reserved. | 
| <> | 149:156823d33999 | 5 | * | 
| <> | 149:156823d33999 | 6 | * Redistribution and use in source and binary forms, with or without | 
| <> | 149:156823d33999 | 7 | * modification, are permitted provided that the following conditions are met: | 
| <> | 149:156823d33999 | 8 | * | 
| <> | 149:156823d33999 | 9 | * 1. Redistributions of source code must retain the above copyright notice, | 
| <> | 149:156823d33999 | 10 | * this list of conditions and the following disclaimer. | 
| <> | 149:156823d33999 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, | 
| <> | 149:156823d33999 | 12 | * this list of conditions and the following disclaimer in the documentation | 
| <> | 149:156823d33999 | 13 | * and/or other materials provided with the distribution. | 
| <> | 149:156823d33999 | 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors | 
| <> | 149:156823d33999 | 15 | * may be used to endorse or promote products derived from this software | 
| <> | 149:156823d33999 | 16 | * without specific prior written permission. | 
| <> | 149:156823d33999 | 17 | * | 
| <> | 149:156823d33999 | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
| <> | 149:156823d33999 | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| <> | 149:156823d33999 | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
| <> | 149:156823d33999 | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
| <> | 149:156823d33999 | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
| <> | 149:156823d33999 | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
| <> | 149:156823d33999 | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
| <> | 149:156823d33999 | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
| <> | 149:156823d33999 | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| <> | 149:156823d33999 | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| <> | 149:156823d33999 | 28 | ******************************************************************************* | 
| <> | 149:156823d33999 | 29 | */ | 
| <> | 149:156823d33999 | 30 | #include "mbed_assert.h" | 
| <> | 149:156823d33999 | 31 | #include "mbed_error.h" | 
| <> | 149:156823d33999 | 32 | #include "spi_api.h" | 
| <> | 149:156823d33999 | 33 | |
| <> | 149:156823d33999 | 34 | #if DEVICE_SPI | 
| <> | 149:156823d33999 | 35 | |
| <> | 149:156823d33999 | 36 | #include "cmsis.h" | 
| <> | 149:156823d33999 | 37 | #include "pinmap.h" | 
| <> | 149:156823d33999 | 38 | #include "PeripheralPins.h" | 
| <> | 149:156823d33999 | 39 | |
| <> | 149:156823d33999 | 40 | |
| <> | 149:156823d33999 | 41 | #if DEVICE_SPI_ASYNCH | 
| AnnaBridge | 187:0387e8f68319 | 42 | #define SPI_S(obj) (( struct spi_s *)(&(obj->spi))) | 
| <> | 149:156823d33999 | 43 | #else | 
| AnnaBridge | 187:0387e8f68319 | 44 | #define SPI_S(obj) (( struct spi_s *)(obj)) | 
| <> | 149:156823d33999 | 45 | #endif | 
| <> | 149:156823d33999 | 46 | |
| <> | 149:156823d33999 | 47 | /* | 
| <> | 149:156823d33999 | 48 | * Only the frequency is managed in the family specific part | 
| <> | 149:156823d33999 | 49 | * the rest of SPI management is common to all STM32 families | 
| <> | 149:156823d33999 | 50 | */ | 
| AnnaBridge | 187:0387e8f68319 | 51 | int spi_get_clock_freq(spi_t *obj) | 
| AnnaBridge | 187:0387e8f68319 | 52 | { | 
| <> | 149:156823d33999 | 53 | struct spi_s *spiobj = SPI_S(obj); | 
| AnnaBridge | 187:0387e8f68319 | 54 | int spi_hz = 0; | 
| <> | 149:156823d33999 | 55 | |
| AnnaBridge | 187:0387e8f68319 | 56 | /* Get source clock depending on SPI instance */ | 
| <> | 149:156823d33999 | 57 | switch ((int)spiobj->spi) { | 
| <> | 149:156823d33999 | 58 | case SPI_1: | 
| AnnaBridge | 187:0387e8f68319 | 59 | /* SPI_1. Source CLK is PCKL2 */ | 
| AnnaBridge | 187:0387e8f68319 | 60 | spi_hz = HAL_RCC_GetPCLK2Freq(); | 
| AnnaBridge | 187:0387e8f68319 | 61 | break; | 
| AnnaBridge | 187:0387e8f68319 | 62 | case SPI_2: | 
| AnnaBridge | 184:08ed48f1de7f | 63 | #ifdef SPI_3 | 
| AnnaBridge | 184:08ed48f1de7f | 64 | case SPI_3: | 
| AnnaBridge | 184:08ed48f1de7f | 65 | #endif | 
| AnnaBridge | 187:0387e8f68319 | 66 | /* SPI_2, SPI_3. Source CLK is PCKL1 */ | 
| AnnaBridge | 187:0387e8f68319 | 67 | spi_hz = HAL_RCC_GetPCLK1Freq(); | 
| AnnaBridge | 187:0387e8f68319 | 68 | break; | 
| AnnaBridge | 187:0387e8f68319 | 69 | default: | 
| AnnaBridge | 187:0387e8f68319 | 70 | error("CLK: SPI instance not set"); | 
| <> | 149:156823d33999 | 71 | break; | 
| <> | 149:156823d33999 | 72 | } | 
| <> | 149:156823d33999 | 73 | return spi_hz; | 
| <> | 149:156823d33999 | 74 | } | 
| <> | 149:156823d33999 | 75 | |
| <> | 149:156823d33999 | 76 | #endif | 


