Skip to content

Commit

Permalink
Merge remote-tracking branch 'cnlohr/master' into other-chip-support
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderMandera committed Jan 8, 2024
2 parents 452e299 + 7e66742 commit a7462c4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
15 changes: 6 additions & 9 deletions ch32v003fun/ch32v003fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ int putchar(int c)
void handle_debug_input( int numbytes, uint8_t * data ) __attribute__((weak));
void handle_debug_input( int numbytes, uint8_t * data ) { }

static void internal_handle_input( uint32_t * dmdata0 )
static void internal_handle_input( volatile uint32_t * dmdata0 )
{
uint32_t dmd0 = *dmdata0;
int bytes = (dmd0 & 0x3f) - 4;
Expand All @@ -1265,11 +1265,12 @@ static void internal_handle_input( uint32_t * dmdata0 )

void poll_input()
{
uint32_t lastdmd = (*DMDATA0);
if( !(lastdmd & 0x80) )
volatile uint32_t * dmdata0 = (volatile uint32_t *)DMDATA0;
if( ((*dmdata0) & 0x80) == 0 )
{
internal_handle_input( (uint32_t*)DMDATA0 );
*DMDATA0 = 0x84; // Negative
internal_handle_input( dmdata0 );
// Should be 0x80 or so, but for some reason there's a bug that retriggers.
*dmdata0 = 0x00;
}
}

Expand Down Expand Up @@ -1337,10 +1338,6 @@ int putchar(int c)
if( timeout-- == 0 ) return 0;

// Simply seeking input.
lastdmd = (*DMDATA0);
if( lastdmd ) internal_handle_input( (uint32_t*)DMDATA0 );

while( (lastdmd = (*DMDATA0)) & 0x80 ) if( timeout-- == 0 ) return 0;
if( lastdmd ) internal_handle_input( (uint32_t*)DMDATA0 );
*DMDATA0 = 0x85 | ((const char)c<<8);
return 1;
Expand Down
39 changes: 39 additions & 0 deletions ch32v003fun/ch32v003fun.h
Original file line number Diff line number Diff line change
Expand Up @@ -11519,6 +11519,45 @@ RV_STATIC_INLINE void __disable_irq()
__asm volatile ("csrw mstatus, %0" : : "r" (result) );
}

/*********************************************************************
* @fn __isenabled_irq
*
* @brief Is Global Interrupt enabled
*
* @return 1: yes, 0: no
*/
RV_STATIC_INLINE uint8_t __isenabled_irq(void)
{
uint32_t result;

__asm volatile(
#if __GNUC__ > 10
".option arch, +zicsr\n"
#endif
"csrr %0," "mstatus": "=r"(result));
return (result & 0x08) != 0u;
}

/*********************************************************************
* @fn __get_cpu_sp
*
* @brief Get stack pointer
*
* @return stack pointer
*/
RV_STATIC_INLINE uint32_t __get_cpu_sp(void);
RV_STATIC_INLINE uint32_t __get_cpu_sp(void)
{
uint32_t result;

__asm volatile(
#if __GNUC__ > 10
".option arch, +zicsr\n"
#endif
"mv %0, sp" : "=r"(result));
return result;
}

/*********************************************************************
* @fn __NOP
*
Expand Down
3 changes: 0 additions & 3 deletions examples/direct_gpio/direct_gpio.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "ch32v003fun.h"
#include <stdio.h>

uint32_t count;

int main()
{
SystemInit();
Expand Down Expand Up @@ -41,7 +39,6 @@ int main()
GPIOC->OUTDR &= ~(1<<(4)); // CLEAR GPIO C4

Delay_Ms( 50 );
count++;
}
}

4 changes: 3 additions & 1 deletion minichlink/99-minichlink.rules
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
SUBSYSTEM=="usb", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="8010", GROUP="plugdev", MODE="0660"
SUBSYSTEM=="usb", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="4004", GROUP="plugdev", MODE="0660"
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="303a", ATTRS{idProduct}=="4004", GROUP="plugdev", MODE="0660"

# rv003usb bootloader
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="b003", GROUP="plugdev", MODE="0660"
#KERNEL=="hiddev*", SUBSYSTEM=="usbmisc", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="b003", GROUP="plugdev", MODE="0660"
3 changes: 2 additions & 1 deletion minichlink/minichlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int main( int argc, char ** argv )
if( i < argc )
hints.serial_port = argv[i];
}
else if( strncmp( v, "-c", 2 ) == 0 )
else if( strncmp( v, "-C", 2 ) == 0 )
{
i++;
if( i < argc )
Expand Down Expand Up @@ -649,6 +649,7 @@ int main( int argc, char ** argv )
fprintf( stderr, " -t Disable 3.3V\n" );
fprintf( stderr, " -f Disable 5V\n" );
fprintf( stderr, " -c [serial port for Ardulink, try /dev/ttyACM0 or COM11 etc]\n" );
fprintf( stderr, " -C [specified programmer, eg. b003boot, ardulink, esp32s2chfun]\n" );
fprintf( stderr, " -u Clear all code flash - by power off (also can unbrick)\n" );
fprintf( stderr, " -E Erase chip\n" );
fprintf( stderr, " -b Reboot out of Halt\n" );
Expand Down

0 comments on commit a7462c4

Please sign in to comment.