Electronics > Microcontrollers

Issue with STM32F1 pull up pin

(1/4) > >>

yashrk:
Hey guys, I am trying to learn bare metal programming and I was trying to get a pin B3 to be set as pull up, with following code. I am trying to check if the pin is pulled up via a multimeter and yes it is not pulled up. I have one pin C13 blinking an LED which is working fine.

I have written simple wrappers to make my life easy.


--- Code: ---#include "stm32f10x.h"
#include "_HAL_GPIO.h"


GPIO_TYPE ledGPIO;
GPIO_TYPE inputPin;

int main(void){
// Configuring GPIO

ledGPIO.port = PORTC;
ledGPIO.pin = 13;
ledGPIO.mode = OUTPUT_MODE;
ledGPIO.mode_type = OUTPUT_GEN_PURPOSE;
ledGPIO.speed = SPEED_50MHZ;

gpio_init(ledGPIO);

inputPin.port = PORTB;
inputPin.pin = 3;
inputPin.mode = INPUT_MODE;
inputPin.mode_type = INPUT_PU_PD;

gpio_init(inputPin);
inputPin.port -> ODR |= (1 << inputPin.pin); // Setting pull up


while(1) {

gpio_write(ledGPIO.port, ledGPIO.pin, LOW);
for ( int i = 0; i <= 5000000; i++);
gpio_write(ledGPIO.port, ledGPIO.pin, HIGH);
for ( int i = 0; i <= 5000000; i++);

}

}



--- End code ---

wek:
What hardware, a "known good" like Nucleo ro Disco, or your own? In the latter case, is there anything connected to that pin? Does setting PB3 to GPIO Output and "blinking" it does produce the expected changes on the output?

Read out and check/post content of GPIO registers.

JW

yashrk:

--- Quote from: wek on April 10, 2024, 05:09:35 pm ---What hardware, a "known good" like Nucleo ro Disco, or your own? In the latter case, is there anything connected to that pin?

--- End quote ---

This is a Bluepill, but you gave me a good idea that I can try running it using CubeIDE and then see if its an hardware problem or a software problem.

yashrk:
Yeah programming using CubeIDE also doesn't work  :-DD

pcprogrammer:
The code you posted is missing a lot of information.

You state to have written wrappers to make life easy, but not showing that code makes it harder for us to say what could be wrong.

What I don't get is why you made a structure for holding the information of a GPIO and then not pass that struct to your gpio_write function, but that is not why the code is failing of course.

Another question is what the system setup is. There is no clock configuration, no peripheral enable, etc shown in your code.  Clearly port C clock is enabled when you see the LED blink, but what about port B clock?

I would say, for bare metal stay clear from any ST software crap.

Here is an example project of mine. Fully bare metal.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod