3006 views|5 replies

862

Posts

2

Resources
The OP
 

2. Evaluation starts with lighting [Copy link]

This post was last edited by wo4fisher on 2022-1-16 14:52

Getting started with a single-chip microcomputer usually starts with the microcontroller output 0/1. The most intuitive phenomenon is lighting up an LED, making an LED flash on and off, multiple LED running lights, etc.

GD32L233C-START has 4 LEDs on board, so there are many ways to play with these 4 LEDs.

1. Analysis of existing resources

The official website provides a wealth of resources, mainly GD32L23x_Firmware_Library_V1.0.1, GD32L23x_AddOn_V1.0.0 (GigaDevice.GD32L23x_DFP_1.0.0.pack) and GD32L23x_Demo_Suites_V1.1.0.

By analyzing the source code of the above resources, GD32L23x_Firmware_Library_V1.0.1 is the latest standard library version, based on V1.0.0, with some peripherals modified. It also provides a wealth of routines based on the GD32L233R-EVAL-V1.0 board.

GD32L23x_AddOn_V1.0.0 provides KEIL and IAR packs. After installation, the version displayed in KEIL is V0.0.0, but by opening the library file source code, you can see that it should be synchronized with GD32L23x_Firmware_Library_V1.0.1.

GD32L23x_Demo_Suites_V1.1.0 mainly provides routines for three boards: GD32L233C-START , GD32L233K_START\GD32L233R_EVAL. Because START is an entry-level board, the onboard resources are limited, and the routines only include LED, Key, EXTI_Key, USART, TIMER_Key, and USBD_CDC.

Although the standard library versions of the other three resource packages are the same, the file sizes of some source code files are different. This needs to be paid attention to when using them.

2. GD32L233C-START LED Hardware Circuit

GD32L233C-START has 4 LEDs in total, which are controlled by four pins PA7, PA8, PC6 and PC7 respectively, and high level is valid.

3. Lighting program in GD32L23x_Demo_Suites_V1.1.0

Unzip the GD32L23x_Demo_Suites_V1.1.0 package to a non-Chinese directory, then open the first example, compile, 0error, 0warning. Then confirm the option information of the project and use CMSIS-DAP.

After downloading, you can see 4 LEDs light up in sequence.

4. Source Code Analysis

4.1 Systick configuration and usage

4.1.1 Configuration

void systick_config(void)
{
    /* setup systick timer for 1000Hz interrupts */
    if(SysTick_Config(SystemCoreClock / 1000U)) {
        /* capture error */
        while(1) {
        }
    }
    /* configure the systick handler priority */
    NVIC_SetPriority(SysTick_IRQn, 0x00U);
}

The configuration procedure is relatively simple, calling two library functions, SysTick_Config() configures the systick's clock configuration and working mode according to the system clock and timing cycle. SysTick_Config() configures the systick's interrupt priority.

4.1.2 Use

volatile static uint32_t delay;
void delay_decrement(void)
{
    if(0U != delay) {
        delay--;
    }
}
void delay_1ms(uint32_t count)
{
    delay = count;

    while(0U != delay) {
    }
}

First, define a variable for decrementing in the tick interrupt. Then the delay_decrement() function is called in the tick interrupt, and when delay is not 0, it is decremented by 1. Use delay_1ms() to delay where a ms-level delay is required, with the parameter being the number of milliseconds to delay.

***Such a delay function actually has limitations. For example, after calling delay_1ms(10) once, after a 10ms delay, before the next call to delay_1ms(), delay is always 0. Compared with the systick delay method that has been used in STM32, the tick delay function given by GD has very large limitations. It can only be used as a delay function.

4.2 GPIO configuration and set/clear operation

    /* enable the LED GPIO clock */
    rcu_periph_clock_enable(RCU_GPIOA);
    /* configure LED GPIO pin */
    gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_7 | GPIO_PIN_8);
    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7 | GPIO_PIN_8);
    /* reset LED GPIO pin */
    gpio_bit_reset(GPIOA, GPIO_PIN_7 | GPIO_PIN_8);
    /* set LED GPIO pin */
    gpio_bit_set(GPIOA, GPIO_PIN_7 | GPIO_PIN_8);

Three steps: Step 1: Turn on the clock; Step 2: gpio_mode_set() sets input and output, pull-up and pull-down, gpio_output_options_set() sets output type and speed; Step 3: gpio_bit_reset() and gpio_bit_set() functions perform pin output set/clear operations. For each function, any number of pins can be operated, and they can be non-continuous pins.

/* set GPIO pin bit */
void gpio_bit_set(uint32_t gpio_periph, uint32_t pin);
/* reset GPIO pin bit */
void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin);
/* write data to the specified GPIO pin */
void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value);
/* write data to the specified GPIO port */
void gpio_port_write(uint32_t gpio_periph, uint16_t data);

