Flasher/PCode API Documentation

From SEGGER Wiki
Jump to: navigation, search


List of PCode API Functions

Return Type Name Type
int CPU_GetUnlockKey(U8* pBuf, U32 BufSize, const char* sMsg) DLL Import
int FILE_Read(const U8* pFilename, U8* pBuf, U32 Offset, U32 Length, U32* pCRC) DLL Import
void I2C_DeInit(void)
int I2C_Init(U32 u32I2CSpeed, U8 u8Address, U32 u32PageSize)
int I2C_TransferBytes(U8 Address, U8* pu8DataOut, U32 u32DataOutLength, U8* pu8DataIn, U32 u32DataInLength)
int I2C_WaitDeviceReady(U8 u8Address, U32 u32TimeoutMs)
int JLINK_AURIX_DAP_ReceiveBlocks(U8 Mode, U32* pDataUp, U32 NumBlocks) Predefined DLL import
int JLINK_AURIX_DAP_ReceiveTelegram(U8 Mode, U8* pDataUp, U32 NumBitsUp) Predefined DLL import
int JLINK_AURIX_DAP_SendBlocks(U8 Mode, const U32* pDataDown, U32 NumBlocks) Predefined DLL import
int JLINK_AURIX_DAP_SendTelegram(U8 Mode, U8 Command, const U8* pDataDown, U32 NumBitsDown) Predefined DLL import
void JLINK_AURIX_DAP_Sync(U8 NumClocks) Predefined DLL import
int JLINK_C2_ReadAddr(U32* pAddr)
int JLINK_C2_ReadData(U8* pData, int NumItems)
int JLINK_C2_WriteAddr(U32 Addr)
int JLINK_C2_WriteData(const U8* pData, int NumItems)
void JLINK_Delay_us(U32 Delay)
int JLINK_ExecCommand(const char* sMsg)
int JLINK_GetConfigData(const char* sKey, char* pDest, U32 MaxSize)
int JLINK_GetConfigValue(const char* sKey, U32* pValue)
int JLINK_GetPinState(U8 iPin)
int JLINK_GetTime(void)
int JLINK_HWUART_Init(int BaudrateHz, U32 Mode)
int JLINK_JTAG_GetU32(int BitPos)
int JLINK_JTAG_GetU32Rev(int BitPos)
int JLINK_JTAG_ReadWriteBits(const U8* pTDI, U8* pTMS, U8* pTDO, U32 NumBits)
int JLINK_JTAG_Reset(void)
void JLINK_JTAG_SetupChain(int IRPre, int DRPre, int IRPost, int DRPost, int IRLenDevice)
int JLINK_JTAG_StartDR(void)
int JLINK_JTAG_Store(U32 tms, U32 tdi, U32 NumBits)
int JLINK_JTAG_StoreClocks(int NumClocks)
int JLINK_JTAG_StoreDR(U32 Data, int NumBits)
int JLINK_JTAG_StoreDRRev(U32 Data, int NumBits)
int JLINK_JTAG_StoreIR(U32 Cmd)
int JLINK_JTAG_Write(U32 tms, U32 tdi, U32 NumBits)
int JLINK_JTAG_WriteClocks(int NumClocks)
int JLINK_JTAG_WriteDR(U32 Data, int NumBits)
int JLINK_JTAG_WriteDRCont(U32 Data, int NumBits)
int JLINK_JTAG_WriteDREnd(U32 Data, int NumBits)
int JLINK_JTAG_WriteDRRev(U32 Data, int NumBits)
int JLINK_JTAG_WriteIR(U32 Imm)
void JLINK_PDI_DeInit(void) DLL Import
int JLINK_PDI_ReadBits(U8* pDataIn, int NumBits)
int JLINK_PDI_WriteBits(const U8* pDataOut, int NumBits)
int JLINK_PIN_Override(const U32* paMode, U32* paState)
void JLINK_SelectTIF(U32 tif)
void JLINK_SPI_Read(U8* pDataIn, int NumBytes, U32 Flags)
int JLINK_SPI_ReadWrite(const U8* pDataOut, U8* pDataIn, U32 NumBytes, U32 Flags)
void JLINK_SPI_Write(const U8* pDataOut, int NumBytes, U32 Flags)
void JLINK_Strobe(U8 Pin, U32 Frequency, U32 NumClocks)
int JLINK_SWD_ReadWriteBits(const U8* pDataIn, const U8* pDirection, U8* pDataOut, int NumBits)
int JLINK_SWIM_Connect(U8 HiSpeed)
void JLINK_SWIM_DeInit(void)
void JLINK_SWIM_DeInitNoStart(void) DLL Import
void JLINK_SWIM_Init(void)
int JLINK_SWIM_ReadMem(U32 Addr, U8* Data, U8 NumBytes)
void JLINK_SWIM_SysReset(void)
int JLINK_SWIM_WriteMem(U32 Addr, const U8* Data, U8 NumBytes)
U32 JLINK_SYS_GetVar(U32 IndexVar)
int JLINK_SYS_memcmp(const U8* pData1, const U8* pData2, int NumBytes)
int JLINK_SYS_Report(const char* sMsg)
int JLINK_SYS_Report1(const char* sMsg, int v)
int JLINK_SYS_SetVar(U32 IndexVar, U32 v)
int JLINK_SYS_Sleep(int Delayms)
void JLINK_TIF_ActivateTargetReset(void)
int JLINK_TIF_ReInit(void)
void JLINK_TIF_ReleaseTargetReset(void)
void JLINK_TIF_SetClrTCK(int OnOff)
void JLINK_TIF_SetClrTDI(int OnOff)
void JLINK_TIF_SetClrTMS(int OnOff)
void JLINK_TIF_SetSpeed(U32 Speed)
int JLINK_UART_DeInit(void)
int JLINK_UART_Init(int BaudrateHz)
int JLINK_UART_Read(U8* pData, U32 NumBytes)
int JLINK_UART_Write(const U8* pData, U32 NumBytes)
void JLINK_WriteBitOff(U8* p, U32 BitOff, U32 v, U32 NumBits)
int M16C_DeInit(void) DLL Import
int M16C_Init(U32 Speed) DLL Import
int M16C_ReadWrite(U8* pDataOut, U8* pDataIn, U32 NumBytes) DLL Import
int SPI2FE_DeInit(void) DLL Import
int SPI2FE_Init(U32 Speed) DLL Import
int SPI2FE_ReadBits(U8* pDataIn, U32 NumBits)
int SPI2FE_ReadBits_RisingEdge(U8* pDataIn, U32 NumBits) DLL Import
int SPI2FE_WriteBits(const U8* pDataOut, U32 NumBits)
int SPI2FE_WriteBits_RisingEdge(U8* pDataOut, U32 NumBits) DLL Import
int SPI_IdleClockLow_DeInit(void) DLL Import
int SPI_IdleClockLow_Init(U32 Speed) DLL Import
int SPI_IdleClockLow_ReadWrite(U8* pDataOut, U32 NumberBytesToWrite, U8* pDataIn, U32 NumberBytesToRead) DLL Import
U32 UTIL_ReverseBits(U32 Data, U32 NumBits) DLL Import
void UTIL_ReverseBytes(U8* pData, U32 NumBytes) DLL Import

