Git Product home page Git Product logo

py32f0-template's People

Contributors

deividalfa avatar iosetting avatar kholia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py32f0-template's Issues

PY32F002 32k flash?

Reading some forums i stumped on this:

https://www.elektroda.pl/rtvforum/topic3951956.html

PY32F002 have a 32k flash memory? The author of the post even do a bootloader using the last 1K of the 32(?) k available. Can anyone confirm that?

The post was written in polish.... But google traductor show me this:

"The bootloader takes into account the larger 32kB FLASH memory of the PY32F002 microcontrollers than stated in the PDF and occupies its last 1kB. The initial 31kB is available to the user."

Examples of I2C DMA

Hi,
first of all: thank you for this fantastic repository. The build system setup is super pragmatic, easy to work with - and everything I have tried so far works nicely. And there is an impressive amount of examples.

I have one project with an accelerometer, where I would like to read at high rates (from the built-in FIFO). And it is also doing computationally intensive processing (some DSP and machine learning). So I would be very interested in using the DMA support to enable doing work on the CPU while the transfers are ongoing. I see that there is a DMA_CHANNEL_MAP_I2C* in the code. So there does seem to be support for this. There are DMA examples for the ADC for example, but I have not seen anything for I2C+DMA. Does anyone have such examples and/or tips&tricks? It is basically just receive that would benefit from DMA. SPI+DMA would also be relevant

IIC 驱动无法使用

测试了下IIC 的驱动,并无法使用,只能发送Addr 后面的buf数据无法发送出来

Unlocking and erasing protected flash on PY32 chips

Hi,

I am experimenting with flash protection on PY32 chips with the following program:

#include <string.h>
#include "main.h"
#include "py32f0xx_bsp_clock.h"
#include "py32f0xx_bsp_printf.h"

static void APP_GPIOConfig(void);

static void APP_FlashSetOptionBytes(void)
{
  FLASH_OBProgramInitTypeDef OBInitCfg;

  LL_FLASH_Unlock();
  LL_FLASH_OB_Unlock();

  OBInitCfg.OptionType = OPTIONBYTE_USER;
  OBInitCfg.USERType = OB_USER_BOR_EN | OB_USER_BOR_LEV | OB_USER_IWDG_SW | OB_USER_WWDG_SW | OB_USER_NRST_MODE | OB_USER_nBOOT1;
  OBInitCfg.USERConfig = OB_BOR_DISABLE | OB_BOR_LEVEL_3p1_3p2 | OB_IWDG_SW | OB_WWDG_SW | OB_RESET_MODE_RESET | OB_BOOT1_SYSTEM;
  LL_FLASH_OBProgram(&OBInitCfg);

  LL_FLASH_OB_RDP_LevelConfig(OB_RDP_LEVEL_1);

  LL_FLASH_Lock();
  LL_FLASH_OB_Lock();
  /* Reload option bytes */
  LL_FLASH_OB_Launch();
}

int main(void)
{
  /* Set clock = 8MHz */
  BSP_RCC_HSI_8MConfig();

  /* Enable peripheral clock */
  LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA | LL_IOP_GRP1_PERIPH_GPIOB);

  BSP_USART_Config(115200);
  printf("SPI Demo: nRF24L01 Wireless\r\nClock: %ld\r\n", SystemCoreClock);

  APP_GPIOConfig();

  LL_mDelay(7000);

  uint32_t rdplvl = READ_BIT(FLASH->OPTR, FLASH_OPTR_RDP);
  if (rdplvl == OB_RDP_LEVEL_0) {
    APP_FlashSetOptionBytes();
  }
  else
  {
    printf("RESET has been configurated as RESET\r\n");
  }

  while (1)
  {
    printf("nRF24L01 check: error\r\n");
    LL_mDelay(2000);
  }
}

static void APP_GPIOConfig(void)
{
  LL_GPIO_InitTypeDef GPIO_InitStruct;

  // PA6 CSN
  LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_6, LL_GPIO_MODE_OUTPUT);
  // PA5 CE
  LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_5, LL_GPIO_MODE_OUTPUT);
  /* PA4 as input */
  GPIO_InitStruct.Pin = LL_GPIO_PIN_4;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}

