cancel
Showing results for 
Search instead for 
Did you mean: 

How to Initialize STM32C011J6

Sourabh15
Associate II

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
gbm
Principal

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

View solution in original post

11 REPLIES 11
gbm
Principal

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
Andrew Neil
Super User

@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

 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.

 

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.

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
Pavel A.
Super User

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.

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?

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?


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