grblHAL / Plugins_spindle

grblHAL plugins for spindle control
Other
9 stars 12 forks source link

Stream claiming logic with MODBUS_RTU_STREAM defined #25

Closed dresco closed 9 months ago

dresco commented 9 months ago

Hi,

Am wondering whether there is an error with the current logic for claiming serial streams?

Have been looking at the F7 driver, and as best as I can see, the instance member checked in the following code is always 0,1, or 2 - and not the number from the SERIALn_PORT / MODBUS_RTU_STREAM definition?

https://github.com/grblHAL/Plugins_spindle/blob/7056c25b302f0719dd3ac1c52e8bb0a1b4624463/modbus_rtu.c#L501-L505

I've been trying to verify this with the F7/H7 Nucleo reference map;

terjeio commented 9 months ago

Have been looking at the F7 driver, and as best as I can see, the instance member checked in the following code is always 0,1, or 2 - and not the number from the SERIALn_PORT / MODBUS_RTU_STREAM definition?

Correct. The SERIALn_PORT definition binds a physical port to an instance at the driver level. Outside of the serial driver code the port instance is used to connect to the port.

dresco commented 9 months ago

Thanks, so instead of this (for instance)

#define SERIAL1_PORT                32 // GPIOD: TX =  8, RX =  9
#define MODBUS_RTU_STREAM           SERIAL1_PORT

The expected way would be like this?

#define SERIAL1_PORT                32 // GPIOD: TX =  8, RX =  9
#define MODBUS_RTU_STREAM           3
terjeio commented 9 months ago

SERIAL1_PORT is for instance #1 so #define MODBUS_RTU_STREAM 1 is the correct definition. #define SERIAL1_PORT 32 is for binding MCU UART peripheral 3 with the second (2) pin map to instance 1.

dresco commented 9 months ago

Ah yes sorry. Got it now, thanks!