void APP_ErrorHandler(void)
{
  while (1);
}

#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line)
{
  while (1);
}
#endif /* USE_FULL_ASSERT */

After power-cycling the PY32 chip (FY32F003 in SOP-8 package), I can no longer erase the chip using J-Link.

Is there a known method to Unlock and Erase the protected flash memory on PY32 chips?

https://dzone.com/articles/unlocking-and-erasing-flash is a good read on this topic but I didn't a method which works for PY32 chips yet.

Thanks for the help.

Does PY32Fxx series support True Open Drain?

Hi IOsetting.

I wonder if PY32Fxx series support True Open Drain when with 3V3 supply like STM8S does. I have read the datasheet and nothing about 5VFT. It seems that you are so familiar with this series. Would you like to confirm if it's supported. Thanks in advance.

[question] What is the story of this repository?

I want to understand where these examples (actually a lot of them!) come from. They look a bit like generated from a codegen tool similar to stm32cubemx.

I was trying to find if puya provides such tool, but it's hard to google this on the western side of the internet.

The actual problem I'd like to solve is running the HAL_I2C_MODE_MEM mode, in hopes of emulating a generic IO expander as close as possible. This would be extremely useful, seeing that any I2C ADC or IO expander are more expensive than this MCU, let alone anything with more fancy utils like charlieplexing, built-in conditions, etc.

PY32F002 SOP8 USART Reset

Hi,

I'm facing a strange problem with PY32F002AL15S6TU SOP package. When compilling the default repo project for PY32F002, printf always reset microcontroller when 0x32(space) is sento do USART1->DR.

I've already tested initializing USART and doing:

USART1->DR = 'A';
delay(); //long enough to send data and be busy
USART1->DR = 'B';
delay();
USART1->DR = 'C';
delay();
USART1->DR = ' '; // Reset here

I'm suspecting because the PIN6 [PA2/PF2-RESET shares functions as Reset and USART TX. But I've disabled reset function writing OptionBytes and the behaviour is the same. py32f002 sop8 pins

PlatformIO?

It's possible to add support in Platform IO for this MCU family? I'm willing to help.

Help with LSI as Clock Source to reduce power consumption

Hi,
As per Py32f030 datasheet, with LSI as clock source the power consumption in run mode is around 0.1ma.

I set the Low Speed Clock Source to LSI 32.768KHZ but it's not working. The power consumption still at around 0.4ma.

I try to set it in HAL mode also but still not working

RCC_OscInitTypeDef OSCINIT;
  RCC_PeriphCLKInitTypeDef LPTIM_RCC;

  /* LSI时钟配置 */
  OSCINIT.LSEState=RCC_LSE_OFF;
  OSCINIT.HSIState=RCC_HSI_OFF;
  OSCINIT.OscillatorType = RCC_OSCILLATORTYPE_LSI;  /* 选择配置LSI */
  OSCINIT.LSIState = RCC_LSI_ON;                    /* LSI开启 */

Any configuration I am missing?

Thanks;

get SWO to work

Hello,

have you been able to get SWO to work with Keil?
if yes please provide the configuration

LL /HAL documentation

First: thanks for your work on this, this is great!

Second: do you know if there exists any documentation for the peripherals libraries? They look like clones of the ST libraries, but I'm not sure what differences there are, or if I can / should just use the ST docs

PY32F002AF15P6TU Breakout board

This is a simple dev board that I design... It has jumpers to select the VCC voltage, it has onboard 3.3vregulator, boot and reset buttons, and the elements for a future software USB?? (The D+ and D- lines are unconnected but exposed on test pads).

I already ordered the elements on LCSC and the boards on JLCPCB. Waiting for them to arrive.

imagen
imagen
imagen
imagen

Microsecond delay

Hi,
I need to migrate code from Arduino to LL which use delayMicroseconds(), which is not availabe in LL as far as I know.

I come across this code of microseconds delay, is it correct?



 uint32_t   wait_loop_index = (usDelay * (SystemCoreClock / 1000000U));
                while(wait_loop_index != 0U)
                {
                    wait_loop_index--;
                }

Thanks;

Urecognized option '--no-warn-rwx-segments'

I think this option is available on gcc 12.x, On Ubuntu default toolchain available is 10.3.1 and this option is not recognized.

ld error: unrecognized option '--no-warn-rwx-segments'

PY32F002B Suppoert

Great project!
Any plan to support Py32F002B series? come with more efficiency low ower consumption.

新人求助 关于ll库

我在makefile里启用了LL库,但是在程序中使用BSP的还是HAL库的,使用LL库的内容也提示错误
图片
图片

`

Use LL library instead of HAL, y:yes, n:no

USE_LL_LIB ?= y

Enable printf float %f support, y:yes, n:no

ENABLE_PRINTF_FLOAT ?= n

Build with FreeRTOS, y:yes, n:no

USE_FREERTOS ?= n

Build with CMSIS DSP functions, y:yes, n:no

USE_DSP ?= n

Build with Waveshare e-paper lib, y:yes, n:no

USE_EPAPER ?= n

Programmer, jlink or pyocd

FLASH_PROGRM ?= pyocd
`

Target LIB_FLAGS = PY32F002Ax5 tries to configure USART2 (which doesn't exist on this device)

I'm trying to compile Examples/LL/GPIO/LED_Toggle - I copied all the source files from there to User, and edited the Makefile to refer to the PY32F002Ax5 device (linker scripts, pyocd target and libraries). I also edited the source file to toggle porta 5.

When I leave the library flags set to the F030x device, it compiles and flashes fine, and the LED blinks. However, when I set the lib_flags to the correct device, I get the following (note the USART complains, as well as the BSP clock warnings):

$ make -j

CC User/main.c
CC User/py32f0xx_it.c
CC Libraries/CMSIS/Device/PY32F0xx/Source/system_py32f0xx.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_pwr.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_flash.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_i2c.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_comp.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_led.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_rtc.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_gpio.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_crc.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_spi.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_lptim.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_dma.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_usart.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_adc.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_rcc.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_exti.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_utils.c
CC Libraries/PY32F0xx_LL_Driver/Src/py32f0xx_ll_tim.c
CC Libraries/BSP_LL/Src/py32f0xx_bsp_led.c
CC Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c
CC Libraries/BSP_LL/Src/py32f0xx_bsp_button.c
AS Libraries/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f002.s
CC Libraries/BSP_LL/Src/py32f0xx_bsp_clock.c
In file included from Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c:4:
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c: In function 'BSP_UART_TxChar':
./Libraries/BSP_LL/Inc/py32f0xx_bsp_printf.h:34:49: error: 'USART2' undeclared (first use in this function); did you mean 'USART1'?
34 | #define DEBUG_USART USART2
| ^~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c:10:28: note: in expansion of macro 'DEBUG_USART'
10 | LL_USART_TransmitData8(DEBUG_USART, ch);
| ^~~~~~~~~~~
./Libraries/BSP_LL/Inc/py32f0xx_bsp_printf.h:34:49: note: each undeclared identifier is reported only once for each function it appears in
34 | #define DEBUG_USART USART2
| ^~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c:10:28: note: in expansion of macro 'DEBUG_USART'
10 | LL_USART_TransmitData8(DEBUG_USART, ch);
| ^~~~~~~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c: In function 'BSP_USART_Config':
./Libraries/BSP_LL/Inc/py32f0xx_bsp_printf.h:35:74: error: 'LL_APB1_GRP1_PERIPH_USART2' undeclared (first use in this function); did you mean 'LL_APB1_GRP2_PERIPH_USART1'?
35 | #define DEBUG_USART_CLK_ENABLE() LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c:53:5: note: in expansion of macro 'DEBUG_USART_CLK_ENABLE'
53 | DEBUG_USART_CLK_ENABLE();
| ^~~~~~~~~~~~~~~~~~~~~~
./Libraries/BSP_LL/Inc/py32f0xx_bsp_printf.h:34:49: error: 'USART2' undeclared (first use in this function); did you mean 'USART1'?
34 | #define DEBUG_USART USART2
| ^~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c:56:26: note: in expansion of macro 'DEBUG_USART'
56 | LL_USART_SetBaudRate(DEBUG_USART, SystemCoreClock, LL_USART_OVERSAMPLING_16, baudRate);
| ^~~~~~~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c: In function '__io_putchar':
./Libraries/BSP_LL/Inc/py32f0xx_bsp_printf.h:34:49: error: 'USART2' undeclared (first use in this function); did you mean 'USART1'?
34 | #define DEBUG_USART USART2
| ^~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c:106:28: note: in expansion of macro 'DEBUG_USART'
106 | LL_USART_TransmitData8(DEBUG_USART, ch);
| ^~~~~~~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c: In function '__io_getchar':
./Libraries/BSP_LL/Inc/py32f0xx_bsp_printf.h:34:49: error: 'USART2' undeclared (first use in this function); did you mean 'USART1'?
34 | #define DEBUG_USART USART2
| ^~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_printf.c:116:40: note: in expansion of macro 'DEBUG_USART'
116 | while (!LL_USART_IsActiveFlag_RXNE(DEBUG_USART));
| ^~~~~~~~~~~
make: *** [rules.mk:80: Build/Libraries/BSP_LL/Src/py32f0xx_bsp_printf.o] Error 1
make: *** Waiting for unfinished jobs....
Libraries/BSP_LL/Src/py32f0xx_bsp_clock.c: In function 'BSP_RCC_HSI_PLL48MConfig':
Libraries/BSP_LL/Src/py32f0xx_bsp_clock.c:14:3: warning: implicit declaration of function 'LL_PLL_ConfigSystemClock_HSI' [-Wimplicit-function-declaration]
14 | LL_PLL_ConfigSystemClock_HSI(&UTILS_ClkInitStruct);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Libraries/BSP_LL/Src/py32f0xx_bsp_clock.c: In function 'BSP_RCC_HSE_PLLConfig':
Libraries/BSP_LL/Src/py32f0xx_bsp_clock.c:65:3: warning: implicit declaration of function 'LL_PLL_ConfigSystemClock_HSE' [-Wimplicit-function-declaration]
65 | LL_PLL_ConfigSystemClock_HSE(HSE_VALUE, LL_UTILS_HSEBYPASS_OFF, &UTILS_ClkInitStruct);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

What is the closest STM32 part¿?

Hello again.
Im wondering what is the closest MCU on the STM32 family to this microcontroller?
I want try to port the arduino core for the PY32F0 and i don't want to start from scratch.

Current Consumption in Deep Sleep LSI

In this example:
https://github.com/IOsetting/py32f0-template/blob/main/Examples/PY32F002B/LL/LPTIM/LPTIM_LSI_DeepStop_WakeUp/main.c


/**
  ******************************************************************************
  * PY32F002B Deep Stop Wake Up By LPTIM(LSI)
  * 
  * Connections
  *  PB5      --->    - LED +   ---> 3.3V
  *  VCC      ---> 3.3V
  *  GND      ---> GND 
  *  
  * - MCU enters deep stop mode after 3 seconds,
  * - LED blinks every 5 seconds (In low voltage LSI becomes slower and slower, the 
  *   interval will be longer than expected)
  * - Current consumption is around 0.6uA in deep stop mode
  */

Its description said it consumes around 0.6uA in deep stop mode.

Is this figure real? As per its datasheet, it should be around 5ua or above.

I don't have Py32F002B to test, I have only F002A.

Possible hardware bug: CCP hangs the system if RDP1 is set ?

I simplify the project as most as I could.
Sorry, it's made for patched CubeIDE, I'm not good with makefiles, but it uses the same files as this template, so it should be easy to setup.
Timer1 CC ISR captures falling edges, sets "new_capture" variable and disables itself.
Systick ISR check for this variable, makes a led pulse as indication, also toggles another led to indicate the system is running, and restarts the capture.
Without RDP, I can beat the CCP input in any way, it always works under any optimization level.
When I enable RDP, it will randomly crash.
I attached the debugger, with RDP enabled I can only access the CPU registers, but I can see the program counter.
In the instant the problem happens, the debugger halts and shows this.
Target halted (Vector catch, PC = 0xFFFFFFFE) and Read register 'pc' (4 bytes) from hardware: 0xFEFFFFFF are clearly a problem!

...Target halted (Vector catch, PC = 0xFFFFFFFE)
Reading common registers: Read register 'r0' (4 bytes) from hardware: 0x0000000A
Read register 'r1' (4 bytes) from hardware: 0x05000000
Read register 'r2' (4 bytes) from hardware: 0x01000000
Read register 'r3' (4 bytes) from hardware: 0x01000000
Read register 'r4' (4 bytes) from hardware: 0xE70B0020
Read register 'r5' (4 bytes) from hardware: 0x01000000
Read register 'r6' (4 bytes) from hardware: 0xDC0BFF1F
Read register 'r7' (4 bytes) from hardware: 0xD80B0020
Read register 'r8' (4 bytes) from hardware: 0x24B763A1
Read register 'r9' (4 bytes) from hardware: 0x64020020
Read register 'r10' (4 bytes) from hardware: 0x1BD00CED
Read register 'r11' (4 bytes) from hardware: 0x273F3419
Read register 'r12' (4 bytes) from hardware: 0x00E0FFFF
Read register 'sp' (4 bytes) from hardware: 0xB80B0020
Read register 'lr' (4 bytes) from hardware: 0xF9FFFFFF
Read register 'pc' (4 bytes) from hardware: 0xFEFFFFFF
Read register 'xpsr' (4 bytes) from hardware: 0x03000061
WARNING: Failed to read memory @ address 0xFFFFFFFE
Read 4 bytes @ address 0x20000BD4 (Data = 0x61000000)
Reading 64 bytes @ address 0x20000BC0
WARNING: Failed to read memory @ address 0x0800080C
WARNING: Failed to read memory @ address 0x08001EFA
WARNING: Failed to read memory @ address 0x08001EFA
Read 4 bytes @ address 0xE000ED04 (Data = 0x00420003)
Read 4 bytes @ address 0xE000ED0C (Data = 0xFA050000)
Read 4 bytes @ address 0xE000ED04 (Data = 0x00420003)
Read 4 bytes @ address 0xE000ED1C (Data = 0x00000000)
Read 4 bytes @ address 0xE000ED20 (Data = 0x00000000)
Read 4 bytes @ address 0xE000ED24 (Data = 0x00000000)
Read 4 bytes @ address 0xE000ED08 (Data = 0x08000000)
Read 4 bytes @ address 0xE000E010 (Data = 0x00000004)
Read 4 bytes @ address 0xE000E014 (Data = 0x000F398E)
Read 4 bytes @ address 0xE000E018 (Data = 0x009F0E6E)
Read 4 bytes @ address 0xE000E01C (Data = 0x80000000)
Read 4 bytes @ address 0xE000E01C (Data = 0x80000000)

This is not a HardFault, as I have a led toggling routine there that would flash a led, it works if I try to access unimplemented memory.

Here's the project:
PY32F002A_test.zip

I've tried other timers with the same result.
Setting other IRQ modes, like PWM, doesn't cause any issues, only in CCP!

reprogramming PY32F002A

Hi, I have successfully build and flashed PY32F002AL15S, using puyocd and ST-LINK V2. However I am unable to get the IC detected again on SWD. I believe since pins are used inside the firmware (which is already flashed), How can I enable SWD again on this chip? as per reference manual, POR should enable those pins, but pyocd does not detect. I do not have any idea how to reprogram this chip.

LL pwm fade

/***
 * Demo: TIM1 PWM output fade on PB3
 * 
 * Board: PY32F002AF15P
 */
#include "main.h"
#include "py32f0xx_bsp_clock.h"
#include "py32f0xx_bsp_printf.h"

static void APP_TIM1Config(void);
static void APP_PWMChannelConfig(void);
static void APP_SystemClockConfig(void);
void setPWM(uint8_t duty);


int main(void)
{
  BSP_RCC_HSI_24MConfig();
  BSP_USART_Config(115200);
  printf("PY32F002AF15P TIM1 PWM Fade PB3 Demo\r\nClock: %ld\r\n", SystemCoreClock);

  APP_TIM1Config();
  APP_PWMChannelConfig();
  
  while(1){
  
    for (uint8_t duty = 1; duty < 255; duty++)
    {
      setPWM(duty);
      LL_mDelay(1);
    }
    for (uint8_t duty = 255; duty > 0; duty--)
    {
      setPWM(duty);
      LL_mDelay(1);
    }
  }
}

static void APP_SystemClockConfig(void)
{
  LL_RCC_HSI_Enable();
  while(LL_RCC_HSI_IsReady() != 1);

  LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSISYS);
  while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSISYS);

  LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  LL_Init1msTick(8000000);
  LL_SetSystemCoreClock(8000000);
}

