cancel
Showing results for 
Search instead for 
Did you mean: 

i have a stm32f030k6t6, i don´t want work with Hal funtions, i want do example: #define led PAD_ODR12; // definition port A 12 output . . . while { led=1; delay_ms(200); led=0; } help me! i need a idea

jdo
Associate II
 
5 REPLIES 5
Artur IWANICKI
ST Employee

Hello. You can refer to one of our sessions where we demonstrate different coding methods without and with library usage. It is "Moving from 8 to 32 bits workshop".(especially part 7).

https://www.st.com/content/st_com/en/support/learning/stm32-education/stm32-moocs/Moving_from_8_to_32_bits_workshop_MOOC.html

You change state of a pin's output by writing to GPIOx_BSRR (which atomically changes GPIOx_ODR), so if LED is on e.g. PB4 you'd write something like

GPIOB->BSRR = 1 << 4; // set

delay_ms(200);

GPIOB->BSRR = 1 << (4 + 16); // clear

delay_ms(200); // if you don't put a delay after clear, you will not see LED blinking

There are macros in the device header, which may or may not be useful (I won't write the delay):

GPIOB->BSRR = GPIO_BSRR_BS4; // set

GPIOB->BSRR = GPIO_BSRR_BR4; // clear

Now you can write your own macros to change pins. This is something developers do themselves to their own liking. For example, I use the following:

#define PIN_SET(pin)  pin##_PORT->BSRR = (1 << (pin##_PIN + 0))

#define PIN_CLR(pin)  pin##_PORT->BSRR = (1 << (pin##_PIN + 16))

#define PIN_GET(pin)  ((pin##_PORT->IDR & (1 << pin##_PIN)) ? 1 : 0)

then in program

#define LED_PORT GPIOB

#define LED_PIN 4

PIN_SET(LED);

PIN_CLR(LED);

but there are many other ways to tackle this.

JW

Here is an usage of something similar, with the HI()/LO() macros being defined together with the individual pins here.

JW

THANKS, I GO TO READ

Hi, i understand the register BSRR and ODR for wirte output, but i want define BSRR or ODR with name LED, and set or clear using LED.

LED =1; // set ODR in 1.

LED =o; // clear ODR in 0.

i have example with stm8 with this macro:

#define led       PD_ODR_ODR4

#define led_dir   PD_DDR_DDR4

#define led_Push  PD_CR1_C14

#define led_fast  PD_CR2_C24

....

.

.

.

void inicializar_pin(void){

     led_dir   = 1;         //  Port D, bit 4 is output.

     led_Push  = 1;         //  Pin is set to Push-Pull mode.

     led_fast  = 1;      

}

// using the port:

led=1;

delay(200);

led=0;

delay(200);

i read macro stm32 in c, but i don´t find a macro how this,and i am doing but i have error compile. i don´t can modify ODR register using led=1.