PX4 / PX4-Autopilot

PX4 Autopilot Software
https://px4.io
BSD 3-Clause "New" or "Revised" License
8.45k stars 13.49k forks source link

STM32H7's PA0 Can not read ADC #17953

Closed Abner0907 closed 3 years ago

Abner0907 commented 3 years ago

@davids5 , Now I have a issue about the PA0, I can not read the adc value or read a random value, it will show a random value in PA0/CHANNEL 16 channel when I type listener adc_report. I can read the PA1 and PA3's adc value. The datasheet said it has a PA0_C. I can not confirm whether this is the reason I can not read the adc. Maybe I have config the PA0 wrong? I am very appreciated that you can give me some notes. many thanks. Screenshot from 2021-07-20 22-27-21

BTW: I have check the hardware. it is ok. And I modify the hardware to PA1. The adc is also ok.

davids5 commented 3 years ago

@Abner0907 What HW is this on? I need to see the board_config.h

davids5 commented 3 years ago

Also the schematic would help

Abner0907 commented 3 years ago

@davids5 Hello,Thank you for your help. The configure is here: https://github.com/Abner0907/Firmware/tree/taloon1000/H7-v1.12.0-rc1/boards/codev/dp1000-v2

The schematic's link is here: https://github.com/CodevDynamics/Opensource_Hardware/blob/main/DP_FC_SCH.pdf

FYI: In the schematic, I have use the STM32H743VIT6 for the chip is stm32f765vi, I have seen the pin definition is the same.

Abner0907 commented 3 years ago

@davids5 I can read channel 17 but can not read channel 16. So for hot fix, I jump a line to Channel 17(PA1), The configuration in my code show this.

davids5 commented 3 years ago

Stop in the debugger and and look at the GPIOA register set (GPIOA_MODER etal). See if it is still in analog mode? I would bet that something in the config is overwriting it.

Also you have a CONFIG_ARCH_CHIP_STM32H743II (176 pin) set in the defconfig You would need to check the pinmap and see if it is it the same at the 100 pin part.

davids5 commented 3 years ago

Also, are the _C pins even bonded out on the V package?

See my notes about the SYSCFG_PMCR default state.

https://github.com/PX4/PX4-Autopilot/blob/master/boards/px4/fmu-v6x/src/board_config.h#L154-L158

But I do not think it applies in the V package.

Abner0907 commented 3 years ago

@davids5 1:

Also you have a CONFIG_ARCH_CHIP_STM32H743II (176 pin) set in the defconfig You would need to check the pinmap and see if it is it the same at the 100 pin part.

I have seen the definition in the datasheet. I think the pinmap is ok.

Screenshot from 2021-07-21 21-20-17

2:

Also, are the _C pins even bonded out on the V package?

Yes, I also think the _C pins is not on the V package.

3:

See my notes about the SYSCFG_PMCR default state.

The register's address is 0x58000404? I have read this register's value through j-link. The value is 0x3000000.

davids5 commented 3 years ago

@Abner0907 What do the GPIO regs show?

Abner0907 commented 3 years ago

@davids5 I add a 6s battery and I measured it, the voltage is 25.3v. The PA0 gpio's pin will show a random value between 6500-8500, the value will change all the time.

Screenshot from 2021-07-21 21-45-39

Abner0907 commented 3 years ago

My real voltage now is 22.03v. What is battery show is: Screenshot from 2021-07-21 21-51-31

davids5 commented 3 years ago

dump the value in GPIOA MODER. Is is set to default? Check the GPIOA AFRL

image

Abner0907 commented 3 years ago

@davids5 J-Link>mem32 0x58020020 1 (GPIOA AFRL) 58020020 = 55500000

J-Link>mem32 0x58020000 1 (GPIOA MODER) 58020000 = 6A83A9FC

It was be set to Input mode?

Screenshot from 2021-07-21 22-09-39

Abner0907 commented 3 years ago

@davids5 Just now I have modify the GPIOA MODER's value to 6A83A9FF. The PA0's adc can be detected correctly. So the PA0's mode is be modified or changed by somewhere?

davids5 commented 3 years ago

Set a HW breakpoint on writes to MODER, then look up the stack.

PA maps to 00 and so does Pin 0 So it anything that is broken passing a 0 to GPIO config can overwrite. PA0...fun....fun...fun :)

Abner0907 commented 3 years ago

@davids5 Hi, I found the reason, I have wrong configure the usb. define the vbus as below:

#define GPIO_OTGFS_VBUS         /* PA9 */ (GPIO_INPUT|GPIO_PULLDOWN|GPIO_SPEED_100MHz|GPIO_PORTA|GPIO_PIN9)

I configured it as

    // stm32_configgpio((GPIO_OTGFS_VBUS & GPIO_PUPD_MASK) | GPIO_PULLDOWN);

It should be configured as:

stm32_configgpio(GPIO_OTGFS_VBUS);
Abner0907 commented 3 years ago

@davids5 many thanks you for your help. It is very usefully.