-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM32WL USART2@2400 not working with every device #15463
Comments
@hallard thank you for raising this issue.Please take a look at the following comments: It would help if you could also specify the versions of any tools you are using? NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'. This indicates to us that at least all the fields have been considered. |
To add some follow up, we succeded to speak at setting I was unable to find for USART2 where the clock source is selected (which one and frequency) on STM32WL for USART2. No idea, even in MBed nor HAL, would be curious to know that @jeromecoutant :-) |
From CubeMX, I could see settings: |
Ok some investigations, I succeeded talking device with some code in #endif /* LPUART1_BASE */
if (obj_s->uart == USART2) {
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;
if (!__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY)) {
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_OFF;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_HSI;
}
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}
if (init_uart(obj) != HAL_OK) {
debug("Cannot initialize UART with baud rate %u\n", baudrate);
}
} This works, and looking in cube IDE since STM32WL MSI is 48MHz HSI for USART2 is 16MHz (stil don't understand why USART2 with PCLK1 set to 48MHz it does not work) Anyway I decided to give a try, setting MSI RC to 32MHz and ABP1 prescaler to 2 in RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_10;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; Giving same frequency on UART2 And this one does not work, this is drving me mad. of course I changed into #endif /* LPUART1_BASE */
if (obj_s->uart == USART2) {
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}
if (init_uart(obj) != HAL_OK) {
debug("Cannot initialize UART with baud rate %u\n", baudrate);
}
} |
Ok, I took the logic analyzer to measure baud rate on different configuration on TX line, results are BTW amazing, I've done all test on LP_UART1 because this one has lot of clock option in mbed. All test are running with default frequencies and prescaler with STM32WL5 I mean
be prepared here are results with different values of please take into account that if multiple values are defined such as default value order in config if done the following (in
Please note also that if baud rate is < { "target.lpuart_clock_source": "USE_LPUART_CLK_PCLK1" }
|
Description of defect
As #15285 we've got some issues with USART2 at 2400bps. We use classic
BufferedSerial
We have different brand of connected devices working at 2400 bps and when using USART2 some have issues and are not responding
All devices work with USART1, LPUART1 at 2400 bps without any issue.
Issue is just on USART2 and at 2400 bps we tried 1200 bps on USART2 with great success (we can't go above 2400 on the devices we have)
We measured baud rate and looks like some shifting (more like 2450 than 2400) and may be some client devices are less or more strict than others on rate.
Target(s) affected by this defect ?
STM32WL
Toolchain(s) (name and version) displaying this defect ?
What version of Mbed-os are you using (tag or sha) ?
mbed-os-99.99.99
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
MBED Studio V1.4.5
How is this defect reproduced ?
Connect different devices on USART pins, send frame and wait answer, then do the same changing USART baud rate.
At 2400 bps on USART2 some devices are not responding (always the same)
I tried to use different clock source LSE (recommended for low baud rate) but not sure it's applied on USART2
I also changed prescaler value (1 2 4 8 16) nothing changed that's very strange.
@jeromecoutant any hints on configuration we could try (even calling HAL API) would be greatly appreciated, in the meanway we continue investigation.
The text was updated successfully, but these errors were encountered: