Is SW4STM32 Little or Big Endian?
Hi All,
Pointers in C.
Is SW4STM32 Little or Big Endian? Which compiler decides GNU or the ARM Cross compiler?
example:
uint32_t TheDataItself = 0;
uint32_t *p32Data = &TheDataItself;
uint8_t *p8Data = (uint8_t*)p32Data;
Where does *p8Data point to? The MSB or the LSB of TheDataItself, a 4 byte unsigned integer as declared above.
(*p8Data+1) jumps the pointer 1 byte further. Correct?
Does (*p32Data+1) jump the pointer 3 bytes or 1 byte?
Greets,
Ben
PS: In everyone’s interest I solved my problem not exactly knowing the endian type. I threw a few trials and got what I wanted. See below. It’s about SPI only being able to shoot maximum 16 bits per transfer while I need at least 18 bit. Solved it by successfully splitting a 32 bit unsigned integer into two unsigned 16 bit integers. Still needed to create an uint8_t *pData for the HAL_SPI_Transmit()’s sake.
(...)
GPIOB->ODR |= 0x4000; // prepare PCM61P LE to HIGH
uint16_t cnt = 1;
uint32_t DAC_Word = 0;
uint32_t *p32Data = &DAC_Word; // p32Data is pointer to DAC_Word - assured both 32bit space!
uint16_t *p16Data = (uint16_t*)p32Data; // p8Data is pointer to p16Data!
uint8_t *p8Data = (uint8_t*)p32Data; // necessary for HAL_SPI_Transmit()
HAL_SPI_Transmit(&hspi2, p8Data, cnt, 10); // obligatory to prepare SPI hardware registers & flags
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
for (DAC_Word=0;DAC_WordDR = *(p16Data+1); // most significan 16-bit word of DAC_Word
for (IdleTom=0;IdleTomODR |= 0x4000; // PCM61P LE to HIGH
SPI2->DR = *p16Data; // least significan 16-bit word of DAC_Word
for (IdleTom=0;IdleTomODR &= 0xBFFF; // PCM61P LE to LOW
}
/* USER CODE BEGIN 3 */
(...)
The HAL library might be easing a lot of work but it does some code bloating slowing down simple intentions. It’s a joy wading through it to look for the core instructions which are related to the MCU’s registers.