Page 1 of 1

GPIO

Posted: Mon 19. Feb 2024, 12:44
by Jakob
Hello

I am trying to use the GPIO Pins as Output based on CAN Signals. I already did the CAN Message part but now I am stuck with the configuration of the Output. I downloaded the DevPack from [0] and found a function HW_GetDIN in hardware.c and also a HW_SetDOUT in hardware.h but there is no such function in hardware.c. From the HW_GetDIN-Function I assume that the GPIOS are connected to the pin 4,5,6, and 7 of the register K. However setting the Mode Register and the Ouput register

GPIOK->MODER |= 0x00005500;
GPIOK->ODR = GPIOK->ODR | 0x000000F0;

did not help. Can you please help?

Regards
Jakob

--- hardware.c ---------------------------------------------------------------

Code: Select all

//! @brief      get DINs 3...0 from I/O pins
//! @param[out] buffer  result buffer (single uint32_t)
HWResult_t  HW_GetDIN ( uint32_t  *buffer)
{
	if ( buffer == NULL)
	 { return HW_ERR_ILLPARAMVAL;}
	buffer[0] = (( GPIOK->IDR >> 4) & 0xF) ^ 0xF;
	return HW_ERR_OK;
}
--------------------------------------------------------------------------------

[0] link to WEB Page removed...** ADMIN **

Re: GPIO

Posted: Mon 19. Feb 2024, 12:53
by PEAK-Support
Please download the latest Package - we have add functions for all Digital / Analog Port(s) that we officially support (part of the Connector - all other Pins should not be used !)

Code: Select all

//! @brief      get AIN from I/O pins
//!
//! @param      buffer  result buffer (single uint32_t)
//!
//! @return             one error of HW_ERR_...
HWResult_t  HW_GetAIN ( uint32_t  *buffer);


//! @brief
//! Read digital inputs. Each bit will represent a digital pin.
//!
//! @param		buffer		Buffer for DIN-value
//!
//! @return		one error of HW_ERR_...
HWResult_t  HW_GetDIN ( uint32_t  *buffer);


//! @brief
//! Set digital outputs. Each bit will represent a digital pin.
//! 
//! @param		buffer		Buffer for DOUT-value
//!
//! @return		one error of HW_ERR_...
HWResult_t  HW_SetDOUT ( uint32_t  *buffer);
If you need some Debug help, and therefor want to use the additional Pins, please check the Debug Folder of the Package.
There you find more information how to do a real single Step Debug via JTAG.

FYI- in the hardware.c file of the HW_IO Sample project, you find all functions as source code:

Code: Select all

//! @brief      get AIN from I/O pins
//! @param[out] buffer  result buffer (single uint32_t)
HWResult_t  HW_GetAIN ( uint32_t  *buffer)
{
   if ( buffer == NULL)
    { return HW_ERR_ILLPARAMVAL;}

   // clear EOC flag
   buffer[0] = ADC2->DR & 0xFFF;
   ADC2->SQR3 = 6;
   ADC2->CR2 |= 1 << 30;
   
   // wait EOC flag
   while ( !( ADC2->SR & ( 1 << 1)))
    {}

   // return raw value
   buffer[0] = ADC2->DR & 0xFFF;

   return HW_ERR_OK;
}



//! @brief      get DINs 3...0 from I/O pins
//! @param[out] buffer  result buffer (single uint32_t)
HWResult_t  HW_GetDIN ( uint32_t  *buffer)
{
	if ( buffer == NULL)
	 { return HW_ERR_ILLPARAMVAL;}

	buffer[0] = (( GPIOK->IDR >> 4) & 0xF) ^ 0xF;
	
	return HW_ERR_OK;
}



//! @brief      set DOUTs 3 ... 0 of the I/O pins
//! @param[in]  buffer input buffer ( single uint32_t)
HWResult_t  HW_SetDOUT ( uint32_t  *buffer)
{
   if ( buffer == NULL)
	 { return HW_ERR_ILLPARAMVAL;}
   
   FPGA->SYS_DOUT_WR = buffer[0];

   return HW_ERR_OK;
}