Skip to content
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
65 changes: 64 additions & 1 deletion ch55xduino/ch55x/boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ ch559.upload.speed=1

##############################################################


ch549.name=CH549 (experimental)
ch549.upload.protocol=ch55x2_3_1
ch549.upload.maximum_size=61439
Expand Down Expand Up @@ -260,4 +261,66 @@ ch549.menu.bootloader_pin.p15.upload.bootcfg=2

ch549.upload.speed=1

##############################################################
##############################################################

ch558.name=CH558 Board
ch558.upload.tool=vnproch55x_usb
ch558.upload.protocol=ch55x2_3_1
#CH558 has 40K flash (48k)
ch558.upload.maximum_size=40960
ch558.build.mcu=mcs51
ch558.menu.clock.24internal=24 MHz (internal)
ch558.menu.clock.24internal.build.f_cpu=24000000L
ch558.menu.clock.24internal.build.f_oscillator_external=0L
ch558.menu.clock.16internal=16 MHz (internal)
ch558.menu.clock.16internal.build.f_cpu=16000000L
ch558.menu.clock.16internal.build.f_oscillator_external=0L
ch558.menu.clock.56internal=56 MHz (internal)
ch558.menu.clock.56internal.build.f_cpu=56000000L
ch558.menu.clock.56internal.build.f_oscillator_external=0L
ch558.menu.clock.24external=24 MHz (external 12M osc)
ch558.menu.clock.24external.build.f_cpu=24000000L
ch558.menu.clock.24external.build.f_oscillator_external=12000000L
ch558.menu.clock.16external=16 MHz (external 12M osc)
ch558.menu.clock.16external.build.f_cpu=16000000L
ch558.menu.clock.16external.build.f_oscillator_external=12000000L
ch558.menu.clock.56external=56 MHz (external 12M osc)
ch558.menu.clock.56external.build.f_cpu=56000000L
ch558.menu.clock.56external.build.f_oscillator_external=12000000L
ch558.build.board=ch558
ch558.build.core=ch55xduino
ch558.build.variant=ch558
ch558.build.mcu=CH558

ch558.upload.use_1200bps_touch=true
ch558.upload.wait_for_upload_port=false

## USB Memory Settings
## ----------------------------------------------
ch558.menu.usb_settings.usbcdc=Default CDC
ch558.menu.usb_settings.usbcdc.upload.maximum_data_size=3948
ch558.menu.usb_settings.usbcdc.upload.xdata_location=148
ch558.menu.usb_settings.usbcdc.build.extra_flags=-DEP0_ADDR=0 -DEP1_ADDR=10 -DEP2_ADDR=20
## ----
ch558.menu.usb_settings.user148=USER CODE w/ 148B USB ram
ch558.menu.usb_settings.user148.upload.maximum_data_size=3948
ch558.menu.usb_settings.user148.upload.xdata_location=148
ch558.menu.usb_settings.user148.build.extra_flags=-DUSER_USB_RAM=148
## ----
ch558.menu.usb_settings.user0=USER CODE w/ 0B USB ram
ch558.menu.usb_settings.user0.upload.maximum_data_size=4096
ch558.menu.usb_settings.user0.upload.xdata_location=0
ch558.menu.usb_settings.user0.build.extra_flags=-DUSER_USB_RAM=0

## ----------------------------------------------
ch558.menu.bootloader_pin.p46=P4.6 pull-down
ch558.menu.bootloader_pin.p46.upload.bootcfg=3
## ----
ch558.menu.bootloader_pin.p51=P5.1 (D+) pull-up
ch558.menu.bootloader_pin.p51.upload.bootcfg=1

# meaningless variables just to keep the makefile happy

ch558.upload.speed=1

