Setup GCC ARM Tool Chain For SAM E54 Xplained Pro

After struggling with config file for SAME54 board we are detailing out steps for setting up a free and fully functional GCC + Eclipse + OpenOCD GDBServer environments for use with the SAME54 Xplained Pro board.

Step 1. Setup GCC ARM Toolchain

There are varity of arm-tool chains like Yagarto, gcc-arm. I will go with GNU Arm® Embedded Toolchain (gcc-arm-none-eabi). The gcc-arm toolchain has hardfp support meaning one can take full advantage of the floating point unit (FPU) and can be used with all Cortex-M0,M3 and M4 parts.

Installing executable on Ubuntu *
Unpack the tarball to the install directory, like this:
$ cd $install_dir && tar xjf gcc-arm-none-eabi-*-yyyymmdd-linux.tar.bz2

In my case i have installed in usr/lib folder.
Update this installation path to ~/.profile file
$ vi ~/.profile
export PATH=”$PATH:/usr/lib/gcc-arm-none-eabi-8-2018-q4-major/bin”

$source ~/.profile
$echo $PATH

Then execute following command to check gcc version
$ arm-none-eabi-gcc -v

For some Ubuntu releases, the toolchain can also be installed via
Launchpad PPA at https://launchpad.net/~team-gcc-arm-embedded/+archive/ubuntu/ppa.

Step 2 – Get SAME54 Example

Go to www.start.atmel.com and download example ‘LED Toggle’ for SAM E54 xplained pro board.

Extract this project to your local folder and navigate to “gcc” folder.
$ cd LED_switcher/gcc
Now execute make comand
$make
This will create “AtmelStart.elf” file
Finished building target: AtmelStart.elf
“arm-none-eabi-objcopy” -O binary “AtmelStart.elf” “AtmelStart.bin”
“arm-none-eabi-objcopy” -O ihex -R .eeprom -R .fuse -R .lock -R .signature \
“AtmelStart.elf” “AtmelStart.hex”
“arm-none-eabi-objcopy” -j .eeprom –set-section-flags=.eeprom=alloc,load –change-section-lma \
.eeprom=0 –no-change-warnings -O binary “AtmelStart.elf” \
“AtmelStart.eep” || exit 0
“arm-none-eabi-objdump” -h -S “AtmelStart.elf” > “AtmelStart.lss”
“arm-none-eabi-size” “AtmelStart.elf”
text data bss dec hex filename
1472 0 65584 67056 105f0 AtmelStart.elf

AtmelStart.bin and AtmelStart.hex are release based images that ought to be downloaded onto the chip when programming it. The .elf file is typically used for debugging. It is identical image as the one in the .bin/.hex files with debug information required by the debugger.

Step 3. Install OpenOCD

Install and configure the debugger software OpenOCD
$sudo openocd -f ~/openocd/tcl/board/microchip_same54_xplained_pro.cfg -c “program AtmelStart.elf verify reset exit”

Open On-Chip Debugger 0.10.0+dev-00755-ga7479fa8 (2019-03-30-16:21)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport “swd”. To override use ‘transport select ‘.
none separate
adapter speed: 2000 kHz
cortex_m reset_config sysresetreq
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: FW Version = 03.25.01B6
Info : CMSIS-DAP: Serial# = ATML2748051800002368
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD DPIDR 0x2ba01477
Info : same54.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : SWD DPIDR 0x2ba01477
target halted due to debug-request, current mode: Thread
xPSR: 0x21000000 pc: 0x000002b6 msp: 0x20010020
** Programming Started **
auto erase enabled
Info : SAM MCU: SAME54P20A (1024KB Flash, 256KB RAM)

Now hit the button on the board and LED on the board will blink! Congratulations! you just built your first program for the SAM E54 Xplained Pro Board..

Login App in Android

To Create any application in android we have to deal with three files:

  • AndroidManifest.xml
  • activity_main.xml
  • MainActivity.java

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.login.login">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

activity_main.xml

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools = "http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height = "match_parent"
tools:context = ".MainActivity">
<TextView android:text = "Login" android:layout_width="wrap_content"
android:layout_height = "wrap_content"
android:id = "@+id/textview"
android:textSize = "35dp"
android:layout_alignParentTop = "true"
android:layout_centerHorizontal = "true" />
<EditText
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id = "@+id/editText"
android:hint = "Enter Name"
android:focusable = "true"
android:textColorHighlight = "#ff7eff15"
android:textColorHint = "#ffff25e6"
android:layout_marginTop = "46dp"
android:layout_alignParentLeft = "true"
android:layout_alignParentStart = "true"
android:layout_alignParentRight = "true"
android:layout_alignParentEnd = "true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:textColorHint="#ffff299f"
android:hint="Password" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attempts Left:"
android:id="@+id/textView2"
android:layout_below="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView3"
android:layout_alignTop="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/textView2"
android:layout_toEndOf="@+id/textview"
android:textSize="25dp"
android:layout_toRightOf="@+id/textview" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="login"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/textview"
android:layout_toStartOf="@+id/textview" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/textview"
android:layout_toEndOf="@+id/textview" />
</RelativeLayout>