API Functions

CPU_GetUnlockKey()

Prototype

__imp int CPU_GetUnlockKey(U8* pBuf, U32 BufSize, const char* sMsg);

Function description

Stores the unlock key for the debug interface of the connected target device in pBuf. This key may either come from a dialog we show now (PC software) or from a file (Key.txt) the user placed beside the config (Flasher stand-alone).

Parameters

Parameter Description
pBuf A pointer to a buffer the key should be stored in. The maximum length of the key is 32 bytes.
BufSize The size of the provided buffer.
sMsg Message for potential dialog being shown in case there is no key that has been preset by the user. This parameter is not used with Flashers.

Return value

Return value Description
== 0 O.K.
== -1 Error. The size of the buffer is too small.

FILE_Read()

Prototype

__imp int FILE_Read(const U8* pFilename, U8* pBuf, U32 Offset, U32 Length, U32* pCRC);

Function description

Reads a file stored on the Flasher.

Parameters

Parameter Description
pFilename A string with the name of the file to open.
pBuf A pointer to a buffer the file should be stored in.
Offset The position within the file to start reading at.
Length The number of bytes to read.
pCRC A pointer to a U32 variable which can be used to pass a start value or the result of a previous CRC calculation. After CRC calculation the variable pCRC is pointing to contains the result of the calculation. If NULL is passed, no CRC calculation is performed.

Return value

Returns the number of bytes that were read.

I2C_DeInit()

Prototype

void I2C_DeInit(void);

Function description

Deinitializes the I2C interface.

I2C_Init()

Prototype

int I2C_Init(U32 u32I2CSpeed, U8 u8Address, U32 u32PageSize);

Function description

Initializes the I2C interface. Using TCK as SCL (serial clock) and TMS as SDA (serial bidirectional data line).

Parameters

Parameter Description
Speed The I2C frequency in hertz to be used.
u8Address Reserved.
u32PageSize Reserved.

Return value

Return value Description
== 0 O.K.
== 1 Error.

Additional information

This function has to be called after selecting the target interface via JLINK_SelectTIF().

I2C_TransferBytes()

Prototype

int I2C_TransferBytes(U8 Address, U8* pu8DataOut, U32 u32DataOutLength, U8* pu8DataIn, U32 u32DataInLength);

Function description

Transfers data between the two devices via I2C. Writes the data from the output buffer and then reads the data which is stored in the input buffer. Data is only written or read if the length of the according buffer is greater than 0. Before data is written from the buffer or read and stored in the input buffer, a start condition is signalled followed by the address. Then the specified amount of data is written or read, followed by a stop condition.

Parameters

Parameter Description
Address Target address within bits [7:1]. LSB (R/W bit) is ignored and set automatically.
pu8DataOut Address of the buffer containing data to write.
u32DataOutLength Number of bytes to write.
pu8DataIn Address of the buffer used for read data.
u32DataInLength Number of bytes to read.

Return value

Return value Description
== 0 O.K.
== 1 Error.

I2C_WaitDeviceReady()

Prototype

int I2C_WaitDeviceReady(U8 u8Address, U32 u32TimeoutMs);

Function description

Waits until the device is ready again after a started programming action.

Parameters

Parameter Description
u8Address Target address.
u32TimeoutMs Timeout in milliseconds.

JLINK_AURIX_DAP_ReceiveBlocks()

Prototype

int JLINK_AURIX_DAP_ReceiveBlocks(U8 Mode, U32* pDataUp, U32 NumBlocks);

Function description

Receives 32-bit data blocks after a sent block read telegram.

Parameters

Parameter Description
Mode Mode[0] == 0: Send data in normal mode.
Mode[0] == 1: Send data in wide mode.
Mode[1] == 0: No individual CRCs for the blocks.
Mode[1] == 1: CRC for each block.
pDataUp Pointer to a buffer the read data blocks should be stored in.
NumBlocks The number of 32-bit blocks to receive.

Return value

Return value Description
== 0 O.K.
== -1 Error. No reply telegram received.
== -2 CRC error.

JLINK_AURIX_DAP_ReceiveTelegram()

Prototype

int JLINK_AURIX_DAP_ReceiveTelegram(U8 Mode, U8* pDataUp, U32 NumBitsUp);

Function description

Receives a DAP reply telegram and stores the specified number of data bits in the provided buffer.

Parameters

Parameter Description
Mode Mode[0] == 0: Send data in normal mode.
Mode[0] == 1: Send data in wide mode.
Mode[1] == 0: Stores all data bits in the provided buffer.
Mode[1] == 1: Stores only even data bits in the provided buffer.
pDataUp Pointer to a buffer the read data should be stored in.
NumBitsUp The number of data bits to extract from the received telegram.

Return value

Return value Description
== 0 O.K.
== -1 Error. No reply telegram received.
== -2 CRC error.

JLINK_AURIX_DAP_SendBlocks()

Prototype

int JLINK_AURIX_DAP_SendBlocks(U8 Mode, const U32* pDataDown, U32 NumBlocks);

Function description

Sends the specified amount of 32-bit blocks, also called parcels, after sending a block write command.

Parameters

Parameter Description
Mode Mode[0] == 0: Send data in normal mode.
Mode[0] == 1: Send data in wide mode.
Mode[1] == 0: No individual CRCs for the blocks.
Mode[1] == 1: CRC for each block.
pDataDown Pointer to a buffer with 32-bit blocks to send.
NumBlocks The number of 32-bit blocks to send.

Return value

Return value Description
== 0 O.K.
== -1 Error.

JLINK_AURIX_DAP_SendTelegram()

Prototype

int JLINK_AURIX_DAP_SendTelegram(U8 Mode, U8 Command, const U8* pDataDown, U32 NumBitsDown);

Function description

Sends a DAP telegram with the specified command and provided data using the specified mode. The telegram is automatically assembled using the provided data and an automatically calculated CRC.

Parameters

Parameter Description
Mode 0: Send data in normal mode.
1: Send data in wide mode.
Command The 5-bit DAP telegram command.
pDataDown Optional data, depending on the command.
NumBitsDown The number of bits of the optional data.

Return value

Always returns 0.

JLINK_AURIX_DAP_Sync()

Prototype

void JLINK_AURIX_DAP_Sync(U8 NumClocks);

Function description

Synchronizes DAP protocol by sending the specified number of clocks.

Parameters

Parameter Description
NumClocks The number of clocks to be sent.

JLINK_C2_ReadAddr()

Prototype

int JLINK_C2_ReadAddr(U32* pAddr);

Function description

Reads the address register of the SiLabs C2 interface.

Parameters

Parameter Description
pAddr Pointer to an U32 variable the read address should be stored in.

Return value

Always returns 0.

JLINK_C2_ReadData()

Prototype

int JLINK_C2_ReadData(U8* pData, int NumItems);

Function description

Reads the specified amount of data via the data register of the SiLabs C2 interface.

Parameters

Parameter Description
pData Pointer to a buffer the read data should be stored in. The buffer has to have enough space for NumItems * sizeof(U8) bytes.
NumItems The number of U8 items to read.

Return value

Always returns 0.

JLINK_C2_WriteAddr()

Prototype

int JLINK_C2_WriteAddr(U32 Addr);

Function description

Writes the address register of the SiLabs C2 interface.

Parameters

Parameter Description
Addr The value to be written into the address register of the C2 interface.

Return value

Always returns 0.

JLINK_C2_WriteData()

Prototype

int JLINK_C2_WriteData(const U8* pData, int NumItems);

Function description

Writes the specified amount of data via the data register of the SiLabs C2 interface.

Parameters

Parameter Description
pData Pointer to a buffer with data to be written.
NumItems The number of U8 items to write.

Return value

Always returns 0.

JLINK_Delay_us()

Prototype

void JLINK_Delay_us(U32 Delay);

Function description

Waits a given period before resuming the PCode's execution.

Parameters

Parameter Description
Delay The period to delay execution in microseconds.

JLINK_ExecCommand()

Prototype

int JLINK_ExecCommand(const char* sMsg);

Function description

Passes a command to the Flasher which is then executed.

Parameters

Parameter Description
sMsg Command string. See below table with available command strings.

Command strings

Following commands are supported:

Command Description
SupplyPower = <dec> Enables (dec == 1) or disables (dec == 0) 5V target power supply.
VTrefTmp = <dec> Sets VTRef's power good voltage threshold to a temporary value specified in millivolt. Allowed range: 1200mV <= dec <= 5000mV

Return value

Return value Description
>= 0 O.K.
< 0 Error.

Example

JLINK_ExecCommand("SupplyPower = 1");

JLINK_GetConfigData()

Prototype

int JLINK_GetConfigData(const char* sKey, char* pDest, U32 MaxSize);

Function description

Reads a setting stored as a string from the flasher configuration file.

Parameters

Parameter Description
sKey Specifies the section and the name of the setting to read from the configuration file with the format [/<section>/]<name>, e.g. "/CONFIG/DeviceName". If the section is omitted and only the name of the setting is provided, e.g. "DeviceName", the CONFIG section will be used.
pDest Pointer to a string buffer in which the setting read from the configuration file will be stored.
MaxSize The full size of the provided buffer. Should be one character larger than the string to read.

Return value

Return value Description
== 0 O.K.
== -1 Error.
== -2 Error. Buffer too small.

Additional information

Case sensitivity is ignored when comparing the name of the setting (i.e. the key) passed to the function with the ones in the configuration file.

JLINK_GetConfigValue()

Prototype

int JLINK_GetConfigValue(const char* sKey, U32* pValue);

Function description

Reads a setting stored as an integer from the flasher configuration file.

Parameters

Parameter Description
sKey Specifies the section and the name of the setting to read from the configuration file with the format [/<section>/]<name>, e.g. "/CONFIG/DeviceName". If the section is omitted and only the name of the setting is provided, e.g. "DeviceName", the CONFIG section will be used.
pValue The address of an U32 variable where the setting's value read from the configuration file shall be stored.

Return value

Return value Description
== 0 O.K.
== -1 Error.

JLINK_GetPinState()

Prototype

int JLINK_GetPinState(U8 iPin);

Function description

Gets the state of a specific pin.

Parameters

Parameter Description
iPin Specifies the pin to get the state from

Parameter iPin

Value Description
0 Pin 3
1 Pin 5
2 Pin 7
3 Pin 9
4 Pin 11
5 Pin 13
6 Pin 15
7 Pin 17

Return value

Return value Description
== 1 Pin state is HIGH
== 0 Pin state is LOW
< 0 Getting state for this pin is not supported by this J-Link

JLINK_GetTime()

Prototype

int JLINK_GetTime(void);

Function description

Returns the time in milliseconds since the Flasher was powered up.

Return value

Time in milliseconds since the Flasher was powered up.

JLINK_HWUART_Init()

Prototype

int JLINK_HWUART_Init(int BaudrateHz, U32 Mode);

Function description

Initializes a UART.

Parameters

Parameter Description
BaudrateHz The baudrate in hertz to be used.
Mode The mode the UART shall be used in. See below table for the mode encoding.

Mode

The following table describes how the mode is encoded in the mode parameter.

Bits Description
Mode[7:0] Duplex mode. (0 == Full duplex, 1 == half-duplex with echo of Tx data on Rx, 2 == half-duplex with no echo of Tx data on Rx)
Mode[15:8] Party enabled. (0 == Parity disabled, 1 == Parity enabled)
Mode[23:16] Parity mode. (0 == Even parity, 1 == Odd parity)
Mode[31:24] Stop bits. (0 == 2 stop bits, 1 == 1 stop bit, 2 == 2 stop bits)

Return value

Always returns 0.

Additional information

This function uses dedicated pins for Tx and Rx and doesn't require #JLINK_PIN_Override() to be called to configure the pins for UART communication.
In full-duplex mode, the TCK pin is used for Tx and the TDI pin is used for Rx.
In half-duplex mode, the TCK pin is used for Tx and Rx.

JLINK_JTAG_GetU32()

Prototype

int JLINK_JTAG_GetU32(int BitPos);

Function description

Gets 32 bits JTAG data from the bit stream output by the DUT (Device under test).

Parameters

Parameter Description
BitPos Specifies the bit position where reading of the U32 data should be started.

Return value

Returns 32 bits of data starting at the bit position specified by BitPos.

Additional information

This function clears the JTAG buffer before data is read.

JLINK_JTAG_GetU32Rev()

Prototype

int JLINK_JTAG_GetU32Rev(int BitPos);

Function description

Retrieves a reversed U32 from the bit stream output by the DUT (Device under test).

Parameters

Parameter Description
BitPos Specifies the bit position where reading of the U32 data should be started.

Return value

Returns 32 bits of bit-reversed data starting at the bit position specified by BitPos.

Additional information

This function clears the JTAG buffer before data is read.

JLINK_JTAG_ReadWriteBits()

Prototype

int JLINK_JTAG_ReadWriteBits(const U8* pTDI, U8* pTMS, U8* pTDO, U32 NumBits);

Function description

Stores the provided data in the JTAG buffer and sends all data contained in the buffer. The received data will be stored in the provided TDO buffer.

Parameters

Parameter Description
pTDI Pointer to a buffer with data to be written on TDI.
pTMS Pointer to a buffer with data to be written on TMS.
pTDO Pointer to a buffer the data read via TDO will be stored in.
NumBits Number of bits to transfer.

Return value

Return value Description
== 0 O.K.
!= 0 Error.

JLINK_JTAG_Reset()

Prototype

int JLINK_JTAG_Reset(void);

Function description

Resets the TAP controller's state machine and puts the TAP into Run-Test/Idle state by issuing 5 clock cycles while TMS is held HIGH followed by one clock cycle while TMS is LOW.

Return value

Always returns 0.

JLINK_JTAG_SetupChain()

Prototype

void JLINK_JTAG_SetupChain(int IRPre, int DRPre, int IRPost, int DRPost, int IRLenDevice);

Function description

Setups the JTAG chain, meaning it specifies all important parameters, so the Flasher knows which device to talk to, how many dummy bits are necessary and how long the IRLen, of the device we shall talk to, is.

Parameters

Parameter Description
IRPre Number of IR (instruction register) bits before DUT (Device under Test).
DRPre Number of DR (data register) bits before DUT (Device under Test).
IRPost Number of IR (instruction register) bits after DUT (Device under Test).
DRPost Number of DR (data register) bits after DUT (Device under Test).
IRLenDevice IR (instruction register) length of the DUT (Device under Test).

Return value

Always returns 0.

JLINK_JTAG_StartDR()

Prototype

int JLINK_JTAG_StartDR(void);

Function description

Brings the state machine of the selected device in the JTAG-chain in SHIFT-DR state.

Return value

Return value Description
>= 0 Bit position in JTAG buffer.

Additional information

Requires the TAP controller to be in Run-Test/Idle state.

Data is stored in the JTAG buffer but not written. This behavior differs from JLINK_JTAG_StartDR() executed by the J-Link DLL, because the J-Link DLL immediately writes the data contained in the JTAG buffer after it was stored there.

After calling this function, JLINK_JTAG_WriteDRCont() and JLINK_JTAG_WriteDREnd() can be used to write data on TDI. JLINK_JTAG_WriteDREnd() has to be the last function call which puts the TAP controller into UPDATE-DR state.

JLINK_JTAG_Store()

Prototype

int JLINK_JTAG_Store(U32 tms, U32 tdi, U32 NumBits);

Function description

Stores the provided data in the JTAG buffer.

Parameters

Parameter Description
tms Bitmask to output on TMS.
tdi Bitmask to output on TDI.
NumBits NumBits to store for each pin. Maximum 32 bits.

Return value

Always returns 0.

JLINK_JTAG_StoreClocks()

Prototype

int JLINK_JTAG_StoreClocks(int NumClocks);

Function description

Stores a given number of clock cycles in the JTAG buffer with TMS being held LOW.

Parameters

Parameter Description
NumClocks The number of clock cycles to be stored in the buffer.

Return value

Always returns 0.

JLINK_JTAG_StoreDR()

Prototype

int JLINK_JTAG_StoreDR(U32 Data, int NumBits);

Function description

Stores data of variable length in the JTAG buffer and remains in UPDATE-DR state.

Parameters

Parameter Description
Data Bitmask to output on TDI.
NumBits Number of bits to store.

Return value

Returns the bit position the data was appended to in the JTAG buffer.

Additional information

Requires the TAP controller to be in Run-Test/Idle state.

This function expects that the JTAG chain has already been configured before.

JLINK_JTAG_StoreDRRev()

Prototype

int JLINK_JTAG_StoreDRRev(U32 Data, int NumBits);

Function description

Stores data of variable length in reversed bit order in the JTAG buffer and remains in UPDATE-DR state.

Parameters

Parameter Description
Data Bitmask to output on TDI.
NumBits Number of bits to store.

Return value

Returns the bit position the data was appended to in the JTAG buffer.

Additional information

Requires the TAP controller to be in Run-Test/Idle state.

This function expects that the JTAG chain has already been configured before.

JLINK_JTAG_StoreIR()

Prototype

int JLINK_JTAG_StoreIR(U32 Cmd);

Function description

Stores a JTAG instruction in the JTAG buffer and remains in UPDATE-IR state.

Parameters

Parameter Description
Cmd The instruction to be stored in the JTAG buffer.

Return value

Returns the bit position the data was appended to in the JTAG buffer.

Additional information

Requires the TAP controller to be in Run-Test/Idle state.

This function expects that the JTAG chain has already been configured before.

JLINK_JTAG_Write()

Prototype

int JLINK_JTAG_Write(U32 tms, U32 tdi, U32 NumBits);

Function description

Stores the provided data in the JTAG buffer and sends all data contained in the buffer.

Parameters

Parameter Description
tms Bitmask to output on TMS.
tdi Bitmask to output on TDI.
NumBits NumBits to store for each pin. Maximum 32 bits.

Return value

Always returns 0.

JLINK_JTAG_WriteClocks()

Prototype

int JLINK_JTAG_WriteClocks(int NumClocks);

Function description

Stores a given number of clock cycles in the JTAG buffer with TMS being held LOW and writes all data contained in the buffer.

Parameters

Parameter Description
NumClocks Number of clock cycles to write.

Return value

Always returns 0.

JLINK_JTAG_WriteDR()

Prototype

int JLINK_JTAG_WriteDR(U32 Data, int NumBits);

Function description

Stores the data of variable length in the JTAG buffer and writes all data contained in the buffer. Remains in the UPDATE-DR state.

Parameters

Parameter Description
Data Bitmask to output on TDI.
NumBits Number of bits to store.

Return value

Returns the bit position the data was appended to in the JTAG buffer.

Additional information

Requires the TAP controller to be in Run-Test/Idle state.

JLINK_JTAG_WriteDRCont()

Prototype

int JLINK_JTAG_WriteDRCont(U32 Data, int NumBits);

Function description

Stores the data of variable length in the JTAG buffer and writes all data contained in the buffer. Remains in the SHIFT-DR state.

Parameters

Parameter Description
Data Bitmask to output on TDI.
NumBits Number of bits to store.

Return value

Returns the bit position the data was appended to in the JTAG buffer.

Additional information

Requires the TAP controller to be in the SHIFT-DR state which is achieved by calling JLINK_JTAG_StartDR(). Thus, JLINK_JTAG_WriteDRCont() can be called multiple times to write data. The last data has to be written by calling JLINK_JTAG_WriteDREnd() in order to bring the TAP controller into UPDATE-DR state.

JLINK_JTAG_WriteDREnd()

Prototype

int JLINK_JTAG_WriteDREnd(U32 Data, int NumBits);

Function description

Stores the data of variable length in the JTAG buffer and writes all data contained in the buffer. Remains in the UPDATE-DR state.

Parameters

Parameter Description
Data Bitmask to output on TDI.
NumBits Number of bits to store.

Return value

Returns the bit position the data was appended to in the JTAG buffer.

Additional information

Requires the TAP controller to be in the SHIFT-DR state which is achieved by calling JLINK_JTAG_StartDR().

JLINK_JTAG_WriteDRRev()

Prototype

int JLINK_JTAG_WriteDRRev(U32 Data, int NumBits);

Function description

Stores the data of variable length in the JTAG buffer and writes all data contained in the buffer. Remains in the UPDATE-DR state.

Parameters

Parameter Description
Data Bitmask to output on TDI.
NumBits Number of bits to store.

Return value

Returns the bit position the data was appended to in the JTAG buffer.

Additional information

Requires the TAP controller to be in Run-Test/Idle state.

JLINK_JTAG_WriteIR()

Prototype

int JLINK_JTAG_WriteIR(U32 Cmd);

Function description

Stores the JTAG instruction in the JTAG buffer and writes all data contained in the buffer. Remains in the UPDATE-IR state.

Parameters

Parameter Description
Cmd The JTAG instruction to write.

Return value

Returns the bit position the instruction was appended to in the JTAG buffer.

JLINK_PDI_DeInit()

Prototype

void JLINK_PDI_DeInit(void);

Function description

Stops the program execution on the S8 core by asserting the reset signal and deactivates pins.

JLINK_PDI_ReadBits()

Prototype

int JLINK_PDI_ReadBits(U8* pDataIn, int NumBits);

Function description

Reads PDI data.

Parameters

Parameter Description
pDataIn Buffer to store read data.
NumBits Number of bits to read. This function only reads full bytes and ignores remaining bits.

Return value

Return value Description
>= 0 Number of read bytes.
== -1 Error.

JLINK_PDI_WriteBits()

Prototype

int JLINK_PDI_WriteBits(const U8* pDataOut, int NumBits);

Function description

Writes PDI data.

Parameters

Parameter Description
pDataOut Buffer to store read data.
NumBits Number of bits to write. This function only writes full bytes and ignores remaining bits.

Return value

Return value Description
== 0 O.K.
== -1 Error.

JLINK_PIN_Override()

Prototype

int JLINK_PIN_Override(const U32* paMode, U32* paState);

Function description

This function allows to override some of the J-Link pins and to assign a special functionality to them (GPIO, UART, ...). For example setting the functionality to GPIO allows to implement almost any protocol on these pins which can give some extra flexibility in some cases.

Parameters

Parameter Description
paMode Pointer to an array with JLINK_PIN_MAX_NUM_PINS U32 elements that holds the configuration to be assigned to the pins.
Each element of the array describes a pin that can be overridden. See Pin Mapping for the assignment of array indices to pins.
paState Optional pointer to an array with JLINK_PIN_MAX_NUM_PINS U32 elements that is used to store the state of each pin. This for example can be used to read the current data on the pin, if it is configured as JLINK_PIN_OVERRIDE_MODE_PIO_IN.
State may be == 0 for LOW or == 1 for HIGH.

Pin Mapping

Array element Description Additional information
0 Pin 3 UART RX/TX
1 Pin 5 UART RX/TX
2 Pin 7 UART RX/TX
3 Pin 9 UART RX/TX
4 Pin 11 UART RX/TX
5 Pin 13 UART RX
Only available as input.
6 Pin 15 UART RX/TX
7 Pin 17 UART RX/TX

Pin Modes

Value Description
JLINK_PIN_OVERRIDE_MODE_RELEASE Releases the override on this pin. It returns to its original functionality.
JLINK_PIN_OVERRIDE_MODE_PIO_IN Configures the pin as GPIO input.
JLINK_PIN_OVERRIDE_MODE_PIO_OUT_LOW Configures the pin as GPIO output state LOW.
JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH Configures the pin as GPIO output state HIGH.
JLINK_PIN_OVERRIDE_MODE_UART_TX Configures the pin as UART Tx pin.
JLINK_PIN_OVERRIDE_MODE_UART_RX Configures the pin as UART rx pin.
JLINK_PIN_OVERRIDE_MODE_UART_RXTX Configures pin for half-duplex UART functionality which means this pin in Tx and Rx. Cannot be used together with other UART defines.
0xFF Ignores the pin.

Return value

Always returns 0.

Example

U32 _aPINMode[JLINK_PIN_MAX_NUM_PINS];  // Array is intialized with zeroes == JLINK_PIN_OVERRIDE_MODE_RELEASE
U32 _aPINState[JLINK_PIN_MAX_NUM_PINS];
void PinOverrideExample(void) {
  //
  // Try setting all pins to HIGH
  //
  _aPINMode[0] = JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH;
  _aPINMode[1] = JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH;
  _aPINMode[2] = JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH;
  _aPINMode[3] = JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH;
  _aPINMode[4] = JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH;
  _aPINMode[5] = JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH;
  _aPINMode[6] = JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH;
  _aPINMode[7] = JLINK_PIN_OVERRIDE_MODE_PIO_OUT_HIGH;
  JLINK_PIN_Override(&_aPINMode[0], &_aPINState[0]);
  //
  // Print all pin states
  //
  JLINK_SYS_Report1("_aPINState[0] => ", _aPINState[0]);
  JLINK_SYS_Report1("_aPINState[1] => ", _aPINState[1]);
  JLINK_SYS_Report1("_aPINState[2] => ", _aPINState[2]);
  JLINK_SYS_Report1("_aPINState[3] => ", _aPINState[3]);
  JLINK_SYS_Report1("_aPINState[4] => ", _aPINState[4]);
  JLINK_SYS_Report1("_aPINState[5] => ", _aPINState[5]);
  JLINK_SYS_Report1("_aPINState[6] => ", _aPINState[6]);
  JLINK_SYS_Report1("_aPINState[7] => ", _aPINState[7]);
  //
  // Restore pin configuration
  //
  _aPINMode[0] = JLINK_PIN_OVERRIDE_MODE_RELEASE;
  _aPINMode[1] = JLINK_PIN_OVERRIDE_MODE_RELEASE;
  _aPINMode[2] = JLINK_PIN_OVERRIDE_MODE_RELEASE;
  _aPINMode[3] = JLINK_PIN_OVERRIDE_MODE_RELEASE;
  _aPINMode[4] = JLINK_PIN_OVERRIDE_MODE_RELEASE;
  _aPINMode[5] = JLINK_PIN_OVERRIDE_MODE_RELEASE;
  _aPINMode[6] = JLINK_PIN_OVERRIDE_MODE_RELEASE;
  _aPINMode[7] = JLINK_PIN_OVERRIDE_MODE_RELEASE;
  JLINK_PIN_Override(&_aPINMode[0], 0);
}

JLINK_SelectTIF()

Prototype

void JLINK_SelectTIF(U32 tif);

Function description

Selects the interface to be used for target communication.

Parameters

Parameter Description
tif The target interface to select. Available target interfaces are:

JLINK_TIF_JTAG (0)
JLINK_TIF_SWD (1)
JLINK_TIF_FINE (3)
JLINK_TIF_ICSP (4)
JLINK_TIF_SPI (5)
JLINK_TIF_C2 (6)
JLINK_TIF_CJTAG (7)
JLINK_TIF_SWIM (8)
JLINK_TIF_PDI (9)
JLINK_TIF_SPI_IDLE_CLOCK_LOW (11)
JLINK_TIF_SPI2FE (13)
JLINK_TIF_QSPI (14)
JLINK_TIF_DAP (16)

Additional information

This function should be called before any other function that performs target communication.

The target interface speed is initially set to 1MHz.

JLINK_SPI_Read()

Prototype

void JLINK_SPI_Read(U8* pDataIn, int NumBytes, U32 Flags);

Function description

Reads data via SPI.

Parameters

Parameter Description
pDataIn Buffer to store read data.
NumBytes Number of bytes to read.
Flags Used to configure the SPI communication. See table below.

Flags

Field Description Options
Value Description
Flags[1:0] Chip select start state JLINK_SPI_FLAG_CS_START_STATE_U nCS not touched at start of transfer
JLINK_SPI_FLAG_CS_START_STATE_0 nCS == LOW at start of transfer
JLINK_SPI_FLAG_CS_START_STATE_1 nCS == HIGH at start of transfer
Flags[3:2] Chip select end state JLINK_SPI_FLAG_CS_END_STATE_U nCS not touched at end of transfer
JLINK_SPI_FLAG_CS_END_STATE_0 nCS == LOW at end of transfer
JLINK_SPI_FLAG_CS_END_STATE_1 nCS == HIGH at end of transfer
Flags[6:5] Selects the line used for chip select.
Chip select is used only if the start and/or end state is set to HIGH or LOW.

JLINK_SPI_FLAG_CS_INDEX_0: nCS0 (Pin 17)
JLINK_SPI_FLAG_CS_INDEX_1: nCS1 (Pin 7)

Return value

Always returns 0.

Additional information

Chip select must be used only with JLINK_TIF_SPI.

For more information about the technical functionality of this function in combination with the selected target interface, please refer to the additional information for target interfaces.

JLINK_SPI_ReadWrite()

Prototype

int JLINK_SPI_ReadWrite(const U8* pDataOut, U8* pDataIn, U32 NumBytes, U32 Flags);

Function description

Transfers data via SPI.

Parameters

Parameter Description
pDataOut Buffer with data to write.
pDataIn Buffer to store read data.
NumBytes Number of bytes to transfer.
Flags Used to configure the SPI communication. See table below.

Flags

Field Description Options
Value Description
Flags[1:0] Chip select start state JLINK_SPI_FLAG_CS_START_STATE_U nCS not touched at start of transfer
JLINK_SPI_FLAG_CS_START_STATE_0 nCS == LOW at start of transfer
JLINK_SPI_FLAG_CS_START_STATE_1 nCS == HIGH at start of transfer
Flags[3:2] Chip select end state JLINK_SPI_FLAG_CS_END_STATE_U nCS not touched at end of transfer
JLINK_SPI_FLAG_CS_END_STATE_0 nCS == LOW at end of transfer
JLINK_SPI_FLAG_CS_END_STATE_1 nCS == HIGH at end of transfer
Flags[6:5] Selects the line used for chip select.
Chip select is used only if the start and/or end state is set to HIGH or LOW.

JLINK_SPI_FLAG_CS_INDEX_0: nCS0 (Pin 17)
JLINK_SPI_FLAG_CS_INDEX_1: nCS1 (Pin 7)

Return value

Always returns 0.

Additional information

Chip select must be used only with JLINK_TIF_SPI.

For more information about the technical functionality of this function in combination with the selected target interface, please refer to the additional information for target interfaces.

JLINK_SPI_Write()

Prototype

void JLINK_SPI_Write(const U8* pDataOut, int NumBytes, U32 Flags);

Function description

Writes data via SPI.

Parameters

Parameter Description
pDataOut Buffer with data to write.
NumBytes Number of bytes to write.
Flags Used to configure the SPI communication. See table below.

Flags

Field Description Options
Value Description
Flags[1:0] Chip select start state JLINK_SPI_FLAG_CS_START_STATE_U nCS not touched at start of transfer
JLINK_SPI_FLAG_CS_START_STATE_0 nCS == LOW at start of transfer
JLINK_SPI_FLAG_CS_START_STATE_1 nCS == HIGH at start of transfer
Flags[3:2] Chip select end state JLINK_SPI_FLAG_CS_END_STATE_U nCS not touched at end of transfer
JLINK_SPI_FLAG_CS_END_STATE_0 nCS == LOW at end of transfer
JLINK_SPI_FLAG_CS_END_STATE_1 nCS == HIGH at end of transfer
Flags[6:5] Selects the line used for chip select.
Chip select is used only if the start and/or end state is set to HIGH or LOW.

JLINK_SPI_FLAG_CS_INDEX_0: nCS0 (Pin 17)
JLINK_SPI_FLAG_CS_INDEX_1: nCS1 (Pin 7)

Return value

Always returns 0.

Additional information

Chip select must be used only with JLINK_TIF_SPI.

For more information about the technical functionality of this function in combination with the selected target interface, please refer to the additional information for target interfaces.

JLINK_Strobe()

Prototype

void JLINK_Strobe(U8 Pin, U32 Frequency, U32 NumClocks);

Function description

Creates a strobe signal on one pin of the target interface. This is used for devices with externally timed flash programming. The initial and final state of the pin is HIGH.

Parameters

Parameter Description
Pin The index of the pin to be used for the strobe. Currently, strobe is supported only for pin 5 with index 1.
Frequency The frequency of the strobe.
NumClocks The strobe will be generated with (NumClocks + 1) clock cycles.

JLINK_SWD_ReadWriteBits()

Prototype

int JLINK_SWD_ReadWriteBits(const U8* pDataIn, const U8* pDirection, U8* pDataOut, int NumBits);

Function description

Reads and writes data via SWD.

Parameters

Parameter Description
pDataIn Buffer with data to write.
pDirection Buffer with direction information. Ones indicate that data should be written, while zeroes indicate that data should be read.
pDataOut Buffer to store read data.
NumBits Total number of bits to be read and written.

Return value

Return value Description
== 0 O.K.
!= 0 Error.

JLINK_SWIM_Connect()

Prototype

int JLINK_SWIM_Connect(U8 HiSpeed);

Function description

Connects to an STM8 device via SWIM.

Parameters

Parameter Description
HiSpeed Enables high speed mode if set to a value other than zero.

Return value

Return value Description
== 0 O.K.
< 0 Error.

Additional information

Requires JLINK_SWIM_Init() to be called before a connect is performed.

JLINK_SWIM_DeInit()

Prototype

void JLINK_SWIM_DeInit(void);

Function description

De-initializes SWIM communication and resets the target so that it starts execution.

JLINK_SWIM_DeInitNoStart()

Prototype

void JLINK_SWIM_DeInitNoStart(void);

Function description

De-initializes SWIM communication without resetting the target.

JLINK_SWIM_Init()

Prototype

void JLINK_SWIM_Init(void);

Function description

Prepares the flasher for SWIM communication.

Additional information

This function has to be called before any other SWIM API function but after selecting the target interface via JLINK_SelectTIF().

JLINK_SWIM_ReadMem()

Prototype

int JLINK_SWIM_ReadMem(U32 Addr, U8* pData, U8 NumBytes);

Function description

Reads memory via SWIM interface.

Parameters

Parameter Description
Addr The address to read from.
Data Pointer to a buffer the read data should be stored in.
NumBytes Number of bytes to read.

Return value

Return value Description
>= 0 Number of read bytes.
< 0 Error.

