mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
630:825f75ca301e
Parent:
552:a1b9575155a3
--- a/targets/hal/TARGET_STM/TARGET_STM32F0/spi_api.c	Mon Sep 28 10:30:09 2015 +0100
+++ b/targets/hal/TARGET_STM/TARGET_STM32F0/spi_api.c	Mon Sep 28 10:45:10 2015 +0100
@@ -1,6 +1,6 @@
 /* mbed Microcontroller Library
  *******************************************************************************
- * Copyright (c) 2014, STMicroelectronics
+ * Copyright (c) 2015, STMicroelectronics
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -39,8 +39,7 @@
 
 static SPI_HandleTypeDef SpiHandle;
 
-static void init_spi(spi_t *obj)
-{
+static void init_spi(spi_t *obj) {
     SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
 
     __HAL_SPI_DISABLE(&SpiHandle);
@@ -62,8 +61,7 @@
     __HAL_SPI_ENABLE(&SpiHandle);
 }
 
-void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
-{
+void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
     // Determine the SPI to use
     SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
     SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
@@ -80,9 +78,11 @@
     if (obj->spi == SPI_1) {
         __SPI1_CLK_ENABLE();
     }
+#if defined(SPI2_BASE)
     if (obj->spi == SPI_2) {
         __SPI2_CLK_ENABLE();
     }
+#endif
 
     // Configure the SPI pins
     pinmap_pinout(mosi, PinMap_SPI_MOSI);
@@ -109,8 +109,7 @@
     init_spi(obj);
 }
 
-void spi_free(spi_t *obj)
-{
+void spi_free(spi_t *obj) {
     // Reset SPI and disable clock
     if (obj->spi == SPI_1) {
         __SPI1_FORCE_RESET();
@@ -118,11 +117,13 @@
         __SPI1_CLK_DISABLE();
     }
 
+#if defined(SPI2_BASE)
     if (obj->spi == SPI_2) {
         __SPI2_FORCE_RESET();
         __SPI2_RELEASE_RESET();
         __SPI2_CLK_DISABLE();
     }
+#endif
 
     // Configure GPIOs
     pin_function(obj->pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
@@ -131,8 +132,7 @@
     pin_function(obj->pin_ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
 }
 
-void spi_format(spi_t *obj, int bits, int mode, int slave)
-{
+void spi_format(spi_t *obj, int bits, int mode, int slave) {
     // Save new values
     if (bits == 16) {
         obj->bits = SPI_DATASIZE_16BIT;
@@ -168,8 +168,7 @@
     init_spi(obj);
 }
 
-void spi_frequency(spi_t *obj, int hz)
-{
+void spi_frequency(spi_t *obj, int hz) {
     // Note: The frequencies are obtained with SPI clock = 48 MHz (APB clock)
     if (hz < 375000) {
         obj->br_presc = SPI_BAUDRATEPRESCALER_256; // 188 kHz
@@ -192,8 +191,7 @@
     init_spi(obj);
 }
 
-static inline int ssp_readable(spi_t *obj)
-{
+static inline int ssp_readable(spi_t *obj) {
     int status;
     SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
     // Check if data is received
@@ -201,8 +199,7 @@
     return status;
 }
 
-static inline int ssp_writeable(spi_t *obj)
-{
+static inline int ssp_writeable(spi_t *obj) {
     int status;
     SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
     // Check if data is transmitted
@@ -210,8 +207,7 @@
     return status;
 }
 
-static inline void ssp_write(spi_t *obj, int value)
-{
+static inline void ssp_write(spi_t *obj, int value) {
     SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
     while (!ssp_writeable(obj));
     if (obj->bits == SPI_DATASIZE_8BIT) {
@@ -224,8 +220,7 @@
     }
 }
 
-static inline int ssp_read(spi_t *obj)
-{
+static inline int ssp_read(spi_t *obj) {
     SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
     while (!ssp_readable(obj));
     if (obj->bits == SPI_DATASIZE_8BIT) {
@@ -238,27 +233,23 @@
     }
 }
 
-static inline int ssp_busy(spi_t *obj)
-{
+static inline int ssp_busy(spi_t *obj) {
     int status;
     SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
     status = ((__HAL_SPI_GET_FLAG(&SpiHandle, SPI_FLAG_BSY) != RESET) ? 1 : 0);
     return status;
 }
 
-int spi_master_write(spi_t *obj, int value)
-{
+int spi_master_write(spi_t *obj, int value) {
     ssp_write(obj, value);
     return ssp_read(obj);
 }
 
-int spi_slave_receive(spi_t *obj)
-{
+int spi_slave_receive(spi_t *obj) {
     return ((ssp_readable(obj) && !ssp_busy(obj)) ? 1 : 0);
 };
 
-int spi_slave_read(spi_t *obj)
-{
+int spi_slave_read(spi_t *obj) {
     SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
     while (!ssp_readable(obj));
     if (obj->bits == SPI_DATASIZE_8BIT) {
@@ -271,8 +262,7 @@
     }
 }
 
-void spi_slave_write(spi_t *obj, int value)
-{
+void spi_slave_write(spi_t *obj, int value) {
     SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
     while (!ssp_writeable(obj));
     if (obj->bits == SPI_DATASIZE_8BIT) {
@@ -285,8 +275,7 @@
     }
 }
 
-int spi_busy(spi_t *obj)
-{
+int spi_busy(spi_t *obj) {
     return ssp_busy(obj);
 }