Skip to content

Commit

Permalink
Merge pull request #248 from Infineon/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jaenrig-ifx committed Jun 21, 2023
2 parents 674ee37 + 70b950a commit a354920
Show file tree
Hide file tree
Showing 33 changed files with 1,050 additions and 1,942 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This repository integrates [Infineon's](https://www.infineon.com/) XMC microcont
- [Prework for SEGGER J-Link](#prework-for-segger-j-link)
- [Using Arduino IDE](#using-arduino-ide)
- [Separation of release packages from version 2.0.0 onwards](#separation-of-release-packages-from-version-200-onwards)
- [Known Issues](#known-issues)
- [Using PlatformIO IDE](#using-platformio-ide)
- [Contributing and Third Party Libraries](#contributing-and-third-party-libraries)
- [Additional Contributors](#additional-contributors)
Expand Down Expand Up @@ -104,6 +105,10 @@ Any new board or feature integration will only be done in the *XMC Family V2.x*
![Board list v1x](https://raw.githubusercontent.com/Infineon/Assets/version-2.x/Pictures/Board_List_v2x.png.jpg)


### Known Issues

* :warning: While using the pins connected to the **LEDs** configured as **INPUT**, there might be some abberation in behavior due to the presence of the series resistor of the LED, as it causes a voltage drop on the pin. In case of such an occurance, it is advised to desolder the series resistor and the LED and thereby using the pin as INPUT.

### Using PlatformIO IDE

- [What is PlatformIO?](http://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=github&utm_medium=xmc-for-arduino)
Expand Down
2 changes: 1 addition & 1 deletion boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ XMC1100_XMC2GO.build.mcu=cortex-m0
XMC1100_XMC2GO.build.f_cpu=32000000L
XMC1100_XMC2GO.build.board=ARM_XMC
XMC1100_XMC2GO.build.board.version=1100
XMC1100_XMC2GO.build.board.type=T038x0064
XMC1100_XMC2GO.build.board.type=Q024x0064
XMC1100_XMC2GO.build.board.v=0064
XMC1100_XMC2GO.build.core=./
XMC1100_XMC2GO.build.variant=XMC1100
Expand Down
68 changes: 68 additions & 0 deletions cores/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ extern "C" {
#include <xmc_uart.h>
#include <xmc_dac.h>
#include <xmc_eru.h>
#include <xmc_spi.h>
#include <xmc_i2c.h>
#include <xmc_i2s.h>

//****************************************************************************
// @Defines
Expand All @@ -55,6 +58,13 @@ extern "C" {
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( (a) * (F_CPU / 1000000L) )

// default XMC_SPI instance is XMC_SPI_0 for all variants
#define XMC_SPI_default XMC_SPI_0
// default XMC_I2C instance is XMC_I2C_0 for all variants
#define XMC_I2C_default XMC_I2C_0
// used by XMC_I2S
#define BUFFER_SIZE 512

//****************************************************************************
// @Typedefs
//****************************************************************************
Expand Down Expand Up @@ -187,6 +197,53 @@ extern "C" {
uint32_t irq_service_request ;
} XMC_UART_t;

/*
* XMC SPI type
*/
typedef struct
{
XMC_USIC_CH_t* channel ;
XMC_SPI_CH_CONFIG_t channel_config ;
XMC_PORT_PIN_t mosi ;
XMC_GPIO_CONFIG_t mosi_config ;
XMC_PORT_PIN_t miso ;
XMC_GPIO_CONFIG_t miso_config ;
XMC_USIC_INPUT_t input_source ;
XMC_PORT_PIN_t sclkout ;
XMC_GPIO_CONFIG_t sclkout_config ;
} XMC_SPI_t;

/*
* XMC I2C type
*/
typedef struct
{
XMC_USIC_CH_t* channel;
XMC_I2C_CH_CONFIG_t channel_config;
XMC_PORT_PIN_t sda;
XMC_GPIO_CONFIG_t sda_config;
XMC_PORT_PIN_t scl;
XMC_GPIO_CONFIG_t scl_config;
XMC_USIC_INPUT_t input_source_dx0;
XMC_USIC_INPUT_t input_source_dx1;
IRQn_Type slave_receive_irq_num;
uint32_t slave_receive_irq_service_request;
IRQn_Type protocol_irq_num;
uint32_t protocol_irq_service_request;
} XMC_I2C_t;

/*
* XMC I2S type
*/
typedef struct
{
XMC_GPIO_CONFIG_t input_config;
XMC_GPIO_CONFIG_t sclk_config;
XMC_GPIO_CONFIG_t wa_config;
IRQn_Type protocol_irq_num;
uint32_t protocol_irq_service_request;
} XMC_I2S_t;

//****************************************************************************
// @Imported Global Variables
//****************************************************************************
Expand All @@ -205,6 +262,17 @@ extern "C" {
#endif
extern XMC_UART_t XMC_UART_debug;
extern XMC_UART_t XMC_UART_on_board;

extern XMC_SPI_t XMC_SPI_0;
// Some boards for eg. XMC4700 Relax Kit has more than one SPI instance
extern XMC_SPI_t XMC_SPI_1;
extern XMC_SPI_t XMC_SPI_2;

extern XMC_I2C_t XMC_I2C_0;
// Some boards for eg. XMC4700 Relax Kit has more than one I2C instance
extern XMC_I2C_t XMC_I2C_1;

extern XMC_I2S_t i2s_config;

//****************************************************************************
// @Prototypes Of Global Functions
Expand Down
7 changes: 4 additions & 3 deletions cores/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ uart_ch_config.stop_bits = (uint8_t)(( config & 0x0f0U ) >> 4 );

XMC_UART_CH_Init( _XMC_UART_config->channel, &uart_ch_config );

XMC_GPIO_Init( _XMC_UART_config->rx.port, _XMC_UART_config->rx.pin, &(_XMC_UART_config->rx_config) );

// dx0 is UART RX: source must be set
XMC_USIC_CH_SetInputSource( _XMC_UART_config->channel, XMC_USIC_CH_INPUT_DX0,
_XMC_UART_config->input_source_dx0 );
Expand Down Expand Up @@ -92,10 +90,13 @@ XMC_USIC_CH_SetInterruptNodePointer(_XMC_UART_config->channel,
_XMC_UART_config->irq_service_request );
NVIC_SetPriority(_XMC_UART_config->irq_num, 3);
NVIC_EnableIRQ(_XMC_UART_config->irq_num);

XMC_UART_CH_Start( _XMC_UART_config->channel );

// TX pin setup put here to avoid startup corrupted characters being first sent
XMC_GPIO_Init( _XMC_UART_config->tx.port, _XMC_UART_config->tx.pin, &(_XMC_UART_config->tx_config) );

XMC_UART_CH_Start( _XMC_UART_config->channel );
XMC_GPIO_Init( _XMC_UART_config->rx.port, _XMC_UART_config->rx.pin, &(_XMC_UART_config->rx_config) );
}


Expand Down
64 changes: 64 additions & 0 deletions cores/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,70 @@ if( channel < NUM_ANALOG_INPUTS )
return value;
}

/* analogRead_variableGain takes parameter of ADC channel number and gain value
return 0xFFFFFFFF for invalid channel
gain value gain factor
0 1
1 3
2 6
3 12
Also, refer to macros in wiring_analog.h
*/

uint32_t analogRead_variableGain( uint8_t channel, uint8_t gain_value )
{
#if(XMC_VADC_SHS_AVAILABLE == 1U)
uint32_t value;

value = 0xFFFFFFFF;
if( channel < NUM_ANALOG_INPUTS )
{
XMC_ADC_t *adc = &mapping_adc[ channel ];

#if(XMC_VADC_GROUP_AVAILABLE == 1U)
// ADC grouping
if( !(adc->enabled) )
{
XMC_VADC_CHANNEL_CONFIG_t vadc_gobal_channel_config;
memset( &vadc_gobal_channel_config, 0, sizeof( XMC_VADC_CHANNEL_CONFIG_t ) );
vadc_gobal_channel_config.input_class = XMC_VADC_CHANNEL_CONV_GROUP_CLASS1;
vadc_gobal_channel_config.result_reg_number = adc->result_reg_num;
vadc_gobal_channel_config.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED;

XMC_VADC_RESULT_CONFIG_t vadc_gobal_result_config = { .g_rcr = 0 };
/* Configure a channel belonging to the aforesaid conversion kernel */
XMC_VADC_GROUP_ChannelInit( adc->group, adc->channel_num, &vadc_gobal_channel_config );
/* Configure a result resource belonging to the aforesaid conversion kernel */
XMC_VADC_GROUP_ResultInit( adc->group, adc->result_reg_num, &vadc_gobal_result_config );
/* Add channel into the Background Request Source Channel Select Register */
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence( VADC, (uint32_t)adc->group_num,
(uint32_t)adc->channel_num );
/* Set the gain factor of the Sample and hold module*/
XMC_VADC_GLOBAL_SHS_SetGainFactor( SHS0, gain_value, (uint32_t)adc->group_num, (uint32_t)adc->channel_num );
}
/* Start conversion manually using load event trigger*/
XMC_VADC_GLOBAL_BackgroundTriggerConversion( VADC );
value = XMC_VADC_GROUP_GetResult( adc->group, adc->result_reg_num );
#else
// XMC1100 no ADC grouping
if( !(adc->enabled) )
/* Add a channel to the background source. */
VADC->BRSSEL[ ADC_CONVERSION_GROUP ] = (uint32_t)( 1U << adc->channel_num );
/* Set the gain factor of the Sample and hold module */
XMC_VADC_GLOBAL_SHS_SetGainFactor( SHS0, gain_value, XMC_VADC_GROUP_INDEX_0, (uint32_t)adc->channel_num );
// Generates conversion request
XMC_VADC_GLOBAL_BackgroundTriggerConversion( VADC );

// Wait until conversion is ready
while( ( ( value = XMC_VADC_GLOBAL_GetDetailedResult( VADC ) ) & VADC_GLOBRES_VF_Msk) == 0u );
#endif
value = ( ( value & VADC_GLOBRES_RESULT_Msk) >> ( ADC_MAX_READ_RESOLUTION - _readResolution ) );
return value;
}
#endif
}


/* Helper function for analogWrite and setAnalogWriteFrequency to scan
mapping tables to determine for a given pin which PWM4, PWM8 or DAC
Expand Down
25 changes: 25 additions & 0 deletions cores/wiring_analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
extern "C" {
#endif

/*********************************************************************************************************************
* MACROS
********************************************************************************************************************/
// ADC gain macros
#define ADC_VAR_GAIN_FACTOR_1 0
#define ADC_VAR_GAIN_FACTOR_3 1
#define ADC_VAR_GAIN_FACTOR_6 2
#define ADC_VAR_GAIN_FACTOR_12 3

//****************************************************************************
// @External Prototypes
//****************************************************************************
Expand Down Expand Up @@ -85,6 +94,22 @@ extern "C" {
*/
extern uint32_t analogRead( uint8_t channel ) ;

/*
* \brief Reads the value from the specified analogue channel and add variable gain at input.
*
* \param channel
* \param gain_factor
*
* gain value gain factor
* 0 1
* 1 3
* 2 6
* 3 12
*
* \return Read value from selected channel, or 0xFFFFFFFF for error.
*/
extern uint32_t analogRead_variableGain( uint8_t channel, uint8_t gain_value ) ;

/*
* \brief Set the resolution of analogRead return values in number of bits.
* \note Default is 10 bits (range from 0 to 1023).
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ getAnalogReadBits KEYWORD2
getAnalogWriteBits KEYWORD2
getAnalogReadMaximum KEYWORD2
getAnalogWriteMaximum KEYWORD2
analogRead_variableGain KEYWORD2

#######################################
# Instances (KEYWORD2)
Expand Down
2 changes: 1 addition & 1 deletion libraries/I2S/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The library has been tested with the XMC4700 Relax Kit, XMC1100 XMC 2Go, and XMC

`Ensure that level shifting is in place as the microphone board has 3.3 V logic level, XMC1100 Boot Kit has 5 V by default.`

This configuration is defined in `utility\xmc_i2s_conf.h`.
This configuration is defined in the respective board configuration files `pins_arduino.h`.

If we take the pin out of XMC for Arduino, the respective pins for SPI are redefined.
Therefore, SPI cannot be used anymore in combination with I2S - please keep this in mind. On the other hand, using `SPI.begin()` and `I2S.begin()` will reactivate the original setting and switching between both interfaces is possible on the fly.
Expand Down
7 changes: 0 additions & 7 deletions libraries/I2S/src/I2S.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
#ifndef I2S_h
#define I2S_h

#if defined(XMC4700_Relax_Kit) || defined(XMC1100_XMC2GO) || defined(XMC1100_Boot_Kit)
#include "utility/xmc_i2s_conf.h"

typedef enum {
I2S_PHILIPS_MODE,
I2S_RIGHT_JUSTIFIED_MODE,
Expand Down Expand Up @@ -260,8 +257,4 @@ class I2SClass

extern I2SClass I2S;

#else
#error "Only XMC4700 Relax Kit, XMC1100 XMC2Go or XMC1100 Boot Kit is supported for I2S"
#endif

#endif /* I2S_h */
18 changes: 0 additions & 18 deletions libraries/I2S/src/utility/xmc_i2s_conf.c

This file was deleted.

Loading

0 comments on commit a354920

Please sign in to comment.