Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, 6 September 2018

Surface Pro (2018) for Embedded Software Development

Summary
This blog examines the feasibility of using the Surface Pro 2018 'Surface' as an alternative to a Windows based laptop or desktop machine for the purpose of embedded software development.

Consideration was given to targeted metrics which consisted of physical handling, connectivity, storage speed and keyboard solutions. For a performance comparison, two common software packages were used to compile example projects on the Surface and a reference Asus laptop. Metrics dependent on factors which were difficult to verify, such as battery life, were not examined.


Surface Pro i5
Surface Pro i5
Testing was performed on a Surface Pro i5 over the duration four weeks, with the default Windows 10 Professional installation.


Surface Pro Hardware
Surface Pro Hardware

The Surface Pro i5 uses the Intel 7300U processor and was loaded with 8GB of RAM running Windows 10 Professional.


Surface Pro Windows Version
Surface Pro Windows Version

Handling and Portability
As a desktop replacement, without the addition of a keyboard such as the Surface Type, the Surface Pro 'Surface' is a befitting of the name space saver. Notably for small benches or work spaces the footprint of the Surface is very appealing which makes shifting or repositioning the Surface comparably easy moving from a laptop.

Off the bench in general use, the low weight of the Surface results in relative ease of movement. The kickstand was adjusted in the same manner a laptop display would be moved to cater for varying locations or seated positions.


Bluetooth
During point and select operation during code changes, use the Surface Pen was used without any issue. Other Bluetooth devices in the same proximity to the Surface did not cause any interference. 

Wireless
The wireless maintained connection whether at short distances (1m) or longer distances (30m) from a wireless router (BiPac). Only one dropout was noted during the test period.

Wi-Fi Bandwidth testing was performed using a local server, albeit slow. The Surface and Asus devices were both loaded with IPerf 3.1.3, then several tests conducted. Tests were conducted using the bidirectional configuration in IPerf.

SO_SNDBUF is 212992
[  4] local x.x.x.x port 56795 connected to y.y.y.y port 5201
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.00   sec  18.8 MBytes   157 Mbits/sec
[  4]   1.00-2.00   sec  15.8 MBytes   132 Mbits/sec
[  4]   2.00-3.00   sec  12.8 MBytes   107 Mbits/sec
[  4]   3.00-4.00   sec  11.5 MBytes  96.2 Mbits/sec
[  4]   4.00-5.00   sec  10.8 MBytes  90.4 Mbits/sec
[  4]   5.00-6.00   sec  10.0 MBytes  83.7 Mbits/sec
[  4]   6.00-7.00   sec  11.6 MBytes  97.6 Mbits/sec
[  4]   7.00-8.00   sec  11.0 MBytes  92.3 Mbits/sec

[  4]   8.00-9.00   sec  10.8 MBytes  90.1 Mbits/sec

Shown below are the results of the bandwidth tests conducted.


Surface Pro vs Asus Wi-Fi Bandwidth Results
Surface Pro vs Asus Wi-Fi Bandwidth Results
USB
The Surface's single port USB connection could certainly be considered a limitation for a embedded software or hardware developer who may need two or more USB ports.

During development the single Surface USB port was connected to a USB hub which facilitated a mouse, keyboard and programming adaptor. In some instances a serial adaptor was required. There were no issues relating to the download of drivers, operation of the USB or the performance of the adaptors.


Storage
For copying medium sized (>500Mb) files between computers either, an SD card or USB drive was used. With a meagre 128 Gb internal SSD, the removable SD card was used to store working files and backups.

The USB port was usually broken out to a hub, consequently little commentary on use with insertion of various USB equipment.

Inserting and removing the SD card from the Surface was seamless. The location of the SD slot behind the kickstand resonated with me for typical operation. 

For comparison of copy speeds for the SD card, an Asus i7-77HQ provided results as a reference device.

SD Speed
SD Card testing was performed with a Strontium Nitro 433X Class 10 16 Gb SD using the test software H2testw 1.4. This package was selected because it was capable of testing SD and USB.


Strontium Nitro 433X
Strontium Nitro 433X
Several tests were conducted using the Strontium Nitro on the Surface and Asus with the results displayed below.


Surface Pro vs Asus SD Card Read Speeds
Surface Pro vs Asus SD Card Read Speeds


Surface Pro vs Asus SD Card Write Speeds
Surface Pro vs Asus SD Card Write Speeds
USB Speed
Speed testing was performed with a Silicon Power USB 3 32GB drive using the same test software, H2testw 1.4, that was used with the SD card.


Silicon Power USB 3 Drive
Silicon Power USB 3 Drive
Again several tests were conducted using the Silicon Power USB on the Surface and Asus with the results displayed below.


Surface Pro vs Asus USB Drive Read Speeds
Surface Pro vs Asus USB Drive Read Speeds
Surface Pro vs Asus USB Drive Write Speeds
Surface Pro vs Asus USB Drive Write Speeds
Software Compile Times
The first application used for comparing software compile times was the 'Maker' popular Arduino, version 1.8.6.

Arduino
Three example projects were built on the Surface and an Asus laptop. Timing of the compile process was performed manually therefore some tolerance in timing shall be noted.


Surface Pro vs Asus Arduino Project Compile Times
Surface Pro vs Asus Arduino Project Compile Times
PSoC Creator
Again three example projects provided by Cypress were built on the Surface and an Asus laptop using PSoC Creator 4.2 'IDE'. Timing of the compile process was taken from the start and end times noted in the IDE output window.


Surface Pro vs Asus PSoC Creator Project Compile Times
Surface Pro vs Asus PSoC Creator Project Compile Times
Code Editing
Editing code with an application such as PSoC Creator, utilising the on-screen Surface keyboard was more cumbersome compared to a standard mechanical keyboard. One of the primary reasons was the standard Surface keyboard on-screen layout results in additional key presses to realise straightforward characters. For instance, at worst case, curly, round or square brackets would require three button presses.
A further reason for using a Surface Keyboard or a similar external keyboard solution was the on-screen keyboard does not display when text areas are clicked for editing. The on-screen keyboard had to be invoked manually.


Silicon Labs PSoC Creator Project on Surface Pro
Silicon Labs PSoC Creator Project on Surface Pro
On-Screen Keyboard
There were some initial complications with phantom presses. Applying the Microsoft HotFix for Surface Pro 4 resolved this issue.

Using the Surface Pro in landscape mode was personally the preferred option when writing code because the rear stand was used in the lowest position. Typing with the Surface flat on the desk was achievable although did not suit my office layout. The above image shows typically the ratio of code to keyboard that was used while developing the Silicon Labs blog.

Surface Pen
For specific editing tasks such as selection of text, repositioning selected text or moving on-screen objects the Surface Pen is a handy tool however, a standard external mouse will achieve the same result. People using the Surface Pen for more advanced tasks may have different feedback on its suitability.

Microsoft Surface Cover (Keyboard)
As a keyboard solution, the Surface Cover was more than reasonable with the depth of keystrokes sufficient to provide tactile feedback. The backlight keys on the Surface Cover were handy when typing whilst in low lighting conditions.


Surface Pro with Surface Cover
Surface Pro with Surface Cover
Final Thoughts
For embedded software development the Surface Pro is a worthy competitor to devices with similar specifications and features already in the market. 

In this setting, pro's for the Surface were the lightweight, fan less design, ease in handling and a solid Wi-Fi performance.

Unsurprisingly con's for the Surface related to limited connectivity resulting from the single USB port, throttled processor performance and initial phantom touch screen issues. The latter touch issue being the most obstructive as this phenomenon prevented device useability to the point of preventing logging onto the Operating System.

In a nutshell choosing the most suitable device ultimately depends on the requirements of the end user. Certainly for embedded software development other devices such as the middle to high end Lenovo Yoga, Dell Inspiron 13 or the HP Spectre may be a more suitable solution.


Tuesday, 9 January 2018

Prolific USB To Serial Code 10 Windows 10 Networked

Summary
Windows device driver Code 10 issues, with legacy Prolific adaptors or counterfeit chips have been investigated by countless people, there however remains instances where many solutions fail to work. 

This blog contains a step by step guide which aims at addressing the Code 10 issue for Windows 10 networked installations (domain) and possibly earlier Windows versions, when current internet listed solutions or the newer Prolific driver 3.8.18.0 driver may not work.

From experience, either the newer Prolific driver for Windows 10 or the guide detailed in the blog, have resolved the issue on networked Windows 10 machines having the code 10.

Why Another Fix
The first reason for this fix relates to Windows 10 computers on a workplace network (domain) where software and driver updates are applied in a blanket roll out, when a newer driver version is available. This is an accepted process that facilitates software improvements however the process is troublesome when there are either driver or hardware related issues. This issue can be addressed by preventing the driver update of the specific USB device.

The second reason for this blog relates to online software fixes released with little or no explanation as to what software mechanisms are under the hood. Running an executable from an unknown website leaves me personally with an uneasy feeling. Installing some malevolent software on a home computer limits exposure to possibly a few computers. Installing the same software on a workplace network, with possibly dozens or more networked computers, is an entirely different matter.

Certainly there are noteworthy websites with documented / packaged fixes that can be tested if not done so already.

http://www.ifamilysoftware.com/news37.html

http://dronespersonalizados.blogspot.com.au/2014/03/pl2303-error-code-10-how-to-fix-windows.html

http://www.totalcardiagnostics.com/support/index.php?/Knowledgebase/Article/View/92

Description of the Fix
Fixing the driver issue (Code 10) can be achieved in four steps.

Step 1. With the Prolific USB adaptor fitted to the target computer, uninstall the Windows Prolific driver from Device Manager for that USB port.

Step 2. With the Prolific USB adaptor fitted in the same port, install the Prolific driver version applicable to the Prolific hardware used. This step may require some experimentation with earlier Prolific driver versions. Version 3.3.2.102 worked for both my Windows 10 installations. Prolific 3.3.2.102 compressed file here on Google drive. This driver is signed and should not be used otherwise.

Step 3. Repeat steps 1 and 2 for all USB ports on the computer, including any USB hubs or docking stations connected to the computer where the Prolific USB device may be connected.

Step 4. Change the local computer Windows Group Policy settings to prevent updates for only that Prolific USB device. For changes to be applied using the Group Policy Editor, the computer must be connected to the relevant Domain. The Group Policy can then updated to prevent Windows Updates for USB devices matching the Prolific USB VID and PID.

Process Explained
The image below is a capture of the Windows 10 Device Manager showing the yellow icon for the Prolific USB to Serial adaptor.


Device Manager Prolific USB to Serial - Code 10
Device Manager Prolific USB to Serial - Code 10
Step 1.
With the Prolific USB device installed, remove the Prolific driver by opening the Properties of the USB device shown in Device Manager.


Device Manager Prolific USB to Serial - Driver
Device Manager Prolific USB to Serial - Driver
Navigate to the Driver tab and click the Uninstall Device button.

Step 2.
Install the suitable Prolific driver for computer and operating system. For a Windows 10 installation on a laptop the Prolific driver version 3.3.2.102 was found to be suitable. This version may vary for other hardware types and Windows installations.
Device Manager Prolific USB to Serial - New Driver
Device Manager Prolific USB to Serial - New Driver

Step 3. 
Repeat the process for each USB port associated with the computer.

On the example laptop used for this blog, using the Prolific USB device on a second USB port results in a new serial port enumeration as shown in the image below. 


Device Manager Prolific USB to Serial - Code 10
Device Manager Prolific USB to Serial - Code 10
Again with the Prolific USB device installed, remove all newer Prolific drivers by opening the Properties of the USB device shown in Device Manager.


Device Manager Prolific USB to Serial - Driver
Device Manager Prolific USB to Serial - Driver
Navigate to the Driver tab and click the Uninstall Device button.


Device Manager Prolific USB to Serial - New Driver
Device Manager Prolific USB to Serial - New Driver

Step 4.

With the computer connected to the computer Domain and the Prolific USB device still installed, open the Properties of the Prolific USB device shown in Device Manager.


Device Manager Prolific USB to Serial - Hardware ID
Device Manager Prolific USB to Serial - Hardware ID
Navigate to the Details tab. 

From the Property drop down list box select the Hardware ID's item. As the information displayed will be used when configuring the Windows Group Policy this window can be left open.

From the Windows Start open the Group Policy Editor by typing gpedit.msc. If the installation is Windows 10 Home the Group Policy Editor will not be found - possibly disabled in Home editions. 


Windows 10 Group Policy Editor
Windows 10 Group Policy Editor
With the Group Policy Editor open, navigate to the Administrative Templates folder, then System, then Device Installation.


Windows 10 Group Policy Editor  - Device Installation
Windows 10 Group Policy Editor  - Device Installation
Select the Device Installation Restrictions folder then in the Window pane to the right, double click the item Prevent installation of drivers that match any of these device ID's. A new window will be displayed.


Windows 10 Group Policy Editor  - Device Installation Restrictions
Windows 10 Group Policy Editor  - Device Installation Restrictions
Click the Enabled radio button in the top left of the window.


Windows 10 Group Policy Editor  - Device Installation Restrictions Enabled
Windows 10 Group Policy Editor  - Device Installation Restrictions Enabled
Click the Show button to configure the Prolific USB ID.


Windows 10 Group Policy Editor  - Device Installation Restrictions Empty ID
Windows 10 Group Policy Editor  - Device Installation Restrictions Empty ID
Switch back to Device Manager and copy the first entry from the Hardware ID.


Device Manager Prolific USB to Serial - Hardware ID
Device Manager Prolific USB to Serial - Hardware ID

Paste this information into the Group Policy Editor. Repeat for process for the second line in Device Manager. The result should be similar to the image shown below.

Windows 10 Group Policy Editor  - Device Installation Restrictions Updated ID
Windows 10 Group Policy Editor  - Device Installation Restrictions Updated ID
Close all windows and restart the computer so that the Group Policy changes are applied.

Driver updates should no longer be applied to that specific USB device.

Note on Limitations - Updating Drivers
Should a similar Prolific or other 'grey' USB device with the same VID and PID require a driver change, then the Windows 10 Group Policy Editor  - Device Installation Restrictions must be changed to Not Configured or Disabled.

Attempting to update the driver, without disabling the installation restriction, will result in a window similar to the image shown below.


Device Manager Update Driver - Forbidden System Policy
Device Manager Update Driver - Forbidden System Policy

Hope this fix helps!

Downloads
Prolific driver 3.3.2.102
Prolific driver 3.3.2.102



Saturday, 25 February 2017

Cypress PSoC VT100 Code Example

Summary
As an alternative interface to one of my projects, basic VT100 functionality was implemented across serial (USB) on a Cypress PSoC4 BLE device. The Cypress iprintf code was used with a wrapper to implement basic VT100 features.

The screen capture below shows basic control of text and colour.

VT100 Example in TeraTerm
VT100 Example in TeraTerm

As a starting reference the
Bash Hackers website was used for the VT100 escape codes. A plethora of information can be found at sites such as Technopedia, TermSys, NorthEastern Uni, ASCII-Table and ISP to name a handful. What has been provided is only a portion of the total VT100 commands available.

Code for the PSoC
For Cypress Creator development environment a separate VT100 source and header file were created with the necessary escape commands.


VT100 Commands
VT100 Commands
Foreground and background colors.


VT100 Colours
VT100 Colours

Cypress already provide a PSoC Creator example project with iprintf, which works effectively as the low level interface. A reference to this library was included in VT100 code.

To use a number of commands at once or to configure the location of the cursor a few functions were written, prototypes below. There is room to improve these functions but for testing they function as required.


VT100 Function Prototypes
VT100 Function Prototypes

Usage in the software main shown below.

VT100 Example Usage
VT100 Example Usage


Testing
Testing was also performed with other terminal packages such as PuTTY and RealTerm.

VT100 Example in PuTTY (Windows)
VT100 Example in PuTTY (Windows)
TermPuTTY under Ubuntu Mate, customised settings

VT100 Example in PuTTY (Ubuntu Mate)
VT100 Example in PuTTY (Ubuntu Mate)

RealTerm was placed in ANSI mode with good results, except for the colours.

VT100 Example in RealTerm
VT100 Example in RealTerm

Downloads


vt100.c
vt100.c

vt100.h
vt100.h



Change Summary

Version 1.02 (15 March 2017)
  • Added GPL details
  • Corrected two text command enumerations
  • Updated PSoC Creator project
Version 1.01 (11 March 2017)
  • Added defines for background colour
  • Changed names of foreground colour defines
  • Updated PSoC Creator project
Version 1.00 (26 February 2017)
  • Created PSoC Creator project for initial vt100 commands


Wednesday, 15 February 2017

MCP23S17 IO Port Expander Header File / Register

Summary
For a recent project the 16bit IO Expander, MCP23S17, from Microchip was enlisted for low voltage input scanning. 

Searching online, at the time of writing this blog, there were no projects using this part with sample code. 

Below is the header file that may be of use.


MCP23S17 Microchip IO Expander QFN Package
Microchip IO Expander QFN Package


Downloads


mcp23s17.h

Code


/******************************
* mcp23s17.h
******************************/

#ifndef mcp23s17_h
#define mcp23s17_h

typedef unsigned char   uint8;
    
#define MCP_READ   0x41     /* Read */
#define MCP_WRITE   0x40     /* Write */
#define Mode_8Bit     1         /* Addressing 8/16bit */
#define Mode_16bit    0

