2020-03-13 10:45 AM
I am trying to get the stm32L010 lpuart TX out of PA14. The datasheet says this is AF6. However, despite uart interrupts etc all working (so I assume the lpuart block is configured ok) I can get nothing on PA14. This isn't helped by the fact that PA14 is also SWCLK so debug is not possible.
However, PA14 can be used for GPIO. So, for IO initialisation I have done the following:
GPIO_InitStruct.Pin = LL_GPIO_PIN_14;
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
// GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_14);
and within LPUART1_IRQHandler() I have added:
// Transmit register empty
if(LL_LPUART_IsActiveFlag_TXE(LPUART1))
{
LL_GPIO_TogglePin(GPIOA, LL_GPIO_PIN_14);
........ etc
}
I can then see PA14 toggling on a regular basis indicating that the lpuart is running and transmitting the data I put in the buffer.
So now it should be a simple case of ensuring lpuart tx is on PA14 instead of the gpio right?
GPIO_InitStruct.Pin = LL_GPIO_PIN_14;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
// GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_14);
You will noticed I left in the LL_GPIO_SetOutputPin(....) as the gpio output should be overriden by the alternative function setting.
Except it is not, I still get the GPIO toggling rather than any serial output.
I also tried setting AF4 (uart2, which is already trasmitting fine on PA3) and still only get GPIO activity on PA14.
Leaving the code as per the first section above (GPIO_Output) but then adding a
GPIOA->AFR[1] = (GPIOA->AFR[1] & 0xf0ffffff) | 0x06000000;
on the end and it still makes no difference.
Basically, whatever I have tried, I cannot get any AF functionality on PA14. Any ideas on what I am doing wrong?
Solved! Go to Solution.
2020-03-13 01:32 PM
Right, I just decided to go back to the absolute basics and found out what the problem is. This is rather embarrassing!!!
I was reading the datasheet for the STM32L010C6 which shows AF6 for lpuart1. Unfortunately my board actually has the STM32L010R8. This does not have LPUART1 on PA14.........
2020-03-13 12:42 PM
Can you also try to write directly to the MODER register?
JW
2020-03-13 12:57 PM
Good point, will give it a go.
2020-03-13 01:13 PM
Thanks for the suggestion Jan, adding
GPIOA->AFR[1] = (GPIOA->AFR[1] & 0xf0ffffff) | 0x06000000;
GPIOA->MODER = (GPIOA->MODER & 0xcfffffff) | 0x20000000;
stops the GPIO toggling so I guess that is progress, but I still see no uart TX.
However changing this to
GPIOA->AFR[1] = (GPIOA->AFR[1] & 0xf0ffffff) | 0x04000000;
GPIOA->MODER = (GPIOA->MODER & 0xcfffffff) | 0x20000000;
and I see serial from the PA14 pin! Of course this is the USART2_TX data, not the LPUART1_TX that I need, but at least it shows that the AF function should work.
So I am now thinking there must be something different with the LPUART compared to the USART that is preventing it generating any output rather than simply bad config of the gpio as I originally thought.
2020-03-13 01:20 PM
Generally it has value when not using debug as it can be used for telemetry output to the end user. Not tried to use in concurrently, and wouldn't expect it to work.
Believe I've seen this work on L011 and L072CZ parts
2020-03-13 01:24 PM
not sure I follow you Clive? Are you referring to using PA14/SWCLK for both debug and serial output at the same time? I am not trying to do that - I accept that I lose debug when using serial.
My confusion is that I can get USART2 on PA14 but not LPUART1 even though I know LPUART1 is working as the TX interrupt routine is active.
2020-03-13 01:32 PM
Right, I just decided to go back to the absolute basics and found out what the problem is. This is rather embarrassing!!!
I was reading the datasheet for the STM32L010C6 which shows AF6 for lpuart1. Unfortunately my board actually has the STM32L010R8. This does not have LPUART1 on PA14.........
2020-03-13 03:51 PM
Thanks for coming back with the solution. Please select your answer as Best so the thread is marked as solved.
JW