2024-02-08 03:49 PM
Hi,
How would one go about giving access to hardware handles in source files other than `main.c`? For instance, the ADC state is stored in a struct called `hadc3` in `main.c`, without an access modifier. I would assume that this is extern by default, but the linker doesn't pick it up when referencing from any other source file. Instead, I get something like:
For reference I am trying to initialize and control a peripheral from a ThreadX thread. Something like:
VOID tbw_thread_entry(ULONG initial_input) {
HAL_ADC_Start(&hadc3);
while (1) {
HAL_ADC_PollForConversion(&hadc3, 20);
int adc_value = HAL_ADC_GetValue(&hadc3);
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
sprintf(msg, "Light: %hu \r\n", adc_read);
HAL_GPIO_TogglePin(GPIOE, 0x0002);
tx_thread_sleep(20);
}
If there is a better way to show code please let me know. As an additional question, in trying to access `HAL_MAX_DELAY` by including `stm32h7xx_hal_def.h`, I get tons of compiler errors:
2024-05-02 06:26 AM
You need the "matching" includes, something like this (from my H563 program):
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include "main.h"
#include "app_filex.h"
2024-05-06 07:07 AM
Hello @xiugaze
If you're encountering an "undeclared handler error" from the compiler when trying to access hardware peripheral handles.
Here's how you can troubleshoot and resolve this issue:
// In your peripheral header file (e.g., peripheral_header.h)
extern Peripheral_HandleType myPeripheralHandle;
// In your source file (e.g., app_threadx.c)
#include "peripheral_header.h"
// In a source file where the handle should be defined (e.g., peripheral.c)
Peripheral_HandleType myPeripheralHandle;
By following these steps, you should be able to resolve the "undeclared handler error" and successfully compile your code. If the problem persists, please provide more details on your setting project if possible, attach your configuration.