Resetting Arduino via code - arduino

I have looked at a dozen different ways to reset my arduino, from connecting pins to the reset pin and jury rigging weird bits of code.
None of them work.
The one bit of code that everybody seems to be using is
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
To which my arduino responds with
C:\Users\Leonardo\AppData\Local\Temp\ccGUYdTQ.s:2259: Error: bad
instruction `jmp 0'
And it then fails uploading the code. I don't know what to do. My full code can be found here http://pastebin.com/CA2Ms2hB but it's huge and I'm not sure if it will be of help.
If anyone could help me understand why software_Reset(); I would really appreciate it, I'm at the end of my rope here.
(also if you have other methods to reset arduino I'll gladly try them)

On ARM based microcontrollers you can call NVIC_SystemReset().
All ARM based microcontrollers are required to implement that.
This is useful because resetFunc() at address 0 may not work on newer ARM based microcontrollers.

I think you are trying to write assembly code in your arduino code editor.
Let me tell you one thing. Arduino code editor does not support assembly language code by default. You can write assembly language code in arduino code editor by going through the process mentioned below:
Caution: We will be modifying the arduino source code to do that.
Get the source code for Arduino IDE: https://github.com/arduino/arduino
Extract the downloaded zip file, you will get a folder named Arduino-master
Open the Sketch.java file in a text editor of your choice. The location of sketch.java is : Arduino-master/app/src/processing/app/Sketch.java
Insert the .s capability:
a. Search for: sc.isExtension("c");
you will see something like this:
//3. then loop over the code[] and save each .java file
for (SketchCode sc : code){
if(sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")){
//no pre-processing services necessary for java files
b. Add sc.isExtension("s") at the end of the if condition. Now your code should look like below:
//3. then loop over the code[] and save each .java file
for (SketchCode sc : code){
if(sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h") || sc.isExtension("s")){
//no pre-processing services necessary for java files
Search for: String[] getExtensions()
You will see some code like this:
/**
* Returns a String[] array of proper extensions.
*/
public String[] getExtensions() {
return new String[] { "ino", "pde", "c", "cpp", "h" };
}
Insert "s" in the returned Array. So, now your code should look like this:
/**
* Returns a String[] array of proper extensions.
*/
public String[] getExtensions() {
return new String[] { "ino", "pde", "c", "cpp", "h", "s" };
}
Save Sketch.java
Open Compiler.java in text editor of your choice. The location of Compiler.java is: Arduino-master/app/src/processing/app/debug/Compiler.java
Search for: compileFiles(
In the command findFilesInFolder(), replace the capital S with a lowercase s.
Repeat step 8 : 3 times more... (4 tiems in total)
Save the Compiler.java file
Download the latest version of java SE 8u111 from http://www.oracle.com
Download and install any java command line tool. But I would recommend Apache ANT.
If you are a windows user:
You can download it here: http://ant.apache.org/
More help on download and install on windows: https://www.mkyong.com/ant/how-to-install-apache-ant-on-windows/
If you are a Mac user:
You need to install it using Homwbrew:
To install Homebrew:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
And then to install Apache ANT:
brew install ant
In Command line go to the directory for Arduino-master/build
Build the Arduino IDE using : ant build, which should end with Build Successful message.
Package the Arduino IDE using: ant dist
It will ask you to enter a version number and give a suggestion e.g.[0105]. Just enter the suggested number with dots and asm. For example: If suggestion is [0105] then enter: 1.0.5.asm
This command may take 6 - 10 minutes to finish. (depending on the speed of your computer)
Then you must get Build Successful!!!
The Arduino IDE that supports assembly language programming can be found in the newly created .zip file
Unzip the file and install the Arduino IDE application.
Now, you should be able to write assembly programs without getting errors in the Arduino IDE.
If you have any problems, Please feel free to ask.

Related

How can I get the path of the dumpfile I've opened in Windbg?

I'm opening dumpfile in Windbg, and I'm writing a PYKD related Python script for working with that dumpfile. Now I'd like to create a file in the directory of that dumpfile, and the name of that file should be based on the dumpfile I've just opened.
In order to do this, I'd simply need to know the path of the dumpfile I've opened, but I don't find the basic Windbg command nor the PYKD command to get this.
How can I get the path of the file, I've opened in Windbg?
I don't know a specific PyKD command, but you could always use dbgCommand() and then use a WinDbg command.
|| should give you the needed information:
0: kd> ||
. 0 64-bit Kernel triage dump: F:\some\path\test.dmp
Please note that || shows the system status and may have multiple lines if you're debugging multiple systems at once:
||1:1:012> ||
0 64-bit Kernel triage dump: F:\some\path\test.dmp
. 1 Live user mode: <Local>
It's likely not applicable in your case.
>>> targetSystem().desc
u'64-bit Kernel bitmap dump: C:\\Users\\User\\AppData\\Local\\Temp\\000030a40_memory.dmp'
desc returns the same string as ||

Why is "isWriteable" returning false using QSerialport?

I have a working program in QT creator on my mac that can write out an FTDI cable using QSerialport. However when I run the exact same program on ubuntu in QT creator the "isWriteable" bool returns false. All other aspects of the program run the same on mac and ubuntu. (the ftdi driver is installed on ubuntu)
Here is the section of code that keeps returning false:
if(FTDI->isWritable())
{
FTDI->putChar(gyroX);
}
Does anyone know what would cause this?
The Docs state for isWritable():
...
This is a convenience function which checks if the OpenMode of the device contains the WriteOnly flag.
See also openMode() ...
So do you open your device with the right flags ? Your should open it either with WriteOnly or ReadWrite (which contains WriteOnly) or something else which contains WriteOnly.

Programming Arduino with Ada

I am am unable to get avr-elf-windows and WinAVR to work. I have managed to build the example supplied with avr-elf-windows (ATmega2560). But if I try and expand to use another chip or start using the WinAVR supplied packages and projects I keep getting errors I cannot work out.
Method 1:
Modify the ATmega2560 example to use the WinAVR packages.
Changed:
with Atmega2560; use Atmega2560;
to:
with AVR; use AVR;
with AVR.Atmega328p; use AVR.atmega328p;
Create a project file to include:
with "C:\WinAVR-20100110\lib\gnat\avr.gpr";
with "C:\WinAVR-20100110\lib\gnat\avr_app.gpr";
Running make I get the following error:
avr-gnatmake: "C:\WinAVR-20100110\lib\gnat\avr_lib\avr-int_img.adb" compilation error
Great, I have a compilation issue, but I cannot see the error.
Method 2:
Open the above project file in GPS. Change the build setting to be gnatmake. GPS now starts reporting errors and warnings:
Project warning: object directory "avr_lib/avr5/obj" not found
Project library directory "C:\WinAVR-20100110\lib\gnat\avr_lib\avr5\lib\" does not exist
The latter issue is very clearly the fact that I have not set up GPS correctly to tell it the values of microcontroller and architecture, but I cannot seem to find anything to resolve this.
Method 3:
To use the WinAVR set up directly using makefiles which then gives me the error:
avr-gnatmake: RTS path not valid: missing adainclude and adalib directories
If I follow the instructions I can find by searching the web I can only find details for building the required libraries under Linux.
Platform: Windows 7.
With the combination of the two answers above I have now managed to link my sample code. As to wether it will work on the Arduino, that is a different issue.
Many thanks for the help.
I have found it a bit frustrating to get this far, and I wonder if there are others out there who may just give up on Ada on the Arduino and go back to the Arduino IDE and therefore missing out on the opportunity to learn a language with more structure. There are many misleading pages out there that also do not help.
You might want to take a look in the paper Integrating 8-bit AVR Micro-Controllers in Ada. Basically you can use a GPS project file arduino.gpr like
project Arduino is
for Source_Dirs use (".", "src");
for Object_Dir use "obj";
for Exec_Dir use "bin";
for Main use ("main.adb");
package Compiler is
for Default_Switches ("ada") use ("-mmcu=avr5");
end Compiler;
package Ide is
for Gnat use "avr-gnat";
for Gnatlist use "avr-gnatls";
for Debugger_Command use "avr-gdb";
end Ide;
package Builder is
for Executable_Suffix use ".elf";
for Default_Switches ("ada") use ("--RTS=rts-zfp");
end Builder;
package Linker is
for Default_Switches ("ada") use ("obj\crtm328p._o", "-nostdlib", "-lgcc", "-mavr5", "-Tdata=0x00800200", "-mmcu=avr5");
end Linker;
end Arduino;
and you can code a spec for your ATmega328P like
with Interfaces; use Interfaces;
with System;
package ATmega328P is
-- PORTB: Port B Data Register
PORTB : Unsigned_8;
for PORTB'Address use System'To_Address (16#25#);
-- DDRB: Port B Data Direction Register
DDRB : Unsigned_8;
for DDRB'Address use System'To_Address (16#24#);
-- PINB: Port B Input Pins
PINB : Unsigned_8;
for PINB'Address use System'To_Address (16#23#);
end ATmega328P;
to be imported by your main file or libraries.
Bear with me if this isn't the immediate answer; I have only used the AVR-Ada toolchain on Linux, so we may have to iterate towards a solution unless someone else spots the problem first.
The first thing to decipher is which version of the AVR-Ada tools you have:
your project file USED to need (using avr-ada 1.1)
with "C:\WinAVR-20100110\lib\gnat\avr.gpr";
Now with avr-ada 1.2.1 you need (instead)
with "C:\WinAVR-20100110\lib\gnat\avr_app.gpr";
for building applications, and <same path>/avr_lib.gpr for libraries.
I don't believe you ever need both! And they may conflict with each other.
I don't know the state of the Windows binary build, but if you need the latest version (recommended : it's a real improvement) you may need to build it from source.
Method 1 : were you running Make from a command line? If so, I would expect to see errors in all their gory details.
Method 2 : can't help you here, I don't know GPS well enough. However I can say that on Linux there are no "avr5" folders in [wherever]/avr/lib/gnat/avr_lib. (AVR5 is correct for the 328p)
Instead there IS a [wherever]/avr/lib/avr5 containing libc and other C-related objects - including the crtm328p.o that Rego names in his linker switches, and a [wherever]/lib/gcc/avr/4.7.2/avr5 folder containing libgcc.a. You probably need to find the former and point GPS at it...
Method 3 : This looks the easiest to fix. The "gnatmake" command needs an --RTS= option pointing at the correct RTS for the 328p. This should be --RTS=rts/avr5 assuming the RTS is correctly installed.
Alternatively a full path ought to work. Here, that would be
--RTS=/opt/avr_472_gnat/lib/gcc/avr/4.7.2/rts/avr5
on Windows you may have to poke around to find the correct path.
Using Method 1 this --RTS option is automatically generated by avr_app.gpr.
It appears that having a mix of 3 or 4 tool chains installed that provide one of aspects of WinAvr, AvrAda causes significant problems (these included WinAvr, Avr-Ada, Cygwin, AVR compiler by Adacore and MinWG).
Starting with a brand new Win7 or Win8 installation perform the following:
Install WinAVR-20100110 to C:\WinAVR-20100110
Copy the content of the Avr-Ada-1.2.0_bin to C:\avr-ada-1.2.0
Add C:\avr-ada-1.2.0\bin to the PATH
Compiling the content of each of the examples in C:\avr-ada-1.2.0\share\doc\avr-ada\apps identifies that some DLLs are missing: libiconv-2.dll, libgmp-10.dll, libmpc-2.dll, libmpfr-1.dll
These can be found in a MinGW installtion.
Create a virtual machine to install MinGW on, in order to ensure it did not mess with the main PC.
Copy the missing DLLs in C:\WinAVR-20100110\bin
The example in DS1820 will not compile due to crc_lib being missing.
In order to upload to the Arduino the makefiles must be modified for your local installation, board type etc.

Use qjson in my Qt symbain app

I'm using Qt to develop a Symbian app.
I downloaded qjson from the link. I followed the instructions in that link and yes, I have the qjson.sis file. Now I need to use it in my app. When I tried, I got this error.
Launch failed: Command answer [command error], 1 values(s) to request: 'C|101|Processes|start|""|"MyProject.exe"|[""]|[]|true'
{"Code":-46,Format="Failed to create the process (verify that the executable and all required DLLs have been transferred) (permission denied)"}
Error: 'Failed to create the process (verify that the executable and all required DLLs have been transferred) (permission denied)' Code: -46
And when I press the launch icon, it shows, "Unable to execute file for security reasons".
Then I install the qjson.sis in my mobile and then tried to install my app, I got this error.
:-1: error: Installation failed: 'Failed to overwrite file owned by another package: c:\sys\bin\qjson.dll in ' Code: 131073; see http://wiki.forum.nokia.com/index.php/Symbian_OS_Error_Codes for descriptions of the error codes
In my .pro file I have this.
symbian: {
addFiles.sources = qjson.dll
addFiles.path = /sys/bin
DEPLOYMENT += addFiles
}
symbian: {
LIBS += -lqjson
}
Any ideas...?
Ok, I've just resolved a similar issue: it seems that your current build of QJson's library has different UID3 than the previous one that you installed on the phone.
Each .SIS file that is installed on the device has an identifier. The phone OS tracks which file was installed by which packacge, and if some new package wants to overwrite an existing file, the OS checks whether the new package has the same 'identity' than the previous owner of the file to be overwritten.
If the identity does not match, this error pops up.
There are number of reasons why this could have happened. For example, you could have simply changed the UID3 of the QJson before the build. Or, maybe you have forgot to set the library's UID3? Check the "src.pro' in the QJson project and go to the half of the file, you'd see lines:
#TARGET.UID3 =
TARGET.CAPABILITY = ReadDeviceData WriteDeviceData
If there's #, then you have forgot to set it and the build process assumed, well, letssay 'a random value'. So, now, set it to something, ie. TARGET.UID3 = 0xE0123456. Remember to correct that once you are ready to publish the application.
If a package with broken UID3 gets onto your phone and is blocking something - simply: uninstall it. Go to Settings/Installations/Installed, then find "qjson" and uninstall it. Afterwards, next installtion of qjson should succeed with no problems.

How to get command line arguments for a running process

In my program, I have been receiving an error when I use a
command-line compile command for mxmlc. The error is related to an
embedded font name not being correctly identified by flex in the
system fonts list.
However, on a whim, I decided to copy the code to Flex Builder and
compile it there. To my surprise, it worked, and it found the proper
font using the same system name I had given (PMingLiU).
I suspected my problem may be a locale one, and that my system cannot
correctly identify the font name because of locale considerations.
I've tried setting the locale of the compile code to en_US, to no
avail. So I would like to ask if anyone here knows how exactly Flex Builder invokes the MXML compiler and what differences there are compared to running mxmlc directly? We know it's not using the mxmlc.exe directly, since we tried replacing mxmlc with our own executable to capture the command line parameters.
If it matters, the OS used is Windows XP.
Although I don't have the exact answer to your question (what command line arguments Flex Builder passes to mxmlc.exe), I do have a meta-answer for you. You can find the command line by using one of two methods.
The first is platform-agnostic but will require you to compile a small C++ program. I've used this approach before when solving similar problems. What you can do is create a wrapper application which simply outputs the command line to a file. Build this application and drop it in as a temporary replacement for your mxmlc.exe, and when Flex Builder executes it you'll be able to access the resulting file "cmdline.txt" to get the full command line that it was called with:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
ofstream cmdLine;
cmdLine.open("cmdline.txt");
for (int i = 0; i < argc; i++) {
cmdLine << argv[i];
if (i < argc)
cmdLine << " ";
}
cmdLine.close();
return 0;
}
If you don't feel right about playing this dirty trick on Flex Builder, there is an alternative assuming you're running on Windows. You can use WMI to iterate over all of the running processes and grab their command line information. Ruby being my language of choice, this would require you to install the Ruby interpreter for Windows which you can do easily with the One-Click Ruby Installer for Windows.
After installing, just run this script as soon as Flex Builder kicks off your build:
require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
processes = wmi.ExecQuery("select * from win32_process")
for process in processes do
cmdLine = process.CommandLine
puts "Command line: #{cmdLine}" if cmdLine =~ /mxmlc/
end
I've added in a regular expression to print out the command line only for processes which were started with "mxmlc" in the command line (which should work for your needs). For a more general solution of iterating over each process, just remove the if clause at the end of the line containing:
puts "Command line: #{cmdLine}" if cmdLine =~ /mxmlc/
This will save you the headache of doing any low-level magic with StartRemoteThread and navigating through the PEB structures.
That's about the best I could do considering the nature of your question and without more information regarding your development OS. If this solves your problem I might suggest that you edit your post so that people facing similar issues can find this solution. A title like "How to get command line arguments for a running process" might be more apt.

Resources