ST Link error when trying to add LED blink code
STM32 NUCLEO 64 -F411RE
From SMT32Cube IDE I build & upload the following code that does nothing ,stripped everything away to show that the ST-Link is working,
#include "stm32f4xx.h"
int main()
{
while(1)
{
/* Do nothing */
}
}
This builds, uploads & does nothing,
File download complete
Time elapsed during download operation: 00:00:00.326
Verifying .
Download verified successfully
Shutting down...
Exit.
I then add some code to blink LED2 on & off
/* hardware_modules.c
light_init: set up GPIOA PA5 as output
light_on : set PA5 high
light_off : set PA5 low
*/
#include "hardware_modules.h"
#include "stm32f4xx.h"
#define GPIOAEN (1U<<0)
void light_init(void)
{
/* Enable clk access to GPIOA */
RCC->AHB1ENR |= GPIOAEN;
/* Set PA5 as an output pin */
GPIOA->MODER = (1U<<10);
GPIOA->MODER &= ~(1U<<11);
}
void light_on(void)
{
/* Set PA5 output to high*/
GPIOA->ODR |= (1U<<5);
}
void light_off(void)
{
/* Set PA5 output to high*/
GPIOA->ODR &=~(1U<<5);
}
The associated header,
/* hardware_modules.h */
#ifndef __HARDWARE_MODULES_H__
#define __HARDWARE_MODULES_H__
#include <stdint.h>
#include <stdbool.h>
void light_init(void);
void light_on(void);
void light_off(void);
#endif
I now put the init into main()
#include "stm32f4xx.h"
#include "hardware_modules.h"
int main()
{
light_init();
while(1)
{
/* Do nothing */
}
}
Builds fine but when I try to upload I get,
Download verified successfully
Error in executing 'cont' command ...
Failed to read all registers from target
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Shutting down...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
If I remove light_init() it all works fine again.
Sanity checked using older projects & they all build & upload fine.
So what in my code is causing this upload error?
