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.
Fork of mbed-dev by
Revision 70:b3a5af880266, committed 2016-02-23
- Comitter:
- neurofun
- Date:
- Tue Feb 23 21:59:35 2016 +0000
- Parent:
- 69:41db872bbc3a
- Commit message:
- Edited DAC routines to allow for the simultaneous use of three channels from two DACs as seen on the STM32F334R8 and STM32F303K8. Edited ADC routines to allow for the simultaneous use of more than one ADC.
Changed in this revision
--- a/targets/hal/TARGET_STM/TARGET_STM32F3/analogin_api.c Mon Feb 22 13:15:10 2016 +0000 +++ b/targets/hal/TARGET_STM/TARGET_STM32F3/analogin_api.c Tue Feb 23 21:59:35 2016 +0000 @@ -116,6 +116,9 @@ AdcHandle.Init.DMAContinuousRequests = DISABLE; AdcHandle.Init.Overrun = OVR_DATA_OVERWRITTEN; +// Added handle state reset code as below + __HAL_ADC_RESET_HANDLE_STATE(&AdcHandle); + if (HAL_ADC_Init(&AdcHandle) != HAL_OK) { error("Cannot initialize ADC"); }
--- 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;