Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adc dma support #2

Merged
merged 7 commits into from
Oct 3, 2017
Merged

Adc dma support #2

merged 7 commits into from
Oct 3, 2017

Conversation

xC0000005
Copy link

This adds support for the ADC in DMA mode (I tested by soldering & connecting thermisters/pull up resistors). Longer term, it would make sense for the ADC read functions to be macros that pull the data from the right index in the DMA buffer since the ADC runs in continuous mode and the buffer is always up to date, but this works perfectly well for now.

On bluepill STM32F103C6 boards, using Timer5 results in a error() vector call. Switch to 4 since these are both general purpose, 16 bit timers.
Some low end machines doe not have EEPROM support. Simulate it using the last two pages of flash. Flash does not allow rewrite between erases, so skip writing the working version if that's enabled.
This is a work in progress to go hand in hand with the STM32 work.
…e pin enumerations in STM boards vs what marlin expects (i.e, try defining PA0 as a temp pin). The hack can be removed with we go to fastio completely. To see this work, set something in adc_pins to a value like PA0 and connect your pullup resistor'd thermistor.
We have an actual ADC init function now.
Remove the pin mode hack that I was using to init PA0.
@victorpv
Copy link
Owner

victorpv commented Oct 3, 2017

Great, let me merge this one right away since it doesn't conflict with anything. I will try to test this later too.

@victorpv victorpv merged commit 56fd08f into victorpv:bugfix-2.0.x Oct 3, 2017
@victorpv
Copy link
Owner

victorpv commented Oct 4, 2017

What is this line for?
USBSerial SerialUSB;

The SerialUSB should normally be automatically declared as "Serial" if you select the option to include SerialUSB in the board settings. I haven't had to add that line to get communication using USB serial, did you face any problem?

@xC0000005
Copy link
Author

I thought I deleted it before I committed (I have "Do not commit" markers around other problems unique to my build. I'm sorry.

@victorpv
Copy link
Owner

victorpv commented Oct 4, 2017

Ok I just tried to resolve all the conflicts and merge your changes and the changes upstream from the official Marling. Now I need to try to merge my changes. After that you should probably resync since all together there will be a lot of changes. I'll post once I have uploaded that.

Keep your own configuration.h file, I try to avoid that in the uploads since it's specific for each user, but there is a folder with configuration.h example files for the different boards, I added 1 folder for the stmf1ret, if you want to add a folder to the Malyan board and put the config there, we should be able to submit that as a PR to Marlin and get it merged.
Thinkyhead corrected a lot of formatting in the code, I had to manually edit a lot of files to keep his changes...

@victorpv
Copy link
Owner

victorpv commented Oct 5, 2017

@xC0000005 I am having trouble getting a reading for the TEMP_BED pin. First I had it set to PA0, so I thought perhaps there is a problem with that enum being 0, so I changed to have PA1 as BED, and PA0 as the extruder, and the problem followed to PA1.
So to clarify, PA0 and PA1 work when assigned to the extruder, but both fail when assigned to the BED.
I also have updated the repo with all the latest changes. Before you resync to it, I advise to make a copy of your local folder, I have lost changes more than once because the github client overwrote them when changing to another branch.

@victorpv
Copy link
Owner

victorpv commented Oct 5, 2017

This seems to work fine for me, if you can test.

enum TEMP_PINS
{
  #if HAS_TEMP_0
    TEMP_0,
  #endif
  #if HAS_TEMP_1
    TEMP_1,
  #endif
  #if HAS_TEMP_2
    TEMP_2,
  #endif
  #if HAS_TEMP_3
    TEMP_3,
  #endif
  #if HAS_TEMP_4
    TEMP_4,
  #endif
  #if HAS_TEMP_BED
    TEMP_BED,
  #endif
  #if ENABLED(FILAMENT_WIDTH_SENSOR)
    FILWIDTH
  #endif
};


void HAL_adc_start_conversion (uint8_t adc_pin) {
  TEMP_PINS pin_index;
#if HAS_TEMP_0
  if (adc_pin == TEMP_0_PIN){
      pin_index = TEMP_0;
  }
#endif
#if HAS_TEMP_1
  if (adc_pin == TEMP_1_PIN) {
    pin_index = TEMP_1;
  }
#endif
#if HAS_TEMP_2
  if (adc_pin == TEMP_2_PIN) {
    pin_index = TEMP_2;
  }
#endif
#if HAS_TEMP_3
  if (adc_pin == TEMP_3_PIN) {
    pin_index = TEMP_3;
  }
#endif
#if HAS_TEMP_4
  if (adc_pin == TEMP_4_PIN) {
    pin_index = TEMP_4;
  }
#endif
#if HAS_TEMP_BED
  if (adc_pin == TEMP_BED_PIN) {
    pin_index = TEMP_BED;
  }
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
  if (adc_pin == FILWIDTH_PIN) {
    pin_index = FILWIDTH;
  }
#endif

  HAL_adc_result = (HAL_adc_results[(int)pin_index] >> 2)& 0x3ff; // shift to get 10 bits only.
}

@xC0000005
Copy link
Author

I had the enum exactly like that and for some reason, thought this was unnecessary. When I'm home I'll compile, hook up the thermistor and test. Sorry for the problem.

@victorpv
Copy link
Owner

victorpv commented Oct 5, 2017 via email

@xC0000005
Copy link
Author

It's working. Given the way enums work, if someone doesn't have a value defined, they should drop out of the list. The result is that if TEMP_0 was not defined, the zero value of the enumeration (and the first entry in the array) would be that referenced by TEMP_1. Any combination should work in this manner.

@xC0000005
Copy link
Author

Ah - I know what's missing. ADC_PIN_COUNT should be the last enum, always present. Then we size adc_pins based on that. I swear I had that working and decided to "simplify." I should have left it in the working state.

@xC0000005 xC0000005 deleted the ADC-DMA-Support branch October 5, 2017 06:27
@victorpv
Copy link
Owner

victorpv commented Oct 5, 2017

By the way I alse tested i2c eeprom yesterday and works fine.

victorpv pushed a commit that referenced this pull request Dec 9, 2017
# This is the 1st commit message:

Choose the timer based on MCU defintion. Timer5 is not valid on C8/CB class boards, so use Timer4 for the step timer.

# This is the commit message #2:

Readme.md update

# This is the commit message #3:

Readme.md update

# This is the commit message #4:

Trying to get readme.md updated

# This is the commit message #5:

readme.md update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants