/**************************************************************** * File Name : main.c * Date : 2025/11/10 * Description : Main program body.*///It working on 4 out of the 5 ports.. PC4 is tied to analog and I don't know how to untie it.//Its working on 5 now:) was a solder issue with PC4.
#include "debug.h"
void GPIO_Config(void){ GPIO_InitTypeDef GPIO_InitStructure = {0}; //structure variable used for the GPIO configuration
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); // to Enable the clock for Port C RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE); // to Enable the clock for Port D RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // to Enable the clock for Port A
//This fixed A2, had to remap from external oscillator :) AFIO->PCFR1 = AFIO->PCFR1 & ~(1 << 15); // Clear bit 15 to use PA1/PA2 as I/O // Or in some libraries: This also works:) //AFIO->PCFR1 &= ~AFIO_PCFR1_PA12_REMAP; // Using library defines
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; // Defines which Pin to configure GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Defines Output Type GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Defines speed GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4; // Defines which Pin to configure GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Defines Output Type GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Defines speed GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // Defines which Pin to configure GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Defines Output Type GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Defines speed GPIO_Init(GPIOA, &GPIO_InitStructure);
/* // Clear the bits for PC4 (pins 4*4 = 16 to 4*4 + 3 = 19) GPIOC->CFGLR &= ~(0xF << 16); // Set to Output mode, max speed (MODE = 11, CNF = 00 -> 0x3) GPIOC->CFGLR |= (0x3 << 16);
// Example for push-pull output (MODE = 01, CNF = 00): GPIOC->CFGLR &= ~(0b1111 << (4 * 4)); // Clear current config for PC4 GPIOC->CFGLR |= (0b0001 << (4 * 4)); // Set to output push-pull mode*/}/*void GPIO_Toggle_INIT(void){ GPIO_InitTypeDef GPIO_InitStructure = {0};
// 1. Enable the clock for GPIOC RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
// 2. Configure PC4 as output GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Push-pull output GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure);}*/
int main(void){ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); SystemCoreClockUpdate(); Delay_Init();
GPIO_Config(); // GPIO_Toggle_INIT(); Delay_Ms(2000);/*#if (SDI_PRINT == SDI_PR_OPEN) SDI_Printf_Enable();#else USART_Printf_Init(115200);#endif printf("SystemClk:%d\r\n", SystemCoreClock); printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() ); printf("This is printf example\r\n");*/
while(1) { Delay_Ms(200); // GPIO_SetBits(GPIOA, GPIO_Pin_2); GPIO_WriteBit(GPIOC, GPIO_Pin_1, Bit_SET); GPIO_WriteBit(GPIOC, GPIO_Pin_2, Bit_SET); GPIO_WriteBit(GPIOC, GPIO_Pin_4, Bit_SET); GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_SET); GPIO_WriteBit(GPIOD, GPIO_Pin_6, Bit_SET); Delay_Ms(200); GPIO_WriteBit(GPIOA, GPIO_Pin_2, Bit_RESET); GPIO_WriteBit(GPIOC, GPIO_Pin_1, Bit_RESET); GPIO_WriteBit(GPIOC, GPIO_Pin_4, Bit_RESET); GPIO_WriteBit(GPIOC, GPIO_Pin_2, Bit_RESET); GPIO_WriteBit(GPIOD, GPIO_Pin_6, Bit_RESET); //GPIO_ResetBits(GPIOA, GPIO_Pin_2); }}