Close

Code Demolition

A project log for NTP Clock Based on STM32H735 Discovery Kit

This is an SNTP clock based on the STM32H735 Discovery Kit.

dmoisandmoisan 03/30/2021 at 15:010 Comments

OK, now for code demolition!

I work at a local public-access TV facility.  I've been there since it opened, and I have overseen three major renovations of our technical spaces (and will see a fourth renovation, after the pandemic!)  We had an executive director who was very enthusiastic about the project, like an eager DIY'er.  One day, we're filling up a dumpster and this guy decides it would be fun to jump up and down in the dumpster to compact all the cardboard, wood and who knew what else.  It's great fun to clown around on the jobsite, right?

He threw his back out.  Cost him his vacation.  Damn.

I shouldn't have to worry about this. I'm working behind a keyboard!

I mentioned in a previous installment that I would be adapting one of the sample projects in the firmware/library package, specifically the HTTP server demo.  It makes a good foundation for my clock.  But I had to make some changes.  Most experienced hackers can skim over this part, but it's worth mentioning how and why I adapted the code. 

First, I removed the references to "httpserver_socket" everywhere in the project.  It's only referenced in main.c, so that's trivial.

I don't use the macro USE_LCD in my code--I always use the LCD, so I'll never need an ifdef. Since we're removing httpserver_socket.c, we have to remove httpserver_socket.h.  I'll mention lcd_trace in a moment. I removed those three lines.

 I then remove the references in StartThread.  This thread is invoked by FreeRTOS, and essentially kicks off the main function of the program.  I'll discuss this in a future installment. 

A word about lcd_trace.  It's an interesting and useful function provided by ST.  It implements a small terminal window on the LCD upon which you can write status messages, printf statements, and so forth.  It's very useful.  But we can't use this, and use the LCD for its intended purpose, so we have to remove it to go on.

We need to remove every line with UTIL_LCD_TRACE_ in it, and the wrapper function LCD_UsrTrace, which is not shown here. These are scattered across the Ethernet and DHCP functions as well.

Note the BSP_LED_Init functions.  Those are staying in the code.  We'll get to them later.

Finally, we delete httpserver_socket.c:

We've spent time deleting code.  Now, we can start to write the code that will make our clock work. Next time, we'll look at FreeRTOS, the literally beating heart of our code.

Discussions