/* get GPIO pin input status */
FlagStatus gpio_input_bit_get(uint32_t gpio_periph, uint32_t pin);
/* get GPIO port input status */
uint16_t gpio_input_port_get(uint32_t gpio_periph);
/* get GPIO pin output status */
FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin);
/* get GPIO port output status */
uint16_t gpio_output_port_get(uint32_t gpio_periph);

/* set GPIO alternate function */
void gpio_af_set(uint32_t gpio_periph, uint32_t alt_func_num, uint32_t pin);
/* lock GPIO pin bit */
void gpio_pin_lock(uint32_t gpio_periph, uint32_t pin);

/* toggle GPIO pin status */
void gpio_bit_toggle(uint32_t gpio_periph, uint32_t pin);
/* toggle GPIO port status */
void gpio_port_toggle(uint32_t gpio_periph);

In the library file, the operations of GPIO, whether input or output, basically cover all the operations used in daily life. When using, just call the corresponding function directly.

Water lamp transformation:

Modify the following code

    /* reset LED GPIO pin   修改前*/
    gpio_bit_reset(GPIOA, GPIO_PIN_7 | GPIO_PIN_8);
    gpio_bit_reset(GPIOC, GPIO_PIN_6 | GPIO_PIN_7);

    /* reset LED GPIO pin   修改后*/
    gpio_bit_reset(GPIOA, GPIO_PIN_7 | GPIO_PIN_8);
    gpio_bit_set(GPIOC, GPIO_PIN_6 | GPIO_PIN_7);

Then change the content of while(1) as follows (comment out the original code and add the following three lines):

        
          /* turn on LED1, turn off LED4 */
//        gpio_bit_set(GPIOA, GPIO_PIN_7);
//        gpio_bit_reset(GPIOC, GPIO_PIN_7);
//        delay_1ms(500);

//        /* turn on LED2, turn off LED1 */
//        gpio_bit_set(GPIOA, GPIO_PIN_8);
//        gpio_bit_reset(GPIOA, GPIO_PIN_7);
//        delay_1ms(500);

//        /* turn on LED3, turn off LED2 */
//        gpio_bit_set(GPIOC, GPIO_PIN_6);
//        gpio_bit_reset(GPIOA, GPIO_PIN_8);
//        delay_1ms(500);

//        /* turn on LED4, turn off LED3 */
//        gpio_bit_set(GPIOC, GPIO_PIN_7);
//        gpio_bit_reset(GPIOC, GPIO_PIN_6);
//        delay_1ms(500);
			    
		  gpio_bit_toggle(GPIOA, GPIO_PIN_7 | GPIO_PIN_8);
		  gpio_bit_toggle(GPIOC, GPIO_PIN_6 | GPIO_PIN_7);
		  delay_1ms(500);

A new running light is now available. With the standard library, lighting a light is very simple.

This post is from GD32 MCU

Latest reply

If you know how to use C language and have the standard library, lighting a lamp is really simple.   Details Published on 2022-1-18 13:52
Personal signature水不撩不知深浅 人不拼怎知输赢
 

6587

Posts

0

Resources
2
 

With the standard library, lighting is really simple.

This post is from GD32 MCU

Comments

In fact, it is mainly determined by the underlying layer. Under the ARM framework, a chip is used, which can be easily migrated to the chip with the same core of other manufacturers. ST is superior to domestic large-scale manufacturers in manuals, standard libraries (of course not only standard libraries) and chip configuration code (cubemx) automation.  Details Published on 2022-1-17 20:21
 
 
 

706

Posts

0

Resources
3
 

It's a pity that I didn't win the lottery, so I didn't have the chance to test it. I haven't played with microcontrollers for a while.

This post is from GD32 MCU
 
 
 

862

Posts

2

Resources
4
 
Jacktang posted on 2022-1-16 21:09 With the standard library, lighting is indeed very simple.

In fact, it is mainly determined by the underlying layer. Under the ARM framework, a chip is used, which can be easily migrated to the chip with the same core from other manufacturers.

In terms of manuals, standard libraries (of course not just standard libraries) and chip configuration code (cubemx) automation, domestic large manufacturers do not seem to be catching up very well. On the contrary, some small manufacturers are doing better.

This post is from GD32 MCU
 
Personal signature水不撩不知深浅 人不拼怎知输赢
 
 

7452

Posts

2

Resources
5
 

ST Family

This post is from GD32 MCU
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

58

Posts

0

Resources
6
 

If you know how to use C language and have the standard library, lighting a lamp is really simple.

This post is from GD32 MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list