CommunityGD32Cores / ArduinoCore-GD32

Arduino core for GD32 devices, community developed, based on original GigaDevice's core
Other
85 stars 33 forks source link

GD32F330F8P6 design guidelines #97

Closed ITstreet1 closed 1 year ago

ITstreet1 commented 1 year ago

This IC uses PA9 and PA10 as a UART RX and TX. But at the same time, they are the I2C0 pins. https://github.com/CommunityGD32Cores/ArduinoCore-GD32/blob/main/variants/GD32F330F8_GENERIC/variant.h

I wonder if can I use these pins as an I2C no matter if I use them for uploading the sketch in BOOT mode? My guess is it does not matter as long as I don't use them in Serial communication while in working mode. If so, do I need some specific design, or I just connect the I2C device to those pins, put it in BOOT mode, upload the sketch, exit the BOOT mode, and let it live its life?

maxgerhardt commented 1 year ago

SERIAL0_RX == PIN_WIRE_SDA shouldn't have happened. The problem is that all of these variant.h files are autogenerated by a script, gd32_genpinmap, and this script doesn't have a very sophisticated "pin allocator" to make sure there isn't a double-usage of a pin in two popular peripherals. It just has a "prefered" pin, and if that pin doesn't exist, it goes to the next preferred pin.

As a result of that, definitions like that can happen.

You're free to change the pins to whatever you want -- in limits with the peripheral, of course.

For I2C

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/blob/2cb8305b43727e6f8d023335621c7e8556ce8034/variants/GD32F330F8_GENERIC/PeripheralPins.c#L114-L126

For UART

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/blob/2cb8305b43727e6f8d023335621c7e8556ce8034/variants/GD32F330F8_GENERIC/PeripheralPins.c#L152-L165

maxgerhardt commented 1 year ago

Hah, I actually have to correct myself here. According to that, the only possibility for "Wire", mapping to I2C0, really is PA9, PA10. Same as for USART0!

So, in the application, don't use Serial and Wire at the same time -- but you can use e.g. Serial and Wire1, or Serial1 and Wire, since they're on different pins (mix+match of USART0, USART1, I2C0, I2C1).

Unfortunately I think if you design the hardware with a I2C device on the I2C0 pins (same as USART0 pins), then uploading firmware in the BOOT0 mode will fail, the I2C devices will react to edges of the UART RX and TX signal and screw with the signal, trying to pull it LOW various times.

ITstreet1 commented 1 year ago

From what I have seen, the same goes for most TSSOP20 chips.

I2C needs a pull-up. Yes, I see the problem. Maybe separate the I2C lines with a jumper? This way I can upload a sketch, then solder the I2C jumper and connect the lines...

maxgerhardt commented 1 year ago

I think you can use a double-throw, double-pole switch where, if the switch is UP, then PA9, PA10 lines are connected to the I2C devices, and if DOWN, they are disconnected (or connected to some UART pin headers). That way it's atleast easily switchable.

ITstreet1 commented 1 year ago

Space is the problem. Three-pad solder joint will do the same job. The same one I use as a BOOT selector. Besides, I shouldn't leave an option for a user to mess it up. :)

maxgerhardt commented 1 year ago

I see.

I think we then can we conclude the the definitions are okay for Serial and Wire because they're really the only pin choices for USART0 and I2C0? Users can still use Serial, Serial1, Wire, Wire1 as needed to mix-match. Connecting the pins to different devices or headers is a hardware problem and can't be solved in this Arduino core.

ITstreet1 commented 11 months ago

Heh,

On GitHub, there is a support for this chip. It clearly says in variants. But, in Arduino IDE, there is none. Version I have installed is 0.0.1

How to add support for this one chip?

maxgerhardt commented 11 months ago

Arduino IDE 2.x or 1.x?

ITstreet1 commented 11 months ago

1.8.19

maxgerhardt commented 11 months ago

F330F8 does exist as a variant here and is referenced in the boards.txt.

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/blob/dfa7ccbef5161f0215d28d9b59aa9f24e61d07f5/boards.txt#L338-L341

Are you sure you're using https://raw.githubusercontent.com/CommunityGD32Cores/GD32Core-New/main/package_gd32_index.json as the package URL? If you have an older version of tis core previously installed, you need to uninstall + reinstall it in the Arduino IDE boards manager.

ITstreet1 commented 11 months ago

LOL. This did the trick. I just reinstalled it. I still get the 0.0.1 version, but this time with all the boards in the list.

Thank you.

maxgerhardt commented 11 months ago

We don't version the core yet, so it's been "0.0.1" forever -- a reinstall however will always install the latest version this git repository.

ITstreet1 commented 11 months ago

I believe it should have versions. I didn't get the update option to a newer version, so I didn't know what to do. I thought I have the newest version, and thought it was some kind of a bug.

Thank you anyway, and thank you for your effort.