-
Notifications
You must be signed in to change notification settings - Fork 3k
Stream obj failure on two STM32L4 custom targets #10425
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
Comments
Internal Jira reference: https://jira.arm.com/browse/MBOCUSTRIA-1151 |
Assuming UART3 is not the console, then it sounds like the HAL is messing up the console serial port when UART3 is initialised. This is either a bug in the HAL, or a pin mapping limitation. The application only gets to specify pins, not UART instances. The UART instance is deduced from the pins. If on this chip your "UART3_RX" and "UART3_TX" pins are actually usable by UART1 as well, then maybe it's deciding to drive those pins using UART1. You might need to modify pin mapping tables to change which the preferred UART instance is for your pins. HALs don't record which pins have already been put into use - indeed some apps rely on them not doing so because they're sloppy about repeated initialization. |
@kjbracey-arm
UART3 is the console, i defined it in PeripheralNames.h
Also i know that declaring a serial object with the same UART port as STUDIO is not a problem at all, i do it all the time and it never cause any issue. If we declare for example uart3 as Serial instance and uart3 as STDIO port, then both serial3.printf and printf can be used, at the same time, without causing any error. I also tried to use UART1 and UART2 as console default and still have the same error, so its not related to which UART is used for console. Also as told, the exact same project unchanged works perfectly fine on the STM32L151 target.
They may be but these GPIOs are not declared for both anyway, and i only use one instance here (uart3). Which pin is used by which UART is defined in PeripheralPins.c and it looks fine to me. Again, this very project is used with STM32L1 target without causing any error.
I dont know how it could be a bug in the HAL because the STM32L1 target works with no problem, and these STM32L4 targets worked perfectly fine in previous version of MBED as well (that said we used MBED 2, not 5 at the time). I suspect it is a problem with mbed. |
@kjbracey-arm
MBED throws the stream error when UART3 is initialized, which ultimately prevent any further print to STDIO since MBED is stuck in a loop after the error occurs. i dont know if the stream error originates from HAL or MBED itself, it occurs as the result of fdopen() is null (presumably). |
You may be getting away with it, but it causes quite a few issues internally. Quite a lot of juggling in the HAL and C retargetting is needed to stop the console+application use conflict causing problems, but not all targets support that juggling. It's definitely not supported if using buffered serial. Still, I would expect this STM platform to work as well as any other STM platform.
When opening UART3 or the same UART as the console?
If Or maybe Can you isolate further where that I gather this is GCC? |
cc @ARMmbed/team-st-mcd |
@kjbracey-arm
OK, i dont use buffered serial anyway, and ultimately i only need the Serial UART, STDIO is used only for finding the issue when it doesnt work as here.
as told, console is UART3. i tried to set console to UART2 / UART1, and open Serial to UART3, it doesnt change anything, error still thrown.
Well, i really doubt it, the target has 128K RAM, and my main is below, as you can see there is nothing in it.
How can i know the cause? i have a breakpoint at this line, i should check in mbed_retarget.cpp?
Yes right, it is GCC ***mbedcli path = |
If you just step through the fdopen at source level, that should reveal something. The call chain should be I don't see anything particularly target-specific here, oddly. |
ok i will do that and let you know.
Yes, i never came across this issue in the past. I can't affirm it is target specific but fact is the same project works perfectly with the STM32L1 target and fail with STM32L4 targets. |
alright, so i stepped debugged in fdopen, landed in mabed_retarget, no error occur here, the returned object fh_i value is 0x03: later in bind_to_fd : later in STD::fdopen: Finally back to Stream::stream, the file pointer is 0x0 which doesnt seem right, hence the jump to MBED_ERROR1 rather than continuing to mbed_set_unbuffered_stream():
|
I just ran this test on our old project folder, mbed-os version : major 5, minor 10, patch 2 and everything works fine here, no stream error or anything. To go ahead i copied the whole target folder from this project to the new project (mbed-os version : major 5, minor 12, patch 0) and the stream error occurs immediately. So something changed between these two version which cause the stream error issue. EDIT: EDIT2: EDIT3: |
From Are we sure it's not an allocation failure? Can you breakpoint malloc? (May be tricky without the source). You say "This target has 128K of RAM". Fine, but does Mbed OS know that? Is the linker map set up correctly? Check how much you can actually allocate. |
Ah, that seems to be it. Your heap has no space allocated:
All the other STM targets have the line
before Apparently STM targets needed to be updated due to a change to their If you're making new/custom targets, I suggest running the GreenTea test suite on them, to show up this sort of platform problem in a systematic way. |
@kjbracey-arm
I will once i have a moment, the failure is likely here
Yes, the linker file reflect that, by the way i told wrongly 128K,t it is actually 160K
|
Oh right, i see now, i will make these changes and see EDIT :
EDIT2: |
@kjbracey-arm 💯 |
Hi @Hoel |
@Hoel I have the same issue on STM32L4 using the USBSerial class (that heritates from Stream) Can you provide the modification you applied to the linker script ? Thanks ! |
Hello, alright, i will provide you my linker script later today |
@jeromecoutant |
Ok i can confirm that the issue is resolved by adding the following line to the linker script :
|
Hello,
and in linker file: on top:
line 137
|
Description
I added three custom targets, one STM32L1 : STM32L151CCU6 and two STM32L4 : STM32L451CEU6 and STM32L462CEU6, the required HAL files


