RIOT OS Gpio Example - c

I have to work with RIOT OS and currently I'm testing out how everything
works (or not work).
Info: RIOT OS is a IOT OS which run on mircocontrollers and arms.
I develop under Debian with Eclispe, the develop environment was setup after the GitHub Guide from RIOT. The Guide
The hello world example works for me without problems.
Now I want to load some of the RIOT modules and then I get errors.
That's what I did so far.
I created a new folder for my project, copy the hello-world example and
adjust the makefile.
Then I adjust the riot project properties like in the guide, just for my example.
Created the new symbol and include xml and imported them.
Re-indexed the riot project
Changed the basic hello world code with my example code.
Try to build it....
This is my example main, it doesn't do much, just init a gpio pin.
#include <stdio.h>
#include "periph/gpio.h"
int main(void)
{
gpio_t pin = GPIO(1,22);
gpio_init(pin,GPIO_OUT);
return 0;
}
And this is the makefile for it
# name of your application
APPLICATION = test
# If no BOARD is found in the environment, use this default:
BOARD ?= nucleo-f303
# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..
# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
DEVELHELP ?= 1
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1
FEATURES_REQUIRED = periph_gpio
include $(RIOTBASE)/Makefile.include
By building the project I get following errors:
In english it would be something like:
- the rule for target "path" failed.
- the rule for target "link" failed.
- make: [link] error 2
- make(1): ["path/main.o"] error 1
This is the part in the riot makefile where the error happen.
Its exactly the same in both file (Makefile.include and Makefile.base).
I hope anybody can me explain what I did wrong or where are my mistakes.
EDIT:
The problem was GPIO() was wrong... its called GPIO_PIN() thats cause the error.

Related

SWUpdate on RPi4 via yocto - error parsing configuration file

After booting SWUpdate yocto-generated image for the first time, executing swupdate results in error message:
Error parsing configuration file: 'globals' section missing, exiting.
I tried to strictly follow SWUpdate's documentation, but it gets short when it comes to yocto integration. I'm using meta-swupdate, meta-swupdate-boards, and meta-openembedded layers together with poky example repository all at Kirkstone tag, building via bitbake update-image and having modyfied local.conf as:
MACHINE ??= "raspberrypi4-64"
ENABLE_UART = "1"
RPI_USE_U_BOOT = "1"
IMAGE_FSTYPES = "wic ext4.gz"
PREFERRED_PROVIDER_u-boot-fw-utils = "libubootenv"
IMAGE_INSTALL:append = " swupdate"
Is there anything else I need to modify to generate the configuration file and be able to run SWUpdate binary properly?
Side question: In the documentation, it's recommended to append swupdate-www to achieve a better web server. However, if I append it, there is no swupdate-www binary inside the `/usr/bin' directory.
As with other recipes folders the recipes-support/swupdate/swupdate/raspberrypi4-64 folder was missing inside the meta-swupdate-boards layer. Therefore, an empty config file was always generated. After adding this folder and all related files, strongly inspired by raspberrypi3 folder, the error was gone and swupdate -h provided the expected output.
There was also one new error during build process thrown by yocto. It was related to missing systemd requirement and was solved by adding:
DISTRO_FEATURES_append = " systemd"
to local.conf

Connect two native Contiki NG motes over SLIP

Since the RPL border router example works as either a Cooja mote or a native mote, I thought using the SLIP code in /services/rpl-border-router/native might work. I made a copy of hello-world. I edited hello-world.c to read
#include "contiki.h"
#include "services/rpl-border-router/native/border-router.h"
#include <stdio.h> /* For printf() */
extern int contiki_argc;
extern char **contiki_argv;
/*---------------------------------------------------------------------------*/
PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
static struct etimer timer;
PROCESS_BEGIN();
/* Setup a periodic timer that expires after 10 seconds. */
etimer_set(&timer, CLOCK_SECOND * 10);
slip_config_handle_arguments(contiki_argc, contiki_argv);
slip_init();
while(1) {
printf("Hello, world\n");
/* Wait for the periodic timer to expire and then restart the timer. */
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
etimer_reset(&timer);
}
PROCESS_END();
}
And edited the makefile:
CONTIKI_PROJECT = hello-world
all: $(CONTIKI_PROJECT)
CONTIKI = ../..
include $(CONTIKI)/Makefile.dir-variables
MODULES += $(CONTIKI_NG_SERVICES_DIR)/rpl-border-router
include $(CONTIKI)/Makefile.include
This inclusion of rpl-border-router module was done because I was getting undefined reference to ‘slip_init()’... and undefined reference to ‘slip_config_handle_arguments(contiki_argc, contiki_argv);’... errors when compiling, despite the #include "services/rpl-border-router/native/border-router.h" line in hello-world.c. This does appear to be the right header to include for declarations of these functions, but if I am mistaken please say so.
From the folder where the edited hello-world code resides, I did make distclean, and then make TARGET=native. If I run this edited hello-world with
sudo ./hello-world.native fd00::3 -s ttyS0
it looks like it is starting up, but I see:
…[INFO: Native ] Added global IPv6 address fd00::302:304:506:708
********SLIP started on ``/dev/ttyS0''
Hello, world
[INFO: BR ] RPL-Border router started
********SLIP started on ``/dev/ttyS0''
opened tun device ``/dev/tun0''
So it is trying to start up the border router as well as opening the SLIP interface, and just below the ifconfig tun0 output (which looks fine) I see
…hello-world.native: serial_input: read: Success
ifconfig tun0 down
netstat -nr | awk '{ if ($2 == "tun0") print "route delete -net "$1; }' | sh
So, it seems I need to do something to stop from starting the border router module. I have seen that there are 'slip.c' and 'slip.h' in os/dev/, used in the slip-radio example but the declaration of 'slip_arch_init()' in slip.h without a definition of slip_arch_init() in slip.c has me confused, and motivated me to use 'slip_init()' from the /services/rpl-border-router/native folder, since in there I can see a pretty normal bit of code opening up a serial interface.
I have done a lot of google searching and searched through several of the more complex examples for something similar to what I am trying to do, but haven’t found anything that seems very close. If there is something ready made then or course that would be the greatest help, but I am sure it must be obvious that my understanding of Make and file interrelations is nowhere near where it needs to be.
Just to be clear, my goal at the moment is to get a SLIP interface up and running on the remote VM so that I can get a ping6 response on the VM with the border router. I will worry about writing the callback once I have some baseline connectivity. Maybe this is a misunderstanding on my part as well.

Why does my program work fine by running it directly but not as a service? Linux C

Goodday guys,
I am trying to build and run program in linux (raspberry) as a service.
It is a sample application that uses the Cerence SDK C API that implements a wake-up-word (WUW) plus command utterance recognition.
I can execute it by ./name.exe or using the Makefile commands.
The problem is that when I execute the program by console it works fine, without any problem.
When I try to execute it as a service (using both systemd or crontab and also rc.local), an error occours.
This is the function that gives me error:
printf("Selecting audio configuration %s\n", audioScenarioName);
rc = nuance_audio_IAudioManager_activateScenario(audioMgr, audioScenarioName);
if (NUANCE_COMMON_OK != rc) {
printf("Audio scenario activation failed: %d\n", rc); <-- returns 1 (error, impossible to activate scenario)
return rc;
}
ActivateScenario it's a function that simply selects the correct mic (audioScenarioName) following a JSON file and the audio manager (audioMgr).
Unfortunately this function returns 1 if something goes wrong, closes the program and nothing else.
This is the JSON:
"type": "AudioInput",
"name": "mic_input",
"adapter_type": "CUSTOM_AUDIO",
"adapter_params": {
"device_name": "default"
},
"audio_format": { "uses": "16khz_1ch" }
The service should be running as root permissions (default).
I also tried by setting the whole folder as chmod -R 777 as a test, but same problem.
This is my service:
[Unit]
Description=My Service
[Service]
Type=simple
ExecStart=+/home/pi/.../nameexec
Restart=on-failure
RestartSec=5
KillMode=process
[Install]
WantedBy=multi-user.target
I've also set the absolute path of its lib directory that it needs into the ld.so.conf file.
The only libraries I put in it are the .so ones, but not .h.
I am now trying to understand what might be different about starting the same executable but in different ways.
Could it be a permissions issue? Or is it not detecting the microphone? Any library out of place?
I really don't know why it works with the classic command and not as a service.
Can someone please help me with this?
Thank you in advance!
I succeeded!
The problem was the microphone being used.
Using Raspbian ver. Desktop, I set the mic from the bottom right part of the taskbar and changed the defaults in/out.
But these settings seem to be not system-wide and not used by the services in background (even though the "User=" is set to "pi").
So I had to change alsa.conf file:
sudo nano /usr/share/alsa/alsa.conf
Then find and edit these lines:
defaults.ctl.card cardnumber
defaults.pcm.card cardnumber
You can find the card number by running arecord -l.

How to compile WPF IronPython project to exe

