test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elijahsj 1:8a094db1347f 1 /* mbed Microcontroller Library
elijahsj 1:8a094db1347f 2 *******************************************************************************
elijahsj 1:8a094db1347f 3 * Copyright (c) 2015, STMicroelectronics
elijahsj 1:8a094db1347f 4 * All rights reserved.
elijahsj 1:8a094db1347f 5 *
elijahsj 1:8a094db1347f 6 * Redistribution and use in source and binary forms, with or without
elijahsj 1:8a094db1347f 7 * modification, are permitted provided that the following conditions are met:
elijahsj 1:8a094db1347f 8 *
elijahsj 1:8a094db1347f 9 * 1. Redistributions of source code must retain the above copyright notice,
elijahsj 1:8a094db1347f 10 * this list of conditions and the following disclaimer.
elijahsj 1:8a094db1347f 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
elijahsj 1:8a094db1347f 12 * this list of conditions and the following disclaimer in the documentation
elijahsj 1:8a094db1347f 13 * and/or other materials provided with the distribution.
elijahsj 1:8a094db1347f 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
elijahsj 1:8a094db1347f 15 * may be used to endorse or promote products derived from this software
elijahsj 1:8a094db1347f 16 * without specific prior written permission.
elijahsj 1:8a094db1347f 17 *
elijahsj 1:8a094db1347f 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
elijahsj 1:8a094db1347f 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
elijahsj 1:8a094db1347f 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
elijahsj 1:8a094db1347f 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
elijahsj 1:8a094db1347f 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
elijahsj 1:8a094db1347f 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
elijahsj 1:8a094db1347f 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
elijahsj 1:8a094db1347f 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
elijahsj 1:8a094db1347f 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
elijahsj 1:8a094db1347f 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
elijahsj 1:8a094db1347f 28 *******************************************************************************
elijahsj 1:8a094db1347f 29 */
elijahsj 1:8a094db1347f 30 #include "mbed_assert.h"
elijahsj 1:8a094db1347f 31 #include "mbed_error.h"
elijahsj 1:8a094db1347f 32 #include "spi_api.h"
elijahsj 1:8a094db1347f 33
elijahsj 1:8a094db1347f 34 #if DEVICE_SPI
elijahsj 1:8a094db1347f 35
elijahsj 1:8a094db1347f 36 #include "cmsis.h"
elijahsj 1:8a094db1347f 37 #include "pinmap.h"
elijahsj 1:8a094db1347f 38 #include "mbed_error.h"
elijahsj 1:8a094db1347f 39 #include "PeripheralPins.h"
elijahsj 1:8a094db1347f 40
elijahsj 1:8a094db1347f 41 #if DEVICE_SPI_ASYNCH
elijahsj 1:8a094db1347f 42 #define SPI_S(obj) (( struct spi_s *)(&(obj->spi)))
elijahsj 1:8a094db1347f 43 #else
elijahsj 1:8a094db1347f 44 #define SPI_S(obj) (( struct spi_s *)(obj))
elijahsj 1:8a094db1347f 45 #endif
elijahsj 1:8a094db1347f 46
elijahsj 1:8a094db1347f 47
elijahsj 1:8a094db1347f 48 /*
elijahsj 1:8a094db1347f 49 * Only the frequency is managed in the family specific part
elijahsj 1:8a094db1347f 50 * the rest of SPI management is common to all STM32 families
elijahsj 1:8a094db1347f 51 */
elijahsj 1:8a094db1347f 52 int spi_get_clock_freq(spi_t *obj) {
elijahsj 1:8a094db1347f 53 struct spi_s *spiobj = SPI_S(obj);
elijahsj 1:8a094db1347f 54 int spi_hz = 0;
elijahsj 1:8a094db1347f 55
elijahsj 1:8a094db1347f 56 /* Get source clock depending on SPI instance */
elijahsj 1:8a094db1347f 57 switch ((int)spiobj->spi) {
elijahsj 1:8a094db1347f 58 case SPI_1:
elijahsj 1:8a094db1347f 59 /* SPI_1. Source CLK is PCKL2 */
elijahsj 1:8a094db1347f 60 spi_hz = HAL_RCC_GetPCLK2Freq();
elijahsj 1:8a094db1347f 61 break;
elijahsj 1:8a094db1347f 62 #if defined(SPI2_BASE)
elijahsj 1:8a094db1347f 63 case SPI_2:
elijahsj 1:8a094db1347f 64 /* SPI_2. Source CLK is PCKL1 */
elijahsj 1:8a094db1347f 65 spi_hz = HAL_RCC_GetPCLK1Freq();
elijahsj 1:8a094db1347f 66 break;
elijahsj 1:8a094db1347f 67 #endif
elijahsj 1:8a094db1347f 68 default:
elijahsj 1:8a094db1347f 69 error("CLK: SPI instance not set");
elijahsj 1:8a094db1347f 70 break;
elijahsj 1:8a094db1347f 71 }
elijahsj 1:8a094db1347f 72 return spi_hz;
elijahsj 1:8a094db1347f 73 }
elijahsj 1:8a094db1347f 74
elijahsj 1:8a094db1347f 75 #endif