#include <stdint.h> #include <stdbool.h> // Assuming STM32 or similar microcontroller…
- User
#include <stdint.h> #include <stdbool.h>
// Assuming STM32 or similar microcontroller #define LED_PIN 5 #define GPIO_PORT ((volatile uint32_t *)0x40021000) // Base address for the GPIO port
void delay(uint32_t count) { for (uint32_t i = 0; i < count; i++) { asm("nop"); // No-operation, just waste some cycles } }
void init_led(void) { // Enable GPIO clock (RCC) for the GPIO port uint32_t *RCC_APB2ENR = (uint32_t *)0x40021018; // Address for the APB2 peripheral clock enable register *RCC_APB2ENR |= (1 << 3); // Enable GPIO clock (assume GPIO is on bit 3)
// Configure LED_PIN as output uint32_t *GPIO_CRL = (uint32_t *)(GPIO_PORT + 0x00); // Control register for pins 0-7 *GPIO_CRL &= ~(0xF << (LED_PIN * 4)); // Clear the pin configuration bits (ERROR 1) *GPIO_CRL |= (0x2 << (LED_PIN * 4)); // Set the pin as output, push-pull mode // Set the LED to OFF initially uint32_t *GPIO_ODR = (uint32_t *)(GPIO_PORT + 0x0C); // Output Data Register *GPIO_ODR &= ~(1 << LED_PIN); // Clear the LED pin to turn it off}
void toggle_led(void) { uint32_t *GPIO_ODR = (uint32_t *)(GPIO_PORT + 0x0C); // Output Data Register *GPIO_ODR ^= (1 << LED_PIN); // Toggle the LED pin state (ERROR 2) }
int main(void) { init_led();
while (1) { toggle_led(); delay(1000000); // Delay between toggling }}
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.