Search code examples
cstm32gpiodac

STM32F4 DAC pins causes problems with adjacent GPIO pin


I have a strange problem that I dont understand. Please bare with me as this is a difficult problem to deconstruct. I will thus give as much information as I can with test cases and results I have found.

The problem:

  • I need to set PA6 LOW and then use the DAC. When the DAC is changed in a transient manner, the pin PA6 will not return to 3V when set to HIGH.
  • In other words, the DAC causes the upper voltage limit of PA6 to be 0.6-0.8V.
  • I have confirmed this with oscilloscope.
  • The following piece of code is called inside a task/thread and executed at 50Hz:
if (enable == 1) 
{
  HAL_GPIO_WritePin(PROPULSION_ENABLE_GPIO_PORT, PROPULSION_ENABLE_GPIO_PIN, GPIO_PIN_RESET);                                                                                                           
  HAL_DAC_SetValue(&PropulsionModule_DAC, PropulsionModule_DAC_CHANNEL, DAC_ALIGN_12B_R, PropulsionData.propulsionSetPoint_12bit);
}
else 
{
  HAL_GPIO_WritePin(PROPULSION_ENABLE_GPIO_PORT, PROPULSION_ENABLE_GPIO_PIN, GPIO_PIN_SET); 
  HAL_DAC_SetValue(&PropulsionModule_DAC, PropulsionModule_DAC_CHANNEL, DAC_ALIGN_12B_R, 0);
}

Setup and environment

  • STM32F4 Discovery board
  • FreeRTOS configured with threads, queues and everything else works as expected
  • I have a single DAC set up on DAC_channel_2 (PA5) and a GPIO_output (PA6).
  • I also have these peripherals enabled, CAN bus, UART, several GPIO's, etc. Please see attached pictureenter image description here

Findings:

  • When I change the PA6 pin to PC4 (the adjacent pin) the problem goes away
  • When I change DAC_channel_2 to DAC_channel_1 the problem goes away
  • I flashed the code to two other brand new, out of the box, boards with the same errors.
  • Once PA6 is faulty and its high state is at 0.6V, resetting the microcontroller will reset the pin PA6 and PA6 will return to 3V in its HIGH state.

Any help would be greatly appreciated.


Solution

  • I found the problem. The problem is the MEMS chip on the discovery board. It is vitally important one realizes that not all pins on the discovery board are usable.

    Refer to the first link below from Page 22 on which pins are available. Please note that some of the pins that are "not free" can still be used. See the application notes on each of the chips on the board in the second link.

    Link 1: https://www.st.com/resource/en/user_manual/dm00039084-discovery-kit-with-stm32f407vg-mcu-stmicroelectronics.pdf

    Link 2: https://ucilnica.fri.uni-lj.si/pluginfile.php/29604/mod_resource/content/1/en.DM00039084.pdf