I've seen many questions in this forum which are questions of how to fix a problems of compiling IronPython WPF to exe.
But the problem is that I haven't seen any guide Step-by-step of how to compile my project.
I understood it includes using the clr module.
I've 6 files:
Window.py, Window.xaml.
Window1.py, Window1.xaml.
Window2.py, Window2.xaml.
That's all the files
Thanks
((irrelevant: Update- 3 hours later:
I've started using SharpDevelop and when I run it through the software itself it can be run. However , when I try to run this through the .exe file in the project's folder it doesn't work... ))
Update 2 - SharpDevelop created an exe file which works but the problem is it didn't encrypt my xaml to dll ..
Have you tried the script from this thread: Ironpython 2.6 .py -> .exe
Supposedly it includes wpf support:
#!/usr/bin/env python
# CompileToStandalone, a Python to .NET ILR compiler which produces standalone binaries
# (C) 2012 Niall Douglas http://www.nedproductions.biz/
# Created: March 2012
import modulefinder, sys, os, subprocess, _winreg
if len(sys.argv)<2:
print("Usage: CompileEverythingToILR.py <source py> [-outdir=<dest dir>]")
sys.exit(0)
if sys.platform=="cli":
print("ERROR: IronPython's ModuleFinder currently doesn't work, so run me under CPython please")
sys.exit(1)
sourcepath=sys.argv[1]
destpath=sys.argv[2][8:] if len(sys.argv)==3 else os.path.dirname(sys.argv[0])
ironpythonpath=None
try:
try:
keyh=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\IronPython\\2.7\\InstallPath")
ironpythonpath=_winreg.QueryValue(keyh, None)
except Exception as e:
try:
keyh=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\IronPython\\2.7\\InstallPath")
ironpythonpath=_winreg.QueryValue(keyh, "")
except Exception as e:
pass
finally:
if ironpythonpath is not None:
_winreg.CloseKey(keyh)
print("IronPython found at "+ironpythonpath)
else:
raise Exception("Cannot find IronPython in the registry")
# What we do now is to load the python source but against the customised IronPython runtime
# library which has been hacked to work with IronPython. This spits out the right set of
# modules mostly, but we include the main python's site-packages in order to resolve any
# third party packages
print("Scanning '"+sourcepath+"' for dependencies and outputting into '"+destpath+"' ...")
searchpaths=[".", ironpythonpath+os.sep+"Lib"]
searchpaths+=[x for x in sys.path if 'site-packages' in x]
finder=modulefinder.ModuleFinder(searchpaths)
finder.run_script(sourcepath)
print(finder.report())
modules=[]
badmodules=finder.badmodules.keys()
for name, mod in finder.modules.iteritems():
path=mod.__file__
# Ignore internal modules
if path is None: continue
# Ignore DLL internal modules
#if '\\DLLs\\' in path: continue
# Watch out for C modules
if os.path.splitext(path)[1]=='.pyd':
print("WARNING: I don't support handling C modules at '"+path+"'")
badmodules.append(name)
continue
modules.append((name, os.path.abspath(path)))
modules.sort()
print("Modules not imported due to not found, error or being a C module:")
print("\n".join(badmodules))
raw_input("\nPress Return if you are happy with these missing modules ...")
with open(destpath+os.sep+"files.txt", "w") as oh:
oh.writelines([x[1]+'\n' for x in modules])
cmd='ipy64 '+destpath+os.sep+'pyc.py /main:"'+os.path.abspath(sourcepath)+'" /out:'+os.path.splitext(os.path.basename(sourcepath))[0]+' /target:exe /standalone /platform:x86 /files:'+destpath+os.sep+'files.txt'
print(cmd)
cwd=os.getcwd()
try:
os.chdir(destpath)
retcode=subprocess.call(cmd, shell=True)
finally:
os.chdir(cwd)
sys.exit(retcode)

building a simple engine for openssl fails

I am just beginning to develop a simple openssl engine. In this process, I referred to this nice website http://sinodun.com/2009/02/developing-an-engine-for-openssl/
I downloaded openssl 1.0.0c and compiled in my own folder as follows:
./config --prefix=/home/workingDir/openssl --openssldir=/home/workingDir/openssl
make
make install
Then I proceeded to copy this simple_engine.c file and compiled it to simple_engine.o and then built shared library simple_engine.so.
These are found in 'workingDir'
After these steps, I changed the 2 openssl.cnf files available under openssl/apps and openssl1.0.0c/ main folders such that:
openssl_conf = openssl_def
[openssl_def]
engines = engines_section
[engines_section]
simple = simple_section
[simple_section]
engine_id = simple
dynamic_path = /home/workingDir/simple_engine.so
MODULE_PATH = /home/workingDir/simple_engine.so
init = 0
[req]
distinguished_name = req_distinguished_name
[req_distinguished_name]
After this I set the LD_LIBRARY_PATH to point to /home/workingDir
Then when I did:
./openssl engine
I get the following error:
Error configuring OpenSSL
3076019848:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(/home/workingDir/simple_engine.so): /home/workingDir/simple_engine.so: undefined symbol: ENGINE_get_static_state
3076019848:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
3076019848:error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:450:
3076019848:error:260BC066:engine routines:INT_ENGINE_CONFIGURE:engine configuration error:eng_cnf.c:204:section=simple_section, name=dynamic_path, value=/home/workingDir/simple_engine.so
3076019848:error:0E07606D:configuration file routines:MODULE_RUN:module initialization error:conf_mod.c:235:module=engines, value=engines_section, retcode=-1
What is the problem? Please help. I am unable to proceed and don't find any documentation.
Thanks
The problem was the MODULE_PATH in the openssl.cnf. When I removed it , it works after recompiling the openssl with shared libs!

Resources