Comments (6)
@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.
Please update the issue header with the missing information.
from mbed-os.
To add some follow up, we succeded to speak at 2400
on USART2 setting baud rate to 2500
setting 2400
measured baud rate with logic analyser => 2310
setting 2500
measured baud rate with logic analyser => 2410
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 mbed-os.
From CubeMX, I could see settings:
I suppose that, as we don't configure usart2 clock, default values are ok...
https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/serial_api.c#L635
from mbed-os.
Interesting so default configuration (As USART1) 2400 do 16 prescaler so 3MHz that should be fast enough to be precise, don't understand why it works with USART1 and not USART2.
I May try to configure USART2 from code issued from cubeMX just to test.
from mbed-os.
Ok some investigations,
I succeeded talking device with some code in serial_baud
of serial_api.c
to set UART2 to HSI
#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 SetSysClock()
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 serial_baud()
#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);
}
}
from mbed-os.
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
- SysClk
48MHz
- PCLK1
48MHz
- HSI
16MHz
be prepared here are results with different values of lpuart_clock_source
in mbed_app.json
please take into account that if multiple values are defined such as default value
USE_LPUART_CLK_LSE|USE_LPUART_CLK_PCLK1|USE_LPUART_CLK_PCLK3
order in config if done the following (in init_uart()
of serial_api.c):
- LSE (only if baud <=9600)
- PCLK1
- PCLK3
- SYSCLK
Please note also that if baud rate is < 4800
then UART prescaler is set to 16
instead of 1
, you can check mbed original code here
{ "target.lpuart_clock_source": "USE_LPUART_CLK_PCLK1" }
USE_LPUART_CLK_PCLK1
- 1200 bps measured 1165
- 2400 bps measured 2330
- 4800 bps nothing goes out from serial
- 9600 bps nothing goes out from serial
USE_LPUART_CLK_LSE
- 1200 bps measured 1165
- 2400 bps measured 2330
- 4800 bps measured 4700
- 9600 bps measured 9450
USE_LPUART_CLK_HSI
- 1200 bps measured 1200
- 2400 bps measured 2403
- 4800 bps measured 4806
- 9600 bps measured 9615
No option in lpuart_clock_source
so in this case default values from mbed applies (see above), so mainly LSE as it's the first in the list.
- 1200 bps measured 1165
- 2400 bps measured 2330
- 4800 bps measured 4700
- 9600 bps measured 9450
What to think? not really sure if there is something wrong somewhere I digged into the code and did not found visible error. But why with PCLK1 nothing goes out from serial at 4800 and 9600 I have no idea.
Anyway looks like best option is to use HSI for baud rate below or equal to 9600 (not sure for higher speed)
First idea would be to set system clock to 16Mhz
and expect same results than HSI, but this does not works either, baud rate shift is always there.
If someone has ability to test with another board (NUCLEO WL55 for example) would be great to confirm.
from mbed-os.
Related Issues (20)
- Buffer overflow vulnerablilty in MbedOS BLE Cordio stack HOT 2
- STM32WL System Clock differs at boot/reset and after deepsleep HOT 2
- Mbed CLI 2 USB no such file or directory HOT 2
- mbed-tools deploy is limiting the git fetch specification HOT 2
- STM32_gen_peripheralPins.py chrashing after generating pinmaps HOT 3
- Linking with error: "cannot move location counter backwards" HOT 1
- BLE start routine freezes when the event_queue dispatching inside mbed-os-ble-utils moved to a thread HOT 1
- Include directive issue with BLE API HOT 1
- PD_14 is not labeled as a SPI CS pin for Nucleo-F413ZH HOT 5
- time(NULL) not returning real RTC value after reboot HOT 1
- PC_13 is unlisted HOT 2
- TARGET_STM32F303xC: SetSysClock() missing HOT 2
- Update hidapi used for non-Linux platforms HOT 2
- Flashing Controller from Docker Container HOT 2
- mbed::CircularBuffer interrupt safe but not thread safe? HOT 2
- STM32 I2CSlave race condition causing timeouts
- LoRaWAN no OTAA Uplink on AS923 region STM32WL HOT 3
- STM32U5 HSI and HSE SetSysClocks missing (only MSI implemented)
- STM32 Cellular/LWIP/PPP 100ms periodic wake after shutdown
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mbed-os.