I wrote my first application for NuttX. I want it to read the state of a button and if its pressed the LED should light up for 1 second. I am using a self created board from a company with a STM32F103 on it. I can activate the app via menuconfig. Then I compile the code and flash the Firmware on the board. I thought if I now open minicom I should be able to execute the app but it isnt possible. What did I do wrong? Also I dont think all of my code is correct. I would appreciate if you could help me there also :)
All my files are:
- Make.defs
include $(wildcard $(APPDIR)/BeispielApp/*/Make.defs)
- Makefile
MENUDESC = "Beispiel App"
include $(APPDIR)/Directory.mk
- BeispielLED.c
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <debug.h>
#include <errno.h>
#include <sched.h>
#include <signal.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "stm32_gpio.h"
#include "stm32f103_minimum.h"
#include "chip.h"
#include "stm32.h"
/****************************************************************************
* Private Data
****************************************************************************/
/* Pin configuration for each STM32F3Discovery button. This array is indexed
* by the BUTTON_* definitions in board.h
*/
static const uint32_t g_buttons[NUM_BUTTONS] =
{
GPIO_BTN_USER1, GPIO_BTN_USER2, GPIO_BTN_USER3,
};
/* This array maps an LED number to GPIO pin configuration */
static const uint32_t g_ledcfg[BOARD_NLEDS] =
{
GPIO_LED1,
};
/****************************************************************************
* Public Functions
****************************************************************************/
static bool g_buttonPressed = false;
static void button_isr(int irq, void *context, void *arg) {
g_buttonPressed = true;
}
/****************************************************************************
* BeispielLED_main
****************************************************************************/
int main(int argc, FAR char *argv[]) {
// Initialisiere GPIOs für Button und LED
stm32_configgpio(g_buttons[i]);
stm32_configgpio(g_ledcfg[i]);
// Registriere den Interrupt-Handler für den Button
irq_attach(NUM_IRQBUTTONS, button_isr, NULL);
up_enable_irq(NUM_IRQBUTTONS);
printf("Warte auf Buttondruck...\n");
while (1) {
if (g_buttonPressed) {
g_buttonPressed = false;
printf("Button wurde gedrückt! LED wird eingeschaltet.\n");
// LED ein- und ausschalten
stm32_gpiowrite(g_ledcfg[i], true); // LED einschalten
usleep(1000000); // 1000ms warten
stm32_gpiowrite(g_ledcfg[i], false); // LED ausschalten
}
}
return 0;
}
- BeispielLED Makefile
include $(APPDIR)/Make.defs
# Beispiel LED built-in application info
PROGNAME = $(CONFIG_BEISPIEL_APP_BEISPIEL_LED_PROGNAME)
PRIORITY = $(CONFIG_BEISPIEL_APP_BEISPIEL_LED_PRIORITY)
STACKSIZE = $(CONFIG_BEISPIEL_APP_BEISPIEL_LED_STACKSIZE)
MODULE = $(CONFIG_BEISPIEL_APP_BEISPIEL_LED)
# Beispiel LED
MAINSRC = BeispielLED.c
include $(APPDIR)/Application.mk
- Kconfig
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config BEISPIEL_APP_BEISPIEL_LED
tristate "Beispiel LED App"
default n
---help---
Enable the Beispiel LED App
if BEISPIEL_APP_BEISPIEL_LED
config BEISPIEL_APP_BEISPIEL_LED_PROGNAME
string "Program name"
default "Beispiel_LED"
---help---
This is the name of the program that will be used when the NSH ELF
program is installed.
config BEISPIEL_APP_BEISPIEL_LED_PRIORITY
int "Beispiel LED task priority"
default 100
config BEISPIEL_APP_BEISPIEL_LED_STACKSIZE
int "Beispiel LED stack size"
default DEFAULT_TASK_STACKSIZE
endif