Skip to content

Add JLink To Portenta Programmers; Add pinPeripheral() (wiring_private.c - note WIP) #28

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ envie_m7.upload.native_usb=true
envie_m7.upload.maximum_size=786432
envie_m7.upload.maximum_data_size=523624

### WIP! Note, this may not be able to coexist - proceed accordingly! --- jcw

## for jlink - REM: Must use WINUSB w/jlink (Zadig good utility for this under win10.)

envie_m7.debug.tool=gdb
envie_m7.bootloader.tool=openocd
envie_m7.bootloader.config=-f target/stm32h7x_dual_bank.cfg
envie_m7.bootloader.programmer=-f interface/jlink.cfg
envie_m7.bootloader.extra_action.preflash=stm32h7x option_write 0 0x01c 0xb86aaf0
envie_m7.bootloader.file=PORTENTA_H7/portentah7_bootloader_mbed_hs.elf

## for stlink

envie_m7.debug.tool=gdb
envie_m7.bootloader.tool=openocd
envie_m7.bootloader.config=-f target/stm32h7x_dual_bank.cfg
Expand Down
63 changes: 63 additions & 0 deletions cores/arduino/WVariant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright (c) 2015 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum _EPioType
{
PIO_NOT_A_PIN=-1, /* Not under control of a peripheral. */
PIO_EXTINT=0, /* The pin is controlled by the associated signal of peripheral A. */
PIO_ANALOG, /* The pin is controlled by the associated signal of peripheral B. */
PIO_SERCOM, /* The pin is controlled by the associated signal of peripheral C. */
PIO_SERCOM_ALT, /* The pin is controlled by the associated signal of peripheral D. */
PIO_TIMER, /* The pin is controlled by the associated signal of peripheral E. */
PIO_TIMER_ALT, /* The pin is controlled by the associated signal of peripheral F. */
PIO_COM, /* The pin is controlled by the associated signal of peripheral G. */
PIO_AC_CLK, /* The pin is controlled by the associated signal of peripheral H. */
PIO_DIGITAL, /* The pin is controlled by PORT. */
PIO_INPUT, /* The pin is controlled by PORT and is an input. */
PIO_INPUT_PULLUP, /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
PIO_OUTPUT, /* The pin is controlled by PORT and is an output. */

PIO_PWM=PIO_TIMER,
PIO_PWM_ALT=PIO_TIMER_ALT,
} EPioType ;

/**
* Pin Attributes to be OR-ed
*/
#define PIN_ATTR_NONE (0UL<<0)
#define PIN_ATTR_COMBO (1UL<<0)
#define PIN_ATTR_ANALOG (1UL<<1)
#define PIN_ATTR_DIGITAL (1UL<<2)
#define PIN_ATTR_PWM (1UL<<3)
#define PIN_ATTR_TIMER (1UL<<4)
#define PIN_ATTR_TIMER_ALT (1UL<<5)
#define PIN_ATTR_EXTINT (1UL<<6)


#ifdef __cplusplus
} // extern "C"
#endif

64 changes: 64 additions & 0 deletions cores/arduino/wiring_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//** just starting suggestion at this point --- jcw - 9/10/20
/*
Copyright (c) 2014 Arduino. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef _WIRING_CONSTANTS_
#define _WIRING_CONSTANTS_

#ifdef __cplusplus
extern "C"{
#endif // __cplusplus

#define LOW (0x0)
#define HIGH (0x1)

#define INPUT (0x0)
#define OUTPUT (0x1)
#define INPUT_PULLUP (0x2)
#define INPUT_PULLDOWN (0x3)

#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105
#define EULER 2.718281828459045235360287471352

#define SERIAL 0x0
#define DISPLAY 0x1

// enum BitOrder {
// LSBFIRST = 0,
// MSBFIRST = 1
// };

// moved to WInterrupts.h
//// LOW 0
//// HIGH 1
//#define CHANGE 2
//#define FALLING 3
//#define RISING 4
//
//#define DEFAULT 1
//#define EXTERNAL 0

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif /* _WIRING_CONSTANTS_ */
205 changes: 205 additions & 0 deletions cores/arduino/wiring_private.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
//** just starting suggestion at this point --- jcw - 9/10/20
/*
Copyright (c) 2015 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// #include <Arduino.h>
// #include "gpio_object.h"
// #include "Wire.h"
// #include "api/Common.h"
#include <wiring_private.h>
// #include "device.h"
// #include "pinmap.h"
// #include "WVariant.h"
// #include "pinmode_arduino.h"
#include "pins_arduino.h"
#include "mbed.h"


static uint8_t pin = 4;
// static gpio_t gpio;
// gpio_t gpio;

// extern PinDescription g_APinDescription[];
#if 0
PinDescription g_APinDescription[] = {
// D0 - D7
{ PH_15, NULL, NULL, NULL }, // D0
{ PK_1, NULL, NULL, NULL }, // D1
{ PJ_11, NULL, NULL, NULL }, // D2
{ PG_7, NULL, NULL, NULL }, // D3
{ PC_7, NULL, NULL, NULL }, // D4
{ PC_6, NULL, NULL, NULL }, // D5
{ PA_8, NULL, NULL, NULL }, // D6
{ PI_0, NULL, NULL, NULL }, // D7

// D8 - D14
{ PC_3, NULL, NULL, NULL }, // D8
{ PI_1, NULL, NULL, NULL }, // D9
{ PC_2, NULL, NULL, NULL }, // D10
{ PH_8, NULL, NULL, NULL }, // D11
{ PH_7, NULL, NULL, NULL }, // D12
{ PA_10, NULL, NULL, NULL }, // D13
{ PA_9, NULL, NULL, NULL }, // D14

// A0 - A6
{ PA_0C, NULL, NULL, NULL }, // A0 ADC2_INP0
{ PA_1C, NULL, NULL, NULL }, // A1 ADC2_INP1
{ PC_2C, NULL, NULL, NULL }, // A2 ADC3_INP0
{ PC_3C, NULL, NULL, NULL }, // A3 ADC3_INP1
{ PC_2_ALT0, NULL, NULL, NULL }, // A4 ADC1_INP12
{ PC_3_ALT0, NULL, NULL, NULL }, // A5 ADC1_INP13
{ PA_4, NULL, NULL, NULL }, // A6 ADC1_INP18

// LEDS
{ PK_5, NULL, NULL, NULL }, // LEDR
{ PK_6, NULL, NULL, NULL }, // LEDG
{ PK_7, NULL, NULL, NULL }, // LEDB
};
#endif


extern struct PinDescription g_APinDescription;
// extern void pinMode(pin_size_t pinNumber, PinMode pinMode);

int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral )
{



// Handle the case the pin isn't usable as PIO
// if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
// if ( g_APinDescription[ulPin].gpio == PIO_NOT_A_PIN )
// if ( g_APinDescription[pin].gpio == PIO_NOT_A_PIN )
// if ( g_APinDescription[pin] == PIO_NOT_A_PIN )
// {
// return -1 ;
// }

switch ( ulPeripheral )
{
case PIO_DIGITAL:
case PIO_INPUT:
case PIO_INPUT_PULLUP:
case PIO_OUTPUT:
// Disable peripheral muxing, done in pinMode
// PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit.PMUXEN = 0 ;

// Configure pin mode, if requested
if ( ulPeripheral == PIO_INPUT )
{
pin_mode( ulPin, INPUT ) ; // pinMode( ulPin, INPUT ) ;

// pinMode( ulPin, INPUT ) ; // pinMode( ulPin, INPUT ) ;
}
else
{
if ( ulPeripheral == PIO_INPUT_PULLUP )
{
pin_mode( ulPin, INPUT_PULLUP ) ; // pinMode( ulPin, INPUT_PULLUP ) ;
// pinMode( ulPin, INPUT_PULLUP ) ; // pinMode( ulPin, INPUT_PULLUP ) ;
}
else
{
if ( ulPeripheral == PIO_OUTPUT )
{
pin_mode( ulPin, OUTPUT ) ; // pinMode( ulPin, OUTPUT ) ;
// gpio_init_out(&gpio, ulPin);
// pinMode( ulPin, OUTPUT ) ; // pinMode( ulPin, OUTPUT ) ;
}
else
{
// PIO_DIGITAL, do we have to do something as all cases are covered?
}
}
}
break ;

case PIO_ANALOG:
case PIO_SERCOM:
case PIO_SERCOM_ALT:
case PIO_TIMER:
case PIO_TIMER_ALT:
case PIO_EXTINT:
case PIO_COM:
case PIO_AC_CLK:
#if 0
// Is the pio pin in the lower 16 ones?
// The WRCONFIG register allows update of only 16 pin max out of 32
if ( g_APinDescription[ulPin].ulPin < 16 )
{
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
PORT_WRCONFIG_WRPINCFG |
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin ) ;
}
else
{
PORT->Group[g_APinDescription[ulPin].ulPort].WRCONFIG.reg = PORT_WRCONFIG_HWSEL |
PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN | PORT_WRCONFIG_PMUX( ulPeripheral ) |
PORT_WRCONFIG_WRPINCFG |
PORT_WRCONFIG_PINMASK( g_APinDescription[ulPin].ulPin - 16 ) ;
}
#else
#if 0
if ( g_APinDescription[ulPin].ulPin & 1 ) // is pin odd?
{
uint32_t temp ;

// Get whole current setup for both odd and even pins and remove odd one
temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXE( 0xF ) ;
// Set new muxing
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXO( ulPeripheral ) ;
// Enable port mux
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ;
}
else // even pin
{
uint32_t temp ;

temp = (PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg) & PORT_PMUX_PMUXO( 0xF ) ;
PORT->Group[g_APinDescription[ulPin].ulPort].PMUX[g_APinDescription[ulPin].ulPin >> 1].reg = temp|PORT_PMUX_PMUXE( ulPeripheral ) ;
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg |= PORT_PINCFG_PMUXEN ; // Enable port mux
}
#endif
#endif
break ;

case PIO_NOT_A_PIN:
return -1l ;
break ;
}

return 0l ;
}



void shiftOutMatrix(pin_size_t dataPin, uint8_t clockPin, BitOrder bitOrder, uint32_t val)
{
uint32_t i;

for (i = 0; i < 32; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)) ? HIGH : LOW);
else
digitalWrite(dataPin, !!(val & (1 << (31 - i))) ? HIGH : LOW);

digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}

23 changes: 21 additions & 2 deletions cores/arduino/wiring_private.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//** just starting suggestion at this point --- jcw - 9/10/20
/*
wiring_private.h
Part of Arduino - http://www.arduino.cc/
Expand All @@ -23,17 +24,35 @@
#ifndef WiringPrivate_h
#define WiringPrivate_h

#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>

#include "Arduino.h"
// #include "gpio_object.h"

#include "Arduino.h"
#include "WVariant.h"
#ifdef __cplusplus
extern "C"{
#endif

// #include "wiring_constants.h"
/// #include "api/Common.h" // H7 equivalent
typedef void (*voidFuncPtr)(void);
#if 0
typedef struct {
uint32_t mask;
__IO uint32_t *reg_in;
__IO uint32_t *reg_set;
__IO uint32_t *reg_clr;
PinName pin;
GPIO_TypeDef *gpio;
uint32_t ll_pin;
} gpio_t;
#endif
// gpio_t gpio;

int pinPeripheral( uint32_t ulPin, EPioType ulPeripheral );
void shiftOutMatrix(pin_size_t dataPin, uint8_t clockPin, BitOrder bitOrder, uint32_t val);
#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
Loading