|
发表于 2023-2-10 18:20:43
|
显示全部楼层
chatgpt回复的代码:
#include "stm32g0xx.h"
#define LED_PIN 5
#define LED_PORT GPIOA
uint32_t ledData[] = {0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080};
void DMA1_Channel1_IRQHandler(void)
{
if (DMA1->ISR & DMA_ISR_TCIF1)
{
DMA1->IFCR |= DMA_IFCR_CTCIF1;
LED_PORT->ODR ^= ledData[7];
}
}
int main(void)
{
// Enable the peripheral clock for GPIOA
RCC->IOPENR |= RCC_IOPENR_GPIOAEN;
// Configure the LED pin as an output
LED_PORT->MODER = (LED_PORT->MODER & ~(GPIO_MODER_MODE5 << (LED_PIN * 2))) | (GPIO_MODER_MODE5_0 << (LED_PIN * 2));
// Enable the peripheral clock for DMA1
RCC->AHB2ENR |= RCC_AHB2ENR_DMA1EN;
// Configure the DMA
DMA1_Channel1->CPAR = (uint32_t) &(LED_PORT->ODR);
DMA1_Channel1->CMAR = (uint32_t) ledData;
DMA1_Channel1->CNDTR = 8;
DMA1_Channel1->CCR = DMA_CCR_DIR | DMA_CCR_MINC | DMA_CCR_TCIE;
// Enable the DMA channel
DMA1_Channel1->CCR |= DMA_CCR_EN;
// Enable the DMA1 channel 1 interrupt in the NVIC
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
while (1)
{
// Wait for the transfer to complete
}
}
|
|