Sunday, March 31, 2024

Simplicity Studio and Keil 8051 compiler issues and tutorial

Working with Simplicity Studio and Keil compiler can be frustrating sometimes. Most of the issues encountered were difficult to solve because the error messages given by the Keil compiler were very confusing. Thus, I will post here the most common issues that I've came across in the hope it will help others and perhaps me in the future.

Contents

 

Keil Error Messages

A list of Keil error codes and their description can be found here: https://developer.arm.com/documentation/101655/0961/Cx51-User-s-Guide/Error-Messages/Errors-and-Warnings/Reference. However, below are scenarios in which the error message and the cause are not related. For example when actually missing a ';' the error message is: syntax error near 'token', expected ';' but when something is not defined because an include file is missing, the error message is: missing ';' before.


missing ';' before

One might think this is obvious - you missed an ';' somewhere. But this is not always the case.

Scenario: error line appears when including a header file.

Solution #1: include SFR declarations in the header file according to the type of the device.

#include <SI_C8051F330_Register_Enums.h>

Solution #2: include stdint.h that defines integer types.

#include <stdint.h>

Solution #3: include stdbool.h.

#include <stdbool.h>

It appears that Keil shows the same error message when a data type is not defined.

 

left side of asn-op not an lvalue

Scenario:

uint64_t test_var = 0;
test_var = 1;

Cause:

Looking at the uint64_t definition in stdint.h reveals the problem:

typedef uint32_t uint64_t[2];

uint64_t is defined as an array of two uint32_t elements so test_var in the example should be used as an array: test_var[0] and test_var[1]

 

syntax error near 'data type', expected '__asm'

Solution: all variables must be defined before any other code.


syntax error near '=', expected '<id>'

Scenario:

uint16_t data = 0;

Solution: i believe data is a reserved keyword. Replacing the variable name with data_x solves the issue. The message 'data is a reserved keyword' should have been used. 

 

Keil no error issues

There are times when you might want the compiler to raise an error message or a warning but it doesn't.

Case #1

 
uint32_t data_x = 0;
data_x = (1 << 31);

This will not make the MSB a one. The 1 should be typecast  (uint32_t)1 << 32. 

 

Simplicity Studio Shortcuts

Here is a list of tips & tricks that can help improve productivity in Simplicity Studio.

  1. Delete a line: CTRL + D
  2. Duplicate a line: CTRL + ALT + DOWN 
  3. Highlight all occurrences of a variable: double click it
  4. Go to last edited line: CTRL + Q
  5. Switch between .h and .c files: CTRL + TAB
  6. Next annotation: CTRL + .
  7. Previous annotation: CTRL + ,
  8. Navigate to previous line history: ALT + LEFT and ALT + RIGHT
  9. Go to where is declared or defined: place cursor on a variable or function name then F3.
  10. Comment/Uncomment: toggle comment selected line(s) using CTRL + /
  11. Block Comment/Uncomment using: toggle comment selected line(s) using CTRL + SHIFT + /
  12. Zoom Out text: CTRL + -
  13. Zoom In text: CTRL + SHIFT + +
  14. Renaming: SHIFT + ALT + R. Sometimes doesn't rename all occurrences. In that case undo, and try again. Saving all files first, might help.
  15. Quick Utility: not sure how it's called but by pressing ALT + SPACE you can invoke some plugins. For example starting the expression with = you can do math.
  16. Content Assist: CTRL + SPACE. Autocompletes or offers a list of suggestions while typing. So if you don't know the name of a function or variable but you remember first characters this can help finding it faster. 
  17. Correct Indentation: CTRL + I
 

    Simplicity Studio 5 Tutorial

    Adding a product (device)

    Press on the Welcome or Launcher button then in My Products section use the + button to add a new product.

    Simplicity Studio v5 - Add Product 01

    On the next window you can search for Kits, Boards and Parts. In this example I use the C8051F330 microcontroller so I have added it in the right side.

    Simplicity Studio v5 - Add Product 02

    At the end, by selecting the added product you can find in the right side, code examples, documentation and compatible tools. Configuration wizard under the compatible tools is worth checking out.

    Creating a new project

    Under File  New select Silicon Labs Project Wizard

    Simplicity Studio v5 - New Project 01

    Next you can search for a board or if you are using a custom board search for target device - the microcontroller. In my case the device is C8051F330. The SDK and Toolchain should also be installed and selected.

    Simplicity Studio v5 - New Project 02

    In the next step you can use an example project or create an empty C project. The Configurator Project can be used to generate code using a graphical interface but is not available for all microcontrollers. Trying to create a configurator project for C8051F330 will result in an error. I did use it with EFM8 and worked very well.

    Simplicity Studio v5 - New Project 03

    Finally chose the project name and location. I recommend changing only the project name and leaving the rest as defaults.

    Simplicity Studio v5 - New Project 04

    Adding Keyboard Shortcuts - Key Binding in Simplicity Studio v5

    In this example lets add a keyboard shortcut for building the selected project. This can be done in Windows  Preferences  General  Keys.

    Adding Shortcuts - Key Binding in Simplicity Studio v5

    First search for the desired command, for example 'build' then select 'Build Project' from the search results. In the Binding input press the key or key combination. If the binding is already used elsewhere, it will appear in the Conflicts box.

    Adding external files in Simplicity Studio

    Linking to external files is useful when you need a library for example and if you update it you don't have to remember to update all files copied in other projects. Including external files can be done in two steps.

    First drag-and-drop the files in the src folder located inside the project folder.

    Simplicity Studio v5 - Adding External Files 00

    Then in the following dialog select 'Link to files'.

    Simplicity Studio v5 - Adding External Files 01

    Last step is to add the include paths in Project Properties  C/C++ Build  Settings  Tool Settings tab  Keil 8051 Compiler  Includes. Here press the + green button then on File system to select the folder where the files included by drag-and-drop are located.

    Simplicity Studio v5 - Adding External Files 02

    In this example I have included the folder containing the uart library files and the folder where utils files are that are included by uart library. 

    Annotations in Simplicity Studio

    An annotation in Simplicity Studio can be a part of many categories such as: bookmarks, breakpoints, info, errors, etc. They can be navigated using the shortcuts CTRL + , and CTRL + . or by using the up and down arrows on the toolbar. They are also highlighted with different colors on the right side bar near the scrollbar. Contrast and colors can be changed by right clicking on the same bar.

    You can enable or disable what is included in annotations category while navigating them. Simply click on the down arrow near any of the annotation buttons on the toolbar to select only what you are interested in.

    Simplicity Studio - Annotations 01

    In case the buttons don't appear, right click on the toolbar and select Restore Hidden Toolbar Entries, then Lock the Toolbars then Unlock the Toolbars. Now the buttons should be visible.

    Simplicity Studio - Annotations 00

    You can add your own annotations such as a bookmark or a task by right clicking on line numbers in the left side bar.

    Simplicity Studio - Annotations 02

    To remove them, right click an annotation and select Remove bookmark or task.


    No comments:

    Post a Comment