mbed library sources. Supersedes mbed-src. Fixes analogIn and analogOut problems for TARGET_STM32F3. Tested on NUCLEO-F303K8, using 3 analogout and 7 analogin channels simultaneously. Added ability for STM32F334R8 and STM32F303K8 to use all three channels of DAC simultaneously. https://developer.mbed.org/users/StevieWray/code/mbed-dev/ Added ability for TARGET_STM32F3 to use more than one ADC simultaneously. https://developer.mbed.org/questions/67997/NUCLEO-F303K8ADC/

Fork of mbed-dev by mbed official

Revision:
70:b3a5af880266
Parent:
8:69ce7aaad4c4
--- a/targets/hal/TARGET_STM/TARGET_STM32F3/analogout_api.c	Mon Feb 22 13:15:10 2016 +0000
+++ b/targets/hal/TARGET_STM/TARGET_STM32F3/analogout_api.c	Tue Feb 23 21:59:35 2016 +0000
@@ -38,13 +38,21 @@
 #define DAC_RANGE (0xFFF) // 12 bits
 #define DAC_NB_BITS  (12)
 
-static DAC_HandleTypeDef DacHandle;
+//the STM32F334R8 has two DACs so define two different handles and a pointer to pick between them in each function
+static DAC_HandleTypeDef DacHandle1; 
+static DAC_HandleTypeDef DacHandle2;
+DAC_HandleTypeDef* DacHandle;
 
 // These variables are used for the "free" function
 static int pa4_used = 0;
 static int pa5_used = 0;
 
 void analogout_init(dac_t *obj, PinName pin) {
+    if(pin==PA_6) //if the pin being used is PA_6 then it is DAC2 otherwise it's DAC1
+        DacHandle = &DacHandle2;
+    else
+        DacHandle = &DacHandle1;
+        
     DAC_ChannelConfTypeDef sConfig;
 
     // Get the peripheral name from the pin and assign it to the object
@@ -73,25 +81,25 @@
 #endif
 
     // Configure DAC
-    DacHandle.Instance = (DAC_TypeDef *)(obj->dac);
+    DacHandle->Instance = (DAC_TypeDef *)(obj->dac);
 
     sConfig.DAC_Trigger      = DAC_TRIGGER_NONE;
     sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;
 
     if (pin == PA_4) {
-        HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1);
+        HAL_DAC_ConfigChannel(DacHandle, &sConfig, DAC_CHANNEL_1);
         pa4_used = 1;
     }
 
 #if defined(DAC_CHANNEL_2)
     if (pin == PA_5) {
-        HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_2);
+        HAL_DAC_ConfigChannel(DacHandle, &sConfig, DAC_CHANNEL_2);
         pa5_used = 1;
     }
 #endif
 
     if (pin == PA_6) {
-        HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1);
+        HAL_DAC_ConfigChannel(DacHandle, &sConfig, DAC_CHANNEL_1);
     }
 
     analogout_write_u16(obj, 0);
@@ -121,25 +129,37 @@
 }
 
 static inline void dac_write(dac_t *obj, int value) {
+    //if the pin being used is PA_6 then it is DAC2 otherwise it's DAC1
+    if(obj->pin==PA_6)
+        DacHandle = &DacHandle2;
+    else
+        DacHandle = &DacHandle1;
+
     if (obj->channel == 1) {
-        HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_1, DAC_ALIGN_12B_R, (value & DAC_RANGE));
-        HAL_DAC_Start(&DacHandle, DAC_CHANNEL_1);
+        HAL_DAC_SetValue(DacHandle, DAC_CHANNEL_1, DAC_ALIGN_12B_R, (value & DAC_RANGE));
+        HAL_DAC_Start(DacHandle, DAC_CHANNEL_1);
     }
 #if defined(DAC_CHANNEL_2)
     if (obj->channel == 2) {
-        HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_2, DAC_ALIGN_12B_R, (value & DAC_RANGE));
-        HAL_DAC_Start(&DacHandle, DAC_CHANNEL_2);
+        HAL_DAC_SetValue(DacHandle, DAC_CHANNEL_2, DAC_ALIGN_12B_R, (value & DAC_RANGE));
+        HAL_DAC_Start(DacHandle, DAC_CHANNEL_2);
     }
 #endif
 }
 
 static inline int dac_read(dac_t *obj) {
+    //if the pin being used is PA_6 then it is DAC2 otherwise it's DAC1
+    if(obj->pin==PA_6)
+        DacHandle = &DacHandle2;
+    else
+        DacHandle = &DacHandle1;
+        
     if (obj->channel == 1) {
-        return (int)HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_1);
+        return (int)HAL_DAC_GetValue(DacHandle, DAC_CHANNEL_1);
     }
 #if defined(DAC_CHANNEL_2)
     if (obj->channel == 2) {
-        return (int)HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_2);
+        return (int)HAL_DAC_GetValue(DacHandle, DAC_CHANNEL_2);
     }
 #endif
     return 0;