Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


STM32F1 SPI Simpleton Implementation Fail

Hi Everyone,

This is about a HAL_SPI_Transmit() single byte transmit issue.
Attached you’ll find the CubeMX configuration project.

Below is code I added in main.c in an attempt to have a simple byte going out via SPI #2 (SPI2).

It is code with which the compiler does complain and says ‘warning: passing argument 2 of ‘HAL_SPI_Transmit’ makes pointer from integer without a cast’ at HAL_SPI_Transmit(&hspi2, pData, cnt, 10);

I follow logic, i.e. say a variable called Person between brackets as (Person) and assigning a number to is is making Person think of value and not Person becoming the value, thus Person as a pointer to a location where value is to be put. The pointer here is pData and the contents concerned located in (pData) thus where pData is pointing to as far as I am concerned. The compiler has other ideas.

/* USER CODE BEGIN 2 */

uint8_t cnt = 1;
uint8_t pData;
uint8_t TheDataItself = 0xFF;
(pData) = TheDataItself;
HAL_SPI_Transmit(&hspi2, pData, cnt, 10); // 10 is the time out value.

/* USER CODE END 2 */

At ‘HAL_SPI_Transmit(&hspi2, pData, cnt, 10);’ the compiler says ‘warning: passing argument 2 of ‘HAL_SPI_Transmit’ makes pointer from integer without a cast’.

By the /* */ comments you can imagine where I added the code in main.c.

Another question: In HAL_SPI_Transmit() pData is uint8_t of type while Size is of uint16_t type. That doesn’t make sense. How can a pointer only reach 255 while the size can go up to 65535. I don’t see any practical purpose in this.

Thanks for any advice,

Greets,
Ben

PS: SOLVED. I appropriately changed pData to &pData. Why? When looking in ST’s help file STM32F103xG HAL User Manual.chm HAL_SPI_Transmit() has pData declared as *pData.

France

Hi Ben,

First of all you should check that in your project settings at “project >> C/C++ Build >> Settings >> Tool Settings >> MCU GCC Compiler >> Warnings” the “All Warnings (-Wall)” option is checked. This will gives you warnings on potential errors you may have in your code.

Second, there is indeed several problems in your code:

  1. You do not need any parentheses in (pData) = ; you can write it simply as pData =
  2. pData, as its name implies, should be a pointer to uint8_t data (bytes);
    1. You should declare it as uint8_t *pData;
    2. Then you cannot assign it a byte, you must assign it the address of a byte, by pData = &TheDataItself;
    3. Finally you can pass to HAL_SPI_Transmit either pData or &TheDataItself, both will request HAL to transmit 1 byte of data (value of cnt), located in the TheDataItself variable
Probably the cleaner way to transmit a byte on the SPI would be to write:
uint8_t TheDataItself = 0xFF;
HAL_SPI_Transmit(&hspi2, &TheDataItself, sizeof(TheDataItself), 10); // 10 is the time out value.

Finally, I think you should read one of the numerous C programming courses you can find on the web: whatever it may look like, C is not a simple programming language, especially when going to pointers, and you need some guidance when starting to program in C.

Hope this helps clarifying things,

Bernard (Ac6)


Hi Bernard,

I’ve been looking in some C- language courses however DIY since by guidance doesn’t come free. Anyway, I changed pData to &pData and the SPI is effectively outputting TheDataItself. I know it’s wrong still by design since the compiler only allocated one byte and I would not be able to send 16 bits. The bummer is I need to send out 18 bits to external DACs. The nuissence is that the HAL library does many things out of protocol where I want to program straightforward not being interested in readability, portability or scalability. The Z80 way as you like. As like ’ SPI2->DR = 0xAA;’ instead of ‘HAL_SPI_Transmit(&hspi2, 0xAA, cnt, 10);’ which does too many things and wastes MIPS. ’ SPI2->DR = 0xAA’ works and so does ‘SPI2->DR = variable’. I’ll take your advice.