Commit Graph

42 Commits

Author SHA1 Message Date
Nico Tonnhofer a890fecc6d STM32F411: use arduino.h for UART pinout.
delete 11 mbed-files
    SIZES          ARM...     stm32f411
    FLASH  :  3124 bytes           1%
    RAM    :   212 bytes           1%
    EEPROM :     0 bytes           0%
2017-03-03 18:54:55 +01:00
Nico Tonnhofer 73df1be2d2 STM32F411: implement PULLUP_ON() and PULLUP_OFF(). 2017-03-03 18:54:55 +01:00
Nico Tonnhofer 313e37c0b2 STM32F411: implement SET_INPUT() and READ(). 2017-03-03 18:54:55 +01:00
Nico Tonnhofer 3a9a442c26 STM32F411: get FastIO for writing into place. 2017-03-03 18:54:55 +01:00
Markus Hitter b47e625d58 pinio.h: support USE_INTERNAL_PULLDOWNS.
That's the counterpart to USE_INTERNAL_PULLUPS and needed on the
Gen7-ARM board.
2016-09-30 13:16:01 +02:00
Markus Hitter aed6f5a14b pinio.h: support pulldown resistors.
These are ARM only, because ATmegas have no such feature.
2016-09-30 13:15:31 +02:00
Markus Hitter 35191306d7 pinio.c/.h: rename PULLUP_OFF() to PULL_OFF().
Before too long we'll support pulldown resistors, so the name
becomes ambiguous (PULLDOWN_OFF() would also turn off a pullup).
2016-09-30 12:42:47 +02:00
Markus Hitter 66dcde54dc mendel.c: move io_init() to pinio.c.
Also rename it to pinio_init(). Other than that a simple
copy/paste operation, with replacing tabs by spaces. No functional
change.
2015-08-12 14:26:35 +02:00
Markus Hitter 083f8f9b22 Make use of PULLUP_ON() and PULLUP_OFF().
This should not change behaviour, but later enable proper
operation on ARM.
2015-08-12 14:26:35 +02:00
Markus Hitter facd1ee606 pinio.h: implement PULLUP_ON() and PULLUP_OFF().
On ARM enabling the pullup on an input pin isn't done by writing
a 1 to the pin, but by setting the corresponding register.
Accordingly we need a distinct function for this.
2015-08-12 14:26:35 +02:00
Markus Hitter 45bcef395e ARM: implement SET_INPUT() and READ().
Tested and found to work. Excellent.

Test code before main():

static void delay(uint32_t delay) {
  while (delay) {
    __ASM volatile ("nop");
    delay--;
  }
}

Test code in main():

  SET_INPUT(PIO0_1);
  SET_INPUT(PIO0_2);
  SET_INPUT(PIO0_3);
  SET_INPUT(PIO0_4);

  delay(5000000);
  while (1) {
    sersendf_P(PSTR("\nPIO0_1  PIO"));
    delay(100000);
    sersendf_P(PSTR("0_2  PIO0_3"));
    delay(100000);
    sersendf_P(PSTR("  PIO0_4\n"));
    delay(100000);
    sersendf_P(PSTR("  %sx"), READ(PIO0_1));
    delay(100000);
    sersendf_P(PSTR("    %sx"), READ(PIO0_2));
    delay(100000);
    sersendf_P(PSTR("    %sx"), READ(PIO0_3));
    delay(100000);
    // PIO0_4 works, but the chip doesn't allow to set a pullup.
    sersendf_P(PSTR("    %sx\n"), READ(PIO0_4));
    delay(5000000);
  }
2015-08-12 14:26:35 +02:00
Markus Hitter 072e3f8ae5 ARM: also set GPIO function and mode.
This also implements more of the FastIO infrastructure.
Unfortunately, definitions aren't exactly straightforward, so we
need lots of tabular data. For example, for the pin function I
I had to step through the user manual, pin by pin.

We also learned a lesson here: Cortex-M0 has a 4 word ( = 16 bytes)
prefetch engine. Loops not starting at such a boundary take
additional 4 clock cycles, making them slower. The tight loop used
for testing previously happened to be 16-byte aligne by accident.
Adding just one line of code in the SET_OUTPUT() macro misaligned
it, so loop repetition rate dropped from 5.3 MHz to 3.7 MHz.

There are many measures to align code to 16-byte boundaries:

 - -falign-functions=16 as gcc flag.

 - -falign-loops=16 as gcc flag, found to not work.

 - -falign-labels=16 as gcc flag, worked for aligning the loop,
   but also bloated the binary by 10%.

 - __attribute__ ((aligned(16))) attached to functions (not
   tested)

 - Adding this just before the loop worked fine and increased the
   binary by just 16 bytes:

     __ASM (".balign 16");

Take care of this when relying on exact execution times, e.g. when
implementing delay_us()!
2015-08-12 14:26:35 +02:00
Markus Hitter c66bf0a8de pinio.h: remove TOGGLE(), GET_INPUT(), GET_OUTPUT() macros.
Nowhere used, which unlikely changes in the forseeable future.
2015-08-12 14:26:35 +02:00
Markus Hitter 2b52233a2d pinio.h: apply the formatting used for ARM for AVR as well.
No functinal change.
2015-08-12 14:26:34 +02:00
Markus Hitter 2c90a2dfc7 ARM: get FastIO for writing into place.
Only SET_OUTPUT() and WRITE() for now, reading follows later.

A loop like this:

  SET_OUTPUT(PIO0_1);
  for (;;) {
    WRITE(PIO0_1, 0);
    WRITE(PIO0_1, 1);
  }

toggles a pin at about 5.3 MHz. The low period is 63 ns on the
scope, so 3 clock cycles. With this loop, the binary is 1648
bytes.

Assembly shows four instructions inside the loop, which is about
as good as it can get:

  movs  r2, #0
  str   r2, [r3, #8]
  adds  r2, #2
  str   r2, [r3, #8]

For comparison, using the MBED provided gpio routines give a
toggle frequency of about 300 kHz, with a low period of 72 clock
cycles. Microoptimisation isn't just the last few percent ...

Tested with this code before main():

static void delay(uint32_t delay) {
  while (delay) {
    __ASM volatile ("nop");
    delay--;
  }
}

... and in main():

  SET_OUTPUT(PIO0_1);
  SET_OUTPUT(PIO0_2);
  SET_OUTPUT(PIO0_3);
  SET_OUTPUT(PIO0_4);
  __ASM (".balign 16");
  while (1) {
    // 1 pulse on pin 1, two pulses on pin 2, ...
    WRITE(PIO0_1, 0);
    WRITE(PIO0_1, 1);
    WRITE(PIO0_2, 0);
    WRITE(PIO0_2, 1);
    WRITE(PIO0_2, 0);
    WRITE(PIO0_2, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    // PIO0_4 needs a pullup 10k to 3.3V
    // to show a visible signal.
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(1000);
  }

With a 10k pullup, PIO0_4 has a rise time of about 1 microsecond.
2015-08-12 14:26:34 +02:00
Markus Hitter 370bb9f93c Move pin I/O macros from arduino.h to pinio.h.
arduino.h is now free of function definitions.
2015-08-12 14:26:34 +02:00
Markus Hitter 808f5dcfca DDA: Move axis calculations into loops, part 6b.
Clean up code to reduce duplication by consolidating code into
loops for per-axis actions.

Part 6b moves do_step() from the "tidiest" place into where it's
currently used, dda.c. Binary size goes down another 34 bytes, to
a total savings of 408 bytes and performance is much better, but
still 16% lower than without using loops:

    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH : 19874 bytes          139%       65%        32%       16%
    RAM   :  2302 bytes          225%      113%        57%       29%
    EEPROM:    32 bytes            4%        2%         2%        1%

short-moves.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 888.
Sum of all LED on time: 320000 clock cycles.
LED on time minimum: 351 clock cycles.
LED on time maximum: 772 clock cycles.
LED on time average: 360.36 clock cycles.

smooth-curves.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 9124.
Sum of all LED on time: 3875874 clock cycles.
LED on time minimum: 356 clock cycles.
LED on time maximum: 773 clock cycles.
LED on time average: 424.8 clock cycles.

triangle-odd.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 1636.
Sum of all LED on time: 640357 clock cycles.
LED on time minimum: 351 clock cycles.
LED on time maximum: 773 clock cycles.
LED on time average: 391.416 clock cycles.
2014-08-31 19:07:59 +02:00
Phil Hord b83449d8c3 DDA: Move axis calculations into loops, part 6a.
Clean up code to reduce duplication by consolidating code into
loops for per-axis actions.

Part 6a is putting stuff inside the step interrupt into a loop,
too. do_step() is put into the "tidiest" place. Binary size goes
down a remarkable 374 bytes, but stepping performance suffers by
almost 30%.

Traumflug's performance measurements:

    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH : 19908 bytes          139%       65%        32%       16%
    RAM   :  2302 bytes          225%      113%        57%       29%
    EEPROM:    32 bytes            4%        2%         2%        1%

short-moves.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 888.
Sum of all LED on time: 354537 clock cycles.
LED on time minimum: 390 clock cycles.
LED on time maximum: 806 clock cycles.
LED on time average: 399.253 clock cycles.

smooth-curves.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 9124.
Sum of all LED on time: 4268896 clock cycles.
LED on time minimum: 395 clock cycles.
LED on time maximum: 807 clock cycles.
LED on time average: 467.875 clock cycles.

triangle-odd.gcode
Statistics (assuming a 20 MHz clock):
LED on occurences: 1636.
Sum of all LED on time: 706846 clock cycles.
LED on time minimum: 390 clock cycles.
LED on time maximum: 807 clock cycles.
LED on time average: 432.057 clock cycles.
2014-08-31 19:07:51 +02:00
Phil Hord 21e5343552 Add config.h wrapper to simplify test automation
Test code which wants to customize config.h can do so without
touching config.h itself by wrapping config.h in a macro variable
which is passed in to the compiler.  It defaults to "config.h" if
no override is provided.

This change would break makefile dependency checking since the selection
of a different header file on the command line is not noticed by make
as a build-trigger.  To solve this, we add a layer to the BUILDDIR path
so build products are now specific to the USER_CONFIG choice if it is
not "config.h".
2014-03-04 19:56:23 +01:00
Phil Hord 3f07a47c06 pinio.h: Fix bug in macro definition
Including a semicolon in a macro function causes problems
when the "function" is called inside an if statement.  Fix
four cases in pinio.h where this error exists but currently
is not harming the code.
2013-12-06 19:24:58 +01:00
Phil Hord 452e2e5cd9 Restore simulation build target.
This code was accidentally removed long ago in a botched merge. This
patch recovers it and makes it build again. I've done minimal testing
and some necessary cleanup. It compiles and runs, but it probably still
has a few dust bunnies here and there.

I added registers and pin definitions to simulator.h and
simulator/simulator.c which I needed to match my Gen7-based config.
Other configs or non-AVR ports will need to define more or different
registers. Some registers are 16-bits, some are 8-bit, and some are just
constant values (enums). A more clever solution would read in the
chip-specific header and produce saner definitions which covered all
GPIOs. But this commit just takes the quick and easy path to support my
own hardware.

Most of this code originated in these commits:

	commit cbf41dd4ad
	Author: Stephan Walter <stephan@walter.name>
	Date:   Mon Oct 18 20:28:08 2010 +0200

	    document simulation

	commit 3028b297f3
	Author: Stephan Walter <stephan@walter.name>
	Date:   Mon Oct 18 20:15:59 2010 +0200

	    Add simulation code: use "make sim"

Additional tweaks:

Revert va_args processing for AVR, but keep 'int' generalization
for simulation. gcc wasn't lying. The sim really aborts without this.

Remove delay(us) from simulator (obsolete).

Improve the README.sim to demonstrate working pronterface connection
to sim. Also fix the build instructions.

Appease all stock configs.

Stub out intercom and shush usb_serial when building simulator.

Pretend to be all chip-types for config appeasement.

Replace sim_timer with AVR-simulator timer:

The original sim_timer and sim_clock provided direct replacements
for timer/clock.c in the main code. But when the main code changed,
simcode did not. The main clock.c was dropped and merged into timer.c.
Also, the timer.c now has movement calculation code in it in some
cases (ACCELERATION_TEMPORAL) and it would be wrong to teach the
simulator to do the same thing. Instead, teach the simulator to
emulate the AVR Timer1 functionality, reacting to values written to
OCR1A and OCR1B timer comparison registers.

Whenever OCR1A/B are changed, the sim_setTimer function needs to be
called. It is called automatically after a timer event, so changes
within the timer ISRs do not need to bother with this.

A C++ class could make this requirement go away by noticing the
assignment. On the other hand, a chip-agnostic timer.c would help
make the main code more portable. The latter cleanup is probably
better for us in the long run.
2013-12-06 19:24:58 +01:00
Markus Hitter 01f7c99881 config.h: introduce PS_MOSFET_PIN for Sanguish support. 2013-10-27 20:01:51 +01:00
Markus Hitter 5d6de1761b Enable internal pullups for endstops on demand, only.
The binary size impact is moderate, like 18 bytes plus
4 bytes per endstop defined.

The story is a follows:

The endstop logic can be used to use a touch probe with PCB
milling. Connect the (conductive) PCB surface to GND, the
spindle/mill bit to the signal line, turn the internal pullups
on and there you go.

However, doing so with pullups always enabled and while milling
under (conductive) water showed polished mill and drill bits to
become matte after a few hours of usage. Obviously, this small
0.5 mA current from the pullup resistors going through the
rotating mill bit is sufficient to get some spark erosion going.
That's bad, as spark erosion happening also means tools become
dull faster than neccessary.

With this patch, pullups are turned on while being used, only,
so this sparc erosion should go away.
2012-12-03 19:48:13 +01:00
Markus Hitter 3d1ebf1186 Review power supply timeout.
- Move the variable from dda.c to pinio.c.

- Reset the timeout on each power on, to guarantee a minimum PSU on time.
2012-07-16 20:13:12 +02:00
Markus Hitter 2eff194cdf Rename STEPPER_ENABLE_INVERT to STEPPER_INVERT_ENABLE.
No functional change, just match the naming of single stepper
enable pins.
2011-10-05 14:13:28 +02:00
Markus Hitter a33964fc51 Clean up enable pin handling.
This includes:

- Initialize them in mendel.c.

- While running, switch the pin only.

- Sort mendel.c the same order as in pinio.h.

- Remove the requirement of a parameter for this flag, like
  it's with all other flags.
2011-10-05 14:13:25 +02:00
Markus Hitter b45969e57a Introduce stepper_enable() and stepper_disable().
This allows to heat up with disables steppers, even if all steppers
share a common enable pin.
2011-10-05 14:13:21 +02:00
Markus Hitter 090da8ddad Clean up handling PS_ON_PIN and STEPPER_ENABLE_PIN.
This means moving power_on() from a macro to a function and
initializing the STEPPER_ENABLE_PIN in mendel.c.
2011-10-05 14:13:15 +02:00
Bas Laarhoven 72fdd33958 Prevent unexpected macro expansion. 2011-08-16 13:59:41 +02:00
Michael Moon 0dc7d77885 Massive Doxygen documentation addition
'make doc' then point your browser at doc/html/

Needs plenty of cleanup and polishing, but the main bulk is here

even documents your configuration! ;)
2011-03-22 01:34:36 +11:00
Markus Hitter 3ee3ee06a1 pinio.h: cosmetics. 2011-03-04 22:51:54 +01:00
Markus Hitter 4cc0c2ca4f Refine enhancements in ea4fdcf a bit. 2011-03-04 22:02:46 +01:00
Ben Jackson ea4fdcf26a mendel.c, pinio.c: Make Z axes optional. 2011-03-04 19:42:00 +11:00
Markus Hitter e688e8b788 Consequences of the stepping extruder now being optional. 2011-03-02 00:43:06 +01:00
Markus Hitter d2bf65822e Make the extruder stepper optional.
Think of DC extruders, milling Mendels, ...
2011-03-02 00:43:03 +01:00
Markus Hitter 475ca7d54a pinio.h: make ?_INVERT_DIR safer. 2011-03-02 00:43:01 +01:00
Markus Hitter 7e8c50fa58 pinio.h: make inverting pins actually work.
To INVERT an endstop, #define X_INVERT_MIN etc.
To leave it uninverted, define nothing, i.e. comment the #define out.

Probably, this change should be extended to INVERT_DIR and
INVERT_ENABLE, too.

The problem was, preprocessor flags are usually set with a simple
"#define X_INVERT_MIN", so X_INVERT_MIN is defined, but of
arbitrary value. Applies to other axes and INVERT_MAX also,
of course.

Initially, it was planned to allow "#define X_INVERT_MIN" as well
as "#define X_INVERT_MIN 0" but that turned out to be _really_
complex. See http://www.velocityreviews.com/forums/t720190-test-of-a-preprocessor-symbol-defined-as-nothing-vs-zero.html .

For curiosity, I've ported this to our purposes, debug messages
left in place:

	#ifdef X_INVERT_MAX
		#if CAT(1,X_INVERT_MAX) == 1
			#warning "X enabled, inverted"
			#define x_max()						(READ(X_MAX_PIN)?0:1)
		#elif X_INVERT_MAX
			#warning "X enabled, inverted"
			#define x_max()						(READ(X_MAX_PIN)?0:1)
		#else
			#warning "X enabled, uninverted"
			#define x_max()						(READ(X_MAX_PIN)?1:0)
		#endif
	#else
		#warning "X enabled, uninverted"
		#define x_max()						(READ(X_MAX_PIN)?1:0)
	#endif
	#warning "X disabled"
	#define	x_max()							(0)
2011-02-27 16:16:30 +01:00
Stephan Walter 8acb072e0b Actually set extruder enable pin if defined 2011-02-27 00:55:14 +11:00
Jacky2k aec41c59aa gcode_process and pinio need to include config.h
Signed-off-by: Michael Moon <triffid.hunter@gmail.com>
2011-02-09 07:46:04 +11:00
Michael Moon 47a23317be allow home-to-max setups 2011-02-08 17:52:32 +11:00
Markus Amsler 021ac75e2f Fix typo in x_min 2011-02-05 13:33:26 +11:00
Michael Moon 266c6ee0e2 merge release-candidate-triffid 2011-01-07 23:29:32 +11:00