Zianne
Zianne

Reputation: 29

"No target connected" in ST-Link Debugger after accidentally removing USB connected to computer without safely ejecting

I am using the Nucleo STM32F446RE board and programming in C in the program Keil for a homework project. Before I start writing the code for any project I would always press the 'configure flash tools' option, go into the 'target' tab change my compiler version (5), then go into the 'Debug' tab, select 'ST-Link Debugger' then the settings button next to it to check whether or not the target is connected. I have never ran into any issues with getting the target to connect up until recently. The homework was basically to connect two external LEDs and Pushbuttons using a bread board. Here are the steps for interfacing:

  1. One Push Button (let’s call it Button1) is to be interfaced with PA1 with an internal pull up configuration.
  2. Second Push Button (let’s call it Button2) is to be interfaced with PA6 with an external pull-down configuration.
  3. One LED (let’s call it LED1) is to be interfaced with PA4
  4. Second LED (let’s call it LED2) is to be interfaced with PA7
  5. USART2 or UART2 configuration for PA2 and PA3.

I ended up following a reference photo I found on this site hackster.io "Working with two LEDs and two PUSH BUTTONs": reference photo I followed (I did not use the Arduino pins I used the photo mainly for the bread board setup). After doing the hardware setup, I moved onto the programming. Below is the code I have come up with so far:

#include <stdint.h>
#include "stm32f4xx.h"


#define Button1 (1)
#define Button2 (6)
#define LED1 (4)
#define LED2 (7)


unsigned char button1_down = 0;
unsigned char button2_down = 0;


int main(void) {
   RCC->AHB1ENR |=  1;                /* enable GPIOA clock */


// Button1
   GPIOA->MODER &= ~(0x0000000C << (Button1*2));        /* clear pin mode */
   GPIOA->PUPDR &= ~(0x0000000C << (Button1*2));        /* clear */
   GPIOA->PUPDR |=  (0x00000004 << (Button1*2));        /* set pin to pull up mode */


// Button2
   GPIOA->MODER &= ~(0x00003000 << (Button2*2));        /* clear pin mode */
   GPIOA->PUPDR &= ~(0x00003000 << (Button2*2));        /* clear */
   GPIOA->PUPDR |=  (0x00002000 << (Button2*2));        /* set pin to pull down mode */


// LED1
   GPIOA->MODER &= ~(0x00000300 << (LED1*2));
   GPIOA->MODER |= (0x00000100 << (LED1*2));
   GPIOA->OTYPER &= ~(1 << LED1);


//LED2
   GPIOA->MODER &= ~(0x0000C000 << (LED2*2));
   GPIOA->MODER |= (0x00004000 << (LED2*2));
   GPIOA->OTYPER &= ~(1 << LED2);


while(1) {
   uint32_t idr_val = ~GPIOA->IDR;
   if (idr_val & (1 << Button1)) {
       if (!button1_down) {
           GPIOA->ODR ^= (1<<LED1);
       }
       button1_down = 1;
   }
       else {
           button1_down = 0;
       }
   if (idr_val & (1 << Button2)) {
       if (!button2_down) {
           GPIOA->ODR ^= (1 << LED2);
       }
       button2_down = 1;
   }
       else {
           button2_down = 0;
       }
   }
}

With this code I expected Button1 to turn on LED1 and Button2 to turn on LED2 but then I looked back at the prompt and saw that I was no supposed to do that. This is what was asked of me:

  1. At the power on, both LEDs remain turned off
  2. When both LEDs are off, one press of Button1 turns on both the LED1 and LED2 and sends a message to computers as ‘LED1 LED2 ON’ via UART.
  3. While both LEDs are on, one press of Button2 will turn off both LEDs and send a message to computers as ‘LED1 LED2 OFF’ via UART.
  4. No impact will be for Button1 when both LEDs are on.
  5. When both LEDs are off, one press of Button2 will blink both LEDs 3 times and send a message to computers as ‘LED1 LED2 Blink’ via UART and keep only LED1 On after the blink.
  6. When only LED1 is on, one press of Button1 will turn off both LEDs and send a message to computers as ‘LED1 LED2 OFF’ via UART.
  7. No impact will be for Button2 when only LED1 is on.

Realizing this I thought, "Fine I'll just see if this does anything" and it did not which was not surprising. After that I mindlessly removed the USB (the end connected to the computer) without safely ejecting and when trying to connected the board again, I keep getting 'No target connected in the debug section of the flash tools configuration even though LD1 and LD2 on the STM32 board come on.

Things I have tried:

  1. Disconnecting and connecting the board multiple times
  2. Using different computers and still getting no target connection (The first and second computer were the desktops in the Lab room and the third and final was my person computer all of which have previously been able to connect to my board and upload the programs to it). All of the computers have still shown that the device was connected under the name 'STM32 STLink'.
  3. Messed around in Device manager on my laptop by going into ports and uninstalling the device.
  4. I have noticed that across all of the computers when trying to eject there is another option under 'Eject STM32 STLink' called 'Eject NOD_F446RE' which I don't think I have seen it before.

What I might think is the problem:

  1. The board is being detected as a USB storage device
  2. My hardware setup was too sketchy and I need to get a new board

Pictures of my setup: Both stm32 and bread board stm32 bread board

Upvotes: 2

Views: 1669

Answers (1)

Zianne
Zianne

Reputation: 29

I was able to fix this issue by doing some type of reset through the STM32CubeProgrammer. While I did not need to get a new board, I suspected that my hardware setup was indeed sketchy so it went into this 'safety' mode I read about a year back when I was having this issue. Thanks to all that helped at the time!

Upvotes: 0

Related Questions