2020-04-19 09:33 AM
Hi to all,
I'm trying to use the Nucleo F446RE board to switch on an external LED. by using directly the registers
IN particular, I have connected the pin PA5 in series with a resistor, a LED and finally with the GND of the board.
The code uses is shown before. Initially I have activated the AHB1 internal pheripheral. Then, I enabled and forced to HIGH the pin PA5 of the board.
int main(int argc, char* argv[])
{
/** AHB1 **/
volatile uint32_t *RCC_AHB1ENR = 0x0;
RCC_AHB1ENR = (uint32_t*)(0x40023800 + 0x30);
*RCC_AHB1ENR = *RCC_AHB1ENR | 0x1;
/** GPIOA **/
volatile uint32_t *GPIOA_MODER = 0x0, *GPIOA_ODR = 0x0;
GPIOA_MODER = (uint32_t*)0x40020000;
*GPIOA_MODER = *GPIOA_MODER | 0x400;
GPIOA_ODR = (uint32_t*)(0x40020000 + 0x14);
*GPIOA_ODR = *GPIOA_ODR | 0x20;
/** Infinite loop **/
while (1);
}
The code is correctly compiled and loaded on the board, bu the problem is that the LED doesn't turn on. Can someome suggest how to modify the code? There are some other registers to modify? Something else to do?
Thank you very much in advance.
2020-04-19 09:52 AM
Code looks good.
Don't you have some debugger installed, so that you can observe the registers?
Isn't the LED reverse polarized? Can you measure the pin's voltage using multimeter?
JW
2020-04-19 11:14 AM
Pin PA5 is already connected to the green LED on that board. You should not need to add another LED. Your code works on my copy of that board.
2020-04-19 12:16 PM
I have no a debugger installed yet. I'm just I'm just studying and Learning the basics, so I wanted to start coding. THe LED is not reverse polarized, but I cannot verify because I have no a multimiter.
Thank you for the answer. I think the code is correct, I have to verify why it doesn't work in some way.
2020-04-19 12:18 PM
Yes I know that PA5 is connected to the green led of the board, but in this case I'm using as a general purpose output, just to try to code a very simple program.
What IDE do you use? There is some trick that can make the code not working during the flashing?
2020-04-19 12:21 PM
Yes I know that PA5 is connected to the green led of the board, but in this case I'm using as a general purpose output, just to try to code a very simple program.
I already tried to change Pin but nothing changed. What IDE do you use? There is some trick that can make the code not working during the flashing?
2020-04-19 12:38 PM
I'm using STMCubeIDE. Maybe you start with a C code example. Code can be generated by STM32CubeIDE. You only add few lines. There is a short intro video https://youtu.be/eumKLXNlM0U. Here are some more examples, but for a different board: https://gitlab.com/stm32mcu/wiki/-/wikis/home
2020-04-19 01:04 PM
@FGiai.1
How exactly do you compile the program? And how exactly do you "burn" the binary into the board?
@KnarfB ,
Can you please post the proven working binary/hex?
JW
2020-04-19 01:17 PM
2020-04-19 01:34 PM
Here is the complete project. It uses @FGiai.1 code as main() in a cube generated project. The only difference to HAL code (not used here) I see is, that HAL code reads *RCC_AHB1ENR back to a volatile dummy variable after the write. Didn't find a hint in the ref man that this is needed.