static void APP_PWMChannelConfig(void)
{
  LL_GPIO_InitTypeDef GPIO_InitTypeDef;
  LL_TIM_OC_InitTypeDef TIM_OC_Initstruct;

  LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);

  /* PB3:AF1->TIM1_CH2 */
  GPIO_InitTypeDef.Pin = LL_GPIO_PIN_3;
  GPIO_InitTypeDef.Mode = LL_GPIO_MODE_ALTERNATE;
  GPIO_InitTypeDef.Alternate = LL_GPIO_AF_1;
  LL_GPIO_Init(GPIOB, &GPIO_InitTypeDef);

  TIM_OC_Initstruct.OCMode = LL_TIM_OCMODE_PWM2;
  TIM_OC_Initstruct.OCState = LL_TIM_OCSTATE_ENABLE;
  TIM_OC_Initstruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  TIM_OC_Initstruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;

  /* Set channel compare value */
  TIM_OC_Initstruct.CompareValue = 0;
  LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH2, &TIM_OC_Initstruct);
}

static void APP_TIM1Config(void)
{
  LL_TIM_InitTypeDef TIM1CountInit = {0};

  LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1);
 
  TIM1CountInit.ClockDivision       = LL_TIM_CLOCKDIVISION_DIV1;
  TIM1CountInit.CounterMode         = LL_TIM_COUNTERMODE_UP;
  TIM1CountInit.Prescaler           = 1;
  /* PWM period = 255 */
  TIM1CountInit.Autoreload          = 256;
  TIM1CountInit.RepetitionCounter   = 0;
  LL_TIM_Init(TIM1, &TIM1CountInit);

  LL_TIM_EnableAllOutputs(TIM1);
  LL_TIM_EnableCounter(TIM1);
}

