[Cryptech-Commits] [user/ft/stm32-dev-bridge] 02/02: Delay after setting output pin, to prevent incorrect reading.

git at cryptech.is git at cryptech.is
Thu Oct 15 10:50:15 UTC 2015


This is an automated email from the git hooks/post-receive script.

fredrik at thulin.net pushed a commit to branch master
in repository user/ft/stm32-dev-bridge.

commit 96d534ed980fb310783fda1592b05463a9be7b91
Author: Fredrik Thulin <fredrik at thulin.net>
Date:   Thu Oct 15 12:45:20 2015 +0200

    Delay after setting output pin, to prevent incorrect reading.
---
 src/short-test/src/main.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/short-test/src/main.c b/src/short-test/src/main.c
index ee1fedb..902a98b 100644
--- a/src/short-test/src/main.c
+++ b/src/short-test/src/main.c
@@ -94,8 +94,7 @@ void configure_all_as_input(GPIO_TypeDef* GPIOx, uint16_t GPIO_Test_Pins)
 
   /* Configure all pins as input. XXX do all pins (0xffff) instead of just GPIO_Test_Pins? */
   GPIO_InitStruct.Pin = GPIO_Test_Pins;
-  //GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;  /* XXX does GPIO_PULLDOWN work with GPIO_MODE_INPUT? */
+  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
   GPIO_InitStruct.Pull = GPIO_PULLDOWN;
   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
   HAL_GPIO_Init(GPIOx, &GPIO_InitStruct);
@@ -168,6 +167,12 @@ void test_for_shorts(char port, GPIO_TypeDef* GPIOx, uint16_t GPIO_Test_Pins)
 
     HAL_GPIO_WritePin(GPIOx, Test_Pin, GPIO_PIN_SET);
 
+    /* Slight delay after setting the output pin. Without this, the Test_Pin
+       bit might read as zero, as it is only sampled once every AHB1 clock cycle.
+       Reference manual DM00031020 section 8.3.1.
+    */
+    HAL_Delay(1);
+
     /* Read all input GPIOs from port at once. XXX check all pins, not just GPIO_Test_Pins? */
     read = GPIOx->IDR & GPIO_Test_Pins;
 



More information about the Commits mailing list