Skip to content

Commit a354920

Browse files
authored
Merge pull request #248 from Infineon/develop
Develop
2 parents 674ee37 + 70b950a commit a354920

File tree

33 files changed

+1050
-1942
lines changed

33 files changed

+1050
-1942
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This repository integrates [Infineon's](https://www.infineon.com/) XMC microcont
1212
- [Prework for SEGGER J-Link](#prework-for-segger-j-link)
1313
- [Using Arduino IDE](#using-arduino-ide)
1414
- [Separation of release packages from version 2.0.0 onwards](#separation-of-release-packages-from-version-200-onwards)
15+
- [Known Issues](#known-issues)
1516
- [Using PlatformIO IDE](#using-platformio-ide)
1617
- [Contributing and Third Party Libraries](#contributing-and-third-party-libraries)
1718
- [Additional Contributors](#additional-contributors)
@@ -104,6 +105,10 @@ Any new board or feature integration will only be done in the *XMC Family V2.x*
104105
![Board list v1x](https://raw.githubusercontent.com/Infineon/Assets/version-2.x/Pictures/Board_List_v2x.png.jpg)
105106

106107

108+
### Known Issues
109+
110+
* :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.
111+
107112
### Using PlatformIO IDE
108113

109114
- [What is PlatformIO?](http://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=github&utm_medium=xmc-for-arduino)

boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ XMC1100_XMC2GO.build.mcu=cortex-m0
6767
XMC1100_XMC2GO.build.f_cpu=32000000L
6868
XMC1100_XMC2GO.build.board=ARM_XMC
6969
XMC1100_XMC2GO.build.board.version=1100
70-
XMC1100_XMC2GO.build.board.type=T038x0064
70+
XMC1100_XMC2GO.build.board.type=Q024x0064
7171
XMC1100_XMC2GO.build.board.v=0064
7272
XMC1100_XMC2GO.build.core=./
7373
XMC1100_XMC2GO.build.variant=XMC1100

cores/Arduino.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ extern "C" {
4747
#include <xmc_uart.h>
4848
#include <xmc_dac.h>
4949
#include <xmc_eru.h>
50+
#include <xmc_spi.h>
51+
#include <xmc_i2c.h>
52+
#include <xmc_i2s.h>
5053

5154
//****************************************************************************
5255
// @Defines
@@ -55,6 +58,13 @@ extern "C" {
5558
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
5659
#define microsecondsToClockCycles(a) ( (a) * (F_CPU / 1000000L) )
5760

61+
// default XMC_SPI instance is XMC_SPI_0 for all variants
62+
#define XMC_SPI_default XMC_SPI_0
63+
// default XMC_I2C instance is XMC_I2C_0 for all variants
64+
#define XMC_I2C_default XMC_I2C_0
65+
// used by XMC_I2S
66+
#define BUFFER_SIZE 512
67+
5868
//****************************************************************************
5969
// @Typedefs
6070
//****************************************************************************
@@ -187,6 +197,53 @@ extern "C" {
187197
uint32_t irq_service_request ;
188198
} XMC_UART_t;
189199

200+
/*
201+
* XMC SPI type
202+
*/
203+
typedef struct
204+
{
205+
XMC_USIC_CH_t* channel ;
206+
XMC_SPI_CH_CONFIG_t channel_config ;
207+
XMC_PORT_PIN_t mosi ;
208+
XMC_GPIO_CONFIG_t mosi_config ;
209+
XMC_PORT_PIN_t miso ;
210+
XMC_GPIO_CONFIG_t miso_config ;
211+
XMC_USIC_INPUT_t input_source ;
212+
XMC_PORT_PIN_t sclkout ;
213+
XMC_GPIO_CONFIG_t sclkout_config ;
214+
} XMC_SPI_t;
215+
216+
/*
217+
* XMC I2C type
218+
*/
219+
typedef struct
220+
{
221+
XMC_USIC_CH_t* channel;
222+
XMC_I2C_CH_CONFIG_t channel_config;
223+
XMC_PORT_PIN_t sda;
224+
XMC_GPIO_CONFIG_t sda_config;
225+
XMC_PORT_PIN_t scl;
226+
XMC_GPIO_CONFIG_t scl_config;
227+
XMC_USIC_INPUT_t input_source_dx0;
228+
XMC_USIC_INPUT_t input_source_dx1;
229+
IRQn_Type slave_receive_irq_num;
230+
uint32_t slave_receive_irq_service_request;
231+
IRQn_Type protocol_irq_num;
232+
uint32_t protocol_irq_service_request;
233+
} XMC_I2C_t;
234+
235+
/*
236+
* XMC I2S type
237+
*/
238+
typedef struct
239+
{
240+
XMC_GPIO_CONFIG_t input_config;
241+
XMC_GPIO_CONFIG_t sclk_config;
242+
XMC_GPIO_CONFIG_t wa_config;
243+
IRQn_Type protocol_irq_num;
244+
uint32_t protocol_irq_service_request;
245+
} XMC_I2S_t;
246+
190247
//****************************************************************************
191248
// @Imported Global Variables
192249
//****************************************************************************
@@ -205,6 +262,17 @@ extern "C" {
205262
#endif
206263
extern XMC_UART_t XMC_UART_debug;
207264
extern XMC_UART_t XMC_UART_on_board;
265+
266+
extern XMC_SPI_t XMC_SPI_0;
267+
// Some boards for eg. XMC4700 Relax Kit has more than one SPI instance
268+
extern XMC_SPI_t XMC_SPI_1;
269+
extern XMC_SPI_t XMC_SPI_2;
270+
271+
extern XMC_I2C_t XMC_I2C_0;
272+
// Some boards for eg. XMC4700 Relax Kit has more than one I2C instance
273+
extern XMC_I2C_t XMC_I2C_1;
274+
275+
extern XMC_I2S_t i2s_config;
208276

209277
//****************************************************************************
210278
// @Prototypes Of Global Functions

cores/HardwareSerial.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ uart_ch_config.stop_bits = (uint8_t)(( config & 0x0f0U ) >> 4 );
5656

5757
XMC_UART_CH_Init( _XMC_UART_config->channel, &uart_ch_config );
5858

59-
XMC_GPIO_Init( _XMC_UART_config->rx.port, _XMC_UART_config->rx.pin, &(_XMC_UART_config->rx_config) );
60-
6159
// dx0 is UART RX: source must be set
6260
XMC_USIC_CH_SetInputSource( _XMC_UART_config->channel, XMC_USIC_CH_INPUT_DX0,
6361
_XMC_UART_config->input_source_dx0 );
@@ -92,10 +90,13 @@ XMC_USIC_CH_SetInterruptNodePointer(_XMC_UART_config->channel,
9290
_XMC_UART_config->irq_service_request );
9391
NVIC_SetPriority(_XMC_UART_config->irq_num, 3);
9492
NVIC_EnableIRQ(_XMC_UART_config->irq_num);
93+
94+
XMC_UART_CH_Start( _XMC_UART_config->channel );
95+
9596
// TX pin setup put here to avoid startup corrupted characters being first sent
9697
XMC_GPIO_Init( _XMC_UART_config->tx.port, _XMC_UART_config->tx.pin, &(_XMC_UART_config->tx_config) );
9798

98-
XMC_UART_CH_Start( _XMC_UART_config->channel );
99+
XMC_GPIO_Init( _XMC_UART_config->rx.port, _XMC_UART_config->rx.pin, &(_XMC_UART_config->rx_config) );
99100
}
100101

101102

cores/wiring_analog.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,70 @@ if( channel < NUM_ANALOG_INPUTS )
216216
return value;
217217
}
218218

219+
/* analogRead_variableGain takes parameter of ADC channel number and gain value
220+
return 0xFFFFFFFF for invalid channel
221+
222+
gain value gain factor
223+
0 1
224+
1 3
225+
2 6
226+
3 12
227+
Also, refer to macros in wiring_analog.h
228+
*/
229+
230+
uint32_t analogRead_variableGain( uint8_t channel, uint8_t gain_value )
231+
{
232+
#if(XMC_VADC_SHS_AVAILABLE == 1U)
233+
uint32_t value;
234+
235+
value = 0xFFFFFFFF;
236+
if( channel < NUM_ANALOG_INPUTS )
237+
{
238+
XMC_ADC_t *adc = &mapping_adc[ channel ];
239+
240+
#if(XMC_VADC_GROUP_AVAILABLE == 1U)
241+
// ADC grouping
242+
if( !(adc->enabled) )
243+
{
244+
XMC_VADC_CHANNEL_CONFIG_t vadc_gobal_channel_config;
245+
memset( &vadc_gobal_channel_config, 0, sizeof( XMC_VADC_CHANNEL_CONFIG_t ) );
246+
vadc_gobal_channel_config.input_class = XMC_VADC_CHANNEL_CONV_GROUP_CLASS1;
247+
vadc_gobal_channel_config.result_reg_number = adc->result_reg_num;
248+
vadc_gobal_channel_config.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED;
249+
250+
XMC_VADC_RESULT_CONFIG_t vadc_gobal_result_config = { .g_rcr = 0 };
251+
/* Configure a channel belonging to the aforesaid conversion kernel */
252+
XMC_VADC_GROUP_ChannelInit( adc->group, adc->channel_num, &vadc_gobal_channel_config );
253+
/* Configure a result resource belonging to the aforesaid conversion kernel */
254+
XMC_VADC_GROUP_ResultInit( adc->group, adc->result_reg_num, &vadc_gobal_result_config );
255+
/* Add channel into the Background Request Source Channel Select Register */
256+
XMC_VADC_GLOBAL_BackgroundAddChannelToSequence( VADC, (uint32_t)adc->group_num,
257+
(uint32_t)adc->channel_num );
258+
/* Set the gain factor of the Sample and hold module*/
259+
XMC_VADC_GLOBAL_SHS_SetGainFactor( SHS0, gain_value, (uint32_t)adc->group_num, (uint32_t)adc->channel_num );
260+
}
261+
/* Start conversion manually using load event trigger*/
262+
XMC_VADC_GLOBAL_BackgroundTriggerConversion( VADC );
263+
value = XMC_VADC_GROUP_GetResult( adc->group, adc->result_reg_num );
264+
#else
265+
// XMC1100 no ADC grouping
266+
if( !(adc->enabled) )
267+
/* Add a channel to the background source. */
268+
VADC->BRSSEL[ ADC_CONVERSION_GROUP ] = (uint32_t)( 1U << adc->channel_num );
269+
/* Set the gain factor of the Sample and hold module */
270+
XMC_VADC_GLOBAL_SHS_SetGainFactor( SHS0, gain_value, XMC_VADC_GROUP_INDEX_0, (uint32_t)adc->channel_num );
271+
// Generates conversion request
272+
XMC_VADC_GLOBAL_BackgroundTriggerConversion( VADC );
273+
274+
// Wait until conversion is ready
275+
while( ( ( value = XMC_VADC_GLOBAL_GetDetailedResult( VADC ) ) & VADC_GLOBRES_VF_Msk) == 0u );
276+
#endif
277+
value = ( ( value & VADC_GLOBRES_RESULT_Msk) >> ( ADC_MAX_READ_RESOLUTION - _readResolution ) );
278+
return value;
279+
}
280+
#endif
281+
}
282+
219283

220284
/* Helper function for analogWrite and setAnalogWriteFrequency to scan
221285
mapping tables to determine for a given pin which PWM4, PWM8 or DAC

cores/wiring_analog.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
extern "C" {
2727
#endif
2828

29+
/*********************************************************************************************************************
30+
* MACROS
31+
********************************************************************************************************************/
32+
// ADC gain macros
33+
#define ADC_VAR_GAIN_FACTOR_1 0
34+
#define ADC_VAR_GAIN_FACTOR_3 1
35+
#define ADC_VAR_GAIN_FACTOR_6 2
36+
#define ADC_VAR_GAIN_FACTOR_12 3
37+
2938
//****************************************************************************
3039
// @External Prototypes
3140
//****************************************************************************
@@ -85,6 +94,22 @@ extern "C" {
8594
*/
8695
extern uint32_t analogRead( uint8_t channel ) ;
8796

97+
/*
98+
* \brief Reads the value from the specified analogue channel and add variable gain at input.
99+
*
100+
* \param channel
101+
* \param gain_factor
102+
*
103+
* gain value gain factor
104+
* 0 1
105+
* 1 3
106+
* 2 6
107+
* 3 12
108+
*
109+
* \return Read value from selected channel, or 0xFFFFFFFF for error.
110+
*/
111+
extern uint32_t analogRead_variableGain( uint8_t channel, uint8_t gain_value ) ;
112+
88113
/*
89114
* \brief Set the resolution of analogRead return values in number of bits.
90115
* \note Default is 10 bits (range from 0 to 1023).

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ getAnalogReadBits KEYWORD2
1616
getAnalogWriteBits KEYWORD2
1717
getAnalogReadMaximum KEYWORD2
1818
getAnalogWriteMaximum KEYWORD2
19+
analogRead_variableGain KEYWORD2
1920

2021
#######################################
2122
# Instances (KEYWORD2)

libraries/I2S/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The library has been tested with the XMC4700 Relax Kit, XMC1100 XMC 2Go, and XMC
3535

3636
`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.`
3737

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

4040
If we take the pin out of XMC for Arduino, the respective pins for SPI are redefined.
4141
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.

libraries/I2S/src/I2S.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161
#ifndef I2S_h
6262
#define I2S_h
6363

64-
#if defined(XMC4700_Relax_Kit) || defined(XMC1100_XMC2GO) || defined(XMC1100_Boot_Kit)
65-
#include "utility/xmc_i2s_conf.h"
66-
6764
typedef enum {
6865
I2S_PHILIPS_MODE,
6966
I2S_RIGHT_JUSTIFIED_MODE,
@@ -260,8 +257,4 @@ class I2SClass
260257

261258
extern I2SClass I2S;
262259

263-
#else
264-
#error "Only XMC4700 Relax Kit, XMC1100 XMC2Go or XMC1100 Boot Kit is supported for I2S"
265-
#endif
266-
267260
#endif /* I2S_h */

libraries/I2S/src/utility/xmc_i2s_conf.c

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)