0

I am currently working on adding some new functionality to a SAMD51 bootloader. The original bootloader code I am basing this off of is the Adafruit UF2 bootloader for SAMD microcontrollers, found here: https://github.com/adafruit/uf2-samdx1

I am currently grafting in some SD-card functionality using code from ASF4 (Atmel Software Framework 4).

I have a pair of files hal_atomic.h and hal_atomic.c that are defined as such:

hal_atomic.h:

#ifndef _HAL_ATOMIC_H_INCLUDED
#define _HAL_ATOMIC_H_INCLUDED

#include "../utils/compiler.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef uint32_t hal_atomic_t;

#define CRITICAL_SECTION_ENTER()             \
    {                                        \
        volatile hal_atomic_t __atomic;      \
        atomic_enter_critical(&__atomic);

#define CRITICAL_SECTION_LEAVE()             \
    atomic_leave_critical(&__atomic);        \
    }

void atomic_enter_critical(hal_atomic_t volatile *atomic);
void atomic_leave_critical(hal_atomic_t volatile *atomic);
uint32_t atomic_get_version(void);

#ifdef __cplusplus
}
#endif

#endif /* _HAL_ATOMIC_H_INCLUDED */

hal_atomic.c:

void atomic_enter_critical(hal_atomic_t volatile *atomic)
{
    *atomic = __get_PRIMASK();
    __disable_irq();
    __DMB();
}

void atomic_leave_critical(hal_atomic_t volatile *atomic)
{
    __DMB();
    __set_PRIMASK(*atomic);
}

uint32_t atomic_get_version(void)
{
    return DRIVER_VERSION;
}

When I attempt to compile this code, I am getting some errors. The code references a function in the CMSIS library called __get_PRIMASK'. That function is defined as follows in a file called core_cmFunc.h`:

__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
{
  uint32_t result;

  __ASM volatile ("MRS %0, primask" : "=r" (result) );
  return(result);
}

When I try to compile the code, I get the following errors:

/asf4/hal/hal_atomic.o: In function `__get_PRIMASK':
/lib/cmsis/CMSIS/Include/core_cmFunc.h:471: multiple definition of `atomic_enter_critical'
/asf4/hal/hal_atomic.o: /lib/cmsis/CMSIS/Include/core_cmFunc.h:471: first defined here

/asf4/hal/hal_atomic.o: In function `__get_PRIMASK':
/lib/cmsis/CMSIS/Include/core_cmFunc.h:471: multiple definition of `atomic_leave_critical'
/asf4/hal/hal_atomic.o: /lib/cmsis/CMSIS/Include/core_cmFunc.h:471: first defined here

/asf4/hal/hal_atomic.o: In function `__get_PRIMASK':
/lib/cmsis/CMSIS/Include/core_cmFunc.h:471: multiple definition of `atomic_get_version'
/asf4/hal/hal_atomic.o: /lib/cmsis/CMSIS/Include/core_cmFunc.h:471: first defined here

collect2.exe: error: ld returned 1 exit status

I'm not sure why it thinks these functions are defined multiple times. I was wondering if anyone could help me make sense of this? Thank you!!!

David
  • 1,847
  • 4
  • 26
  • 35

0 Answers0