Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Device Functions


(warning)

Warning

Microvisor Public Beta

Microvisor is in a pre-release phase and the information contained in this document is subject to change. Some features referenced below may not be fully available until Microvisor's General Availability (GA) release.

Microvisor system calls currently include the following functions for device-oriented operations:


Device information functions

device-information-functions page anchor


Peripheral-register access functions

peripheral-register-access-functions page anchor

Return values and errors

return-values-and-errors page anchor

All of the functions described below return a 32-bit integer that is one of the values from the standard Microvisor enumeration MvStatus. All possible error values for a given system call are provided with each function's description.

Success is always signaled by a return value of zero (MV_STATUS_OKAY).


Get the device's unique SID

Declaration


_10
extern enum MvStatus mvGetDeviceId(uint8_t *buffer,
_10
uint32_t length);

Parameters

ParameterDescription
bufferA pointer to non-secure memory into which the device ID will be written by Microvisor
lengthThe size of the buffer in bytes. Must be 34

Possible errors

Error ValueDescription
MV_STATUS_PARAMETERFAULTbuffer does not reference memory accessible to the application
MV_STATUS_INVALIDBUFFERSIZElength is not the correct size for result, i.e., 34 bytes

Description

Every Microvisor-enabled device has associated with it a unique 34-character identifier called an SID. This is set during the production of the microcontroller containing Microvisor. Use this function to read the SID, which can then be used to identify the device in your interactions with the Microvisor cloud. You may also use it for device identification purposes within your own cloud and mobile apps.

Although the SID is output as Ascii text, it is not a C string. To use the SID characters with C string-manipulation functions, and printf(), ensure your buffer is 35 characters long and terminated with a nul ('\0').

Example


_10
uint8_t buffer[35] = { 0 };
_10
mvGetDeviceId(buffer, 34);
_10
printf("Device ID: %s\n", buffer);


Get the current frequency of the CPU clock

Declaration


_10
extern enum MvStatus mvGetSysClk(uint32_t *frequency);

Parameters

ParameterDescription
frequencyA pointer to non-secure memory into which the frequency will be written by Microvisor

Possible errors

Error ValueDescription
MV_STATUS_PARAMETERFAULTfrequency does not reference memory accessible to the application

Get the current frequency of the microcontroller's Advanced High-performance Bus (AHB)

Declaration


_10
extern enum MvStatus mvGetHClk(uint32_t *frequency);

Parameters

ParameterDescription
frequencyA pointer to non-secure memory into which the frequency will be written by Microvisor

Possible errors

Error ValueDescription
MV_STATUS_PARAMETERFAULTfrequency does not reference memory accessible to the application

Get the current frequency of the microcontroller's Advanced Peripheral Bus (APB1)

Declaration


_10
extern enum MvStatus mvGetPClk1(uint32_t *frequency);

Parameters

ParameterDescription
frequencyA pointer to non-secure memory into which the frequency will be written by Microvisor

Possible errors

Error ValueDescription
MV_STATUS_PARAMETERFAULTfrequency does not reference memory accessible to the application

Get the current frequency of the microcontroller's Advanced Peripheral Bus (APB2)

Declaration


_10
extern enum MvStatus mvGetPClk2(uint32_t *frequency);

Parameters

ParameterDescription
frequencyA pointer to non-secure memory into which the frequency will be written by Microvisor

Possible errors

Error ValueDescription
MV_STATUS_PARAMETERFAULTfrequency does not reference memory accessible to the application

Register access functions

Microvisor includes a set of functions which provide application code with access to the contents of host microcontroller peripheral registers that are claimed by Microvisor. An example is reading the Reset and Clock Controller (RCC) configuration: this is needed by the application to determine the underlying clock speeds and so configure a peripheral, but RCC owned by Microvisor so that it can control key clocks.

Non-secure code, i.e., the application, can't directly read or write these registers, at least not in a way that yields unambiguous values. TrustZone ensures writes from non-secure code are always ignored and reads return zero, but does not inform the application that it has done so. Microvisor therefore provides mediated read and write access to these secure registers.

(warning)

Warning

Attempts to access peripheral registers outside of these system calls are trapped by Microvisor, which treats them as illegal accesses and restarts the application. This is done to alert the developer, who can then modify their code to prevent the illegal access.

Microvisor maintains a list of registers that the application is able to access through these system calls. These are provided as non-secure mappings; Microvisor translates the value to a secure mapping. If the call does not provide access to a given register, the call returns an error value.

For each valid register, Microvisor also maintains masks of the bits that are readable and the bits that are writable by the application. Bits the application is not permitted to access are unset in reads and unchanged by writes.

(information)

Info

These system calls can be used for any register, including those that the application has non-secure access to. If the supplied address references a register that is implicitly accessible to the application, then Microvisor makes the access directly on the non-secure mapping. This is as if the application made the access itself. A consequence of this is that you can use these calls in your cade consistently across all register access operations.


Read the contents of a device peripheral register

Declaration


_10
extern enum MvStatus mvPeriphPeek32(uint32_t *register,
_10
uint32_t *register_value;

Parameters

ParameterDescription
registerThe non-secure address of the register being accessed
register_valueA pointer to non-secure memory into which the register's contents will be written by Microvisor

Possible errors

Error ValueDescription
MV_STATUS_PERIPHERALACCESSFAULTregister addresses an unsupported register, or is not word-aligned
MV_STATUS_PARAMETERFAULTregister_value does not reference memory accessible to the application

Description

This call reads the contents of one of the microcontroller's peripheral registers and writes the result to non-secure memory.

Example


_10
int64_t readRegisterOrNegOnError(uint32_t reg) {
_10
uint32_t tmp = 0;
_10
extern enum MvStatus status = mvPeriphPeek32(reg, &tmp);
_10
return (status == MV_STATUS_OKAY ? (int64_t)tmp : -1);
_10
}


Write data to a device peripheral register

Declaration


_10
extern enum MvStatus mvPeriphPoke32(uint32_t *register,
_10
uint32_t mask,
_10
uint32_t xor_value);

Parameters

ParameterDescription
regThe non-secure address of the register being accessed
maskA mask to indicate the the bits that will be affected by the write
xor_valueA value to Exclusive OR with the register's current contents

Possible errors

Error ValueDescription
MV_STATUS_PERIPHERALCCESSFAULTregister addresses an unsupported register, or is not word-aligned

Description

Use this function to update the value held by a microcontroller peripheral register. The call can be used for a variety of different operations, from writing specific values to the register, to performing bit-level changes. The function applies the following logic to the value of the chosen register:


_10
*register = (*register & ~mask) ^ xor_value

and with appropriate mask and XOR values, these operations are possible:

OperationMask ValueXOR value
Clear bitsBits to clear0x00000000
Set bitsBits to setBits to set
Toggle bits0x00000000Bits to toggle
Change the whole register0xFFFFFFFFNew value

Rate this page: