add e22 demo on stm32/stm32f4discovery board

This commit is contained in:
wgzAIIT 2022-05-20 11:31:14 +08:00
parent 40f20e65f1
commit fb2dd71136
5 changed files with 200 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config EXAMPLES_E22
tristate "E22 driver example"
default n
depends on STM32_USART3
select SERIAL_TERMIOS
---help---
Enable the e22 driver example
if EXAMPLES_E22
config EXAMPLES_E22_PROGNAME
string "Program name"
default "e22"
---help---
This is the name of the program that will be used when the NSH ELF
program is installed.
config EXAMPLES_E22_PRIORITY
int "E22 task priority"
default 100
config EXAMPLES_E22_STACKSIZE
int "E22 stack size"
default DEFAULT_TASK_STACKSIZE
endif

View File

@ -0,0 +1,23 @@
############################################################################
# apps/examples/gpio/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifneq ($(CONFIG_EXAMPLES_E22),)
CONFIGURED_APPS += $(APPDIR)/examples/e22_demo
endif

View File

@ -0,0 +1,34 @@
############################################################################
# apps/examples/gpio/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
# GPIO, World! built-in application info
PROGNAME = $(CONFIG_EXAMPLES_E22_PROGNAME)
PRIORITY = $(CONFIG_EXAMPLES_E22_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_E22_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_E22)
# GPIO, World! Example
MAINSRC = e22_main.c
include $(APPDIR)/Application.mk

View File

@ -0,0 +1,111 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file e22_main.c
* @brief e22 demo
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022.05.20
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/ioctl.h>
#include <nuttx/config.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <nuttx/ioexpander/gpio.h>
int main(int argc, FAR char *argv[])
{
int fd, m0fd, m1fd;
int ret;
int i;
struct termios tio;
char sendbuffer1[4] = {0xC0,0x05,0x01,0x09};
char sendbuffer2[7] = {0xC0,0x00,0x04,0x12,0x34,0x00,0x61};
char sendbuffer3[3] = {0xC1,0x00,0x04};
char buffer[256];
int readlen;
fd = open("/dev/ttyS3", O_RDWR);
if(fd < 0)
{
printf("Error opening serial: %d\n", fd);;
}
ret = tcgetattr(fd, &tio);
if (ret < 0)
{
printf("Error getting attributes: %d\n", ret);
}
ret = cfsetspeed(&tio, B9600);
if (ret < 0)
{
printf("Error setting baud rate: %d\n", ret);
}
ret = tcsetattr(fd, TCSANOW, &tio);
if (ret < 0)
{
printf("Error getting attributes: %d\n", ret);
}
m0fd = open("/dev/gpout0", O_RDWR);
m1fd = open("/dev/gpout1", O_RDWR);
ioctl(m0fd, GPIOC_WRITE, (unsigned long)0);
ioctl(m1fd, GPIOC_WRITE, (unsigned long)1);
sleep(1);
write(fd, sendbuffer1,4);
sleep(1);
readlen = read(fd, buffer, 256);
printf("readlen1 = %d\n", readlen);
for(i = 0;i< readlen; ++i)
{
printf("0x%x\n", buffer[i]);
}
write(fd, sendbuffer2,7);
sleep(1);
readlen = read(fd, buffer, 256);
printf("readlen1 = %d\n", readlen);
for(i = 0;i< readlen; ++i)
{
printf("0x%x\n", buffer[i]);
}
write(fd, sendbuffer3,3);
sleep(1);
readlen = read(fd, buffer, 256);
printf("readlen1 = %d\n", readlen);
for(i = 0;i< readlen; ++i)
{
printf("0x%x\n", buffer[i]);
}
close(fd);
close(m0fd);
close(m1fd);
return 0;
}

View File

@ -47,6 +47,7 @@ CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_PWR=y CONFIG_STM32_PWR=y
CONFIG_STM32_SPI1=y CONFIG_STM32_SPI1=y
CONFIG_STM32_USART2=y CONFIG_STM32_USART2=y
CONFIG_STM32_USART3=y
CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_NSH=y
CONFIG_USART2_RXBUFSIZE=128 CONFIG_USART2_RXBUFSIZE=128
CONFIG_USART2_SERIAL_CONSOLE=y CONFIG_USART2_SERIAL_CONSOLE=y