702 views
in System Integration by
Hello,

I'm Working on a STM32 based hardware, and want ot implement an SPI communication launched by the gui.

I have initialized the SPI peropherals in the init of a Deviceclass Object.

I'd like to call the HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout) function from a native statement insert in a Command Method of the Deviceclass autoobject.

My question in, what would be the correct way to pass to this function the uint8_t *pData array pointer, and eventually the array?

Thanks.

1 Answer

0 votes
by

Hello Riccardo_F,

if you plan is to pass Chora array to C function, you should know that in the generated code the array is a usual C array. You can pass it directly. For example:

array uint8  data[16];
var   uint16 size;

data[0]  = ...
data[1]  = ...
data[15] = ...
size     = 16;

native ( data, size )
{
  extern HAL_SPI_Transmit( SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size,
                           uint32_t Timeout);

  HAL_SPI_Transmit( ???, data, size, ??? );
}

I hope it answers your question.

Best regards

Paul Banach

 

by
//method declaration

method bool SPI_Send
(
     arg uint8           arrayData                //how do I pass an array here?
     arg unit16          arraySize
     arg comTimeout      comTimeout
)





//method implementation



$if $prototyper

//for Chora error unused variables 

comTimeout;
arrayData;
arraySize;

$endif


$if !$prototyper


var bool send_result=false;

  native (arrayData,arraySize,comTimeout,send_result)
  {

      extern HAL_SPI_Transmit( SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size,uint32_t Timeout);

      send_result = (HAL_SPI_Transmit(&hspi2,&arrayData,arraySize, comTimeout) == HAL_OK) ; 

  }

  return send_result;

$endif

Ok, but how do i pass an array in the method declaration or a pointer to that? 

 

i get this error

by

Hello Riccardo_F,

passing arrays in Chora methods via parameters or return values is not possible. To workaround it, you can create a class containing an array member and pass an object of such class in method parameter. Then within the method you can access the array found inside the object.

Nevertheless, if you plan to pass the array to native statement, an additional step will be required where a locally declared array is used and the data from the array found in the object are copied to the local array. Then the local array can be passed to native statement. Passing members of objects to native statement is not possible.

I hope it helps you further.

Best regards

Paul Banach

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...