Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include "libmaple.h"
- #include "boards.h"
- #include "gpio.h"
- #include "delay.h"
- #include "usart.h"
- #include "dma.h"
- #define LEV_SENSE_I2C_ADDR 0x55
- #define TEMP_SENSE_I2C_ADDR 0x48
- #define STR_SIZE 11
- uint8 tx_buf[STR_SIZE];
- // Force init to be called *first*, i.e. before static object allocation.
- // Otherwise, statically allocated objects that need libmaple may fail.
- __attribute__((constructor)) void premain() {
- init();
- }
- static void dma_handler()
- {
- dma_disable(DMA1, DMA_CH1);
- }
- int main(void)
- {
- gpio_set_mode(GPIOB, 3, GPIO_OUTPUT_PP);
- gpio_set_mode(GPIOA, 9, GPIO_AF_OUTPUT_PP);
- gpio_set_mode(GPIOA, 10, GPIO_INPUT_FLOATING);
- usart_init(USART1);
- usart_set_baud_rate(USART1, PCLK2, 115200);
- usart_enable(USART1);
- USART1->regs->CR3 |= USART_CR3_DMAT;
- snprintf(tx_buf, STR_SIZE-1, "test dma\r\n");
- dma_init(DMA1);
- dma_mode_flags fl = (DMA_FROM_MEM | DMA_MINC_MODE | DMA_TRNS_CMPLT);
- dma_setup_transfer(DMA1, DMA_CH1, &(USART1->regs->DR), DMA_SIZE_32BITS, tx_buf, DMA_SIZE_8BITS, fl);
- dma_set_num_transfers(DMA1, DMA_CH1, STR_SIZE);
- dma_attach_interrupt(DMA1, DMA_CH1, dma_handler);
- dma_enable(DMA1, DMA_CH1);
- USART1->regs->DR = tx_buf[0];
- uint8 toggle = 0;
- while(1) {
- if (toggle == 0)
- toggle = 1;
- else
- toggle = 0;
- gpio_write_bit(GPIOB, 3, toggle);
- delay_s(1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement