Skip to content

Commit

Permalink
Merge pull request #238 from 9Volts9er/develop
Browse files Browse the repository at this point in the history
GPIO Init after USIC CH Start
  • Loading branch information
boramonideep committed May 17, 2023
2 parents f58509d + aa4d0bd commit 70b950a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 49 deletions.
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
32 changes: 6 additions & 26 deletions libraries/SPI/src/HW_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ void SPIClass::init()
/* Configure the data input line selected */
XMC_SPI_CH_SetInputSource(XMC_SPI_config->channel, XMC_SPI_CH_INPUT_DIN0, (uint8_t)XMC_SPI_config->input_source);

/* Start the SPI_Channel */
XMC_SPI_CH_Start(XMC_SPI_config->channel);

/* Initialize SPI SCLK out pin */
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_SPI_config->sclkout.port, (uint8_t)XMC_SPI_config->sclkout.pin, &(XMC_SPI_config->sclkout_config));

/* Configure the input pin properties */
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_SPI_config->miso.port, (uint8_t)XMC_SPI_config->miso.pin, &(XMC_SPI_config->miso_config));

/* Configure the output pin properties */
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_SPI_config->mosi.port, (uint8_t)XMC_SPI_config->mosi.pin, &(XMC_SPI_config->mosi_config));

/* Initialize SPI SCLK out pin */
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_SPI_config->sclkout.port, (uint8_t)XMC_SPI_config->sclkout.pin, &(XMC_SPI_config->sclkout_config));

/* Start the SPI_Channel */
XMC_SPI_CH_Start(XMC_SPI_config->channel);

interruptMode = SPI_IMODE_NONE;
interruptSave = 0;
interruptMask = 0;
Expand All @@ -122,28 +122,8 @@ void SPIClass::end()
// Only disable HW when USIC is used for SPI
if((XMC_SPI_config->channel->CCR & USIC_CH_CCR_MODE_Msk) == XMC_USIC_CH_OPERATING_MODE_SPI)
{
XMC_GPIO_CONFIG_t default_input_port_config = {
.mode = XMC_GPIO_MODE_INPUT_TRISTATE,
.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH,
#if UC_FAMILY == XMC1
.input_hysteresis = XMC_GPIO_INPUT_HYSTERESIS_STANDARD
#endif
};

XMC_GPIO_CONFIG_t default_output_port_config = {
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW,
#if UC_FAMILY == XMC1
.input_hysteresis = XMC_GPIO_INPUT_HYSTERESIS_STANDARD
#endif
};

XMC_SPI_CH_Stop(XMC_SPI_config->channel);

XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_SPI_config->miso.port, (uint8_t)XMC_SPI_config->miso.pin, &default_input_port_config);
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_SPI_config->mosi.port, (uint8_t)XMC_SPI_config->mosi.pin, &default_output_port_config);
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_SPI_config->sclkout.port, (uint8_t)XMC_SPI_config->sclkout.pin, &default_output_port_config);

XMC_SPI_config->channel->DXCR[XMC_USIC_CH_INPUT_DX0] = (uint32_t)(XMC_SPI_config->channel->DXCR[XMC_USIC_CH_INPUT_DX0] | (USIC_CH_DX0CR_DSEN_Msk)) & (~USIC_CH_DX0CR_INSW_Msk);
XMC_USIC_CH_SetInputSource(XMC_SPI_config->channel, XMC_USIC_CH_INPUT_DX0, XMC_INPUT_A);
}
Expand Down
28 changes: 8 additions & 20 deletions libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ void TwoWire::begin(void)
0,
XMC_USIC_CH_FIFO_SIZE_16WORDS,
(uint32_t)(15));

XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->sda.port, (uint8_t)XMC_I2C_config->sda.pin, &(XMC_I2C_config->sda_config));
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->scl.port, (uint8_t)XMC_I2C_config->scl.pin, &(XMC_I2C_config->scl_config));


XMC_USIC_CH_SetInterruptNodePointer(XMC_I2C_config->channel,
XMC_USIC_CH_INTERRUPT_NODE_POINTER_PROTOCOL,
XMC_I2C_config->protocol_irq_service_request);
Expand All @@ -109,6 +106,9 @@ void TwoWire::begin(void)
XMC_I2C_CH_EnableEvent(XMC_I2C_config->channel, (uint32_t)(XMC_I2C_CH_EVENT_NACK | XMC_I2C_CH_EVENT_DATA_LOST | XMC_I2C_CH_EVENT_ARBITRATION_LOST | XMC_I2C_CH_EVENT_ERROR));

XMC_I2C_CH_Start(XMC_I2C_config->channel);

XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->sda.port, (uint8_t)XMC_I2C_config->sda.pin, &(XMC_I2C_config->sda_config));
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->scl.port, (uint8_t)XMC_I2C_config->scl.pin, &(XMC_I2C_config->scl_config));
}

void TwoWire::begin(uint8_t address)
Expand All @@ -126,9 +126,6 @@ void TwoWire::begin(uint8_t address)
XMC_USIC_CH_SetInputSource(XMC_I2C_config->channel, XMC_USIC_CH_INPUT_DX0, XMC_I2C_config->input_source_dx0);
XMC_USIC_CH_SetInputSource(XMC_I2C_config->channel, XMC_USIC_CH_INPUT_DX1, XMC_I2C_config->input_source_dx1);

XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->sda.port, (uint8_t)XMC_I2C_config->sda.pin, &(XMC_I2C_config->sda_config));
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->scl.port, (uint8_t)XMC_I2C_config->scl.pin, &(XMC_I2C_config->scl_config));

XMC_USIC_CH_SetInterruptNodePointer(XMC_I2C_config->channel,
XMC_USIC_CH_INTERRUPT_NODE_POINTER_RECEIVE,
XMC_I2C_config->slave_receive_irq_service_request);
Expand All @@ -154,6 +151,9 @@ void TwoWire::begin(uint8_t address)
XMC_I2C_CH_EnableEvent(XMC_I2C_config->channel, (uint32_t)((uint32_t)XMC_I2C_CH_EVENT_SLAVE_READ_REQUEST | (uint32_t)XMC_I2C_CH_EVENT_STOP_CONDITION_RECEIVED));

XMC_I2C_CH_Start(XMC_I2C_config->channel);

XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->sda.port, (uint8_t)XMC_I2C_config->sda.pin, &(XMC_I2C_config->sda_config));
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->scl.port, (uint8_t)XMC_I2C_config->scl.pin, &(XMC_I2C_config->scl_config));
}

void TwoWire::begin(int address)
Expand All @@ -166,19 +166,7 @@ void TwoWire::end(void)
// Only disable HW when USIC is used for I2C
if((XMC_I2C_config->channel->CCR & USIC_CH_CCR_MODE_Msk) == XMC_USIC_CH_OPERATING_MODE_I2C)
{

XMC_GPIO_CONFIG_t default_output_port_config = {
.mode = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN,
.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH,
#if UC_FAMILY == XMC1
.input_hysteresis = XMC_GPIO_INPUT_HYSTERESIS_STANDARD
#endif
};

XMC_I2C_CH_Stop(XMC_I2C_config->channel);

XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->sda.port, (uint8_t)XMC_I2C_config->sda.pin, &default_output_port_config);
XMC_GPIO_Init((XMC_GPIO_PORT_t*)XMC_I2C_config->scl.port, (uint8_t)XMC_I2C_config->scl.pin, &default_output_port_config);
XMC_I2C_CH_Stop(XMC_I2C_config->channel);

XMC_USIC_CH_SetInputSource(XMC_I2C_config->channel, XMC_USIC_CH_INPUT_DX0, XMC_INPUT_A);
XMC_USIC_CH_SetInputSource(XMC_I2C_config->channel, XMC_USIC_CH_INPUT_DX1, XMC_INPUT_A);
Expand Down

0 comments on commit 70b950a

Please sign in to comment.