#ifdef Mode_16Bit
    /******************************
    * Control register for BANK=0
    ******************************/
    #define IODIRA        0x00      /* Data Direction Register for PORTA */
    #define IODIRB        0x01      /* Data Direction Register for PORTB */ 
    #define IPOLA         0x02      /* Input Polarity Register for PORTA */ 
    #define IPOLB         0x03      /* Input Polarity Register for PORTB */ 
    #define GPINTENA      0x04      /* Interrupt-on-change enable Register for PORTA */ 
    #define GPINTENB      0x05      /* Interrupt-on-change enable Register for PORTB */ 
    #define DEFVALA       0x06      /* Default Value Register for PORTA */    
    #define DEFVALB       0x07      /* Default Value Register for PORTB */      
    #define INTCONA       0x08      /* Interrupt-on-change control Register for PORTA */  
    #define INTCONB       0x09      /* Interrupt-on-change control Register for PORTB */      
    #define IOCON         0x0A      /* Configuration register for device */                      
    #define GPPUA         0x0C      /* 100kOhm pullup resistor register for PORTA (sets pin to input when set) */    
    #define GPPUB         0x0D      /* 100kOhm pullup resistor register for PORTB (sets pin to input when set) */      
    #define INTFA         0x0E      /* Interrupt flag Register for PORTA */        
    #define INTFB         0x0F      /* Interrupt flag Register for PORTB */    
    #define INTCAPA       0x10      /* Interrupt captured value Register for PORTA */  
    #define INTCAPB       0x11      /* Interrupt captured value Register for PORTB */    
    #define GPIOA         0x12      /* General purpose I/O Register for PORTA */  
    #define GPIOB         0x13      /* General purpose I/O Register for PORTB */ 
    #define OLATA         0x14      /* Output latch Register for PORTA */ 
    #define OLATB         0x15      /* Output latch Register for PORTB */
#endif

#ifdef Mode_8Bit
    /******************************
    * Control register for BANK=1
    ******************************/
    #define IODIRA        0x00      /* Data Direction Register for PORTA */
    #define IPOLA         0x01      /* Input Polarity Register for PORTA */  
    #define GPINTENA      0x02      /* Interrupt-on-change enable Register for PORTA */     
    #define DEFVALA       0x03      /* Default Value Register for PORTA */    
    #define INTCONA       0x04      /* Interrupt-on-change control Register for PORTA */     
    #define IOCONA        0x05      /* Configuration register for device */          
    #define GPPUA         0x06      /* 100kOhm pullup resistor register for PORTA (sets pin to input when set) */     
    #define INTFA         0x07      /* Interrupt flag Register for PORTA */
    #define INTCAPA       0x08      /* Interrupt captured value Register for PORTA */
    #define GPIOA         0x09      /* General purpose I/O Register for PORTA */  
    #define OLATA         0x0A      /* Output latch Register for PORTA */ 
    #define IODIRB        0x10      /* Data Direction Register for PORTB */ 
    #define IPOLB         0x11      /* Input Polarity Register for PORTB */ 
    #define GPINTENB      0x12      /* Interrupt-on-change enable Register for PORTB */
    #define DEFVALB       0x13      /* Default Value Register for PORTB */      
    #define INTCONB       0x14      /* Interrupt-on-change control Register for PORTB */
    #define IOCONB        0x15      /* Configuration register for device */  
    #define GPPUB         0x16      /* 100kOhm pullup resistor register for PORTB (sets pin to input when set) */        
    #define INTFB         0x17      /* Interrupt flag Register for PORTB */    
    #define INTCAPB       0x18      /* Interrupt captured value Register for PORTB */    
    #define GPIOB         0x19      /* General purpose I/O Register for PORTB */ 
    #define OLATB         0x1A      /* Output latch Register for PORTB */
#endif
    
/* Config bits - IOCON */
#define BANK  0x80
#define MIRROR  0x40
#define SEQOP  0x20
#define DISSLW  0x10
#define HAEN  0x08
#define ODR      0x04
#define INTPOL  0x02

/******************************
* Prototypes
******************************/
void MCP23S17_init();
void MCP23S17_write(uint8 address, uint8 value);
uint8 MCP23S17_read(uint8 address);
uint8 MCP23S17_verify(uint8 address, uint8 verify_data);
    
#endif
/* END */



Change Summary

Version 1.00 (10 February 2017)

  • Created register mapping for MCP23S17, 8 and 16 bit modes