MainActivity.java

package com.login.login;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity  {
Button b1,b2;
EditText ed1,ed2;
TextView tx1;
int counter = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.button);
ed1 = (EditText)findViewById(R.id.editText);
ed2 = (EditText)findViewById(R.id.editText2);
b2 = (Button)findViewById(R.id.button2);
tx1 = (TextView)findViewById(R.id.textView3);
tx1.setVisibility(View.GONE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(ed1.getText().toString().equals("manasi") &&
ed2.getText().toString().equals("abc")) {
Toast.makeText(getApplicationContext(),
"Redirecting...",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(),"Wrong Credentials",Toast.LENGTH_SHORT).show();
tx1.setVisibility(View.VISIBLE);
tx1.setBackgroundColor(Color.RED);
counter--;
tx1.setText(Integer.toString(counter));
if (counter == 0) {
b1.setEnabled(false);
}
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}

Output:

Navigation from one screen to another screen in android

Functionality:

How to interact with activity,when a button is clicked,navigate from current screen(current activity) to another screen(another activity).

Activity:

In android,an activity is representing a single screen.Most applications have multiple activities to represent different screens.for example,one activity to display a list of the application settings,another to display application status.

To Create any application in android we have to deal with three files:

  • AndroidManifest.xml
  • activity_main.xml
  • MainActivity.java

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nav.navigation"
>
<application
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Second_screen"></activity>
</application>
</manifest>

Strings.xml:

<resources>
<string name="app_name">Navigation</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="button_name">Go to second screen</string>
<string name="title1">Welcome to Navigation (First screen)</string>
<string name="title2">Welcome to Navigation (second screen)</string>
</resources>

In this example,we have to navigate from one to another screen so we need to create two layout files and two java files.

activity_main.xml:

This is layout file which represents first screen.First screen contains one textview and button.Textview is texted as “Welcome to Navigation” and button texted as “Go To second screen”.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="@string/title1"  />
<Button
android:id="@+id/first_screen_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/head"
android:layout_marginTop="16dp"
android:text="@string/button_name"
/>
</RelativeLayout>

MainActivity.java:

This java file contains code to navigate to second screen.file has OnClickListener which make Button click to go to second screen.

package com.nav.navigation;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
private Button nextScreen;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nextScreen = (Button) findViewById(R.id.first_screen_button);
nextScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent agn = new Intent(MainActivity.this, Second_screen.class);
startActivity(agn);
}
});
}
public void onClick(View v) {
}
}

second_screen.xml:

This is layout file which represents second screen.second screen contains one textview.Textview is texted as “Welcome to Second Screen”.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/title2"/>
</RelativeLayout>

Second_screen.java

This java file contains code of action to be performed after clicking on button in first screen.

package com.nav.navigation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class Second_screen extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_screen);
TextView tv = new TextView(this);
tv.setText("Welcome to Second screen");
setContentView(tv);
}
public void onClick(View v) {
}
}

Output:

First screen
Second screen

Calculator App in Android

Here ,we are creating simple and basic functions calculator App. This app can help you to understand the layouts, buttons and action handling. To create this app we need to use different widgets such as TextView, button, EditText etc.This app is able to perform following basic four mathematical functions :

  • Addition
  • Subtraction
  • Multiplication
  • Division

To Create any application in android we have to deal with three files:

  • AndroidManifest.xml
  • activity_main.xml
  • MainActivity.java

AndroidManifest.xml

The AndroidManifest.xml contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.calculator.calculator2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

activity_main.xml

The activity is a Java class, and the layout is an XML file, so the names we’ve given here will create a Java class file called MainActivity.java and an XML file called activity_main.xml. layout containing two EditTexts,4 Buttons and one textview. Give them id according to their name so that when we’ll write java code, it will be helpful to understand which buttons we are dealing with.To arrange these widgets we need to use different layouts.Here,we used linear layout to display EditText, Buttons and TextView in linear fashion.Use of widgets is as follows:

  • EditText:we used two EditTexts to get two input values from user.
  • Buttons: we used four Buttons which performs functions of addition,subtraction,multiplication and division.
  • TextView:TextView is used to display result.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1"
android:layout_marginLeft="10pt"
android:layout_marginRight="10pt"
android:layout_marginTop="3pt">
<EditText
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5pt"
android:id="@+id/etNum1"
android:layout_width="match_parent"
android:inputType="numberDecimal">
</EditText>
<EditText
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5pt"
android:id="@+id/etNum2"
android:layout_width="match_parent"
android:inputType="numberDecimal">
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_marginTop="3pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="+"
android:textSize="8pt"
android:id="@+id/btnAdd">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="-"
android:textSize="8pt"
android:id="@+id/btnSub">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="*"
android:textSize="8pt"
android:id="@+id/btnMult">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="/"
android:textSize="8pt"
android:id="@+id/btnDiv">
</Button>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt"
android:textSize="12pt"
android:layout_marginTop="3pt"
android:id="@+id/tvResult"
android:gravity="center_horizontal">
</TextView>
</LinearLayout>

MainActivity.java

The main activity code is a Java file MainActivity.java. This is the actual application file which ultimately gets converted to a Dalvik executable and runs your application.

OnClick Listener:

Tis listener is used to get get result once we click on button.In this example,to get input from user we used getText() method.Once user input two values to perform operation user need to press any button.switch case is used to give functionality to buttons.Suppose user clicked on Addition button control goes to case R.id.btnAdd and it performs ‘+’ operation

package com.calculator.calculator2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class MainActivity extends AppCompatActivity implements OnClickListener {
EditText etNum1;
EditText etNum2;
Button btnAdd;
Button btnSub;
Button btnMult;
Button btnDiv;
TextView tvResult;
String oper = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etNum1 = (EditText) findViewById(R.id.etNum1);
etNum2 = (EditText) findViewById(R.id.etNum2);
btnAdd = (Button) findViewById(R.id.btnAdd);
btnSub = (Button) findViewById(R.id.btnSub);
btnMult = (Button) findViewById(R.id.btnMult);
btnDiv = (Button) findViewById(R.id.btnDiv);
tvResult = (TextView) findViewById(R.id.tvResult);
btnAdd.setOnClickListener(this);
btnSub.setOnClickListener(this);
btnMult.setOnClickListener(this);
btnDiv.setOnClickListener(this);
}
@Override
public void onClick(View v) {
float num1 = 0;
float num2 = 0;
float result = 0;
// check if the fields are empty
if (TextUtils.isEmpty(etNum1.getText().toString())
|| TextUtils.isEmpty(etNum2.getText().toString())) {
return;
}
num1 = Float.parseFloat(etNum1.getText().toString());
num2 = Float.parseFloat(etNum2.getText().toString());
switch (v.getId()) {
case R.id.btnAdd:
oper = "+";
result = num1 + num2;
break;
case R.id.btnSub:
oper = "-";
result = num1 - num2;
break;
case R.id.btnMult:
oper = "*";
result = num1 * num2;
break;
case R.id.btnDiv:
oper = "/";
result = num1 / num2;
break;
default:
break;
}
// form the output line
tvResult.setText(num1 + " " + oper + " " + num2 + " = " + result);
}
}

Output:

USB Communication

About Android USB

Android supports USB devices through two modes:

  • Android Accessory: In this mode external USB device acts as host.
  • Android Host: In this mode Android Device acts as host and powers the external device.

Manifest File for USB connection

We want to be notified when an external USB device is attached to the Android device.This can be done adding a new intent filter entry to the Activity that should be started by the system when a USB device is plugged in.

<activity  
.......
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
<meta-data  android:name=
"android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />    
<meta-data android:name=
"android.hardware.usb.action.USB_DEVICE_DETACHED"
android:resource="@xml/device_filter" />
</activity>  

In above code, MainActivity registers to be informed when a USB device is connected (USB_DEVICE_ATTACHED) or disconnected (USB_DEVICE_DETACHED). If we want to restrict the type of devices, we can include a device filter XML file indicated in the meta-data element.This file is stored in /res/xml folder and lists combinations of vendor id , product id ,manufacturer,version etc.

USB Configuration in java file

To receive the USB events, we need to create a BroadcastReceiver and then register it. In this case, the events will be received via the onReceive() method of BroadcastReceiver.

