Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
{
"configurations": [
{
"name": "Linux",
"name": "Linux-ARM",
"includePath": [
"${workspaceFolder}/**"
"${workspaceFolder}/**", // Your project headers
"/usr/include", // System headers
"/usr/local/include", // Extra system headers
"/opt/arm-toolchain/include" // Toolchain headers (adjust path)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The include path "/opt/arm-toolchain/include" is an absolute path specific to a particular machine setup. This makes the workspace configuration non-portable for other contributors. Consider using environment variables or relative paths to ensure the project can be configured correctly on different systems.

],
"defines": [
"STM32F407xx", // Example MCU macro, adjust as needed
"USE_HAL_DRIVER", // HAL driver macro if using STM32 HAL
"__GNUC__" // Compiler macros
],
"defines": [],
"cStandard": "c99",
"intelliSenseMode": "linux-gcc-arm",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-arm", // Use ARM GCC IntelliSense
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"browse": {
"path": [
"${workspaceFolder}/**",
"/usr/include",
"/usr/local/include",
"/opt/arm-toolchain/include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
Expand Down
19 changes: 19 additions & 0 deletions bsp/Inc/ADC.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,23 @@ adc_status_t adc_read(ADC_HandleTypeDef *h, ADC_ChannelConfTypeDef* sConfig, Que
*/
adc_status_t adc_deinit(ADC_HandleTypeDef *h);

/**
* @brief Returns the ADC reference voltage.
*
* This function retrieves the reference voltage (Vref) used by the ADC
* for conversion scaling. The value represents the voltage against which
* all ADC input measurements are compared.
*
* @note The returned value is typically in millivolts (mV), but this depends
* on the implementation. Ensure unit consistency when using it in
* calculations.
*
* @return uint32_t
* The ADC reference voltage value.
*
* @warning The ADC must be initialized and properly configured before
* calling this function, otherwise the returned value may be invalid.
*/
uint32_t adc_get_vref(void);

#endif
8 changes: 6 additions & 2 deletions bsp/Src/ADC.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ adc_status_t adc_deinit(ADC_HandleTypeDef *h) {
if (HAL_ADC_DeInit(h) != HAL_OK) return ADC_DEINIT_FAIL;

return ADC_OK;
}
}

uint32_t adc_get_vref(void) {
// this wasn't my doing
return ADC_CHANNEL_VREFINT;
}
Comment on lines +52 to +55
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The function adc_get_vref is documented to return the reference voltage for scaling calculations, but it currently returns ADC_CHANNEL_VREFINT. In the STM32 HAL, ADC_CHANNEL_VREFINT is a macro used to select the internal reference channel (typically a bitmask or index), not a voltage value. This will cause incorrect results in any scaling logic. It should return the actual reference voltage (e.g., 3300 for 3.3V).

uint32_t adc_get_vref(void) {
    return 3300; // Return nominal VREF in mV
}


adc_status_t adc_read(ADC_HandleTypeDef *h, ADC_ChannelConfTypeDef* sConfig, QueueHandle_t q) {
if (sConfig == NULL || h == NULL || q == NULL) {
return ADC_CHANNEL_CONFIG_FAIL;
}
}

// BSP only configures channel ranks
#if defined(STM32F4xx)
Expand Down
Loading
Loading