Where is the actual source code for HAL_ADC_Read?

I’ve been noticing a large amount of ADC noise and there are a number of posts about addressing the noise on the older spark core devices. There is even some sample code which suggests modifying adc_hal.c. I am now able to locally build code but it appears that the new photon module uses this function instead:


Where is the source for DYNALIB_FN?

As the name suggests DYNALIB_FN() (all capital letters) is only a macro that helps dynamic binding of a particular function that’s passed in as paramerter

        #define DYNALIB_FN(tablename, name) \
            const char check_name_##tablename_##name[0]={}; /* this will fail if the name is already defined */ \
            void name() __attribute__((naked)); \
            void name() { \
                asm volatile ( \
                    ".equ offset, ( " __SX(__COUNTER__) " * 4)\n" \
                    ".extern dynalib_location_" #tablename "\n" \
                    "push {r3, lr}\n"           /* save register we will change plus storage for sp value */ \
                                                /* pushes highest register first, so lowest register is at lowest memory address */ \
                                                /* SP points to the last pushed item, which is r3. sp+4 is then the pushed lr value */ \
                    "ldr r3, =dynalib_location_" #tablename "\n" \
                    "ldr r3, [r3]\n"                    /* the address of the jump table */ \
                    "ldr r3, [r3, #offset]\n"    /* the address at index __COUNTER__ */ \
                    "str r3, [sp, #4]\n"                /* patch the link address on the stack */ \
                    "pop {r3, pc}\n"                    /* restore register and jump to function */ \
                ); \

So judging by this


I’d guess you want to know where to find HAL_ADC_Read(), but if I want to find a particlular function I just do a file system search (e.g. grep) on the local clone of the firmware repo and select the one that matches my desired platform.

1 Like

Thanks I normally do a search and I found 3 files with HAL_ADC_read. I put an intentional syntax error in all three locations and did a make clean and the code still compiled.

So that function source code is linking in from somewhere else.

My guess is that the Photon is making use of ST’s HAL but I’m not familiar enough with the code to prove that to myself.

Has anyone characterized the ADC I’m seeing +/- 5 counts on a pure DC signal with low impedance and local decoupling. I expected better, and I believe it has to do with running the ADC too fast based on prior experience with other chips.

Is the DC source referenced to the devices 3V3 rail ?

One serious problem with the ADC is the fact that the only reference is the 3V3 rail, so for an external voltage source, the reference can move more than you’d wish. This may be the source of your variability.

I believe that if you need accurate measurements, the built-in ADC capability is only usable for ratiometric readings that are derived directly from the 3V3 rail (e.g. a potential divider.)

For non-ratiometric uses or when high accuracy is desired, I suggest an i2c or spi connected external ADC to your specs.

1 Like

The ADC i’m reading is directly divided off the 3.3V rail.

Ok. So I’m building code from the “Latest” branch. I’m running make with “Photon” because I’m using a “Photon” module.

I’ve got this .h file acd_hal.h

void HAL_ADC_Set_Sample_Time(uint8_t ADC_SampleTime);
int32_t HAL_ADC_Read(pin_t pin);
void HAL_ADC_DMA_Init();

I’ve spent hours looking now and I cannot find the definition for HAL_ADC_Read. Will someone please tell me what the name of the c file that contains this function is?

I can tell you where it is not:


I just don’t understand how the code compiles. Is there something tricky going on like code getting pulled in from some precompiled library? Please help.

That’s where it is - what is it that makes you think otherwise?

1 Like

I put some code in that file which would for sure cause a syntax error and the binary still compiled. Changes to that file don’t seem to affect the overall build. I’ve tried building with a command line as well as building with a netbeans project.

What is the command line you’re building with?