JLINK_SWIM_SysReset()

Prototype

void JLINK_SWIM_SysReset(void);

Function description

Sends a system reset.

Return value

Return value Description
== 1 O.K.
== -1 Error.

JLINK_SWIM_WriteMem()

Prototype

int JLINK_SWIM_WriteMem(U32 Addr, const U8* Data, U8 NumBytes);

Function description

Writes memory via SWIM interface.

Parameters

Parameter Description
Addr The address to write to.
Data Pointer to a buffer with data that shall be written.
NumBytes Number of bytes to write.

Return value

Return value Description
>= 0 Number of written bytes.
< 0 Error.

JLINK_SYS_GetVar()

Prototype

U32 JLINK_SYS_GetVar(U32 IndexVar);

Function description

Returns the value of a pseudo variable.

Parameters

Parameter Description
IndexVar The index of the variable whose value should be returned.

Return value

Returns the value of the variable with the specified index.

Additional information

This function is mainly used by the compiler when specific variables are accessed. The following code shows such access which is changed by the compiler to a call to JLINK_SYS_GetVar() with the according index of the variable.

void Foo(void) {
  U32 PinState;
  PinState = JLINK_JTAG_TCKPin;  // Compiler generates a call to JLINK_SYS_GetVar() to retrieve the value of JLINK_JTAG_TCKPin
}

JLINK_SYS_memcmp()

Prototype

int JLINK_SYS_memcmp(const U8* pData1, const U8* pData2, int NumBytes);

Function description

Compares two buffers byte by byte and returns whether both buffer are equal or not.

Parameters

Parameter Description
pData1 Pointer to the first buffer.
pData2 Pointer to the second buffer.
NumBytes Number of bytes to compare.

Return value

Return value Description
== 0 Both buffers are equal for the given number of bytes that were compared.
!= 0 The buffers are different. The returned value is the difference of the first bytes that differ.

JLINK_SYS_Report()

Prototype

int JLINK_SYS_Report(const char* sMsg);

Function description

Outputs a string via Telnet.

Parameters

Parameter Description
sMsg The string to be sent via Telnet.

Return value

Always returns 0.

JLINK_SYS_Report1()

Prototype

int JLINK_SYS_Report1(const char* sMsg, int v);

Function description

Outputs a string followed by a 32-bit hexadecimal value via Telnet.

Parameters

Parameter Description
sMsg The string to be sent via Telnet.
v A 32-bit value to be shown in hexadecimal form.

Return value

Always returns 0.

JLINK_SYS_SetVar()

Prototype

int JLINK_SYS_SetVar(U32 IndexVar, U32 v);

Function description

Sets the value of a pseudo variable.

Parameters

Parameter Description
IndexVar The index of the variable whose value should be returned.
v The value the pseudo variable should be set to.

Return value

Always returns 0.

Additional information

This function is mainly used by the compiler when specific variables are accessed. The following code shows such access which is changed by the compiler to a call to JLINK_SYS_SetVar() with the according index of the variable.

void Foo(void) {
  JLINK_JTAG_TCKPin = 1;  // Compiler generates a call to JLINK_SYS_SetVar() to set the value of JLINK_JTAG_TCKPin
}

JLINK_SYS_Sleep()

Prototype

int JLINK_SYS_Sleep(int Delayms);

Function description

Stops the execution of the pcode for the specified time.

Parameters

Parameter Description
Delayms The minimum time in milliseconds the flasher shall wait before continuing execution of the pcode.

Return value

Always returns 0.

JLINK_TIF_ActivateTargetReset()

Prototype

void JLINK_TIF_ActivateTargetReset(void);

Function description

Asserts the target reset pin by setting nRESET to LOW.

JLINK_TIF_ReInit()

Prototype

int JLINK_TIF_ReInit(void);

Function description

Re-initializes the currently selected target interface.

Return value

Return value Description
== 0 O.K.
== -262 Re-initialization not available for the selected target interface.

Additional information

Re-initialization is currently only supported for cJTAG, which performs the initialization of TAP7 in order to make TAPs behind it accessible.

JLINK_TIF_ReleaseTargetReset()

Prototype

void JLINK_TIF_ReleaseTargetReset(void);

Function description

De-asserts the target reset pin by setting nRESET to HIGH.

JLINK_TIF_SetClrTCK()

Prototype

void JLINK_TIF_SetClrTCK(int OnOff);

Function description

Sets the state of TCK (pin 9).

Parameters

Parameter Description
OnOff 0: Sets TCK to LOW
1: Sets TCK to HIGH

JLINK_TIF_SetClrTDI()

Prototype

void JLINK_TIF_SetClrTDI(int OnOff);

Function description

Sets the state of TDI (pin 5).

Parameters

Parameter Description
OnOff 0: Sets TDI to LOW
1: Sets TDI to HIGH

JLINK_TIF_SetClrTMS()

Prototype

void JLINK_TIF_SetClrTMS(int OnOff);

Function description

Sets the state of TMS (pin 7).

Parameters

Parameter Description
OnOff 0: Sets TMS to LOW
1: Sets TMS to HIGH

JLINK_TIF_SetSpeed()

Prototype

void JLINK_TIF_SetSpeed(U32 Speed);

Function description

Sets the target interface speed [Hz] used for communication.

Parameters

Parameter Description
Speed The frequency in hertz to be used for the target communication.

Additional information

The default frequency after JLINK_SelectTIF() is 1MHz. Changing the target interface speed will re-initilize the target interface.

JLINK_UART_DeInit()

Prototype

int JLINK_UART_DeInit(void);

Function description

De-initializes the UART interface.

Return value

Always returns 0.

JLINK_UART_Init()

Prototype

int JLINK_UART_Init(int BaudrateHz);

Function description

Initializes the UART interface. The used mode is 8n1.

Parameters

Parameter Description
BaudrateHz The baud rate to be used.

Return value

Always returns 0.

Additional information

Before calling JLINK_UART_Init(), the modes of the pins to be used have to be set via JLINK_PIN_Override().

JLINK_UART_Read()

Prototype

int JLINK_UART_Read(U8* pData, U32 NumBytes);

Function description

Reads data from the Rx buffer that were received via the UART interface.

Parameters

Parameter Description
pData Pointer to a buffer the read data should be stored in.
NumBytes Number of bytes to read.

Return value

The number of bytes read from the Rx buffer.

JLINK_UART_Write()

Prototype

int JLINK_UART_Write(const U8* pData, U32 NumBytes);

Function description

Writes data into the Tx buffer which is then written via the UART interface.

Parameters

Parameter Description
pData Pointer to a buffer with data to be written.
NumBytes Number of bytes to write.

Return value

The number of bytes written into the Tx buffer.

JLINK_WriteBitOff()

Prototype

void JLINK_WriteBitOff(U8* p, U32 BitOff, U32 v, U32 NumBits);

Function description

Writes a given number of bits to a memory address with a specified offset.

Parameters

