Skip to content
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

Example does not compile, core 2.6.0 #2077

Closed
brightproject opened this issue Jul 20, 2023 · 9 comments
Closed

Example does not compile, core 2.6.0 #2077

brightproject opened this issue Jul 20, 2023 · 9 comments
Labels
invalid This doesn't seem right

Comments

@brightproject
Copy link

brightproject commented Jul 20, 2023

Example from here doesn't compile in Arduino IDE 1.8.19 and on BlackPill stm32f401ccu6

//                      RX    TX
HardwareSerial Serial1(PA10, PA9);

void setup() {
  Serial1.begin(115200); 
}

void loop() {
  Serial1.println("Hello World!");
  delay(1000);
}

c:/users/admin/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/12.2.1-1.2/bin/../lib/gcc/arm-none-eabi/12.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\admin\AppData\Local\Temp\arduino_cache_150181\core\core_a9c0fc81ed87578aed206a502d28436a.a(HardwareSerial.cpp.o):(.bss.Serial1+0x0): multiple definition of `Serial1'; sketch\Test.ino.cpp.o:(.bss.Serial1+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1

Related link.
This code work awesome

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println("Hello, Serial port!");
  
  delay(1000); 
}

And this one

void setup() {
  Serial1.begin(115200);
}

void loop() {
  Serial1.println("Hello, Serial port!");
  
  delay(1000); 
}

If compile code

//                      RX    TX
HardwareSerial Serial2(PB7, PB6);

void setup() {
  Serial.begin(115200); 
  Serial2.begin(115200); 
}

void loop() {
    Serial2.println("Data received from Serial 2");
    delay(200);
    Serial.println("Data received from Serial");
    delay(200);
}

I get output on PA9
Скриншот 20-07-2023 14 38 46
And that's where it all ends...
And on PB6 exactly the same conclusion
Скриншот 20-07-2023 14 41 20

Green - Serial on PA9
Yellow - Serial2 on PB6

Serial ports through HardwareSerial do not work adequately.

@fpistm fpistm added the invalid This doesn't seem right label Jul 20, 2023
@fpistm
Copy link
Member

fpistm commented Jul 20, 2023

Hi @brightproject
it seems you don't understand how Serial instance is defined.
By default each board defined a default Serial instance which is mapped on a Serialx where x is the number of an U(S)ARTx.

For the BlackPill:

// UART Definitions
#ifndef SERIAL_UART_INSTANCE
#define SERIAL_UART_INSTANCE 1
#endif
// Default pin used for generic 'Serial' instance
// Mandatory for Firmata
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX PA10
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX PA9
#endif
#ifndef HSE_VALUE
#define HSE_VALUE 25000000U
#endif

So Serial is equal to Serial1.

When you instantiate manually a Serial2 using PB6 and PB7, you used also USART1 so it is normal as Serial/Serial1 and Serial2 are instantiate against the same USART1 IP.

For Ref:

#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_TX[] = {
{PA_2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PA_11, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)},
{PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{NC, NP, 0}
};
#endif
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_RX[] = {
{PA_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PA_12, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)},
{PB_7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{NC, NP, 0}
};
#endif

Please read carefully the Wiki:
https://github.com/stm32duino/Arduino_Core_STM32/wiki/API#hardwareserial

By default, only one Serialx instance is available mapped to the generic Serial name.

@fpistm fpistm closed this as completed Jul 20, 2023
@brightproject
Copy link
Author

brightproject commented Jul 20, 2023

it seems you don't understand how Serial instance is defined.

Yes, you are right, until recently I did not quite understand UART.
I'm sorry for the confusion and redundant issue.
This code work good.

HardwareSerial RPI(PB7,PB6);
HardwareSerial DEBUG(USART2);

void setup() {

  RPI.begin(115200);
  DEBUG.begin(115200); // begin Serial


}

void loop() {
 
  DEBUG.println("debug");
  RPI.println("RPI");
 
} 

It turns out that I cannot use the I2C bus on PB6 and PB7 at the same time(simultaneously), I cannot use UART1?

@fpistm
Copy link
Member

fpistm commented Jul 20, 2023

It turns out that I cannot use the I2C bus on PB6 and PB7 at the same time(simultaneously), I cannot use UART1?

You can, but in all your example there is no I2C code using Wire library.
Default pins for Wire are PB6/PB7:

// I2C definitions
#ifndef PIN_WIRE_SDA
#define PIN_WIRE_SDA PB7
#endif
#ifndef PIN_WIRE_SCL
#define PIN_WIRE_SCL PB6
#endif

So simply use Serial instance which using PA9/PA10 and Wire instance which using PB6/PB7.
If you use one of the default Wire example like I2C scanner, you will see your I2C device address print on the Serial.

@brightproject
Copy link
Author

brightproject commented Jul 20, 2023

Yes, that's right - by default, I2C works on PB7/PB6, and Serial1 on PA10/PA9.
But I had a problem with the STM32F401 and therefore began to understand, and found non-working ports.
Now I figured out the USART's and I will figure out why the I2C and USART1 bus does not work at the same time, specifically on my hardware.
On three BlackPills at the same time is not normal.
ESP32 accepts code without any problems, so I started thinking about STM32 core.

@fpistm
Copy link
Member

fpistm commented Jul 20, 2023

Honestly, I don't understand your issue.
What it exactly your code? I2C and Serial works properly on blackPill F4. I've one and have no issue.

@brightproject
Copy link
Author

brightproject commented Jul 20, 2023

Honestly, I don't understand your issue.

It all started with what I checked the code on stm32f401 with the MPU9250 board connected via I2C.
photo1687531275
But I made a small mistake when designing the board, and I received 5 volts, instead of 3.3 volt from the CH340 at the UART input, while everything worked well and without failures.
254691537-a34ce68d-8687-4055-bd72-bcca9159458b
For about 4 days the code worked, and I normally received data on Serial1.
252167195-e587a91c-4687-4fdf-b793-d44e798876fe
Then I updated the STM core to 2.6.0 and after, I could not run the example for normal work, that have worked before.
And the next morning my SSD broke - I'm sure it's just a coincidence.
While I was repairing the main computer, I checked the code on the second laptop, and the code did not work either.
From which I decided that the problems with the iron, and the STM core had nothing to do with it.
When I repaired the main computer, I installed a new kernel 2.6.0, StmCubeProgrammer.
But the example code didn't work.
I began to deal with the output to the Serial port, and in fact, after a few days, I wrote an issue.
When I dealt with the work of I2C and USART at the same time, I came across issue and topic with problems with I2C in the STM core, and I again had thoughts about problems with the core.
Because 3 BlackPills cannot work in the same way.
Do you happen to have an MPU9250 board or at least an MPU6500 board?
Could you check out the example with the BlackPill and the STM core?
Just change in code
#define SerialPort SerialUSB
on
#define SerialPort Serial

This code

HardwareSerial DEBUG(USART2);

void setup() {
  Serial.begin(115200);
  DEBUG.begin(115200);
}

void loop() {
  DEBUG.println("debug");
  Serial.println("Serial1");
} 

works, and I conclude that the PA10 port did not burn out, but something may have happened to the TIM_1_CH3 timer and now it is impossible to start I2C and Serial1 on the microcontroller at the same time.
PS.
Also, in the process of working with I2C, I could not increase the speed from 100 KHz.
Doesn't work in sketch code.
Wire.setClock(400000);
Only when I changed it in the *cpp file of the library.
100 KHz is clearly defined by the analyzer
100mHz
and 400 KHz is already 333.3 KHz real(Pull-up resistors to 3.3 volts 4.7 kΩ).
The team that is working on the ESP32 core has solved the problem of lowering the set frequency.
333 3mHz

@fpistm
Copy link
Member

fpistm commented Jul 20, 2023

Well, I've got an MPU-9250 an it works as expected with a blackPill F4 and the MPU9250_Basic.ino and it works as expected:

18:57:39.331 -> Accel: 0.80, -0.59, -0.15 g
18:57:39.331 -> Gyro: 34.63, -25.06, 99.09 dps
18:57:39.331 -> Mag: 55.51, -41.86, 7.35 uT
18:57:39.377 -> Time: 63826 ms
18:57:39.377 ->
18:57:39.470 -> Accel: 0.73, -0.65, -0.16 g
18:57:39.470 -> Gyro: -26.89, 5.37, 17.01 dps
18:57:39.470 -> Mag: 57.91, -36.91, 6.75 uT
18:57:39.470 -> Time: 63926 ms
18:57:39.470 ->
18:57:39.563 -> Accel: 0.97, -0.33, -0.12 g
18:57:39.563 -> Gyro: -15.24, 25.00, -174.21 dps
18:57:39.563 -> Mag: 57.01, -37.51, 6.90 uT
18:57:39.563 -> Time: 64026 ms
18:57:39.563 ->
18:57:39.655 -> Accel: 0.93, -0.18, -0.13 g
18:57:39.655 -> Gyro: -24.51, -2.01, -49.70 dps
18:57:39.655 -> Mag: 45.01, -46.51, 6.90 uT
18:57:39.655 -> Time: 64126 ms
18:57:39.655 ->
18:57:39.733 -> Accel: 0.75, -0.58, -0.26 g
18:57:39.733 -> Gyro: 15.00, -40.55, 163.35 dps
18:57:39.733 -> Mag: 45.31, -48.01, 6.90 uT
18:57:39.733 -> Time: 64226 ms
18:57:39.778 ->
18:57:39.857 -> Accel: 0.76, -0.67, -0.23 g

I've also tested with https://github.com/hideakitai/MPU9250 and it works too.

@fpistm
Copy link
Member

fpistm commented Jul 20, 2023

About:

Wire.setClock(400000);

It have to be called after the Wire.begin() but as it is encapsulate in the Sparkfun library you have to edit it or kept 100kHz.

Exactly here:
https://github.com/sparkfun/SparkFun_MPU-9250-DMP_Arduino_Library/blob/f46b97c4dff33c83eebc775a7fce5b70df071984/src/SparkFunMPU9250-DMP.cpp#L44C1-L45

	 Wire.begin();
+        Wire.setClock(400000);

@brightproject
Copy link
Author

brightproject commented Jul 20, 2023

Well, I've got an MPU-9250 an it works as expected with a blackPill F4 and the MPU9250_Basic.ino and it works as expected:

Thank you very much for taking the time to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants