Reputation: 29
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:
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:
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:
What I might think is the problem:
Upvotes: 2
Views: 1669
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