have been grabbed from STM32CubeMX and are of same version as the other Nucleo STM32L4 official targets (STM32Cube_FW_L4_V1.11.0). ClI is up to date (installed on OSX with MBEDCLI installer). The project has been created two days ago from the CLi so mbed-os is also up to date. Project is building fine with all 3 targets.
The stream failure issue occurs on the two STM32L4 targets only (on the STM32L1 target everything works fine). It is caused by the serial port instance (uart3 in this case but i tried uart1 and uart2 with same result) and it occurs immediately, before the main is reached. Since the error is related to stream it also prevent mbed to display the error in serial port.
in mbed_config i enabled everything related to error capture:
I finally found a way to get the error printed on console, if i add a simple printf statement at the beginning of the main and then only declare the serial port inside the main afterwards then the error is printed (however it doesnt show the file or line number as it should, for some reasons).
Also, if i remove the serial port declaration everything works fine and the led is blinking as it should.
I exported to whole project to SW4STM32 in order to step debug and after hundreds of steps i landed in stream.cpp line 31 where the error occurs, fopen and the file object fails for some unknown reasons and the mbed error is thrown.
I tried to build with --profile=release in CLI, same error, i also tried to set MBED_CONF_RTOS_PRESENT to 0, same error. This target has 128K of RAM so it is unrelated to lack of ram, also it works fine on STM32L151 which has only 32K of RAM.
One interresting fact is that if i dont declare the serial port at all and only use stdio printf statements they are working fine, correctly redirected to the uart3 port which is set as default for STDIO and there is no stream error (maybe stream is not used in this case?).
Here is the console output when the stream failure occurs:
I dont think there are any official targets with STM32L451CE or STM32L462CE. If really needed i can send one of our targets along with a STLink for testing purppose, i can also run any binary / target folder that MBED or ST team would provide for test. Attached are the two target folders and the targets.json file.
targets.json.zip
Archive.zip
the main.cpp test file is as follow:
#include "mbed.h"
If uart3 is declared after the LED then error occurs immediately and nothing is printed on console, if instead uart3 is declared only after the first printf statement, then the first printf statement works and the stream error is printed in console uart3.printf statement never works since it is after the stream error in both cases. If uart3 is never declared nor used and only stduio printf statements are used, everything works fine and no error occurs (but this is not an option since we need all 3 uart ports to be working).
Issue request type
The text was updated successfully, but these errors were encountered: