Devchannel Team / X_NUCLEO_IDB0XA1

Dependents:   Hello_BLE F446RE-BLE

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Wolfgang Betz
Date:
Wed Sep 02 07:50:35 2015 +0200
Revision:
115:3b47df81a56b
Parent:
113:31c73e9b0108
Child:
116:1aa0d2da72e4
Merge commit '05e0fdbf467718fa524cc667f5c9f85228096655' into ble_wb

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 90:26c0c9807ab4 1 /**
Wolfgang Betz 90:26c0c9807ab4 2 ******************************************************************************
Wolfgang Betz 90:26c0c9807ab4 3 * @file stm32_bluenrg_ble.cpp
Wolfgang Betz 90:26c0c9807ab4 4 * @author CL
Wolfgang Betz 90:26c0c9807ab4 5 * @version V1.0.0
Wolfgang Betz 90:26c0c9807ab4 6 * @date 15-June-2015
Wolfgang Betz 90:26c0c9807ab4 7 * @brief
Wolfgang Betz 90:26c0c9807ab4 8 ******************************************************************************
Wolfgang Betz 90:26c0c9807ab4 9 * @attention
Wolfgang Betz 90:26c0c9807ab4 10 *
Wolfgang Betz 90:26c0c9807ab4 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Wolfgang Betz 90:26c0c9807ab4 12 *
Wolfgang Betz 90:26c0c9807ab4 13 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 90:26c0c9807ab4 14 * are permitted provided that the following conditions are met:
Wolfgang Betz 90:26c0c9807ab4 15 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 90:26c0c9807ab4 16 * this list of conditions and the following disclaimer.
Wolfgang Betz 90:26c0c9807ab4 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 90:26c0c9807ab4 18 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 90:26c0c9807ab4 19 * and/or other materials provided with the distribution.
Wolfgang Betz 90:26c0c9807ab4 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 90:26c0c9807ab4 21 * may be used to endorse or promote products derived from this software
Wolfgang Betz 90:26c0c9807ab4 22 * without specific prior written permission.
Wolfgang Betz 90:26c0c9807ab4 23 *
Wolfgang Betz 90:26c0c9807ab4 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 90:26c0c9807ab4 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 90:26c0c9807ab4 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 90:26c0c9807ab4 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 90:26c0c9807ab4 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 90:26c0c9807ab4 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 90:26c0c9807ab4 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 90:26c0c9807ab4 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 90:26c0c9807ab4 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 90:26c0c9807ab4 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 90:26c0c9807ab4 34 *
Wolfgang Betz 90:26c0c9807ab4 35 ******************************************************************************
Wolfgang Betz 90:26c0c9807ab4 36 */
Wolfgang Betz 90:26c0c9807ab4 37
Wolfgang Betz 90:26c0c9807ab4 38 /* Includes ------------------------------------------------------------------*/
Wolfgang Betz 90:26c0c9807ab4 39 #include "BlueNRGGap.h"
Wolfgang Betz 90:26c0c9807ab4 40 #include "BlueNRGDevice.h"
Wolfgang Betz 90:26c0c9807ab4 41 #include "Utils.h"
Wolfgang Betz 90:26c0c9807ab4 42
Wolfgang Betz 90:26c0c9807ab4 43 // FIXME: find a better way to get the instance of the BlueNRG device
Wolfgang Betz 90:26c0c9807ab4 44 extern BlueNRGDevice bluenrgDeviceInstance;
Wolfgang Betz 90:26c0c9807ab4 45
Wolfgang Betz 90:26c0c9807ab4 46
Wolfgang Betz 90:26c0c9807ab4 47 ////////////////////////////////////////
Wolfgang Betz 90:26c0c9807ab4 48 // Start of C function wrappers
Wolfgang Betz 90:26c0c9807ab4 49 #ifdef __cplusplus
Wolfgang Betz 90:26c0c9807ab4 50 extern "C" {
Wolfgang Betz 90:26c0c9807ab4 51 #endif
Wolfgang Betz 90:26c0c9807ab4 52
Wolfgang Betz 90:26c0c9807ab4 53 #include "stm32_bluenrg_ble.h"
Wolfgang Betz 90:26c0c9807ab4 54 #include "gp_timer.h"
Wolfgang Betz 90:26c0c9807ab4 55 #include "debug.h"
Wolfgang Betz 90:26c0c9807ab4 56
Wolfgang Betz 90:26c0c9807ab4 57 void BlueNRG_RST(void)
Wolfgang Betz 90:26c0c9807ab4 58 {
Wolfgang Betz 90:26c0c9807ab4 59 bluenrgDeviceInstance.reset();
Wolfgang Betz 90:26c0c9807ab4 60 }
Wolfgang Betz 90:26c0c9807ab4 61
Wolfgang Betz 90:26c0c9807ab4 62 uint8_t BlueNRG_DataPresent(void)
Wolfgang Betz 90:26c0c9807ab4 63 {
Wolfgang Betz 90:26c0c9807ab4 64 return (bluenrgDeviceInstance.dataPresent());
Wolfgang Betz 90:26c0c9807ab4 65 }
Wolfgang Betz 90:26c0c9807ab4 66
Wolfgang Betz 90:26c0c9807ab4 67
Wolfgang Betz 90:26c0c9807ab4 68 /**
Wolfgang Betz 90:26c0c9807ab4 69 * @brief This function is a utility to print the log time
Wolfgang Betz 90:26c0c9807ab4 70 * in the format HH:MM:SS:MSS (DK GUI time format)
Wolfgang Betz 90:26c0c9807ab4 71 * @param None
Wolfgang Betz 90:26c0c9807ab4 72 * @retval None
Wolfgang Betz 90:26c0c9807ab4 73 */
Wolfgang Betz 115:3b47df81a56b 74 void print_csv_time(void){
Wolfgang Betz 115:3b47df81a56b 75 uint32_t ms = 0;//ms_counter;
Wolfgang Betz 115:3b47df81a56b 76 PRINT_CSV("%02d:%02d:%02d.%03d", ms/(60*60*1000)%24, ms/(60*1000)%60, (ms/1000)%60, ms%1000);
Wolfgang Betz 115:3b47df81a56b 77 }
Wolfgang Betz 90:26c0c9807ab4 78
Wolfgang Betz 90:26c0c9807ab4 79 /**
Wolfgang Betz 90:26c0c9807ab4 80 * @brief Writes data to a serial interface.
Wolfgang Betz 90:26c0c9807ab4 81 * @param data1 : 1st buffer
Wolfgang Betz 90:26c0c9807ab4 82 * @param data2 : 2nd buffer
Wolfgang Betz 90:26c0c9807ab4 83 * @param n_bytes1: number of bytes in 1st buffer
Wolfgang Betz 90:26c0c9807ab4 84 * @param n_bytes2: number of bytes in 2nd buffer
Wolfgang Betz 90:26c0c9807ab4 85 * @retval None
Wolfgang Betz 90:26c0c9807ab4 86 */
Wolfgang Betz 90:26c0c9807ab4 87 void Hal_Write_Serial(const void* data1, const void* data2, int32_t n_bytes1,
Wolfgang Betz 90:26c0c9807ab4 88 int32_t n_bytes2)
Wolfgang Betz 90:26c0c9807ab4 89 {
Wolfgang Betz 90:26c0c9807ab4 90 struct timer t;
Wolfgang Betz 90:26c0c9807ab4 91
Wolfgang Betz 90:26c0c9807ab4 92 Timer_Set(&t, CLOCK_SECOND/10);
Wolfgang Betz 90:26c0c9807ab4 93
Wolfgang Betz 90:26c0c9807ab4 94 #ifdef PRINT_CSV_FORMAT
Wolfgang Betz 115:3b47df81a56b 95 print_csv_time();
Wolfgang Betz 90:26c0c9807ab4 96 for (int i=0; i<n_bytes1; i++) {
Wolfgang Betz 90:26c0c9807ab4 97 PRINT_CSV(" %02x", ((uint8_t *)data1)[i]);
Wolfgang Betz 90:26c0c9807ab4 98 }
Wolfgang Betz 90:26c0c9807ab4 99 for (int i=0; i<n_bytes2; i++) {
Wolfgang Betz 90:26c0c9807ab4 100 PRINT_CSV(" %02x", ((uint8_t *)data2)[i]);
Wolfgang Betz 90:26c0c9807ab4 101 }
Wolfgang Betz 90:26c0c9807ab4 102 PRINT_CSV("\n");
Wolfgang Betz 90:26c0c9807ab4 103 #endif
Wolfgang Betz 90:26c0c9807ab4 104
Wolfgang Betz 90:26c0c9807ab4 105 while(1){
Wolfgang Betz 90:26c0c9807ab4 106 if(BlueNRG_SPI_Write((uint8_t *)data1,(uint8_t *)data2, n_bytes1, n_bytes2)==0) break;
Wolfgang Betz 90:26c0c9807ab4 107 if(Timer_Expired(&t)){
Wolfgang Betz 90:26c0c9807ab4 108 break;
Wolfgang Betz 90:26c0c9807ab4 109 }
Wolfgang Betz 90:26c0c9807ab4 110 }
Wolfgang Betz 90:26c0c9807ab4 111 }
Wolfgang Betz 90:26c0c9807ab4 112
Wolfgang Betz 90:26c0c9807ab4 113
Wolfgang Betz 90:26c0c9807ab4 114 /**
Wolfgang Betz 90:26c0c9807ab4 115 * @brief Activate internal bootloader using pin.
Wolfgang Betz 90:26c0c9807ab4 116 * @param None
Wolfgang Betz 90:26c0c9807ab4 117 * @retval None
Wolfgang Betz 90:26c0c9807ab4 118 */
Wolfgang Betz 90:26c0c9807ab4 119 void BlueNRG_HW_Bootloader(void)
Wolfgang Betz 90:26c0c9807ab4 120 {
Wolfgang Betz 90:26c0c9807ab4 121 // FIXME: this is not implemented yet
Wolfgang Betz 90:26c0c9807ab4 122 while (1);
Wolfgang Betz 90:26c0c9807ab4 123 }
Wolfgang Betz 90:26c0c9807ab4 124
Wolfgang Betz 90:26c0c9807ab4 125 /**
Wolfgang Betz 90:26c0c9807ab4 126 * @brief Reads from BlueNRG SPI buffer and store data into local buffer.
Wolfgang Betz 90:26c0c9807ab4 127 * @param buffer : Buffer where data from SPI are stored
Wolfgang Betz 90:26c0c9807ab4 128 * @param buff_size: Buffer size
Wolfgang Betz 90:26c0c9807ab4 129 * @retval int32_t : Number of read bytes
Wolfgang Betz 90:26c0c9807ab4 130 */
Wolfgang Betz 90:26c0c9807ab4 131 int32_t BlueNRG_SPI_Read_All(uint8_t *buffer,
Wolfgang Betz 90:26c0c9807ab4 132 uint8_t buff_size)
Wolfgang Betz 90:26c0c9807ab4 133 {
Wolfgang Betz 90:26c0c9807ab4 134 int32_t ret = bluenrgDeviceInstance.spiRead(buffer, buff_size);
Wolfgang Betz 90:26c0c9807ab4 135
Wolfgang Betz 90:26c0c9807ab4 136 return ret;
Wolfgang Betz 90:26c0c9807ab4 137 }
Wolfgang Betz 90:26c0c9807ab4 138
Wolfgang Betz 90:26c0c9807ab4 139 /**
Wolfgang Betz 90:26c0c9807ab4 140 * @brief Writes data from local buffer to SPI.
Wolfgang Betz 90:26c0c9807ab4 141 * @param data1 : First data buffer to be written
Wolfgang Betz 90:26c0c9807ab4 142 * @param data2 : Second data buffer to be written
Wolfgang Betz 90:26c0c9807ab4 143 * @param Nb_bytes1: Size of first data buffer to be written
Wolfgang Betz 90:26c0c9807ab4 144 * @param Nb_bytes2: Size of second data buffer to be written
Wolfgang Betz 90:26c0c9807ab4 145 * @retval Number of read bytes
Wolfgang Betz 90:26c0c9807ab4 146 */
Wolfgang Betz 90:26c0c9807ab4 147 int32_t BlueNRG_SPI_Write(uint8_t* data1,
Wolfgang Betz 90:26c0c9807ab4 148 uint8_t* data2, uint8_t Nb_bytes1, uint8_t Nb_bytes2)
Wolfgang Betz 90:26c0c9807ab4 149 {
Wolfgang Betz 90:26c0c9807ab4 150 int32_t ret = bluenrgDeviceInstance.spiWrite(data1, data2, Nb_bytes1, Nb_bytes2);
Wolfgang Betz 90:26c0c9807ab4 151
Wolfgang Betz 90:26c0c9807ab4 152 return ret;
Wolfgang Betz 90:26c0c9807ab4 153 }
Wolfgang Betz 90:26c0c9807ab4 154
Wolfgang Betz 90:26c0c9807ab4 155 /**
Wolfgang Betz 90:26c0c9807ab4 156 * @brief Enable SPI IRQ.
Wolfgang Betz 90:26c0c9807ab4 157 * @param None
Wolfgang Betz 90:26c0c9807ab4 158 * @retval None
Wolfgang Betz 90:26c0c9807ab4 159 */
Wolfgang Betz 90:26c0c9807ab4 160 void Enable_SPI_IRQ(void)
Wolfgang Betz 90:26c0c9807ab4 161 {
Wolfgang Betz 90:26c0c9807ab4 162 bluenrgDeviceInstance.enable_irq();
Wolfgang Betz 90:26c0c9807ab4 163 }
Wolfgang Betz 90:26c0c9807ab4 164
Wolfgang Betz 90:26c0c9807ab4 165 /**
Wolfgang Betz 90:26c0c9807ab4 166 * @brief Disable SPI IRQ.
Wolfgang Betz 90:26c0c9807ab4 167 * @param None
Wolfgang Betz 90:26c0c9807ab4 168 * @retval None
Wolfgang Betz 90:26c0c9807ab4 169 */
Wolfgang Betz 90:26c0c9807ab4 170 void Disable_SPI_IRQ(void)
Wolfgang Betz 90:26c0c9807ab4 171 {
Wolfgang Betz 90:26c0c9807ab4 172 bluenrgDeviceInstance.disable_irq();
Wolfgang Betz 90:26c0c9807ab4 173 }
Wolfgang Betz 90:26c0c9807ab4 174
Wolfgang Betz 90:26c0c9807ab4 175 /**
Wolfgang Betz 90:26c0c9807ab4 176 * @brief Clear Pending SPI IRQ.
Wolfgang Betz 90:26c0c9807ab4 177 * @param None
Wolfgang Betz 90:26c0c9807ab4 178 * @retval None
Wolfgang Betz 90:26c0c9807ab4 179 */
Wolfgang Betz 90:26c0c9807ab4 180 void Clear_SPI_IRQ(void)
Wolfgang Betz 90:26c0c9807ab4 181 {
Wolfgang Betz 90:26c0c9807ab4 182 }
Wolfgang Betz 90:26c0c9807ab4 183
Wolfgang Betz 90:26c0c9807ab4 184 /**
Wolfgang Betz 90:26c0c9807ab4 185 * @brief Clear EXTI (External Interrupt) line for SPI IRQ.
Wolfgang Betz 90:26c0c9807ab4 186 * @param None
Wolfgang Betz 90:26c0c9807ab4 187 * @retval None
Wolfgang Betz 90:26c0c9807ab4 188 */
Wolfgang Betz 90:26c0c9807ab4 189 void Clear_SPI_EXTI_Flag(void)
Wolfgang Betz 90:26c0c9807ab4 190 {
Wolfgang Betz 90:26c0c9807ab4 191 }
Wolfgang Betz 90:26c0c9807ab4 192
Wolfgang Betz 90:26c0c9807ab4 193
Wolfgang Betz 90:26c0c9807ab4 194
Wolfgang Betz 90:26c0c9807ab4 195
Wolfgang Betz 90:26c0c9807ab4 196 #ifdef __cplusplus
Wolfgang Betz 90:26c0c9807ab4 197 }
Wolfgang Betz 90:26c0c9807ab4 198 #endif
Wolfgang Betz 90:26c0c9807ab4 199 // End of C function wrappers
Wolfgang Betz 90:26c0c9807ab4 200 ////////////////////////////////////////
Wolfgang Betz 90:26c0c9807ab4 201
Wolfgang Betz 90:26c0c9807ab4 202 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/