2025-12-17 1:57 AM
Hi There,
So, I got some of the STM32C011J6 MCUs for my simple project of reading sensors data and generating an interrupt.
But I am in a dilemma, that the MCU's has I2C Pins, SWD Pins for programming, GPIO pins to act as interrupt but how to initialize it in CUBEMX.
I am planning to build PCB after I successfully assign pins in CUBEMX.
When I choose I2C, It blocks the SWD Pins and Vice versa. Also, is External Crystal necessary for such MCU? Looking forward to most of the suggestions and resources.
My plan is to read a sensor data via I2C and generate interrupt on a GPIO Pin.
Solved! Go to Solution.
2025-12-17 2:19 AM
For prototyping and development, keep the PA13 and PA14 pins as SWD.
Maybe you should start by using a Nucleo board with C031, develop the software on it, then migrate to your target MCU.
It will be hard anyway with C011J, since there is no alternative for I2C1_SDA, so maybe you should consider another MCU with slightly more pins.
All the details in clocking may be found in reference Manual, RCC section. It's impossible to do any engineering work without the RefMan, so I would suggest you get acquainted with it.
2025-12-17 2:19 AM
For prototyping and development, keep the PA13 and PA14 pins as SWD.
Maybe you should start by using a Nucleo board with C031, develop the software on it, then migrate to your target MCU.
It will be hard anyway with C011J, since there is no alternative for I2C1_SDA, so maybe you should consider another MCU with slightly more pins.
All the details in clocking may be found in reference Manual, RCC section. It's impossible to do any engineering work without the RefMan, so I would suggest you get acquainted with it.
2025-12-17 2:32 AM - edited 2025-12-17 2:33 AM
@Sourabh15 wrote:When I choose I2C, It blocks the SWD Pins and Vice versa.
Well, that is inherent in choosing a package with such a small pin count, isn't it?
There are simply not enough pins to give access to all of those features simultaneously!
This should have been clear from the datasheet.
This is not just an SMT32 issue - the same thing affects all low pin count microcontrollers.
It has been said that, "if you don't have enough resources to devote 10% to debug/diagnostics, then you just don't have enough resources" - in this context, "resources" includes pins!
it's always important that part of your design is, "How will I debug this thing?"
See: Design for Debug.
As @gbm said, you should at least start your development on a device with more pins.
If you really must, then move to the lowest pin count when your code is stable and well-proven. You will need to do very rigorous testing before that - because your debug options are severely limited!
2025-12-17 5:26 PM
> is External Crystal necessary for such MCU?
One of selling points of STM32C0 is ability to run without external crystal. So it probably can work for you.
2025-12-17 9:00 PM
Hey,
You have a point. But then help me clarifying that I won't be able to use this MCU in any condition? If this would be the case then why do manufacturer bring up such units.
Yes! I already got myself the nucleo board for dev purpose.
2025-12-17 11:24 PM
If I2C is used in the application, C011J It may be used in the final product but not for development. Once your software is debugged on Nucleo board with C031, you may migrate it to the device with lower pin count.
In the final prototype, to make it possible to reprogram the chip, you should keep the default configuration of SWD pins at startup, then reconfigure them to their target functions after, say, 3..5 seconds, This way it will still be possible to access the debug interface right after power-on.
2025-12-18 2:34 PM
To add a bit to the reply of @gbm : instead of delay you can use a free pin (if there is one) as input. When you connect SWD, connect also that pin to VCC or ground. Without debugger, set the pin in the opposite state. Then the program will know whether to initialize I2C. IIRC it is also possible to detect the debugger connection in the program, then no extra pin is needed.
2025-12-19 8:49 AM
This sounds logically right but is there any way or method to do it? Can the MCU used in both the configuration after I make a PCB for it?
2025-12-19 8:52 AM
Thanks for the additional information, How can a pin set to a opposite state? Like don't consider me a PRO :)
Can you please explain this technique?
2025-12-20 1:13 AM - edited 2025-12-20 1:22 AM
@Sourabh15 wrote:How can a pin set to a opposite state?
You apply the signal externally:
If you want the default to be I2C active, then fit a pull-down - then you only set it high when you want to use SWD.
The connector that you use to connect the debugger/programmer for SWD could include a link to set the pin high
PS:
eg, something like this: