FreeRTOS+lwip for GD32450
This demo is based on the GD32450I-EVAL board. On the board,the Tamper key
connected to PC13 and the LED1 connected to PE2. It provides a description to
use the key to control the LED by the polling mode. The user can toggle the output
state of LED1 by pressing the Tamper key.
单片机源程序如下:
- /*!
- \file main.c
- \brief GPIO keyboard polling demo
- */
- /*
- Copyright (C) 2016 GigaDevice
- 2016-10-19, V1.0.0, demo for GD32F4xx
- */
- #include "gd32f4xx.h"
- #include "gd32f450i_eval.h"
- #include "systick.h"
- #include "stdio.h"
- #include "gd25qxx.h"
- #include "ff.h"
- #include "mylog.h"
- #include "stdlib.h"
- uint32_t flash_id = 0;
- #define SFLASH_ID 0xC84013 //0xC84015
- #define FLASH_WRITE_ADDRESS 0x000000
- #define FLASH_READ_ADDRESS FLASH_WRITE_ADDRESS
- char *gpBuff = NULL;
- int main(void)
- {
- int32_t i, j, is_successful;
- char szItem[256];
-
- //gpBuff = (char *)malloc(1000);
-
- //gd_eval_key_init(KEY_TAMPER,KEY_MODE_GPIO);
- gd_eval_key_init(KEY_TAMPER, KEY_MODE_EXTI);
- systick_config();
- gd_eval_gpio_init(LED1);
- //gd_eval_gpio_init(BUZZER1);
- //gd_eval_gpio_init(RELAY1);
- gd_eval_gpio_init(WTN6170);
-
- gd_eval_gpio_on(LED1);
- //gd_eval_gpio_off(BUZZER1);
- //gd_eval_gpio_off(RELAY1);
- delay_1ms(300);
- //gd_eval_gpio_on(BUZZER1);
- //gd_eval_gpio_on(RELAY1);
-
- /* USART interrupt configuration */
- //nvic_irq_enable(USART0_IRQn, 0, 0);
- nvic_irq_enable(UART3_IRQn, 0, 0);
- /* configure EVAL_COM1 */
- //gd_eval_com_init(EVAL_COM0);
- gd_eval_com_init2(com3);
- /* enable USART0 receive interrupt */
- usart_interrupt_enable(EVAL_COM3, USART_INTEN_RBNEIE);
- /* enable USART0 transmit interrupt */
- //usart_interrupt_enable(EVAL_COM3, USART_INTEN_TBEIE);
-
- get_chip_serial_num();
- /* output a message on hyperterminal using printf function */
- LogInfo("\r\n Application start! chipID:%X%X%X SHORT:%d, INT:%d, LONG:%d, QWORD:%d\r\n", _gChipID[2], _gChipID[1], _gChipID[0],
- sizeof(short), sizeof(int), sizeof(long), sizeof(long long));
- sprintf(szItem, "chipID:%X-%X-%X\r\n", _gChipID[2], _gChipID[1], _gChipID[0]);
- LogInfo("%s", szItem);
-
- //configure SPI4 GPIO and parameter
- spi_flash_init();
- // /* get flash id */
- // flash_id = spi_flash_read_id();
- // LogInfo("\r\nThe Flash_ID:0x%X,%d\r\n\r\n", flash_id, sizeof(FATFS));
- // //flash id is correct
- // if(SFLASH_ID == flash_id) {
- // LogInfo("\r\nWrite to tx_buffer:\r\n\r\n");
- // /* printf tx_buffer value */
- // for(i = 0; i < BUFFER_SIZE; i++){
- // tx_buffer[i] = i;
- // LogInfo("0x%02X ",tx_buffer[i]);
- // if(15 == i%16)
- // LogInfo("\r\n");
- // }
- // LogInfo("\r\nrRead from rx_buffer:\r\n\r\n");
- // /* erase the specified flash sector */
- // spi_flash_sector_erase(FLASH_WRITE_ADDRESS);
- // /* write tx_buffer data to the flash */
- // //qspi_flash_buffer_write(tx_buffer,FLASH_WRITE_ADDRESS,256);
- // spi_flash_buffer_write(tx_buffer,FLASH_WRITE_ADDRESS,256);
- // delay_1ms(10);
- //
- // /* read a block of data from the flash to rx_buffer */
- // //qspi_flash_buffer_read(rx_buffer,FLASH_READ_ADDRESS,256);
- // spi_flash_buffer_read(rx_buffer,FLASH_READ_ADDRESS,256);
- // /* printf rx_buffer value */
- // for(i = 0; i < BUFFER_SIZE; i ++){
- // LogInfo("0x%02X ", rx_buffer[i]);
- // if(15 == i%16)
- // LogInfo("\r\n");
- // }
- // if(ERROR == memory_compare(tx_buffer,rx_buffer,256)){
- // LogInfo("\r\nErr:Data Read and Write aren't Matching.\r\n");
- // is_successful = 1;
- // }
- // }else{
- // /* spi flash read id fail */
- // LogInfo("\r\nSPI Flash: Read ID Fail!\r\n");
- // }
-
- //spi_flash_bulk_erase();
- delay_1ms(100);
- testFatfs_ram();
- testFatfs_flash();
-
- while(1){
- gd_eval_gpio_off(UART3_CTRL);
- // if(RESET == gd_eval_key_state_get(KEY_TAMPER)){
- // /* delay 100ms for software removing jitter */
- // delay_1ms(100);
- // if(RESET == gd_eval_key_state_get(KEY_TAMPER)){
- // gpio_bit_write(LED1_GPIO_PORT, LED1_PIN, (bit_status)((1 - gpio_output_bit_get(LED1_GPIO_PORT, LED1_PIN))));
- // }
- // }
- }
- }
- /* retarget the C library printf function to the USART */
- int fputc(int ch, FILE *f)
- {
- gd_eval_gpio_on(UART3_CTRL);
- usart_data_transmit(EVAL_COM3, (uint8_t)ch);
- while(RESET == usart_flag_get(EVAL_COM3, USART_FLAG_TBE));
- //gd_eval_gpio_off(UART3_CTRL);
-
- return ch;
- }
复制代码
所有资料51hei提供下载:
GD32450i-EVAL(20180913).rar
(2.19 MB, 下载次数: 89)
|