void setPWM(uint8_t duty)
{
  LL_TIM_OC_SetCompareCH2(TIM1, (uint16_t)duty);
}

void APP_ErrorHandler(void)
{
  while (1);
}

app crashes during UART transmit (printf) on PY32F002AL15S6TU

I compiled the code without changing anything (except changing the target in the make file) using arm-none-eabi-gcc.exe (GCC) 12.2.0 and loaded the bin file to PY32F002AL15S6TU.

When I comment out printf the led is flashing as expected, otherwise it just crashes and writes garbage to the UART pin.

What really strange is, when I try sending 'e' with
huart->Instance->DR = (uint8_t)('e' & 0xFFU);
it works
but with 'a':
huart->Instance->DR = (uint8_t)('a' & 0xFFU);
it sends garbage and the app crashes!!!

Has anyone faced similar issues?

Arduino Support

Hello, thank you for this project once again.
I want to add Arduino support for the PY32F002.
As IOsetting mentioned earlier, there are some projects that do this for another chip called AIR001.
I've collected some test sketches and can confirm that if I upload the hexadecimal to the PY32F002, it works perfectly.
So, I'm thinking of cloning the repository and adapting the source code for this MCU.
I have some questions about how to do this.
Is it correct to take the source code from the repository and adapt it for this MCU?
Would any of you be interested in doing this?
Is it worth doing this?
Some of you have mentioned that the resources of this MCU might not be sufficient for the Arduino environment.
Based on the results and libraries ported by the other project, do you believe this to be the case?
Thank you and warm regards!

C++ Support

Hi,
I am from Arduino. I can get some code here to work. Somehow, I am not able to get CPP library to work here.

Any suggestion on how to get CPP to work here?

Thanks;

ADC support on PY32F002A

Hi, i'm currently trying to get the LL ADC demos to work on the py32F002A, the basic led blink/uart demos work just fine but the ADC demo makes use of DMA features which don't exist on this specific MCU (030 and 003 only), even after commenting out the dma related lines the demo doesn't seem to work (no uart output besides the first line stating the name of the demo and the clock speed).

Do you have any idea what would need to be changed to acquire ADC data on the 002A?

Stop Mode on other families beside Py32f002B

Hi,
I try to adapt your code to other families but I have to remark two lines out as it's only available on Py32F002B and it goes to 12ua,

/* STOP mode with deep low power regulator ON */
  //LL_PWR_SetLprMode(LL_PWR_LPR_MODE_LDPR);

  /* SRAM retention voltage aligned with digital LDO output */
  //LL_PWR_SetStopModeSramVoltCtrl(LL_PWR_SRAM_RETENTION_VOLT_CTRL_LDO);

https://github.com/IOsetting/py32f0-template/blob/main/Examples/PY32F002B/LL/PWR/PWR_DeepStop/main.c

I try the OpenPuya git and I can only get 8ua.

I use Py32f002a and Py32f030

ADC_COMP_IRQn on PY32F002A

Hello,

Thank you a lot for this repository, it's very useful!
I found a possible confusing issue: I'm using ADC on 02A with ADC_COMP_IRQn interrupt and I found out that it never triggers if I compile with MCU_TYPE = PY32F002Ax5 but it works fine when compiling for PY32F003x6 . The code is Examples/PY32F0xx/LL/ADC/ADC_SingleConversion_TriggerTimer .

Here is what I tried and found: (a) I tried my own code as well, same issue. (b) I also tried without interrupt: busy wait like example ADC_InternalTemperature this works fine in all cases so ADC is working properly. (c) I don't know how to debug with SWD and OCD yet so I used a led to indicate if interrupt is called. (d) my project is using other interrupts like TIM16_IRQn, EXTI2_3_IRQn, etc so I know other interrupts work, the code to enable them too.

I came to conclusion that the ADC is working but the interrupt ADC_COMP_IRQn is either (1) never enabled properly if MCU_TYPE = PY32F002Ax5 when doing this:

  LL_ADC_EnableIT_EOC(ADC1); // interrupt
  NVIC_SetPriority(ADC_COMP_IRQn, 0);
  NVIC_EnableIRQ(ADC_COMP_IRQn);
  LL_ADC_REG_StartConversion(ADC1); // start conversion, should trigger interrupt

or (2) the interrupt is raised but its routine is never called through IRQ. I'm out of idea how to debug this. I thought to report as it may be a bug, and very sneaky one. I have checked the headers and similar device-specific files, I couldn't find an obvious difference about the ADC.

Deep sleep current consumption

Hi,
I plan to use it for remote sensor with 3 aaa batteries.
I cannot find any info regarding its current consumption in deep sleep.

thanks

Vscode Picoprobe Debug

Hi,

I'm using picoprobe and pyocd to flash py32f002 uC, but when i'm trying your config file launch.json to debug through vscode/picoprobe, nothing happens.

What could be the problem? Can I use your config launch.json with picoprobe?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.