0

STM32 Adventures – output clock to pin


When working with STM32 using registries only it is important that you have REFERENCE MANUAL and DATASHEET available. We will use them a lot πŸ™‚


 

In today’s post we will be outputting SYSCLK to external pin of our STM32F407 discoveryΒ board. As mentioned we dive into our RM and find part responsible for RCC configurations. From there it is easy to see which bits we need to output SYSCLK to our pin.

stm32_clockoutput_01

 

As you can see on the above reset value shows that desired SYSCLK and default no prescaler will be selected. Then in this instance let’s find out on which pin we have to enable our alternate function.

To do this we need to find it in DS.

stm32_clockoutput_02

 

Great – it is default system function! So the only thing we should do is just set this PIN as output

int main(void)
{

	RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;	// Enable clock: GPIOC

	/*
	 *  Enable SYSCLK output to PC9
	 */
	GPIOC->MODER |= GPIO_MODER_MODER9_1 ;   // AF: PC9 => MCO2
}

 

let’s see it if works by looking into our logic level analyzer

stm32_clockoutput_03

 

We will defenitely be able to use this functionality in interacting with external hardware – but thats for future posts

6

Gitlab – custom pre-receive hook

As many of you I’m also using Gitlab to manage some of my projects. What I have recently been doing – was discovering how great it is to enable pipeline within your projects.

That have enabled me to install several runners and configure different stages of deployments for my repositories. While this all sounds cool it relies on single file called .gitlab-ci.yml

This would not be a big problem if not the fact that some of repositories have other developers working on it and potentially changing that file could present a security risk for my services/servers. So to overcome this I have come up with pre-receive hook that is now sort of ACL for my file unless secret commit message is included.

Installing

In repository create folder called *custom_hooks* i.e.

/var/opt/gitlab/git-data-disk/repositories/rafpe/ci-test.git/custom_hooks

Then create file called *pre-receive* and apply permissions to it

chmod +x pre-receive
chown git.git pre-receive

AfterwardsΒ you can just select the language you are interested in programming your custom git hook – below is my Ruby attempt.

What it does it check if thr push is not by any chance unathorised change to our gitlab-ci.yml file.

You would be able to change this file if your commit message will be done with specific secret. But I leave this forΒ ppl to adapt for their needs.

Script

#!/usr/bin/env ruby

our_secret = "aaaa"

params = gets
oldref = params.split()[0]
newref = params.split()[1]
refname = params.split()[2]



changed_files = `git diff --no-commit-id --name-only #{oldref}..#{newref}`

            if changed_files.include? '.gitlab-ci.yml' then
            commit_messages = `git log --pretty=%s #{newref} | head -3`.split("\n")

             unless commit_messages.include? our_secret
              puts "================================================================= "
              puts "β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—     β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  "
              puts "β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•     β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β•β•β•β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— "
              puts "β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—       β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘        β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘ "
              puts "β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•  β–ˆβ–ˆ   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•  β–ˆβ–ˆβ•‘        β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•”β•β•β•  β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘ "
              puts "β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β• "
              puts "β•šβ•β•  β•šβ•β•β•šβ•β•β•β•β•β•β• β•šβ•β•β•β•β• β•šβ•β•β•β•β•β•β• β•šβ•β•β•β•β•β•   β•šβ•β•   β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•  "
              puts "================================================================= "
              puts ""
              puts " oldref is #{oldref}"
              puts " newref is #{newref}"
              puts " refname is #{refname}"
              puts " "
              puts " We are very very sorry but your change seems to violate our policies! "
              puts " Please check with your nearest Guru! :) ERROR_ID: 001        "
              puts "================================================================= "

              exit 1
             end

            end # if changed_files.include?
exit 0

 

I hope this will get you going and leave comments if you make some interesting changes to it πŸ™‚