private static final String ACTION_USB_ATTACHED  = "android.hardware.usb.action.USB_DEVICE_ATTACHED";  
private static final String ACTION_USB_DETACHED  = "android.hardware.usb.action.USB_DEVICE_DETACHED"; 
BroadcastReceiver bReceiver= new BroadcastReceiver() {...};  
IntentFilter filter = new IntentFilter();  
filter.addAction(ACTION_USB_ATTACHED);  
filter.addAction(ACTION_USB_DETACHED);  
registerReceiver(bReceiver,filter); 
public void onReceive(Context context, Intent intent) {  
String action = intent.getAction();          
if (action.equalsIgnoreCase(ACTION_USB_DETACHED)) {...}         ...
}

Permission

Before communicating with the USB accessory, your application must have permission from your users.If you want to obtain permission explicitly, then you need to call requestPermission(). In onCreate() you need to create permission intent and pass that to requestPermission().

openAccessory()

Once permission granted openAccessory() method will be called.This method is used to communicate with accessory.file descriptor can be used to set up input and output streams to read and write data to descriptor.The streams represent the accessory’s input and output endpoints.

ATSAME54 Config File Using Openocd

Sometimes solutions are very simple. Openocd (Open On-Chip Debugger) is used on ubuntu for debugging and flashing programs to your target board. We are using SAM E54 Xplained Pro board. The problem started when we could not locate openocd config file for ATSAME54. After searching on google for a while we came to know that atsame5x.cfg we have to apply patch from openocd to get this working. As per openocd site they mentioned that support for ARM M4 series is added for microchip SAM D/E series controllers.

We have downloaded patch updated openocd and after running it using following command, could not connect to board and got same error.

$ openocd -f tcl/board/microchip_same54_xplained_pro.cfg 
Open On-Chip Debugger 0.10.0+dev-00409-g1ae106de (2019-03-18-12:24)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
none separate
adapter speed: 2000 kHz
cortex_m reset_config sysresetreq
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: unable to open CMSIS-DAP device 0x3eb:0x2111

At this time also we are unable to connect to board, we were constantly in touch with Microchip Support but they were also not getting answer to this. Their easy recommendation was :-

Customers are able to go ahead with the tutorial given in Microchip Developer Help.
There are no out of the box IDEs provided by Microchip for Linux, but a lot of people successfully installed Eclipse and used it for development including full debugging. So, you could get some good help from online forums.
We are sorry for not being much help on this. We cannot try it at our end.
Otherwise, you can install Windows through virtual box on a Linux Operating system and install the Atmel Studio on the virtual box.”

We are being startup company we do not want to invest in microsoft windows just to use Atmel studio, so we continued digging.

And the simple solution to this long going problem was use “sudo” . Neither Microchip website nor online forums mentioned about it. It was clear from the error that it was unable to open CMSIS-DAP device.

$ sudo openocd -f tcl/board/microchip_same54_xplained_pro.cfg 
Open On-Chip Debugger 0.10.0+dev-00409-g1ae106de (2019-03-18-12:24)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
none separate
adapter speed: 2000 kHz
cortex_m reset_config sysresetreq
srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 03.25.01B6
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD DPIDR 0x2ba01477
Info : same54.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections

To program your target board use

> sudo openocd -f tcl/board/microchip_same54_xplained_pro.cfg -c “program firmware.elf verify reset exit”

Ceedling Unit Testing

Unit testing is code that calls some other code to check if it performing as expected.Ceedling is a build system specifically designed for running unit tests in c. Unity and CMock are open source tools for testing c.Ceedling has feature of automatic generation of mock.

  • Unity is a unit test framework.
  • CMock creates the fake versions of other modules.Using these fake versions we can verify whether our module is working correctly or not.
  • Ceedling include unit test framework(Unity) and Mocking framework(CMock).
  • It requires Ruby to run and it uses GCC to build each test.
  • Ceedling comes with a command line tool that can be used to generate the project.

Check out details on how to mock local variable in ceedling, and Ceedling Unit Testing With ATSAME54 Micro-controller.

Display selected item of ListView using toast in android

ListView

In Android, List of scroll-able items can be displayed using ListView. Users can select any list item by clicking on it.

Problem Statement:

Develop an application to create list of fruits using ListView and display selected fruit of ListView using toast. How to get the selected item from ListView?

Several Ways to create ListView:

There 2 ways to create ListView:

  • we can assign ListView by giving values in main.xml.
  • we can assign values in string.xml.

Sample Code:

Here is sample code for ListView using toast in android, Created two files to develop an application.

  • Layout file(activity_main.xml):This file contains code to design an GUI of an application. In this we have used widget ListView to display list and TextView to display text on lists.
  • Activity file(MainActivity.java): This file contains code to perform activity on listview.In this we have created Array, ArrayList, Adapter and ListView. We have added created Array into ArrayList then ArrayList into Adapter and then Adapter into ListView.

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:context=".MainActivity">
<ListView
android:id="@+id/listViewID"
android:layout_width="match_parent"
android:layout_height="495dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

