Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


STM32F051 debug and program problem

Hello,

I am currently migrating from AVR to STM32 with STM32F051C8T6 on small project (PWM regulator with feedback from back EMF). First there was problem to force system workbench connect to MCU. The problem was in configuration file for debbuger/programer as I found on some forum (problem with NRST pin). Now I am able to program and “debug” via SW.
BUT, I have strange problem with jumping to functions/procedures. The code I programmed is included.
The problem is when I try to “step in to” via F5 on the row where InitializeTimer(1000) is, nothing happen. Nothing. It will not jump into InitializeTimer.
This also sometimes happen with LED() and I have no fucking idea what is wrong.
Also when I program flash memory with this program, it looks like it freezes on InitializeTimer(1000) - or sometimes on LED(). So it is probably not debug problem. Perhaps startup file is broken?

Please, can anybody help me? I am kind of out with ideas what to do.

  1. include “stm32f0xx.h”
  2. include “stm32f0xx_rcc.h”
  3. include “stm32f0xx_tim.h”
  4. include “stm32f0xx_gpio.h”
  5. include
  6. include “delay.h”

  1. define LED_PORT GPIOA
  2. define LED_STATUS GPIO_Pin_11
  3. define PWM_PIN GPIO_Pin_8
  4. define TXD_PIN GPIO_Pin_9

  1. define BTN_PORT GPIOB
  2. define BTN_START GPIO_Pin_7


volatile uint8_t motor_on = 0;
void Init(void);
void Setup_Init_Clocks();
void LED(uint8_t on);

void InitializeTimer(int period);
void InitializePWMChannel();

void LED(uint8_t on)
{
if (on > 0)
{
GPIO_SetBits(LED_PORT, LED_STATUS);
}
else {
GPIO_ResetBits(LED_PORT, LED_STATUS);
}
}

int main(void)
{
Setup_Init_Clocks();
Init();
LED(1);
InitializeTimer(1000);
InitializePWMChannel();


while(1)
{
}
return 1;
}


void Init(void)
{
RCC_ClocksTypeDef RCC_Clocks;
GPIO_InitTypeDef GPIO_InitStructure;

/* GPIOA-B Periph clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

/* Configure
* PB7 USER Button input
* */
GPIO_InitStructure.GPIO_Pin = BTN_START;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(BTN_PORT, &GPIO_InitStructure);

/* Configure PA8, PA9 and PA11 in output pushpull mode
* PA11 = Blue LED
* */
GPIO_InitStructure.GPIO_Pin = LED_STATUS | PWM_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(LED_PORT, &GPIO_InitStructure);

/* SysTick end of count event each 1us */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000000);
}

void Setup_Init_Clocks()
{
// Set up 48 MHz Core Clock using HSI (8Mhz) with PLL x 6
RCC_PLLConfig(RCC_PLLSource_HSI, RCC_PLLMul_6);
RCC_PLLCmd(ENABLE);

// Wait for PLLRDY after enabling PLL.
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) != SET)
{ }

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select the PLL as clock source.
SystemCoreClockUpdate();
}

void InitializeTimer(int period)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

TIM_TimeBaseInitTypeDef timerInitStructure;
timerInitStructure.TIM_Prescaler = 16;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = period;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &timerInitStructure);
TIM_Cmd(TIM1, ENABLE);
}

void InitializePWMChannel()
{
TIM_OCInitTypeDef outputChannelInit = {0};
outputChannelInit.TIM_OCMode = TIM_OCMode_PWM1;
outputChannelInit.TIM_Pulse = 500;
outputChannelInit.TIM_OutputState = TIM_OutputState_Enable;
outputChannelInit.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OC1Init(TIM1, &outputChannelInit);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);

GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void SetPWM(uint16_t pwm)
{
TIM_SetCompare1(TIM1, (uint32_t) pwm);
}


I also attached file after hitting F5 (step into InitializeTimer(1000)).

 

Newest Forum Posts

  1. reservation car service Seattle by Jamesprede, 2025-05-01 10:06
  2. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  10. Build a project in "release" mode by tang, 2025-02-20 10:36

Last-Modified Blogs