STM32C011J6M6 (SO8 package) - trying reconfigure Pin 8 from STLINK (SWCLK) to GPIO on-the-fly (after boot)
I am attempting to reconfigure Pin 8 (datasheet default assignments are PB6/PA14-BOOT0/PC15-OSCX_OUT) from PA14-BOOT0 to PB6 GPIO Output Open Drain (GPIO_MODE_OUTPUT_OD) a short time after start-up.
My current attempt (code below) does not accomplish this (instead, once the port pin reconfiguration code below has run, an attached STLINK device can still connect to the MCU, or if already connected to MCU, continues to function.)
IMPORTANT: I have not yet and do not plan to change MCU option bytes (using STM32Programmer).
Intention: In the application (under development, written in C using STM32CubeIDE, using HAL), at power-up, a connected STLINK device should function normally. A short time later (under condition set in firmware), the application firmware is expected to reconfigure Pin 8 from power-on default (as Port A, GPIO bit 14, Alternate Function 0, which is STLINK SWCLK) to a different configuration (as Port B, GPIO bit 6, Open Drain output).
This change should (ideally) be able to occur in three external configurations:
(1) STLINK device is not present) on Pins 7 and 8.
(2) STLINK device is present on pins 7 and 8 but has not yet gone into connected state via STM32CubeProgrammer (in this configuration attempting STM32CubeProgrammer Connect is expected to fail.)
(3) STLINK device is present on pins 7 and 8 and has gone into connected state via STM32CubeProgrammer (in this configuration, the existing connection between MCU and STLINK is expected to fail.)
Here is the function I am using to attempt reconfiguration (this is based on the code STM32CubeMX generated to configure Port B bit 6 as GPIO Output Open Drain, but modified to reflect my current attempt to disconnected Pin 8 from Port A GPIO bit 14 and then connect in 8 to Port B GPIO bit 6.)
Current function is reflected in code below:
// Initialization of Port B bit 6 as generated by STM32CubeMX then modified in attempt
// to switch on-the-fly from STLINK (power-up) to GPIO configuration.
static void MX_GPIO_Init_B6(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOB_CLK_ENABLE();
// STM32C11J6M6
// Pin 8 is PB6/PA14-BOOT0/PC15-OSCX_OUT
// At power-up (no option bytes changed PA14 is AF0 (SWCLK)
// On subsequent condition which will call MX_GPIO_Init_B6(),
// programmatically switch from PA14/ALTERNATE/AF0 to PB6/GPIO_OUTPUT_OD
// Configure PA14 to ANALOG - intent here is to disconnect STLINK (attached
// and idle or attached and connected).
GPIO_InitStruct.Pin = GPIO_PIN_14;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; // MODE_INPUT should switch away from _ALTERATE
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // Write structure to PORT A pin 14
// Configure PB6 to output open drain - intent here is to connect Pin 8 to GPIO B
// bit 6 "PB6" so that it is used as GPIO and would no longer serve as SWCLK.
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); // Should float high once STLINK removed
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); // Write structure to PORT B Pin 6
// BELOW DOES NOT APPEAR TO HAVE INTENDED RESULT (STLINK STILL RUNNING) 12/13/2025
// HAL_SYSCFG_SetPinBinding(HAL_BIND_SO8_PIN8_PB6); // This should switch PIN8 to PB6
// LL_SYSCFG_ConfigPinMux(pin_binding);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
Thank you for any comments, advice, requests for further/new/clarifying information, or any other interaction
Dave
