netzahuatl.edgardo

Basic : How to alternatively define Alternate function on STM32F302?

Discussion created by netzahuatl.edgardo on Nov 22, 2017
Latest reply on Nov 22, 2017 by waclawek.jan

Hello,

 

I´m using the CubeMx software only to stablish minor settings, I am trying to get PA7 on my F302R8 board as a complementary output, but without writing the following:

 

GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF6_TIM1;  // THIS ONE RIGHT HERE
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 

Is there any other way to define it, more like classic C?

 

This is how I´ve been defining my ports so far, I want to do something similar :

 

GPIOx->AFR[0]|=2; // 0 for (1 to 7 AFRLy ) and 1 (for 8 to 15 AFRHy)
GPIOx->MODER|=(0<<0)|(1<<1);// Alternate function on Px
GPIOx->OSPEEDR|=(1<<0)|(1<<1); //High speed on Px
GPIOx->PUPDR|=(0<<0)|(0<<1);

 

Apparently  GPIOx->AFR[n]|=X; only defines the High (1) and low (0) part and its function (X=0...7) but I´m not sure because there is also the pin on which the function outputs.

 

 

Thank you

Outcomes