##############################################################
2 changes: 1 addition & 1 deletion ch55xduino/ch55x/cores/ch55xduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void digitalWrite(__data uint8_t pin, __xdata uint8_t val);
* @return HIGH or LOW (uint8_t).
*/
uint8_t digitalRead(__data uint8_t pin);
#if defined(CH559)
#if defined(CH559) || defined(CH558)
uint16_t analogRead(__data uint8_t pin);
#else
/**
Expand Down
4 changes: 2 additions & 2 deletions ch55xduino/ch55x/cores/ch55xduino/HardwareSerial1.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void Serial1_begin(__data unsigned long baud) {

IE_UART1 = 1;
EA = 1; // Enable serial 1 interrupt
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
__data uint32_t x;
__data uint8_t x2;
SER1_LCR |= bLCR_DLAB; // change baudrate
Expand Down Expand Up @@ -65,7 +65,7 @@ uint8_t Serial1_write(__data uint8_t SendDat) {
uart1_flag_sending = 1;
#if defined(CH551) || defined(CH552)
SBUF1 = SendDat;
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
SER1_THR = SendDat;
#elif defined(CH549)
SBUF1 = SendDat;
Expand Down
4 changes: 2 additions & 2 deletions ch55xduino/ch55x/cores/ch55xduino/HardwareSerial1ISR.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void uart1IntRxHandler() {
if (nextHead != uart1_rx_buffer_tail) {
#if defined(CH551) || defined(CH552)
Receive_Uart1_Buf[uart1_rx_buffer_head] = SBUF1;
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
Receive_Uart1_Buf[uart1_rx_buffer_head] = SER1_RBR;
#elif defined(CH549)
Receive_Uart1_Buf[uart1_rx_buffer_head] = SBUF1;
Expand All @@ -33,7 +33,7 @@ void uart1IntTxHandler() {
} else {
#if defined(CH551) || defined(CH552)
SBUF1 = Transmit_Uart1_Buf[uart1_tx_buffer_tail];
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
SER1_THR = Transmit_Uart1_Buf[uart1_tx_buffer_tail];
#elif defined(CH549)
SBUF1 = Transmit_Uart1_Buf[uart1_tx_buffer_tail];
Expand Down
2 changes: 1 addition & 1 deletion ch55xduino/ch55x/cores/ch55xduino/USBCDC.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void setControlLineStateHandler() {

while (1)
;
#elif defined(CH559) && (BOOT_LOAD_ADDR == 0xF400)
#elif (defined(CH559) | defined(CH558) ) && (BOOT_LOAD_ADDR == 0xF400)
USB_CTRL = 0;
EA = 0; // Disabling all interrupts is required.
delayMicroseconds(50000);
Expand Down
4 changes: 2 additions & 2 deletions ch55xduino/ch55x/cores/ch55xduino/USBhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void USBDeviceCfg() {
#if defined(CH551) || defined(CH552) || defined(CH549)
UDEV_CTRL = bUD_PD_DIS; // Disable DP/DM pull-down resistor
#endif
#if defined(CH559)
#if defined(CH559) || defined(CH558)
UDEV_CTRL = bUD_DP_PD_DIS; // Disable DP/DM pull-down resistor
#endif
UDEV_CTRL |= bUD_PORT_EN; // Enable physical port
Expand All @@ -526,7 +526,7 @@ void USBDeviceIntCfg() {
}

void USBDeviceEndPointCfg() {
#if defined(CH559)
#if defined(CH559) || defined(CH558)
// CH559 use differend endianness for these registers
UEP0_DMA_H = ((uint16_t)Ep0Buffer >> 8); // Endpoint 0 data transfer address
UEP0_DMA_L = ((uint16_t)Ep0Buffer >> 0); // Endpoint 0 data transfer address
Expand Down
2 changes: 1 addition & 1 deletion ch55xduino/ch55x/cores/ch55xduino/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void Uart1_ISR(void) __interrupt(INT_NO_UART1) {
uart1IntTxHandler();
U1TI = 0;
}
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
uint8_t interruptStatus = SER1_IIR & 0x0f;
switch (interruptStatus) {
case U1_INT_RECV_RDY:
Expand Down
6 changes: 5 additions & 1 deletion ch55xduino/ch55x/cores/ch55xduino/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ void init() {
#warning F_CPU invalid or not set
#endif

#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
#if F_CPU == 24000000
CLOCK_CFG =
CLOCK_CFG & ~MASK_SYS_CK_DIV | 12; // 24MHz, 12M*(24 default PLL)/12=24M
Expand Down Expand Up @@ -1229,7 +1229,11 @@ void init() {

// init PWM
PWM_CK_SE = 93; // DIV by 94 for 1K freq on 24M clk
#if defined(CH558)
PWM3_CTRL = 0;
#else
PWM_CTRL = 0;
#endif

// init T0 for millis
TMOD = (TMOD & ~0x0F) | (bT0_M1); // mode 2 for autoreload
Expand Down
12 changes: 7 additions & 5 deletions ch55xduino/ch55x/cores/ch55xduino/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "pins_arduino_include.h"
// clang-format on

#if defined(CH559)
#if defined(CH559) || defined(CH558)
uint16_t analogRead(__data uint8_t pin)
#else
uint8_t analogRead(__data uint8_t pin)
Expand All @@ -30,7 +30,7 @@ uint8_t analogRead(__data uint8_t pin)
;

return ADC_DATA;
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)

__data uint8_t pinMask = 1 << pin;
P1_IE &= ~(pinMask); // Close other data functions of P1 port, if only part of
Expand Down Expand Up @@ -119,7 +119,7 @@ void analogWrite(__data uint8_t pin, __xdata uint16_t val) {
}
}
}
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
pinMode(pin, OUTPUT);
if (val == 0) {
digitalWrite(pin, LOW);
Expand All @@ -136,6 +136,7 @@ void analogWrite(__data uint8_t pin, __xdata uint16_t val) {
PWM_CYCLE = 255;
}
switch (pwmPin) {
#if defined(CH559)
case PIN_PWM1:
PIN_FUNC &= ~(bPWM1_PIN_X); // CH559 only has 1 bit for 2 PWMs
PWM_CTRL |= bPWM_OUT_EN;
Expand All @@ -146,13 +147,12 @@ void analogWrite(__data uint8_t pin, __xdata uint16_t val) {
PWM_CTRL |= bPWM2_OUT_EN;
PWM_DATA2 = val;
break;
#endif
case PIN_PWM3:
case PIN_PWM3_:
if (pwmPin == PIN_PWM3) {
P1_DIR |= bPWM3; // push pull
P1_PU |= bPWM3;
PIN_FUNC &= ~bTMR3_PIN_X;
} else {
P4_DIR |= bPWM3_; // push pull
P4_PU |= bPWM3_;
PIN_FUNC |= bTMR3_PIN_X;
Expand All @@ -170,6 +170,7 @@ void analogWrite(__data uint8_t pin, __xdata uint16_t val) {
T3_FIFO_H = 0;
T3_CTRL |= bT3_CNT_EN;
break;
#if defined(CH559)
case PIN_PWM1_:
PIN_FUNC |= (bPWM1_PIN_X);
PWM_CTRL |= bPWM_OUT_EN;
Expand All @@ -180,6 +181,7 @@ void analogWrite(__data uint8_t pin, __xdata uint16_t val) {
PWM_CTRL |= bPWM2_OUT_EN;
PWM_DATA2 = val;
break;
#endif
case NOT_ON_PWM:
default:
if (val < 128) {
Expand Down
47 changes: 36 additions & 11 deletions ch55xduino/ch55x/cores/ch55xduino/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void pinMode(__data uint8_t pin,
P4_DIR_PU &= ~bit;
}
#endif
#if defined(CH559)
#if defined(CH559) || defined(CH558)
if (port == P0PORT) {
PORT_CFG &= ~bP0_OC;
P0_PU &= ~bit;
Expand Down Expand Up @@ -88,7 +88,7 @@ void pinMode(__data uint8_t pin,
P4_DIR_PU |= bit;
}
#endif
#if defined(CH559)
#if defined(CH559) || defined(CH558)
if (port == P0PORT) {
PORT_CFG &= ~bP0_OC;
P0_PU |= bit;
Expand Down Expand Up @@ -133,7 +133,7 @@ void pinMode(__data uint8_t pin,
P4_DIR_PU |= bit;
}
#endif
#if defined(CH559)
#if defined(CH559) || defined(CH558)
if (port == P0PORT) {
PORT_CFG &= ~bP0_OC;
P0_DIR |= bit;
Expand Down Expand Up @@ -172,8 +172,31 @@ void pinMode(__data uint8_t pin,
P4_DIR_PU &= ~bit;
}
#endif
// todo: OC mode for CH559
}
#if defined(CH559) || defined(CH558)
// open drain settings - see table 10.2.2 on page 28.
// Selected as "High-impedance input weak standard bi-directional mode with open drain output, pins without pull-up resistor."
// Ports P0-P3 support pure input, push-pull output and standard bi-direction modes, P4 supports pure input and push-pull output modes.
if (port == P0PORT) {
PORT_CFG |= bP0_OC; // clear bP0_OC bit to get open drain and bi-dir modes.
P0_DIR &= ~bit;
P0_PU &= ~bit;
} else if (port == P1PORT) {
PORT_CFG |= bP1_OC;
P1_DIR |= bit;
P1_PU &= ~bit;
} else if (port == P2PORT) {
PORT_CFG |= bP2_OC;
P2_DIR |= bit;
P2_PU &= ~bit;
} else if (port == P3PORT) {
PORT_CFG |= bP3_OC;
P3_DIR |= bit;
P3_PU &= ~bit;
} else if (port == P4PORT) {
P4_DIR |= bit; // Open Drain not supported; fall back to normal output.
}
#endif
} // End of Open Drain mode.
}

static void turnOffPWM(__data uint8_t pwm) {
Expand All @@ -200,8 +223,9 @@ static void turnOffPWM(__data uint8_t pwm) {
}
break;
}
#elif defined(CH559)
#elif defined(CH559) | defined(CH558)
switch (pwm) {
#if defined(CH559) // CH558 only has one PWM(3)
case PIN_PWM1:
if ((PIN_FUNC & bPWM1_PIN_X) == 0) {
PWM_CTRL &= ~bPWM_OUT_EN;
Expand All @@ -222,6 +246,7 @@ static void turnOffPWM(__data uint8_t pwm) {
PWM_CTRL &= ~bPWM2_OUT_EN;
}
break;
#endif
case PIN_PWM3:
if ((PIN_FUNC & bTMR3_PIN_X) == 0) {
if (T3_CTRL & bT3_OUT_EN) {
Expand All @@ -241,7 +266,7 @@ static void turnOffPWM(__data uint8_t pwm) {
pwm;
return;
#endif
// todo: PWM mode for CH559
// todo: PWM mode for CH559 and CHA558
}

uint8_t digitalRead(__data uint8_t pin) {
Expand All @@ -260,7 +285,7 @@ uint8_t digitalRead(__data uint8_t pin) {
__data uint8_t portBuf = 0;

switch (port) {
#if defined(CH551) || defined(CH552) || defined(CH549) || defined(CH559)
#if defined(CH551) || defined(CH552) || defined(CH549) || defined(CH559) || defined(CH558)
case P1PORT:
portBuf = P1;
break;
Expand All @@ -281,7 +306,7 @@ uint8_t digitalRead(__data uint8_t pin) {
case P5PORT:
portBuf = P5;
break;
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
case P0PORT:
portBuf = P0;
break;
Expand Down Expand Up @@ -318,7 +343,7 @@ void digitalWrite(__data uint8_t pin, __xdata uint8_t val) {
EA = 0;

switch (port) {
#if defined(CH551) || defined(CH552) || defined(CH549) || defined(CH559)
#if defined(CH551) || defined(CH552) || defined(CH549) || defined(CH559) || defined(CH558)
case P1PORT:
if (val == LOW) {
P1 &= ~bit;
Expand Down Expand Up @@ -363,7 +388,7 @@ void digitalWrite(__data uint8_t pin, __xdata uint8_t val) {
P5 |= bit;
}
break;
#elif defined(CH559)
#elif defined(CH559) || defined(CH558)
case P0PORT:
if (val == LOW) {
P0 &= ~bit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void setControlLineStateHandler() {

while (1)
;
#elif defined(CH559) && (BOOT_LOAD_ADDR == 0xF400)
#elif (defined(CH559) || defined(CH558)) && (BOOT_LOAD_ADDR == 0xF400)
USB_CTRL = 0;
EA = 0; // Disabling all interrupts is required.
delayMicroseconds(50000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void USBDeviceCfg() {
#if defined(CH551) || defined(CH552) || defined(CH549)
UDEV_CTRL = bUD_PD_DIS; // Disable DP/DM pull-down resistor
#endif
#if defined(CH559)
#if defined(CH559) || defined(CH558)
UDEV_CTRL = bUD_DP_PD_DIS; // Disable DP/DM pull-down resistor
#endif
UDEV_CTRL |= bUD_PORT_EN; // Enable physical port
Expand All @@ -522,7 +522,7 @@ void USBDeviceIntCfg() {
}

void USBDeviceEndPointCfg() {
#if defined(CH559)
#if defined(CH559) || defined(CH558)
// CH559 use differend endianness for these registers
UEP0_DMA_H = ((uint16_t)Ep0Buffer >> 8); // Endpoint 0 data transfer address
UEP0_DMA_L = ((uint16_t)Ep0Buffer >> 0); // Endpoint 0 data transfer address
Expand Down
Loading