You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -244,7 +244,9 @@ Gowin also provides a CMSIS Peripheral Access Layer System in the "CMSIS\system\
244
244
- The "gw1ns4c.h" header file which defines the register structs of the various peripherals and the memory addresses at which the peripherals can be found. Gowin suggests that the user only imports this specific header in their "main.c" file.
245
245
- The "system_gw1ns4c.c" file which is primarily used for clock configuration, it defines global system/peripheral clock variables, and functions for initializing and updating them. The SystemCoreClock variable in particular is part of CMSIS-Core and various peripherals may rely on its value for their operation so it's important that it matches the real-life clocking situation (the clock signal at the EMPU's clock pin). SystemCoreClockUpdate() simply copies the predefined __SYSTEM_CLOCK macro by default, but it can be modified to update SystemCoreClock in order to match frequency changes from the PLL (PLLVR can change output clock division dynamically to obtain a slower clock for power-saving purposes).
246
246
247
-
Finally, GMD requires a linker script that defines the size of available SRAM and flash, and the placement of various code sections. A sample linker script is provided by Gowin as "Script/flash/gmd/gw1ns4c_flash.ld".
247
+
GMD requires a linker script that defines the size of available SRAM and flash, and the placement of various code sections. A sample linker script is provided by Gowin as "Script/flash/gmd/gw1ns4c_flash.ld".
248
+
249
+
Finally, the StdPeriph_Driver folder contains libraries for the various peripherals including UART, GPIO, timers etc... To use a peripheral you should consult the comments in its driver library source file.
248
250
249
251
### **Clock and SRAM configuration**
250
252
@@ -389,15 +391,15 @@ Each C file gets a listing inside the Debug directory, for example the "main.c"
389
391
//Initializes UART0
390
392
void initializeUART()
391
393
{
392
-
UART_InitTypeDef uartInitStruct;
393
-
//Enable transmission
394
-
uartInitStruct.UART_Mode.UARTMode_Tx = ENABLE;
395
-
//Disable reception
396
-
uartInitStruct.UART_Mode.UARTMode_Rx = DISABLE;
397
-
//9600 baud rate typical of Arduinos
398
-
uartInitStruct.UART_BaudRate = 9600;
399
-
//Initialize UART0 using the struct configs
400
-
UART_Init(UART0, &uartInitStruct);
394
+
UART_InitTypeDef uartInitStruct;
395
+
//Enable transmission
396
+
uartInitStruct.UART_Mode.UARTMode_Tx = ENABLE;
397
+
//Disable reception
398
+
uartInitStruct.UART_Mode.UARTMode_Rx = DISABLE;
399
+
//9600 baud rate typical of Arduinos
400
+
uartInitStruct.UART_BaudRate = 9600;
401
+
//Initialize UART0 using the struct configs
402
+
UART_Init(UART0, &uartInitStruct);
401
403
}
402
404
403
405
void initializeTimer() {
@@ -455,6 +457,103 @@ Each C file gets a listing inside the Debug directory, for example the "main.c"
455
457
456
458
* If the retargeting doesn't work for whatever reason, try using UART_SendString(UART0, char*) instead. You can use snprintf() to format a string in advance before sending it.
457
459
### **1602 Character LCD library**
460
+
You can interface the EMPU itself with a Hitachi HD44780-based (or compatible) character LCD by using a simple library I made a while back, it works by bit-banging LCD commands through the GPIOs and functions in 4-bit data bus mode for now.
461
+
*[Download the LCD library repository](https://github.com/verilog-indeed/nano_4k_1602_lcd), extract and copy the LCD_LIBRARY folder to your GMD project's folder.
462
+
* Refresh the project explorer then go to the project's properties and head to "C/C++ Build -> Settings -> GNU ARM Cross C Compiler -> Includes", add the "LCD_LIBRARY/Includes" directory to the include paths.
463
+
* Try this LCD example: (replace contents of main.c)
464
+
```
465
+
/* Includes ------------------------------------------------------------------*/
//Reset timer just in case it was modified elsewhere
535
+
TIMER_SetValue(TIMER0, 0);
536
+
TIMER_EnableIRQ(TIMER0);
537
+
538
+
uint32_t reloadVal = CYCLES_PER_MILLISEC * ms;
539
+
//Timer interrupt will trigger when it reaches the reload value
540
+
541
+
TIMER_SetReload(TIMER0, reloadVal);
542
+
TIMER_StartTimer(TIMER0);
543
+
//Block execution until timer wastes the calculated amount of cycles
544
+
while (TIMER_GetIRQStatus(TIMER0) != SET);
545
+
546
+
TIMER_StopTimer(TIMER0);
547
+
TIMER_ClearIRQ(TIMER0);
548
+
TIMER_SetValue(TIMER0, 0);
549
+
}
550
+
```
551
+
* Connect a 16x2 LCD (16-pin module) to the board:
552
+
* Disconnect the Nano 4K. Connect power and ground of the LCD's controller and backlight, and connect the output of a potentiometer to V0 for contrast setting. You can power it on and make sure the contrast adjustment works.
553
+
* Connect pins 32, 31, 30, 29, 28 and 27 of the Nano 4K to the pins E, RS, D4, D5, D6 and D7 of the LCD respectively.
554
+
* Tie the RW pin on the LCD to ground.
555
+
* Build the project, connect the Nano 4K and flash the updated files. You should see a message on the LCD:
0 commit comments