I created a C project for the SAMD10 MCU and have an issue that i did not have before with the same code.
I have to add that i uninstalled my previous version of ATMEL studio and installed the latest version ( 7.0.2397 ).
my problem is that i get a warning about implicit declaration when i use the delay function in the "asdf.c" file , but i don't get the warning when i use the delay function in the main.c file.
The "implicit declaration of function '_delay_ms' [-Wimplicit-function-declaration]" warning takes me to the "asdf.c" file , not the delay function in the "main.c" file.
How do i properly use the delay function in other files thna the "main.c" file ?
Here are the contents 4 files...
main.c
#define F_CPU 8000000UL #include "sam.h" #include "delay.h" #include "asdf.h" int main(void) { /* Initialize the SAM system */ SystemInit(); /* Replace with your application code */ while (1) { _delay_ms(11); } }
asdf.h
void asdf_func(int asdf_var);
asdf.c
void asdf_func(int asdf_var) { asdf_var+1; _delay_ms(11); }
delay.h
#ifndef DELAY_H_HEADER #define DELAY_H_HEADER #define RAMFUNC __attribute__ ((section(".ramfunc"))) #define OPTIMIZE_HIGH __attribute__((optimize("Os"))) #define cpu_ms_2_cy(ms, f_cpu) (((uint64_t)(ms) * (f_cpu) + (uint64_t)(7e3-1ul)) / (uint64_t)7e3) #define cpu_us_2_cy(us, f_cpu) (((uint64_t)(us) * (f_cpu) + (uint64_t)(7e6-1ul)) / (uint64_t)7e6) #define delay_cycles portable_delay_cycles #define cpu_delay_s(delay) delay_cycles(cpu_ms_2_cy(1000 * delay, F_CPU)) #define cpu_delay_ms(delay) delay_cycles(cpu_ms_2_cy(delay, F_CPU)) #define cpu_delay_us(delay) delay_cycles(cpu_us_2_cy(delay, F_CPU)) #define _delay_us cpu_delay_us #define _delay_ms cpu_delay_ms #define _delay_s cpu_delay_s // Delay loop is put to SRAM so that FWS will not affect delay time OPTIMIZE_HIGH RAMFUNC void portable_delay_cycles(uint32_t n) { __asm ( "loop: DMB \n" #ifdef __ICCARM__ "SUBS r0, r0, #1 \n" #else "SUB r0, r0, #1 \n" #endif "CMP r0, #0 \n" "BNE loop " ); }