This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issue with Bare-Metal Programming of nRF52-DK

Hey everyone,

I've been trying to get this basic bare-metal application to work. I don't need a softdevice as I'm just trying to turn on an LED. The application compiles just fine, I can step through the code with the debugger, but the registers don't seem to be set! Can anyone help?

Thanks,

~Aaron

nRF52_Temp.zip

Parents
  • Hi,

    I tested your code and saw the same behaviour. Adding the 'volatile' keyword to *ptr seemed to fix it.

    volatile uint32_t* ptr = (uint32_t*) 0x5000072C;

    I'm no compiler expert so I can't explain why though. I just a had hunch. 

  • Hi @MartinBL,

    Thanks for your response. That's definitely a step in the right direction! Now, if we change that entire section to:

    GPIO->PIN_CNF[11] = ((uint32_t) GPIO_PIN_CNF_DIR_OUTPUT << GPIO_PIN_CNF_DIR_Pos) |
        ((uint32_t) GPIO_PIN_CNF_INPUT_DISCONNECT << GPIO_PIN_CNF_INPUT_Pos) |
        ((uint32_t) GPIO_PIN_CNF_NOPULL << GPIO_PIN_CNF_PULL_Pos) |
        ((uint32_t) GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) |
        ((uint32_t) GPIO_PIN_CNF_NOSENSE << GPIO_PIN_CNF_SENSE_Pos);
    GPIO->OUTSET = (1UL << 11);

    You'll notice that it doesn't work again! I don't understand! The definition of those register types have all volatile members.

    Thanks,

    ~Aaron

  • Seems to work for me. Can you try to read out the GPIO->PIN_CNF[11] register with

    nrfjprog --memrd 0x5000072C

    before and after you configure the GPIO?

    My output is 00000002 before the configuration and 00000303 after, which is the correct configuration. 

    This code toggles LED_2 on my nRF52 DK kit. 

    #include "board.h"
    #include "basics.h"
    
    int main(void) {
      init(); // Test
    
      while (1) {
        GPIO->PIN_CNF[18] = ((uint32_t) GPIO_PIN_CNF_DIR_OUTPUT << GPIO_PIN_CNF_DIR_Pos) |
          ((uint32_t) GPIO_PIN_CNF_INPUT_DISCONNECT << GPIO_PIN_CNF_INPUT_Pos) |
          ((uint32_t) GPIO_PIN_CNF_NOPULL << GPIO_PIN_CNF_PULL_Pos) |
          ((uint32_t) GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) |
          ((uint32_t) GPIO_PIN_CNF_NOSENSE << GPIO_PIN_CNF_SENSE_Pos);
        GPIO->OUTSET = (1UL << 18);
        GPIO->OUTCLR = (1UL << 18);
      }
    
      return 0;
    

Reply
  • Seems to work for me. Can you try to read out the GPIO->PIN_CNF[11] register with

    nrfjprog --memrd 0x5000072C

    before and after you configure the GPIO?

    My output is 00000002 before the configuration and 00000303 after, which is the correct configuration. 

    This code toggles LED_2 on my nRF52 DK kit. 

    #include "board.h"
    #include "basics.h"
    
    int main(void) {
      init(); // Test
    
      while (1) {
        GPIO->PIN_CNF[18] = ((uint32_t) GPIO_PIN_CNF_DIR_OUTPUT << GPIO_PIN_CNF_DIR_Pos) |
          ((uint32_t) GPIO_PIN_CNF_INPUT_DISCONNECT << GPIO_PIN_CNF_INPUT_Pos) |
          ((uint32_t) GPIO_PIN_CNF_NOPULL << GPIO_PIN_CNF_PULL_Pos) |
          ((uint32_t) GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) |
          ((uint32_t) GPIO_PIN_CNF_NOSENSE << GPIO_PIN_CNF_SENSE_Pos);
        GPIO->OUTSET = (1UL << 18);
        GPIO->OUTCLR = (1UL << 18);
      }
    
      return 0;
    

Children
Related