Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


Delays not working

Hey all,
I’m trying to alternately blink two leds on a STM32F103 on pins 13 and 14 of port C. In the while loop below, neither the myDelay() or myDelay2() functions have any effect - both LEDS turn on at once (perhaps blinking too fast to see them switching?) regardless of what delay time I specify. The commented-out section (switching the leds with a button press) works fine. Any help appreciated, thanks!

KatBar

code:

/**
******************************************************************************
* @file main.c
* @author KatBar
* @version V1.0
* @date 01-December-2018
* @brief Default main function.
******************************************************************************

  • /

  1. define ButtonPin 0b0001000000000000 // pin 12

  1. include “stm32f10x.h”
  2. include
  3. include


int Button(void)
{
if ((GPIOB->IDR & ButtonPin) == 0)
{
return(1);
}
else
{
return(0);
}
}

  1. include “stm32f10x.h”
  2. include
  3. include


static volatile uint32_t sysTickCount = 0;
volatile uint32_t i = 0; //volatile to avoid being optimized away

void myDelay(uint32_t nTime)
{
sysTickCount = nTime;
while(sysTickCount != 0);
}

void myDelay2(void)
{
for (i=0;i>5000000;i++) {}
}

void SysTick_Handler()
{
if (sysTickCount != 0) {
sysTickCount--;
}
}


int main(void)
{
/*
I2C_InitTypeDef i2c_struct;
I2C_StructInit(&i2c_struct);
I2C_Init(I2C1, &i2c_struct);
*/

//Enable clock on APB2 peripheral bus (ports) for button and LEDs
RCC->APB2ENR |= 0x0018; // enable clock on PORTC GPIO and PORTB GPIO
GPIOB->CRH = 0x00080000; // set PortB pin 12 as input, pullup
GPIOC->CRH = 0x02200000; // set PortC pins 13 and 14 as outputs
while(1)
{
/*
if (Button())
{
GPIOC->ODR |= 0b0010000000000000; // turn off PC13
GPIOC->ODR &= 0b1011111111111111; // turn on PC14 (active LOW)
}
else
{
GPIOC->ODR &= 0b1101111111111111; // turn on PC13 (active LOW)
GPIOC->ODR |= 0b0100000000000000; // turn off PC14
}
*/

// myDelay(500000);
myDelay2();
GPIOC->ODR |= 0b0010000000000000; // turn off PC13
GPIOC->ODR &= 0b1011111111111111; // turn on PC14
// myDelay(500000);
myDelay2();
GPIOC->ODR &= 0b1101111111111111; // turn on PC13}
GPIOC->ODR |= 0b0100000000000000; // turn off PC14

}

}

France

Hello,

In myDelay2, the error is obvious: you write your loop incorrectly: for (i=0;i>5000000;i++) {}
while it should be for (i=0;i != 5000000;i++) {} ; your loop is in fact never executed: i is initialized to 0 so it’s not greater than 5000000...

For myDelay1, I think the error is a bit more tricky: you probably never get out of myDelay as you don’t initialize the SysTick timer, so should not get any interrupt. Moreover, if you initialize the SysTick timer as usual, you will get interrupts every 10ms, meaning your delay count of 500000 means 5000 seconds: nearly 2 hours!

Note also that you do not initialize the LED outputs, so they are both in the same state (probably ON) at program start and as your delay is either too short or too long you don’t see them blinking...

To debug you can just set a breakpoint in your Delay functions or SysTick_Handler to check what happens.

Hope this helps,

Bernard (Ac6)

Thanks so much, Bernard - It works! Thank you.

I am using STM32F446RE (nucleo board) and Keil uVision5.33..0

following is the snippet:

  1. include
  2. include “Board_LED.h”

int32_t custom_delay()
{
uint32_t unTimeDelay = 0;
uint32_t unTimeDelayCounter = 50000;
for(unTimeDelay = 0; unTimeDelay != unTimeDelayCounter; unTimeDelay++);
return 1;
}

int main (void)
{
uint32_t unLEDIndex = 0;
int32_t nFunctionReturn = 0;
nFunctionReturn = LED_Initialize();
while(1)
{
nFunctionReturn = LED_Off(unLEDIndex);
nFunctionReturn = custom_delay();
nFunctionReturn = LED_On(unLEDIndex);
}
return 0;
}
The delay above is not working.

France

What do you mean by “not working”?

Looking at your code, anyway, even if you run the core at only 16MHz (the default at reset), a 50000 loop, if correctly optimized by the compiler, may run for only 5 to 10 ms, meaning the blinking will be totally invisible.

Try first by increasing a lot the loop delay (from 50,000 to 5,000,000 for example, or even more if you run at 480MHz) and see what happens.

Bernard (Ac6)

BTW, this forum is for users of System Workbench for STM32, not of Keil µVision...