Skip to main content
Associate
December 17, 2025
Solved

How to Initialize STM32C011J6

  • December 17, 2025
  • 5 replies
  • 1142 views

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.

Sourabh15_0-1765965467811.png

 

Best answer by gbm

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.

5 replies

gbm
gbmBest answer
Principal
December 17, 2025

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Sourabh15Author
Associate
December 18, 2025

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.

gbm
Principal
December 18, 2025

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Andrew Neil
Super User
December 17, 2025

@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!

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Pavel A.
Super User
December 18, 2025

 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.

 

Pavel A.
Super User
December 18, 2025

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.

Sourabh15Author
Associate
December 19, 2025

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?

Andrew Neil
Super User
December 20, 2025

@Sourabh15 wrote:

How can a pin set to a opposite state? 


You apply the signal externally:

  • If you apply VDD, SWD is active;
  • If you apply GND, I2C is active.

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:

AndrewNeil_2-1766222535228.png

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Sourabh15Author
Associate
December 25, 2025

Hey Andrew,

Thanks for your help with the diagram.

I created something in the CubeMX, can you just check if the assigned pins are good?

Sourabh15_0-1766639150929.png

And as schematic is concerned, I am planning to keep three components on the PCB for easy debug. Do you feel I am going in a good direction?

Sourabh15_1-1766639316971.png

I am eagerly waiting for your feedback.