cancel
Showing results for 
Search instead for 
Did you mean: 

32F051K86 GPIO initialization problem LL_ libraries

Adrian.M
Associate II

I have a bootloader + 1 wire serial uploader code

because of space restrictions it uses LL_ libraries for initialization.

We have different hardware designs,

when using PA2 as IO pin it works !

when using PB4 as IO it does not !

The main program uses HAL_libraries

there both pins work as expected.

are there differences in Initialization between GPIOA and GPIOB

when using LL_ ?

what am I missing ?????

this is the initialization section

void systemGpioInit(void) {
  LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
  LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
 
  GPIO_InitStruct.Pin = INPUT_PIN;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  LL_GPIO_Init(INPUT_GPIO, &GPIO_InitStruct);
}

5 REPLIES 5
TDK
Guru

There's no difference in initialization. Gotta be a bug somewhere, doesn't appear to be in the small section of code you posted. Keep checking.

Examine the GPIO registers.

If you feel a post has answered your question, please click "Accept as Solution".
Adrian.M
Associate II

@TDK

How can that be ?

when using PA2

the 1 wire read routine recognizes the bootloader init string correctly

(0x0d 0x42 0x4c 0x48 0x65 0x6c 0x69 0xf4 0x7d)

when using PB4 i get

(0x34 0x08 0x30 0x20 0x94 0xb0 0xa4 0xd0 0xf4)

This is the read routine :

void fourWayGetChar() {
  fourWayConfigReceive();
  fourWayRxByte = 0;
 
  while (!(INPUT_GPIO->IDR & INPUT_PIN)) {
    // wait for rx to go high
  }
 
  while ((INPUT_GPIO->IDR & INPUT_PIN)) {
    // wait for rx to go low
    if (TIM2->CNT > 250 && fourWayCharReceived) {
      return;
    }
  }
  // wait to get the center of bit time
  delayMicroseconds(FOUR_WAY_BIT_TIME_HALF);
 
  uint8_t bitIndex = 0;
  while (bitIndex < 8) {
    delayMicroseconds(FOUR_WAY_BIT_TIME);
    fourWayRxByte = fourWayRxByte | ((( INPUT_GPIO->IDR & INPUT_PIN)) >> FOUR_WAY_SHIFT_AMOUNT) << bitIndex;
    bitIndex++;
  }
  // wait till the stop bit time begins
  delayMicroseconds(FOUR_WAY_BIT_TIME_HALF);
  fourWayCharReceived = true;
}
 
void fourWayConfigReceive() {
  LL_GPIO_SetPinMode(INPUT_GPIO, INPUT_PIN, LL_GPIO_MODE_INPUT);
}
 
void fourWayConfigTransmit() {
  LL_GPIO_SetPinMode(INPUT_GPIO, INPUT_PIN, LL_GPIO_MODE_OUTPUT);
}
 
void delayMicroseconds(uint32_t micros) {
  TIM2->CNT = 0;
  while (TIM2->CNT < micros) {
    // wait
  }
}

Adrian.M
Associate II

A small update:

I took a closer look at the received data in binary

I use 19200baud 8N1

PB4 (bad) , PA2 (good) , PBX = PB4 >>2

PB4 1011 0000 1010 0100 1101 0000 1111 0100

PA2 0110 1100 0110 1001 1111 0100 0111 1101

PBX xx10 1100 0010 1001 0011 0100 0011 1101

It seems that the data is delayed approximate 100µs and some "Hi" bits do not get read.

Like some sort of capacitance pull down lowpass filter is active on the input.

TDK
Guru

Looks like the external pullup could be too weak, or missing. Or the pin is connected to something else on the board affecting the signal.

If you feel a post has answered your question, please click "Accept as Solution".
Adrian.M
Associate II

@TDK​ 

No.

  1. there is no external influence (i removed the external components)
  2. I also connected the pins together (the same pa2 works pb4 not)
  3. I use the internal pullup (GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;)

This is definitely a LL_ library problem

I will begin debugging GPIO and RCC registers, to see the differences !

br, adrian