MainActivity.java

package com.toast.listviewe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.view.ViewGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity{
ListView fruitView;
String[] fruits = new String[]
{
"Mango",
"Orange",
"Guava",
"Banana",
"Pineapple",
"Apple"
};
List<String> fruitList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fruitView = (ListView) findViewById(R.id.listViewID);
fruitList = new ArrayList<String>(Arrays.asList(fruits));
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, android.R.id.text1, fruitList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView ListItemShow = (TextView) view.findViewById(android.R.id.text1);
ListItemShow.setTextColor(Color.parseColor("#ffffff"));
return view;
}
};
fruitView.setAdapter(adapter);
fruitView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this, "clicked item is " +fruits[position], Toast.LENGTH_SHORT).show();
}
});
}
}

Output:

Hello World in android studio using activity,service & broadcastReceiver

Problem Statement:

Printing Hello World text using activity,service and broadcast receiver.

This program demonstrates how to call any activity from service and service from broadcast receiver. The application starts from broadcast receiver then control goes to service and service call activity to print “Hello World”.

Several ways To create an application:

  • LocalBroadcastManager:This can be used ,If you want to send broadcasts to your application.
  • BroadcastReceiver:This can be used,If you want to send broadcasts across applications.

About Code:

I have created 3 java classes namely broadcast,MyService,MyActivity.

  • broadcast.java :This class inherits BroadcastReceiver class and contains method onReceive(Context context, Intent intent) to create an intent and to call startService() method.
  • MyService.java:This class inherits Service class and contains method onBind(Intent intent) to create intent and to call startActivity().
  • MainActivity.java:This class inherits Activity class and contains method onCreate() to create an application.

Output:

Output

Manifest File:AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.all.ActivityServiceBroadcast">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<receiver android:name=".broadcast">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
</receiver>
<service
android:name=".MyService"
android:enabled="false"
android:exported="true"></service>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Layout file:activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

BroadcastReceiver file:broadcast.java

package com.all.ActivityServiceBroadcast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class broadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
String action = intent.getAction();
}
}

Service file:MyService.java

package com.all.ActivityServiceBroadcast;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
Intent ActivityIntent = new Intent(this,MainActivity.class);
startActivity(ActivityIntent);
throw new UnsupportedOperationException("Not yet implemented");
}
}

Activity file:MainActivity.java

package com.all.ActivityServiceBroadcast;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle SavedInstanceState) {
super.onCreate(null);
setContentView(R.layout.activity_main);
}
}


Advantages and Disadvantages of Tkinter and wxpython

#Tkinter:

Pros:

part of python, nothing extra to download. Very simple syntax. The text widget is remarkably powerful and very easy to work with. The canvas widget is also very easy and powerful. No other toolkit provides the same mix of ease and power than those two widgets in my experience. Uses native widgets on the mac and windows. Tk is rock solid with few cross-platform idiosyncrasies. I think Tkinter’s binding mechanism is far superior to wxPython’s; it’s more flexible and consistent. I think Tkinter’s three geometry managers – pack, place and grid – are much more powerful and easy to use than the wxPython sizers.

  1. Mature, stable.
  2. Widely ported.
  3. Simple API is easy to learn.

Cons:

Sometimes hard to debug in that Tkinter widgets at their core aren’t python objects; tkinter provides a wrapper around the actual tk widgets which sometimes means you get weird error messages. There is very little printing support (you can generate postscript docs from the canvas, but there’s no built-in support in the text widget for printing). Some people claim Tk is ugly. Tkinter isn’t as “pythonic” as wxPython

  1. Non-native look-and-feel.
  2. Simplistic model is easy to learn, but becomes cumbersome with complex interfaces.
  3. To be truly usable, requires downloading extra toolkits
  4. Probably a dead-end technology, as toolkits such as wxPython gain mindshare.

#wxPython:

Pros:

It has many more widgets, though often that means there are three types of notebook widgets rather than one kitchen-sink widget. wxPython widgets are first class python objects which is really nice. wxPython seems to be more popular; some people care about that, some don’t. wxPython has much better printing support than Tkinter.

  1. Large library of widgets
  2. Native look-and-feel.
  3. Very flexible.
  4. Very helpful user community.

Cons:


wxPython requires a separate download which can be a pain to manage when you deploy your app. wxPython is a bit buggy IMO, and there are definite cross-platform issues.

  1. Very active development (although this is a pro as well ) means that there are quite often bugs and, less often, API changes.
  2. Requires downloading and installing (not included with Python)