Skip to main content
bnymntrz
Associate III
November 19, 2018
Question

hello, stm32f407 's code is working while debug I can see the data to the registers but I do not have any reaction when I load the card I would appreciate if you help ..

    This topic has been closed for replies.

    9 replies

    Tesla DeLorean
    Guru
    November 19, 2018

    I'm not entirely sure what you're doing or if this is a custom board, or whatever.

    If behaviour stand-alone vs debugger is different, make sure BOOT0 pin is pulled low. Output diagnostic/telemetry data out a USART, and avoid routines dependent on ITM or debug support.

    Also make sure to enable all clocks and GPIOs you need, don't rely on side effects of the debugger connecting and initializing functionality it uses.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    bnymntrz
    bnymntrzAuthor
    Associate III
    November 19, 2018
    Thank you very much sir, everything you say is activated, clock signals are activated, and in case of boot0 pin 0, I see the data going to the TIM-> CCR registers, but there is no response when I load the card.

    Tesla DeLorean
    Guru
    November 19, 2018

    >>but there is no response when I load the card

    Sorry I don't know what this means or what card you're talking about.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    bnymntrz
    bnymntrzAuthor
    Associate III
    November 19, 2018
     I'm talking about the stm32f407vg card, sir

    bnymntrz
    bnymntrzAuthor
    Associate III
    November 19, 2018
    Sir, the card is running but there is no reaction at the pin outputs, there is no error in compiling the program and the debug is running when I load it on the card, there is no response.
    Sir, the card is running but there is no reaction at the pin outputs, there is no error in compiling the program and the debug is running when I load it on the card, there is no response.

    bnymntrz
    bnymntrzAuthor
    Associate III
    November 19, 2018
    this is code sir; 
     
     
     
    #include "stm32f4xx.h" // Device header
    #include "stm32f4xx_gpio.h" // Keil::Device:StdPeriph Drivers:GPIO
    #include "stm32f4xx_rcc.h" // Keil::Device:StdPeriph Drivers:RCC 
    #include "stm32f4xx_tim.h" // Keil::Device:StdPeriph Drivers:TIM
    #include "RTE_Device.h" // Keil::Device:Startup
    #include "RTE_Components.h" // Component selection
    #include "misc.h "
    #include "stm32f4xx_adc.h" // Keil::Device:StdPeriph Drivers:ADC
     
     
     
     
     
    uint16_t adc_okuma(void){
     
    ADC_RegularChannelConfig(ADC2,ADC_Channel_9,1,ADC_SampleTime_56Cycles);
    ADC_SoftwareStartConv(ADC2);
    	
    	while(ADC_GetFlagStatus(ADC2,ADC_FLAG_EOC)== RESET);
    	
    	return ADC_GetConversionValue(ADC2);
    }
     
    void delay(uint32_t time){
    	
    	while(time)
    	time--;
    }
     
    	int main(){
    		
    		
    	GPIO_InitTypeDef APORT;
     GPIO_InitTypeDef CPORT;
    	GPIO_InitTypeDef ADCIO;
     ADC_InitTypeDef ADC_CONFIG;
    	ADC_CommonInitTypeDef ADCORTAK;
    		 TIM_OCInitTypeDef PWM;
    	TIM_TimeBaseInitTypeDef TIMER;
    	
    		
    		
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
    	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
    		RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2,ENABLE);
    		RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
    	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,ENABLE);
    	
    		
    	CPORT.GPIO_Mode = GPIO_Mode_AF;
    	CPORT.GPIO_OType = GPIO_OType_PP;
    	CPORT.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
    	CPORT.GPIO_PuPd = GPIO_PuPd_NOPULL;
    	CPORT.GPIO_Speed = GPIO_Speed_100MHz;
    	GPIO_Init(GPIOC,&CPORT);
    		
    	APORT.GPIO_Mode = GPIO_Mode_AF;
    	APORT.GPIO_OType = GPIO_OType_PP;
    	APORT.GPIO_Pin = GPIO_Pin_8| GPIO_Pin_9;
    	APORT.GPIO_PuPd = GPIO_PuPd_NOPULL;
    	APORT.GPIO_Speed = GPIO_Speed_100MHz;
    	GPIO_Init(GPIOA,&APORT);
    	
    	
    		GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
    		GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_TIM1);
    		
    		GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM8);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_TIM8);
    		GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM8);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_TIM8);
     
     
     
     
     
     ADCIO.GPIO_Mode = GPIO_Mode_AN;
    	ADCIO.GPIO_OType = GPIO_OType_PP;
    	ADCIO.GPIO_Pin = GPIO_Pin_1;
    	ADCIO.GPIO_PuPd = GPIO_PuPd_NOPULL;
    	ADCIO.GPIO_Speed = GPIO_Speed_100MHz;
    	GPIO_Init(GPIOB,&ADCIO);
     
    	
     ADCORTAK.ADC_Mode = ADC_Mode_Independent;
    	ADCORTAK.ADC_Prescaler = ADC_Prescaler_Div4;
     ADC_CommonInit(&ADCORTAK);
     
     ADC_CONFIG.ADC_Resolution = ADC_Resolution_8b;
    	ADC_Init(ADC2, &ADC_CONFIG);
    	ADC_Cmd(ADC2,ENABLE);
     
     
    	
     
     
     
    	
     
    	
    	
     
     
    	uint8_t OKUNAN_DEGER;
    	uint8_t ADC_DATA;
    	
     OKUNAN_DEGER = adc_okuma();
    	
    	 ADC_DATA = OKUNAN_DEGER * 500;
     
    	TIMER.TIM_Prescaler = 4199;
    	TIMER.TIM_Period = 1023;
    	TIMER.TIM_CounterMode = TIM_CounterMode_Up;
    	TIMER.TIM_ClockDivision = 0;
    	TIM_TimeBaseInit(TIM1,&TIMER);
     TIM_Cmd(TIM1,ENABLE);
    	
    	TIMER.TIM_Prescaler = 4199;
    	TIMER.TIM_Period = 1023;
    	TIMER.TIM_CounterMode = TIM_CounterMode_Up;
    	TIMER.TIM_ClockDivision = 0;
    	TIM_TimeBaseInit(TIM8,&TIMER);
     TIM_Cmd(TIM8,ENABLE);
    	
    	
    PWM.TIM_OCMode = TIM_OCMode_PWM1;
    PWM.TIM_OCPolarity = TIM_OCPolarity_High;
    PWM.TIM_OutputState = TIM_OutputState_Enable;
    PWM.TIM_Pulse = 0; 
    TIM_OC1Init(TIM1, &PWM); 
    TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
     
     
     
    PWM.TIM_OCMode = TIM_OCMode_PWM1;
    PWM.TIM_OCPolarity = TIM_OCPolarity_High;
    PWM.TIM_OutputState = TIM_OutputState_Enable;
    PWM.TIM_Pulse = 0; 
    TIM_OC2Init(TIM1, &PWM); 
    TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
    TIM_ARRPreloadConfig(TIM1,ENABLE);
     
     
     
    	
    	PWM.TIM_OCMode = TIM_OCMode_PWM1;
    PWM.TIM_OCMode = TIM_OCMode_PWM1;
    PWM.TIM_OCPolarity = TIM_OCPolarity_High;
    PWM.TIM_OutputState = TIM_OutputState_Enable;
    PWM.TIM_Pulse = 0; 
    TIM_OC1Init(TIM8, &PWM); 
    TIM_OC1PreloadConfig(TIM8, TIM_OCPreload_Enable);
     
    	PWM.TIM_OCMode = TIM_OCMode_PWM2;
    PWM.TIM_OCPolarity = TIM_OCPolarity_High;
    PWM.TIM_OutputState = TIM_OutputState_Enable;
    PWM.TIM_Pulse = 0; 
    TIM_OC2Init(TIM8, &PWM); 
    TIM_OC2PreloadConfig(TIM8, TIM_OCPreload_Enable);
     
    		
    PWM.TIM_OCMode = TIM_OCMode_PWM1;
    PWM.TIM_OCPolarity = TIM_OCPolarity_High;
    PWM.TIM_OutputState = TIM_OutputState_Enable;
    PWM.TIM_Pulse = 0; 
    TIM_OC3Init(TIM8, &PWM); 
    TIM_OC3PreloadConfig(TIM8, TIM_OCPreload_Enable);
    	
    	PWM.TIM_OCMode = TIM_OCMode_PWM1;
    PWM.TIM_OCPolarity = TIM_OCPolarity_High;
    PWM.TIM_OutputState = TIM_OutputState_Enable;
    PWM.TIM_Pulse = 0; 
    TIM_OC4Init(TIM8, &PWM); 
    TIM_OC4PreloadConfig(TIM8, TIM_OCPreload_Enable);
    TIM_ARRPreloadConfig(TIM8,ENABLE);
     
     
     
     
     
     
     
     
    		
    		
    	
    	
    while(1){
    	
    	
     
    	
    		
    		TIM1->CCR1 = ADC_DATA;
    		TIM1->CCR2 = 0;
    		TIM8->CCR1 = 0;
    	 TIM8->CCR2 = ADC_DATA;
    		TIM8->CCR3 = 0;
    		TIM8->CCR4 = 0;
    		delay(2000);
    		
    		TIM1->CCR1 = 0;
    		TIM1->CCR2 = 0;
    		TIM8->CCR1 = 0;
    	 TIM8->CCR2 = ADC_DATA;
    		TIM8->CCR3 = ADC_DATA;
    		TIM8->CCR4 = 0;
    		delay(2000);
    		
    		TIM1->CCR1 = 0;
    		TIM1->CCR2 = ADC_DATA;
    		TIM8->CCR1 = 0;
    	 TIM8->CCR2 = 0;
    		TIM8->CCR3 = ADC_DATA;
    		TIM8->CCR4 = 0;
     
    		 delay(2000);
     		
    		TIM1->CCR1 = 0;
    		TIM1->CCR2 = ADC_DATA;
    		TIM8->CCR1 = ADC_DATA;
    	 TIM8->CCR2 = 0;
    		TIM8->CCR3 = 0;
    		TIM8->CCR4 = 0;
    		 
    		 delay(2000);
     
     TIM1->CCR1 = 0;
    		TIM1->CCR2 = 0;
    		TIM8->CCR1 = ADC_DATA;
    	 TIM8->CCR2 = 0;
    		TIM8->CCR3 = 0;
    		TIM8->CCR4 = ADC_DATA;
     delay(2000);
     
     
     TIM1->CCR1 = ADC_DATA;
    		TIM1->CCR2 = 0;
    		TIM8->CCR1 = 0;
    	 TIM8->CCR2 = 0;
    		TIM8->CCR3 = 0;
    		TIM8->CCR4 = ADC_DATA;
     
     
    	}
    	
     
    	
    	
    	
     
     
    }
     
     

    Tesla DeLorean
    Guru
    November 19, 2018

    >>stm32f407vg

    That's a chip, do you have the STM32F4-Discovery board?

    1. TIM_OCInitTypeDef PWM = {0};
    2. TIM_TimeBaseInitTypeDef TIMER = {0};

    Both TIM1 and TIM8 are Advanced Timers, they have more fields which you are not initializing properly, clear the variables so at least there isn't random data in the structures.

    Also you need to enable outputs for them

     /* Main Output Enable */

     TIM_CtrlPWMOutputs(TIM1, ENABLE);

     TIM_CtrlPWMOutputs(TIM8, ENABLE);

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    bnymntrz
    bnymntrzAuthor
    Associate III
    November 20, 2018
    I tried but not.

    bnymntrz
    bnymntrzAuthor
    Associate III
    November 20, 2018
    sir, it is a need to talk to you thanks to the many you have solved ..