STM32F2 odd serial port behaviour.
Hi,
I have an odd behaviour I can't presently understand or fix. I'm hoping someone can advise some way to track/fix it.
It's happening on USART3, PD8/9 on an STM32F205.
When Debug mode is enabled, the serial port works fine.
Wen Debug is not enabled, for release, the Tx line (PD8) never goes high.
I've checked through all the initialisation and can't _see_ anything wrong.
One factor on this particular serial port that may be relevant is that I swap modes between AF and OUT because when the unit with which I communicate is supposed to be depowered, it tend to stay on by stealing power from the Tx line: I doubt it matters, but the power control is via PD10.
--------8<--------------------
static inline void
disable_Pod_power( void )
{
uint32_t moder_copy;
syslog( "Depower Pod\n");
Pod_Power = NO;
USART3_TX_GPIO_PORT->ODR &= ~(1<<(USART3_TX_GPIO_PIN)); // pre-set output low
// Turn off alternate-function so we don't try to power the Pod
// via the Tx data line.
moder_copy = USART3_TX_GPIO_PORT->MODER;
moder_copy &= (~(3<<(USART3_TX_GPIO_PIN<<1)));
moder_copy |= (GPIO_Mode_OUT<<(USART3_TX_GPIO_PIN<<1)) ;
USART3_TX_GPIO_PORT->MODER = moder_copy; // and do it...
// and turn off the pod power.
GPIO_ResetBits( USART3_EN_GPIO_PORT, (1<<USART3_EN_GPIO_PIN) );
}
--------8<--------
static inline void
enable_Pod_power( void )
{
uint32_t moder_copy;
syslog( "Power Pod\n");
// Turn on the Pod power.
GPIO_SetBits( USART3_EN_GPIO_PORT, (1<<USART3_EN_GPIO_PIN) );
// and enable the alternate-function.
moder_copy = USART3_TX_GPIO_PORT->MODER;
moder_copy &= (~(3<<(USART3_TX_GPIO_PIN<<1)));
moder_copy |= (GPIO_Mode_AF<<(USART3_TX_GPIO_PIN<<1)) ;
USART3_TX_GPIO_PORT->MODER = moder_copy; // and do it...
Pod_Power = YES;
}
--------8<--------
At present I have STARTUP_FROM_RESET in the Debug code and that's what I'm shipping and it appears fine, so I have an puzzle not a catastrophe.
Gordon.
-
Hi Gordon,
I don't know if this is new for the 3.x series, but I've noticed a fair amount of my code acts differently due to optimization settings. Even in debug, if I up the optimization to level 1, I get some routines that no longer work correctly. Even with "static" and "volatile" and moving things around to prevent optimizing out unfortunately.
Perhaps check the optimization level in your release build vs. your debug build. If they are different, set your release build to the same level as the debug and see if it works...
Matt
Please sign in to leave a comment.
Comments
2 comments