Parameter Description
p The memory address used together with the bit offset `BitOff` to calculate the memory location the value `v` should be written to.
BitOff The bit offset used together with the address `p` to calculate the memory location the value `v` should be written to.
v The value that should be written to the memory location calculated with the address `p` abd bit offsett `BitOff`.
NumBits Number of bits to write.

M16C_DeInit()

Prototype

int M16C_DeInit(void);

Function description

De-initializes the M16C interface.

Return value

Return value Description
== 0 O.K.
!= 0 Error.

M16C_Init()

Prototype

int M16C_Init(U32 Speed);

Function description

Initializes the M16C interface.

Parameters

Parameter Description
Speed The frequency in hertz to be used for the target communication.

Return value

Return value Description
== 0 O.K.
== -1 Error.

Additional information

This function has to be called after selecting the target interface via JLINK_SelectTIF().

M16C_ReadWrite()

Prototype

int M16C_ReadWrite(U8* pDataOut, U8* pDataIn, U32 NumBytes);

Function description

Writes and reads the specified number of bytes.

Parameters

Parameter Description
pDataOut Pointer to buffer with data to write.
pDataIn Pointer to a buffer the read data should be stored in.
NumBytes The number of bytes to write and read.

Return value

Always returns 0.

SPI2FE_DeInit()

Prototype

__imp int SPI2FE_DeInit(void);

Function description

De-initializes the SPI2FE interface.

Return value

Always returns 0.

SPI2FE_Init()

Prototype

__imp int SPI2FE_Init(U32 Speed);

Function description

Initializes the SPI2FE interface.

Parameters

Parameter Description
Speed The frequency in hertz to be used for the SPI communication.

Return value

Always returns 0.

Additional information

This function has to be called after selecting the target interface via JLINK_SelectTIF().

SPI2FE_ReadBits()

Prototype

int SPI2FE_ReadBits(U8* pDataIn, U32 NumBits);

Function description

Reads data via SPI.

Parameters

Parameter Description
pDataIn Pointer to a buffer the read data should be stored in.
NumBits Number of bits to read.

Return value

Return value Description
== 0 O.K.
< 0 Error.

Additional information

For more information about the technical functionality of this function in combination with the selected target interface, please refer to the additional information for target interfaces.

SPI2FE_ReadBits_RisingEdge()

Prototype

__imp int SPI2FE_ReadBits_RisingEdge(U8* pDataIn, U32 NumBits);

Function description

Reads data via SPI.

Parameters

Parameter Description
pDataIn Pointer to a buffer the read data should be stored in.
NumBits Number of bits to read.

Return value

Return value Description
== 0 O.K.
< 0 Error.

Additional information

For more information about the technical functionality of this function in combination with the selected target interface, please refer to the additional information for target interfaces.

This function must only be used with JLINK_TIF_SPI2FE.

SPI2FE_WriteBits()

Prototype

int SPI2FE_WriteBits(const U8* pDataOut, U32 NumBits);

Function description

Writes data via SPI.

Parameters

Parameter Description
pDataOut Buffer with data to write.
NumBits Number of bits to write.

Return value

Return value Description
== 0 O.K.
< 0 Error.

Additional information

For more information about the technical functionality of this function in combination with the selected target interface, please refer to the additional information for target interfaces.

SPI2FE_WriteBits_RisingEdge()

Prototype

__imp int SPI2FE_WriteBits_RisingEdge(U8* pDataOut, U32 NumBits);

Function description

Writes data via SPI.

Parameters

Parameter Description
pDataOut Buffer with data to write.
NumBits Number of bits to write.

Return value

Return value Description
== 0 O.K.
< 0 Error.

Additional information

For more information about the technical functionality of this function in combination with the selected target interface, please refer to the additional information for target interfaces.

This function must only be used with JLINK_TIF_SPI2FE.

SPI_IdleClockLow_DeInit()

Prototype

__imp int SPI_IdleClockLow_DeInit(void);

Function description

De-initializes the SPI for idle clock low mode.

SPI_IdleClockLow_Init()

Prototype

__imp int SPI_IdleClockLow_Init(U32 Speed);

Function description

Initializes the SPI for idle clock low mode.

Parameters

Parameter Description
Speed The frequency in hertz to be used for the SPI communication.

Additional information

This function has to be called after selecting the target interface via JLINK_SelectTIF().

SPI_IdleClockLow_ReadWrite()

Prototype

__imp int SPI_IdleClockLow_ReadWrite(U8* pDataOut, U32 Unused, U8* pDataIn, U32 NumBytes);

Function description

Parameters

Parameter Description
pDataOut Pointer to a buffer with data to write.
Unused This parameter is not used.
pDataIn Pointer to a buffer the read data should be stored in.
NumBytes Number of bytes to write and read.

Return value

Return value Description
== 0 O.K.
< 0 Error.

UTIL_ReverseBits()

Prototype

__imp U32 UTIL_ReverseBits(U32 Data, U32 NumBits);

Function description

Reverses the specified number of bits and return the result.

Parameters

Parameter Description
Data The data to be reversed.
NumBits The number of bits to revserse.

Return value

The result of the reversed data. If less than 32 bits are reversed, the result is shifted to the right by (32 - NumBits).

UTIL_ReverseBytes()

Prototype

__imp void UTIL_ReverseBytes(U8* pData, U32 NumBytes);

Function description

Reverses each byte in the provided buffer individually.

Parameters

Parameter Description
pData Pointer to a buffer with bytes to be reversed.
NumBytes The number of bytes to be reversed.

Additional Information for Target Interfaces

SPI, SPI2FE and QSPI

  • JLINK_SPI_*() functions can only transfer full bytes while SPI2FE_*() functions can be used to transfer single bits
  • if data is sampled on rising or falling edge depends on the selected target interface
  • SPI2FE_WriteBits_RisingEdge() and SPI2FE_ReadBits_RisingEdge(), which samples data on rising edge, must only be used with JLINK_TIF_SPI2FE
  • CS functionality of JLINK_SPI_*() functions must only be used with JLINK_TIF_SPI

When JLINK_TIF_SPI is selected:

  • data is written on pin 5
  • data is sampled on rising edge
  • data out pin is HIGH for 0 and LOW for 1
  • clock is HIGH when inactive
  • pin 7 and 17 are HIGH after the interface is selected to disable chip select for those two lines

When JLINK_TIF_SPI2FE is selected:

  • data is written on pin 7
  • data is sampled on falling edge
  • data out pin is HIGH for 1 and LOW for 0
  • clock is LOW when inactive

When JLINK_TIF_SPI_IDLE_CLOCK_LOW is selected:

  • data is written on pin 5
  • data is sampled on rising edge
  • data out pin is HIGH for 0 and LOW for 1
  • clock is LOW when inactive

When JLINK_TIF_QSPI is selected:

  • following assignment of pin functionality is used:
    • SCK => pin 9
    • IO0 => pin 5
    • IO1 => pin 3
    • IO2 => pin 11
    • IO3 => pin 17
    • nCS => pin 7
  • data is sampled on rising edge
  • data pins are HIGH for 0 and LOW for 1
  • clock is HIGH when inactive